#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*/ O_RDONLY;
int /*<<< orphan*/ close(int /*<<< orphan*/);
unsigned int crc32_partial(char *, int, unsigned int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int open(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, unsigned int);
int read(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ stderr;
int main(int argc, const char *argv[]) {
  if (argc == 2) {
    close(0);
    int fd = open(argv[1], O_RDONLY);
    if (fd) {
      fprintf(stderr, "cannot read file %s: %m\n", argv[1]);
      return 1;
    }
  } else if (argc > 2) {
    return 2;
  }
  unsigned crc32_complement = -1;
  static char RBuff[(1 << 24)];
  int r;
  do {
    r = read(0, RBuff, (1 << 24));
    if (r < 0) {
      fprintf(stderr, "error reading input: %m\n");
      return 1;
    }
    crc32_complement = crc32_partial(RBuff, r, crc32_complement);
  } while (r);
  printf("%08x\n", ~crc32_complement);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    11da <main+0x7a>
xor    %edi,%edi
call   1040 <close@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e52(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11d5 <main+0x75>
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe3e(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1277 <main+0x117>
jmp    11f5 <main+0x95>
cmpl   $0x2,-0x8(%rbp)
jle    11f0 <main+0x90>
movl   $0x2,-0x4(%rbp)
jmp    1277 <main+0x117>
jmp    11f5 <main+0x95>
movl   $0xffffffff,-0x18(%rbp)
xor    %edi,%edi
lea    0x2e6b(%rip),%rsi
mov    $0x1000000,%edx
call   1050 <read@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    123f <main+0xdf>
mov    0x2db5(%rip),%rax
mov    (%rax),%edi
lea    0xded(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1277 <main+0x117>
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0x2e24(%rip),%rdi
call   1080 <crc32_partial@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    11fc <main+0x9c>
mov    -0x18(%rbp),%esi
xor    $0xffffffff,%esi
lea    0xdc7(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
cmp    $0x2,%edi
jne    11a6 <main+0x46>
mov    %rsi,%rbx
xor    %edi,%edi
call   1040 <close@plt>
mov    0x8(%rbx),%rdi
mov    0x2e6a(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
test   %eax,%eax
je     11ad <main+0x4d>
mov    0x2e48(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rdx
lea    0xe63(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    1212 <main+0xb2>
mov    $0x2,%eax
jg     1217 <main+0xb7>
mov    $0xffffffff,%ebx
lea    0x2eb7(%rip),%r14
nopl   0x0(%rax)
xor    %edi,%edi
mov    %r14,%rsi
mov    $0x1000000,%edx
call   1050 <read@plt>
test   %eax,%eax
js     11fb <main+0x9b>
mov    %eax,%ebp
mov    %r14,%rdi
mov    %eax,%esi
mov    %ebx,%edx
call   1080 <crc32_partial@plt>
mov    %eax,%ebx
test   %ebp,%ebp
jne    11c0 <main+0x60>
not    %ebx
lea    0xe42(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
xor    %eax,%eax
jmp    1217 <main+0xb7>
mov    0x2dd6(%rip),%rax
mov    (%rax),%edi
lea    0xe0e(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str = [25 x i8] c"cannot read file %s: %m\0A\00"
@main.RBuff = internal global [16777216 x i8] zeroinitializer
@.str.1 = [25 x i8] c"error reading input: %m\0A\00"
@.str.2 = [6 x i8] c"%08x\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp eq i32 %9, 2
br i1 %10, label %11, label %27
11: ; preds = %2
%12 = call i32 @close(i32 0)
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = load i32, i32* @O_RDONLY
%17 = call i32 @open(i8* %15, i32 %16)
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %26
20: ; preds = %11
%21 = load i32, i32* @stderr
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %24)
store i32 1, i32* %3
br label %51
26: ; preds = %11
br label %32
27: ; preds = %2
%28 = load i32, i32* %4
%29 = icmp sgt i32 %28, 2
br i1 %29, label %30, label %31
30: ; preds = %27
store i32 2, i32* %3
br label %51
31: ; preds = %27
br label %32
32: ; preds = %31, %26
store i32 -1, i32* %7
br label %33
33: ; preds = %44, %32
%34 = call i32 @read(i32 0, i8* getelementptr inbounds ([16777216 x i8], [16777216 x i8]* @main.RBuff, i64 0, i64 0), i32 16777216)
store i32 %34, i32* %8
%35 = load i32, i32* %8
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %33
%38 = load i32, i32* @stderr
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %51
40: ; preds = %33
%41 = load i32, i32* %8
%42 = load i32, i32* %7
%43 = call i32 @crc32_partial(i8* getelementptr inbounds ([16777216 x i8], [16777216 x i8]* @main.RBuff, i64 0, i64 0), i32 %41, i32 %42)
store i32 %43, i32* %7
br label %44
44: ; preds = %40
%45 = load i32, i32* %8
%46 = icmp ne i32 %45, 0
br i1 %46, label %33, label %47
47: ; preds = %44
%48 = load i32, i32* %7
%49 = xor i32 %48, -1
%50 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %49)
store i32 0, i32* %3
br label %51
51: ; preds = %47, %37, %30, %20
%52 = load i32, i32* %3
ret i32 %52
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str = [25 x i8] c"cannot read file %s: %m\0A\00"
@main.RBuff = internal global [16777216 x i8] zeroinitializer
@.str.1 = [25 x i8] c"error reading input: %m\0A\00"
@.str.2 = [6 x i8] c"%08x\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %4, label %15
4: ; preds = %2
%5 = tail call i32 @close(i32 0)
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = load i32, i32* @O_RDONLY
%9 = tail call i32 @open(i8* %7, i32 %8)
%10 = icmp eq i32 %9, 0
br i1 %10, label %17, label %11
11: ; preds = %4
%12 = load i32, i32* @stderr
%13 = load i8*, i8** %6
%14 = tail call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %13)
br label %31
15: ; preds = %2
%16 = icmp sgt i32 %0, 2
br i1 %16, label %31, label %17
17: ; preds = %4, %15
br label %18
18: ; preds = %17, %25
%19 = phi i32 [ %26, %25 ], [ -1, %17 ]
%20 = tail call i32 @read(i32 0, i8* getelementptr inbounds ([16777216 x i8], [16777216 x i8]* @main.RBuff, i64 0, i64 0), i32 16777216)
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = load i32, i32* @stderr
%24 = tail call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
br label %31
25: ; preds = %18
%26 = tail call i32 @crc32_partial(i8* getelementptr inbounds ([16777216 x i8], [16777216 x i8]* @main.RBuff, i64 0, i64 0), i32 %20, i32 %19)
%27 = icmp eq i32 %20, 0
br i1 %27, label %28, label %18
28: ; preds = %25
%29 = xor i32 %26, -1
%30 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %29)
br label %31
31: ; preds = %11, %22, %28, %15
%32 = phi i32 [ 1, %11 ], [ 2, %15 ], [ 1, %22 ], [ 0, %28 ]
ret i32 %32
}