Gcc seems to be generating a 4-byte wide strlen scanner during -O3 which is tripping up valgrind. I'm not sure if this should be considered a gcc bug or a valgrind bug:
-O1: 4005a2: b8 00 00 00 00 mov $0x0,%eax 4005a7: 48 c7 c1 ff ff ff ff mov $0xffffffffffffffff,%rcx 4005ae: f2 ae repnz scas %es:(%rdi),%al 4005b0: 48 f7 d1 not %rcx
-O3: 4004b8: 48 89 c6 mov %rax,%rsi 4004bb: 8b 0e mov (%rsi),%ecx 4004bd: 48 83 c6 04 add $0x4,%rsi 4004c1: 8d 91 ff fe fe fe lea -0x1010101(%rcx),%edx 4004c7: f7 d1 not %ecx 4004c9: 21 ca and %ecx,%edx 4004cb: 81 e2 80 80 80 80 and $0x80808080,%edx 4004d1: 74 e8 je 4004bb <main+0x1b> 4004d3: 89 d1 mov %edx,%ecx 4004d5: 48 89 c7 mov %rax,%rdi 4004d8: c1 e9 10 shr $0x10,%ecx 4004db: f7 c2 80 80 00 00 test $0x8080,%edx 4004e1: 0f 44 d1 cmove %ecx,%edx 4004e4: 48 8d 4e 02 lea 0x2(%rsi),%rcx 4004e8: 48 0f 44 f1 cmove %rcx,%rsi 4004ec: 00 d2 add %dl,%dl 4004ee: 48 83 de 03 sbb $0x3,%rsi 4004f2: 48 29 c6 sub %rax,%rsi
Gcc seems to be generating a 4-byte wide strlen scanner during -O3 which is tripping up valgrind. I'm not sure if this should be considered a gcc bug or a valgrind bug:
-O1: ffff,%rcx
4005a2: b8 00 00 00 00 mov $0x0,%eax
4005a7: 48 c7 c1 ff ff ff ff mov $0xffffffffffff
4005ae: f2 ae repnz scas %es:(%rdi),%al
4005b0: 48 f7 d1 not %rcx
-O3: %rcx),% edx
4004b8: 48 89 c6 mov %rax,%rsi
4004bb: 8b 0e mov (%rsi),%ecx
4004bd: 48 83 c6 04 add $0x4,%rsi
4004c1: 8d 91 ff fe fe fe lea -0x1010101(
4004c7: f7 d1 not %ecx
4004c9: 21 ca and %ecx,%edx
4004cb: 81 e2 80 80 80 80 and $0x80808080,%edx
4004d1: 74 e8 je 4004bb <main+0x1b>
4004d3: 89 d1 mov %edx,%ecx
4004d5: 48 89 c7 mov %rax,%rdi
4004d8: c1 e9 10 shr $0x10,%ecx
4004db: f7 c2 80 80 00 00 test $0x8080,%edx
4004e1: 0f 44 d1 cmove %ecx,%edx
4004e4: 48 8d 4e 02 lea 0x2(%rsi),%rcx
4004e8: 48 0f 44 f1 cmove %rcx,%rsi
4004ec: 00 d2 add %dl,%dl
4004ee: 48 83 de 03 sbb $0x3,%rsi
4004f2: 48 29 c6 sub %rax,%rsi