#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) {
  unsigned long i;
  check_bytes(addr);
  for (i = 0; i < (256UL * 1024 * 1024); 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    -0x10(%rbp),%rdi
call   1040 <check_bytes@plt>
movq   $0x0,-0x18(%rbp)
cmpq   $0x10000000,-0x18(%rbp)
10
jae    1198 <read_bytes+0x78>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    -0x18(%rbp),%rcx
movsbl %cl,%ecx
cmp    %ecx,%eax
je     1182 <read_bytes+0x62>
mov    -0x18(%rbp),%rsi
lea    0xe8f(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    119f <read_bytes+0x7f>
jmp    1187 <read_bytes+0x67>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    113d <read_bytes+0x1d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_bytes>:
push   %rbx
mov    %rdi,%rbx
call   1040 <check_bytes@plt>
mov    $0x3,%esi
mov    $0x2000000,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl -0x3(%rbx,%rsi,1),%ecx
lea    -0x2000000(%rax),%edx
sar    $0x18,%edx
cmp    %ecx,%edx
jne    1199 <read_bytes+0x79>
movsbl -0x2(%rbx,%rsi,1),%ecx
lea    -0x1000000(%rax),%edx
sar    $0x18,%edx
cmp    %ecx,%edx
jne    119f <read_bytes+0x7f>
movsbl -0x1(%rbx,%rsi,1),%ecx
mov    %eax,%edx
sar    $0x18,%edx
cmp    %ecx,%edx
jne    11a5 <read_bytes+0x85>
movsbl (%rbx,%rsi,1),%ecx
lea    0x1000000(%rax),%edx
sar    $0x18,%edx
cmp    %ecx,%edx
jne    11a9 <read_bytes+0x89>
add    $0x4,%rsi
add    $0x4000000,%eax
cmp    $0x10000003,%rsi
jne    1140 <read_bytes+0x20>
xor    %eax,%eax
pop    %rbx
ret
add    $0xfffffffffffffffd,%rsi
jmp    11a9 <read_bytes+0x89>
add    $0xfffffffffffffffe,%rsi
jmp    11a9 <read_bytes+0x89>
add    $0xffffffffffffffff,%rsi
lea    0xe50(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [17 x i8] c"Mismatch at %lu\0A\00"
define i32 @read_bytes(i8* %0) {
%2 = tail call i32 @check_bytes(i8* %0)
br label %3
3: ; preds = %42, %1
%4 = phi i64 [ 0, %1 ], [ %43, %42 ]
%5 = getelementptr inbounds i8, i8* %0, i64 %4
%6 = load i8, i8* %5
%7 = sext i8 %6 to i32
%8 = trunc i64 %4 to i32
%9 = shl i32 %8, 24
%10 = ashr exact i32 %9, 24
%11 = icmp eq i32 %10, %7
br i1 %11, label %15, label %12
12: ; preds = %33, %24, %15, %3
%13 = phi i64 [ %4, %3 ], [ %16, %15 ], [ %25, %24 ], [ %34, %33 ]
%14 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i64 %13)
br label %45
15: ; preds = %3
%16 = or i64 %4, 1
%17 = getelementptr inbounds i8, i8* %0, i64 %16
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = trunc i64 %16 to i32
%21 = shl i32 %20, 24
%22 = ashr exact i32 %21, 24
%23 = icmp eq i32 %22, %19
br i1 %23, label %24, label %12
24: ; preds = %15
%25 = or i64 %4, 2
%26 = getelementptr inbounds i8, i8* %0, i64 %25
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = trunc i64 %25 to i32
%30 = shl i32 %29, 24
%31 = ashr exact i32 %30, 24
%32 = icmp eq i32 %31, %28
br i1 %32, label %33, label %12
33: ; preds = %24
%34 = or i64 %4, 3
%35 = getelementptr inbounds i8, i8* %0, i64 %34
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = trunc i64 %34 to i32
%39 = shl i32 %38, 24
%40 = ashr exact i32 %39, 24
%41 = icmp eq i32 %40, %37
br i1 %41, label %42, label %12
42: ; preds = %33
%43 = add nuw nsw i64 %4, 4
%44 = icmp eq i64 %43, 268435456
br i1 %44, label %45, label %3
45: ; preds = %42, %12
%46 = phi i32 [ 1, %12 ], [ 0, %42 ]
ret i32 %46
}