#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 EOF;
int getchar();
int /*<<< orphan*/ printf(char *, int, ...);
int main() {
  int j, k;
  int c = getchar();
  for (j = 0, c = 0; (c != EOF); j++) {
    if (j % (1024 * 1024) == 0)
      printf("Received %0d MB\n", j / (1024 * 1024));
    if (((unsigned char)c) != ((unsigned char)j)) {
      printf("Diff byte 0x%08x  got 0x%02x\n", j, c);
      c = getchar();
      for (k = 0; (k < 16) && (c != EOF); k++) {
        printf("0x%08x  got 0x%02x\n", j, c);
        j++;
        c = getchar();
      }
      c = EOF;
    } else
      c = getchar();
  }
  printf("Checked %d MB = %d = 0x%08x\n", j / (1024 * 1024), j, j);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x10(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    0x2e97(%rip),%rcx
cmp    (%rcx),%eax
je     1255 <main+0x135>
mov    -0x8(%rbp),%eax
mov    $0x100000,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1188 <main+0x68>
mov    -0x8(%rbp),%eax
mov    $0x100000,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
movzbl %al,%eax
mov    -0x8(%rbp),%ecx
movzbl %cl,%ecx
cmp    %ecx,%eax
je     1238 <main+0x118>
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xe68(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
xor    %eax,%eax
cmpl   $0x10,-0xc(%rbp)
mov    %al,-0x11(%rbp)
jge    11e2 <main+0xc2>
mov    -0x10(%rbp),%eax
mov    0x2e0e(%rip),%rcx
cmp    (%rcx),%eax
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    11f2 <main+0xd2>
jmp    1227 <main+0x107>
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xe1c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11c1 <main+0xa1>
mov    0x2dba(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
jmp    1242 <main+0x122>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x10(%rbp)
jmp    1247 <main+0x127>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1147 <main+0x27>
mov    -0x8(%rbp),%eax
mov    $0x100000,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
mov    -0x8(%rbp),%edx
mov    -0x8(%rbp),%ecx
lea    0xdc0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <getchar@plt>
mov    0x2eb1(%rip),%r15
cmpl   $0x0,(%r15)
je     11da <main+0xba>
lea    0xeb8(%rip),%r14
xor    %ebp,%ebp
xor    %ebx,%ebx
nopl   0x0(%rax)
test   $0xfffff,%ebx
jne    1167 <main+0x47>
mov    %ebx,%esi
shr    $0x14,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebp,%eax
xor    %bl,%al
jne    1180 <main+0x60>
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %eax,%ebp
add    $0x1,%ebx
cmp    (%r15),%eax
jne    1150 <main+0x30>
jmp    11da <main+0xba>
lea    0xe8a(%rip),%rdi
mov    %ebx,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    (%r15),%eax
je     11d7 <main+0xb7>
lea    0xe76(%rip),%r14
xor    %ecx,%ecx
nopw   0x0(%rax,%rax,1)
mov    %ecx,%ebp
lea    (%rbx,%rbp,1),%esi
mov    %r14,%rdi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
call   1040 <getchar@plt>
lea    0x1(%rbp),%ecx
cmp    $0xe,%ebp
ja     11d5 <main+0xb5>
cmp    (%r15),%eax
jne    11b0 <main+0x90>
add    %ecx,%ebx
add    $0x1,%ebx
lea    0xfffff(%rbx),%esi
test   %ebx,%ebx
cmovns %ebx,%esi
sar    $0x14,%esi
lea    0xe40(%rip),%rdi
mov    %ebx,%edx
mov    %ebx,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i32 0
@.str = [17 x i8] c"Received %0d MB\0A\00"
@.str.1 = [30 x i8] c"Diff byte 0x%08x got 0x%02x\0A\00"
@.str.2 = [20 x i8] c"0x%08x got 0x%02x\0A\00"
@.str.3 = [29 x i8] c"Checked %d MB = %d = 0x%08x\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 (...) @getchar()
store i32 %5, i32* %4
store i32 0, i32* %2
store i32 0, i32* %4
br label %6
6: ; preds = %55, %0
%7 = load i32, i32* %4
%8 = load i32, i32* @EOF
%9 = icmp ne i32 %7, %8
br i1 %9, label %10, label %58
10: ; preds = %6
%11 = load i32, i32* %2
%12 = srem i32 %11, 1048576
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %10
%15 = load i32, i32* %2
%16 = sdiv i32 %15, 1048576
%17 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %16)
br label %18
18: ; preds = %14, %10
%19 = load i32, i32* %4
%20 = trunc i32 %19 to i8
%21 = zext i8 %20 to i32
%22 = load i32, i32* %2
%23 = trunc i32 %22 to i8
%24 = zext i8 %23 to i32
%25 = icmp ne i32 %21, %24
br i1 %25, label %26, label %52
26: ; preds = %18
%27 = load i32, i32* %2
%28 = load i32, i32* %4
%29 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %27, i32 %28)
%30 = call i32 (...) @getchar()
store i32 %30, i32* %4
store i32 0, i32* %3
br label %31
31: ; preds = %47, %26
%32 = load i32, i32* %3
%33 = icmp slt i32 %32, 16
br i1 %33, label %34, label %38
34: ; preds = %31
%35 = load i32, i32* %4
%36 = load i32, i32* @EOF
%37 = icmp ne i32 %35, %36
br label %38
38: ; preds = %34, %31
%39 = phi i1 [ false, %31 ], [ %37, %34 ]
br i1 %39, label %40, label %50
40: ; preds = %38
%41 = load i32, i32* %2
%42 = load i32, i32* %4
%43 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %41, i32 %42)
%44 = load i32, i32* %2
%45 = add nsw i32 %44, 1
store i32 %45, i32* %2
%46 = call i32 (...) @getchar()
store i32 %46, i32* %4
br label %47
47: ; preds = %40
%48 = load i32, i32* %3
%49 = add nsw i32 %48, 1
store i32 %49, i32* %3
br label %31
50: ; preds = %38
%51 = load i32, i32* @EOF
store i32 %51, i32* %4
br label %54
52: ; preds = %18
%53 = call i32 (...) @getchar()
store i32 %53, i32* %4
br label %54
54: ; preds = %52, %50
br label %55
55: ; preds = %54
%56 = load i32, i32* %2
%57 = add nsw i32 %56, 1
store i32 %57, i32* %2
br label %6
58: ; preds = %6
%59 = load i32, i32* %2
%60 = sdiv i32 %59, 1048576
%61 = load i32, i32* %2
%62 = load i32, i32* %2
%63 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i32 %60, i32 %61, i32 %62)
ret i32 0
}

LLVM IR (-O2):
@EOF = global i32 0
@.str = [17 x i8] c"Received %0d MB\0A\00"
@.str.1 = [30 x i8] c"Diff byte 0x%08x got 0x%02x\0A\00"
@.str.2 = [20 x i8] c"0x%08x got 0x%02x\0A\00"
@.str.3 = [29 x i8] c"Checked %d MB = %d = 0x%08x\0A\00"
define i32 @main() {
%1 = tail call i32 (...) @getchar()
%2 = load i32, i32* @EOF
%3 = icmp eq i32 %2, 0
br i1 %3, label %41, label %4
4: ; preds = %0, %36
%5 = phi i32 [ %37, %36 ], [ 0, %0 ]
%6 = phi i32 [ %39, %36 ], [ 0, %0 ]
%7 = and i32 %6, 1048575
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %4
%10 = lshr i32 %6, 20
%11 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %10)
br label %12
12: ; preds = %9, %4
%13 = xor i32 %5, %6
%14 = and i32 %13, 255
%15 = icmp eq i32 %14, 0
br i1 %15, label %36, label %16
16: ; preds = %12
%17 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %6, i32 %5)
%18 = tail call i32 (...) @getchar()
%19 = load i32, i32* @EOF
%20 = icmp eq i32 %18, %19
br i1 %20, label %33, label %21
21: ; preds = %16, %21
%22 = phi i32 [ %27, %21 ], [ %18, %16 ]
%23 = phi i32 [ %28, %21 ], [ 0, %16 ]
%24 = phi i32 [ %26, %21 ], [ %6, %16 ]
%25 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %24, i32 %22)
%26 = add nuw nsw i32 %24, 1
%27 = tail call i32 (...) @getchar()
%28 = add nuw nsw i32 %23, 1
%29 = icmp ult i32 %23, 15
%30 = load i32, i32* @EOF
%31 = icmp ne i32 %27, %30
%32 = select i1 %29, i1 %31, i1 false
br i1 %32, label %21, label %33
33: ; preds = %21, %16
%34 = phi i32 [ %6, %16 ], [ %26, %21 ]
%35 = add nsw i32 %34, 1
br label %41
36: ; preds = %12
%37 = tail call i32 (...) @getchar()
%38 = load i32, i32* @EOF
%39 = add nuw nsw i32 %6, 1
%40 = icmp eq i32 %37, %38
br i1 %40, label %41, label %4
41: ; preds = %36, %33, %0
%42 = phi i32 [ 0, %0 ], [ %35, %33 ], [ %39, %36 ]
%43 = sdiv i32 %42, 1048576
%44 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i32 %43, i32 %42, i32 %42)
ret i32 0
}