#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
int strlen(char *);
int test_strlen(char *);
void test_one(char *s) {
  unsigned long offset;
  for (offset = 0; offset < 256; offset++) {
    int x, y;
    unsigned long i;
    y = strlen(s + offset);
    x = test_strlen(s + offset);
    if (x != y) {
      printf("strlen() returned %d, should have returned %d (%p offset %ld)\n",
             x, y, s, offset);
      for (i = offset; i < 256; i++)
        printf("%02x ", s[i]);
      printf("\n");
    }
  }
}


x86 assembly (clang, -O0):
<test_one>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
cmpq   $0x100,-0x10(%rbp)
jae    11ff <test_one+0xcf>
mov    -0x8(%rbp),%rdi
add    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
add    -0x10(%rbp),%rdi
call   1030 <test_strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
je     11e9 <test_one+0xb9>
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%r8
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x100,-0x20(%rbp)
jae    11db <test_one+0xab>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11a2 <test_one+0x72>
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11ee <test_one+0xbe>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1144 <test_one+0x14>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_one>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    $0xffffffffffffffff,%r14
lea    0xee3(%rip),%r15
xor    %r12d,%r12d
jmp    1181 <test_one+0x41>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%r12
add    $0x1,%r14
cmp    $0x100,%r12
je     11e8 <test_one+0xa8>
lea    (%rbx,%r12,1),%rbp
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %eax,%r13d
mov    %rbp,%rdi
call   1030 <test_strlen@plt>
cmp    %r13d,%eax
je     1170 <test_one+0x30>
lea    0xe5c(%rip),%rdi
mov    %eax,%esi
mov    %r13d,%edx
mov    %rbx,%rcx
mov    %r12,%r8
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14,%rbp
nopl   0x0(%rax)
movsbl 0x1(%rbx,%rbp,1),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbp
cmp    $0xff,%rbp
jb     11c0 <test_one+0x80>
mov    $0xa,%edi
call   1040 <putchar@plt>
jmp    1170 <test_one+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [63 x i8] c"strlen() returned %d, should have returned %d (%p offset %ld)\0A\00"
@.str.1 = [6 x i8] c"%02x \00"
@.str.2 = [2 x i8] c"\0A\00"
define void @test_one(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i32
%5 = alloca i32
%6 = alloca i64
store i8* %0, i8** %2
store i64 0, i64* %3
br label %7
7: ; preds = %45, %1
%8 = load i64, i64* %3
%9 = icmp ult i64 %8, 256
br i1 %9, label %10, label %48
10: ; preds = %7
%11 = load i8*, i8** %2
%12 = load i64, i64* %3
%13 = getelementptr inbounds i8, i8* %11, i64 %12
%14 = call i32 @strlen(i8* %13)
store i32 %14, i32* %5
%15 = load i8*, i8** %2
%16 = load i64, i64* %3
%17 = getelementptr inbounds i8, i8* %15, i64 %16
%18 = call i32 @test_strlen(i8* %17)
store i32 %18, i32* %4
%19 = load i32, i32* %4
%20 = load i32, i32* %5
%21 = icmp ne i32 %19, %20
br i1 %21, label %22, label %44
22: ; preds = %10
%23 = load i32, i32* %4
%24 = load i32, i32* %5
%25 = load i8*, i8** %2
%26 = load i64, i64* %3
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str, i64 0, i64 0), i32 %23, i32 %24, i8* %25, i64 %26)
%28 = load i64, i64* %3
store i64 %28, i64* %6
br label %29
29: ; preds = %39, %22
%30 = load i64, i64* %6
%31 = icmp ult i64 %30, 256
br i1 %31, label %32, label %42
32: ; preds = %29
%33 = load i8*, i8** %2
%34 = load i64, i64* %6
%35 = getelementptr inbounds i8, i8* %33, i64 %34
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %37)
br label %39
39: ; preds = %32
%40 = load i64, i64* %6
%41 = add i64 %40, 1
store i64 %41, i64* %6
br label %29
42: ; preds = %29
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %44
44: ; preds = %42, %10
br label %45
45: ; preds = %44
%46 = load i64, i64* %3
%47 = add i64 %46, 1
store i64 %47, i64* %3
br label %7
48: ; preds = %7
ret void
}

LLVM IR (-O2):
@.str = [63 x i8] c"strlen() returned %d, should have returned %d (%p offset %ld)\0A\00"
@.str.1 = [6 x i8] c"%02x \00"
define void @test_one(i8* %0) {
br label %2
2: ; preds = %1, %20
%3 = phi i64 [ 0, %1 ], [ %21, %20 ]
%4 = getelementptr inbounds i8, i8* %0, i64 %3
%5 = tail call i32 @strlen(i8* %4)
%6 = tail call i32 @test_strlen(i8* %4)
%7 = icmp eq i32 %6, %5
br i1 %7, label %20, label %8
8: ; preds = %2
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([63 x i8], [63 x i8]* @.str, i64 0, i64 0), i32 %6, i32 %5, i8* %0, i64 %3)
br label %10
10: ; preds = %8, %10
%11 = phi i64 [ %16, %10 ], [ %3, %8 ]
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = add nuw nsw i64 %11, 1
%17 = icmp ult i64 %11, 255
br i1 %17, label %10, label %18
18: ; preds = %10
%19 = tail call i32 @putchar(i32 10)
br label %20
20: ; preds = %18, %2
%21 = add nuw nsw i64 %3, 1
%22 = icmp eq i64 %21, 256
br i1 %22, label %23, label %2
23: ; preds = %20
ret void
}