#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*/ check_bytes(char *);
int /*<<< orphan*/ printf(char *, unsigned long);
int read_bytes(char *addr, size_t length) {
  unsigned long i;
  check_bytes(addr);
  for (i = 0; i < length; i++)
    if (*(addr + i) != (char)i) {
      printf("Mismatch at %lu\n", i);
      return 1;
    }
  return 0;
}


x86 assembly (clang, -O0):
<read_bytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <check_bytes@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    119c <read_bytes+0x7c>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    -0x20(%rbp),%rcx
movsbl %cl,%ecx
cmp    %ecx,%eax
je     1186 <read_bytes+0x66>
mov    -0x20(%rbp),%rsi
lea    0xe8b(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11a3 <read_bytes+0x83>
jmp    118b <read_bytes+0x6b>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1141 <read_bytes+0x21>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_bytes>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <check_bytes@plt>
test   %r14,%r14
je     115b <read_bytes+0x3b>
xor    %eax,%eax
xor    %esi,%esi
nopl   0x0(%rax,%rax,1)
movsbl (%rbx,%rsi,1),%ecx
mov    %eax,%edx
sar    $0x18,%edx
cmp    %ecx,%edx
jne    115f <read_bytes+0x3f>
add    $0x1,%rsi
add    $0x1000000,%eax
cmp    %rsi,%r14
jne    1140 <read_bytes+0x20>
xor    %eax,%eax
jmp    1170 <read_bytes+0x50>
lea    0xe9a(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [17 x i8] c"Mismatch at %lu\0A\00"
define i32 @read_bytes(i8* %0, i64 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
store i8* %0, i8** %4
store i64 %1, i64* %5
%7 = load i8*, i8** %4
%8 = call i32 @check_bytes(i8* %7)
store i64 0, i64* %6
br label %9
9: ; preds = %27, %2
%10 = load i64, i64* %6
%11 = load i64, i64* %5
%12 = icmp ult i64 %10, %11
br i1 %12, label %13, label %30
13: ; preds = %9
%14 = load i8*, i8** %4
%15 = load i64, i64* %6
%16 = getelementptr inbounds i8, i8* %14, i64 %15
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = load i64, i64* %6
%20 = trunc i64 %19 to i8
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %18, %21
br i1 %22, label %23, label %26
23: ; preds = %13
%24 = load i64, i64* %6
%25 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i64 %24)
store i32 1, i32* %3
br label %31
26: ; preds = %13
br label %27
27: ; preds = %26
%28 = load i64, i64* %6
%29 = add i64 %28, 1
store i64 %29, i64* %6
br label %9
30: ; preds = %9
store i32 0, i32* %3
br label %31
31: ; preds = %30, %23
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
@.str = [17 x i8] c"Mismatch at %lu\0A\00"
define i32 @read_bytes(i8* %0, i64 %1) {
%3 = tail call i32 @check_bytes(i8* %0)
%4 = icmp eq i64 %1, 0
br i1 %4, label %19, label %5
5: ; preds = %2, %16
%6 = phi i64 [ %17, %16 ], [ 0, %2 ]
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = trunc i64 %6 to i32
%11 = shl i32 %10, 24
%12 = ashr exact i32 %11, 24
%13 = icmp eq i32 %12, %9
br i1 %13, label %16, label %14
14: ; preds = %5
%15 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i64 %6)
br label %19
16: ; preds = %5
%17 = add nuw i64 %6, 1
%18 = icmp eq i64 %17, %1
br i1 %18, label %19, label %5
19: ; preds = %16, %2, %14
%20 = phi i32 [ 1, %14 ], [ 0, %2 ], [ 0, %16 ]
ret i32 %20
}