#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 */
typedef int uint32_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int calculate_crc32(void *, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(void *, int, long, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(void *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ init_crc();
void *malloc(long);
int /*<<< orphan*/ memset(void *, int /*<<< orphan*/, long);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  FILE *fp = fopen(argv[1], "rb");
  long len;
  void *buf;
  fseek(fp, 0, SEEK_END);
  len = ftell(fp);
  rewind(fp);
  buf = malloc(len);
  memset(buf, 0, len);
  fread(buf, 1, len, fp);
  fclose(fp);
  init_crc();
  uint32_t crc = calculate_crc32(buf, (uint32_t)len);
  printf("%08x\n", crc);
  free(buf);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe1b(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2def(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1090 <ftell@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <rewind@plt>
mov    -0x20(%rbp),%rdi
call   10a0 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rdx
xor    %esi,%esi
call   1080 <memset@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    $0x0,%al
call   10e0 <init_crc@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    %eax,%esi
call   10c0 <calculate_crc32@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%esi
lea    0xd8d(%rip),%rdi
call   1060 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    0x8(%rsi),%rdi
lea    0xe30(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,%rbx
mov    0x2e09(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    %rbx,%rdi
call   1090 <ftell@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1070 <rewind@plt>
mov    %r15,%rdi
call   10a0 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
xor    %esi,%esi
mov    %r15,%rdx
call   1080 <memset@plt>
mov    %r14,%rdi
mov    $0x1,%esi
mov    %r15,%rdx
mov    %rbx,%rcx
call   1040 <fread@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
call   10e0 <init_crc@plt>
mov    %r14,%rdi
mov    %r15d,%esi
call   10c0 <calculate_crc32@plt>
lea    0xdb9(%rip),%rdi
mov    %eax,%esi
call   1060 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@.str.1 = [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 i64
%8 = alloca i8*
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %6
%14 = load i32*, i32** %6
%15 = load i32, i32* @SEEK_END
%16 = call i32 @fseek(i32* %14, i32 0, i32 %15)
%17 = load i32*, i32** %6
%18 = call i64 @ftell(i32* %17)
store i64 %18, i64* %7
%19 = load i32*, i32** %6
%20 = call i32 @rewind(i32* %19)
%21 = load i64, i64* %7
%22 = call i8* @malloc(i64 %21)
store i8* %22, i8** %8
%23 = load i8*, i8** %8
%24 = load i64, i64* %7
%25 = call i32 @memset(i8* %23, i32 0, i64 %24)
%26 = load i8*, i8** %8
%27 = load i64, i64* %7
%28 = load i32*, i32** %6
%29 = call i32 @fread(i8* %26, i32 1, i64 %27, i32* %28)
%30 = load i32*, i32** %6
%31 = call i32 @fclose(i32* %30)
%32 = call i32 (...) @init_crc()
%33 = load i8*, i8** %8
%34 = load i64, i64* %7
%35 = trunc i64 %34 to i32
%36 = call i32 @calculate_crc32(i8* %33, i32 %35)
store i32 %36, i32* %9
%37 = load i32, i32* %9
%38 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %37)
%39 = load i8*, i8** %8
%40 = call i32 @free(i8* %39)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@.str.1 = [6 x i8] c"%08x\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = tail call i32* @fopen(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @SEEK_END
%7 = tail call i32 @fseek(i32* %5, i32 0, i32 %6)
%8 = tail call i64 @ftell(i32* %5)
%9 = tail call i32 @rewind(i32* %5)
%10 = tail call i8* @malloc(i64 %8)
%11 = tail call i32 @memset(i8* %10, i32 0, i64 %8)
%12 = tail call i32 @fread(i8* %10, i32 1, i64 %8, i32* %5)
%13 = tail call i32 @fclose(i32* %5)
%14 = tail call i32 (...) @init_crc()
%15 = trunc i64 %8 to i32
%16 = tail call i32 @calculate_crc32(i8* %10, i32 %15)
%17 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%18 = tail call i32 @free(i8* %10)
ret i32 0
}