#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 */
struct cksum_table {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
struct cksum_table *cksum_stream(char *, size_t *);
int compare_checksums(struct cksum_table *, size_t, char *,
                      struct cksum_table *, size_t, char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ free(struct cksum_table *);
struct cksum_table *read_table(char *, size_t *);
int main(int argc, char *argv[]) {
  char *fname = "example.grb", *table_fname = "example.cksum";
  if (argc > 1)
    fname = argv[1];
  if (argc > 2)
    table_fname = argv[2];
  size_t nvars;
  struct cksum_table *file_vars = cksum_stream(fname, &nvars);
  if (!file_vars)
    exit(EXIT_FAILURE);
  int retcode;
  {
    size_t num_ref_entries;
    struct cksum_table *ref_var_table =
        read_table(table_fname, &num_ref_entries);
    if (num_ref_entries == (size_t)-1)
      exit(EXIT_FAILURE);
    retcode = compare_checksums(file_vars, nvars, "file", ref_var_table,
                                num_ref_entries, "reference table");
    free(ref_var_table);
  }
  return retcode;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe93(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xe94(%rip),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    1192 <main+0x42>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    11a8 <main+0x58>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1050 <cksum_stream@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11d2 <main+0x82>
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x20(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1060 <read_table@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0xffffffffffffffff,-0x40(%rbp)
jne    11fc <main+0xac>
mov    0x2deb(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x48(%rbp),%rcx
mov    -0x40(%rbp),%r8
lea    0xe07(%rip),%rdx
lea    0xe05(%rip),%r9
call   1040 <compare_checksums@plt>
mov    %eax,-0x34(%rbp)
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
mov    -0x34(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0xeab(%rip),%r14
cmp    $0x2,%edi
jl     1172 <main+0x22>
mov    0x8(%rsi),%rdi
je     1179 <main+0x29>
mov    0x10(%rsi),%r14
jmp    1179 <main+0x29>
lea    0xe87(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1050 <cksum_stream@plt>
test   %rax,%rax
je     11db <main+0x8b>
mov    %rax,%r15
lea    0x8(%rsp),%rsi
mov    %r14,%rdi
call   1060 <read_table@plt>
mov    0x8(%rsp),%r8
cmp    $0xffffffffffffffff,%r8
je     11db <main+0x8b>
mov    %rax,%rbx
mov    0x10(%rsp),%rsi
lea    0xe68(%rip),%rdx
lea    0xe66(%rip),%r9
mov    %r15,%rdi
mov    %rax,%rcx
call   1040 <compare_checksums@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.cksum_table = type { i32 }
@.str = [12 x i8] c"example.grb\00"
@.str.1 = [14 x i8] c"example.cksum\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [5 x i8] c"file\00"
@.str.3 = [16 x i8] c"reference table\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca %struct.cksum_table*
%10 = alloca i32
%11 = alloca i64
%12 = alloca %struct.cksum_table*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8** %6
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8** %7
%13 = load i32, i32* %4
%14 = icmp sgt i32 %13, 1
br i1 %14, label %15, label %19
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
store i8* %18, i8** %6
br label %19
19: ; preds = %15, %2
%20 = load i32, i32* %4
%21 = icmp sgt i32 %20, 2
br i1 %21, label %22, label %26
22: ; preds = %19
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 2
%25 = load i8*, i8** %24
store i8* %25, i8** %7
br label %26
26: ; preds = %22, %19
%27 = load i8*, i8** %6
%28 = call %struct.cksum_table* @cksum_stream(i8* %27, i64* %8)
store %struct.cksum_table* %28, %struct.cksum_table** %9
%29 = load %struct.cksum_table*, %struct.cksum_table** %9
%30 = icmp ne %struct.cksum_table* %29, null
br i1 %30, label %34, label %31
31: ; preds = %26
%32 = load i32, i32* @EXIT_FAILURE
%33 = call i32 @exit(i32 %32)
unreachable
34: ; preds = %26
%35 = load i8*, i8** %7
%36 = call %struct.cksum_table* @read_table(i8* %35, i64* %11)
store %struct.cksum_table* %36, %struct.cksum_table** %12
%37 = load i64, i64* %11
%38 = icmp eq i64 %37, -1
br i1 %38, label %39, label %42
39: ; preds = %34
%40 = load i32, i32* @EXIT_FAILURE
%41 = call i32 @exit(i32 %40)
unreachable
42: ; preds = %34
%43 = load %struct.cksum_table*, %struct.cksum_table** %9
%44 = load i64, i64* %8
%45 = load %struct.cksum_table*, %struct.cksum_table** %12
%46 = load i64, i64* %11
%47 = call i32 @compare_checksums(%struct.cksum_table* %43, i64 %44, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), %struct.cksum_table* %45, i64 %46, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
store i32 %47, i32* %10
%48 = load %struct.cksum_table*, %struct.cksum_table** %12
%49 = call i32 @free(%struct.cksum_table* %48)
%50 = load i32, i32* %10
ret i32 %50
}

LLVM IR (-O2):
%struct.cksum_table = type { i32 }
@.str = [12 x i8] c"example.grb\00"
@.str.1 = [14 x i8] c"example.cksum\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [5 x i8] c"file\00"
@.str.3 = [16 x i8] c"reference table\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i64
%4 = alloca i64
%5 = icmp sgt i32 %0, 1
br i1 %5, label %6, label %13
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = icmp eq i32 %0, 2
br i1 %9, label %13, label %10
10: ; preds = %6
%11 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = load i8*, i8** %11
br label %13
13: ; preds = %2, %10, %6
%14 = phi i8* [ %8, %10 ], [ %8, %6 ], [ getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), %2 ]
%15 = phi i8* [ %12, %10 ], [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), %6 ], [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), %2 ]
%16 = bitcast i64* %3 to i8*
%17 = call %struct.cksum_table* @cksum_stream(i8* %14, i64* %3)
%18 = icmp eq %struct.cksum_table* %17, null
br i1 %18, label %19, label %22
19: ; preds = %13
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %13
%23 = bitcast i64* %4 to i8*
%24 = call %struct.cksum_table* @read_table(i8* %15, i64* %4)
%25 = load i64, i64* %4
%26 = icmp eq i64 %25, -1
br i1 %26, label %27, label %30
27: ; preds = %22
%28 = load i32, i32* @EXIT_FAILURE
%29 = call i32 @exit(i32 %28)
unreachable
30: ; preds = %22
%31 = load i64, i64* %3
%32 = call i32 @compare_checksums(%struct.cksum_table* %17, i64 %31, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), %struct.cksum_table* %24, i64 %25, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%33 = call i32 @free(%struct.cksum_table* %24)
ret i32 %32
}