#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 INT_MAX;
int ReadVarint();
int /*<<< orphan*/ Reset();
int /*<<< orphan*/ WriteVarint(int);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  {
    int a = INT_MAX / 2;
    printf("checking %i\n", a);
    WriteVarint(a);
    int b = ReadVarint();
    if (a != b) {
      printf("Uh oh... %i != %i\n", a, b);
      return 1;
    }
    Reset();
  }
  printf("success\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e92(%rip),%rax
mov    (%rax),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
call   1030 <WriteVarint@plt>
mov    $0x0,%al
call   1060 <ReadVarint@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
je     11b2 <main+0x72>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11ce <main+0x8e>
mov    $0x0,%al
call   1050 <Reset@plt>
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    0x2e8e(%rip),%rax
mov    (%rax),%eax
mov    %eax,%ebp
shr    $0x1f,%ebp
add    %eax,%ebp
sar    %ebp
lea    0xe94(%rip),%rdi
xor    %ebx,%ebx
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,%edi
call   1040 <WriteVarint@plt>
xor    %eax,%eax
call   1070 <ReadVarint@plt>
cmp    %eax,%ebp
jne    119e <main+0x4e>
xor    %eax,%eax
call   1060 <Reset@plt>
lea    0xe89(%rip),%rdi
call   1030 <puts@plt>
jmp    11b5 <main+0x65>
lea    0xe68(%rip),%rdi
mov    %ebp,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@INT_MAX = global i32 0
@.str = [13 x i8] c"checking %i\0A\00"
@.str.1 = [19 x i8] c"Uh oh... %i != %i\0A\00"
@.str.2 = [9 x i8] c"success\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = load i32, i32* @INT_MAX
%5 = sdiv i32 %4, 2
store i32 %5, i32* %2
%6 = load i32, i32* %2
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = load i32, i32* %2
%9 = call i32 @WriteVarint(i32 %8)
%10 = call i32 (...) @ReadVarint()
store i32 %10, i32* %3
%11 = load i32, i32* %2
%12 = load i32, i32* %3
%13 = icmp ne i32 %11, %12
br i1 %13, label %14, label %18
14: ; preds = %0
%15 = load i32, i32* %2
%16 = load i32, i32* %3
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %15, i32 %16)
store i32 1, i32* %1
br label %21
18: ; preds = %0
%19 = call i32 (...) @Reset()
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %1
br label %21
21: ; preds = %18, %14
%22 = load i32, i32* %1
ret i32 %22
}

LLVM IR (-O2):
@INT_MAX = global i32 0
@.str = [13 x i8] c"checking %i\0A\00"
@.str.1 = [19 x i8] c"Uh oh... %i != %i\0A\00"
@str = [8 x i8] c"success\00"
define i32 @main() {
%1 = load i32, i32* @INT_MAX
%2 = sdiv i32 %1, 2
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = tail call i32 @WriteVarint(i32 %2)
%5 = tail call i32 (...) @ReadVarint()
%6 = icmp eq i32 %2, %5
br i1 %6, label %9, label %7
7: ; preds = %0
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %2, i32 %5)
br label %12
9: ; preds = %0
%10 = tail call i32 (...) @Reset()
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0))
br label %12
12: ; preds = %7, %9
%13 = phi i32 [ 1, %7 ], [ 0, %9 ]
ret i32 %13
}