#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);
void read_bytes(char *addr) {
  unsigned long i;
  check_bytes(addr);
  for (i = 0; i < (128UL * 1024 * 1024); i++)
    if (*(addr + i) != (char)i) {
      printf("Mismatch at %lu\n", i);
      break;
    }
}


x86 assembly (clang, -O0):
<read_bytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <check_bytes@plt>
movq   $0x0,-0x10(%rbp)
cmpq   $0x8000000,-0x10(%rbp)
08
jae    1191 <read_bytes+0x71>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    -0x10(%rbp),%rcx
movsbl %cl,%ecx
cmp    %ecx,%eax
je     117b <read_bytes+0x5b>
mov    -0x10(%rbp),%rsi
lea    0xe8f(%rip),%rdi
call   1030 <printf@plt>
jmp    1191 <read_bytes+0x71>
jmp    1180 <read_bytes+0x60>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    113d <read_bytes+0x1d>
add    $0x10,%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    1197 <read_bytes+0x77>
movsbl -0x2(%rbx,%rsi,1),%ecx
lea    -0x1000000(%rax),%edx
sar    $0x18,%edx
cmp    %ecx,%edx
jne    119d <read_bytes+0x7d>
movsbl -0x1(%rbx,%rsi,1),%ecx
mov    %eax,%edx
sar    $0x18,%edx
cmp    %ecx,%edx
jne    11a3 <read_bytes+0x83>
movsbl (%rbx,%rsi,1),%ecx
lea    0x1000000(%rax),%edx
sar    $0x18,%edx
cmp    %ecx,%edx
jne    11a7 <read_bytes+0x87>
add    $0x4,%rsi
add    $0x4000000,%eax
cmp    $0x8000003,%rsi
jne    1140 <read_bytes+0x20>
pop    %rbx
ret
add    $0xfffffffffffffffd,%rsi
jmp    11a7 <read_bytes+0x87>
add    $0xfffffffffffffffe,%rsi
jmp    11a7 <read_bytes+0x87>
add    $0xffffffffffffffff,%rsi
lea    0xe52(%rip),%rdi
pop    %rbx
jmp    1030 <printf@plt>

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

LLVM IR (-O2):
@.str = [17 x i8] c"Mismatch at %lu\0A\00"
define void @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, 134217728
br i1 %44, label %45, label %3
45: ; preds = %42, %12
ret void
}