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

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ SEEK_SET;
scalar_t__ btol(int /*<<< orphan*/ *);
int calculate_crc(int /*<<< orphan*/ *, scalar_t__ *);
int /*<<< orphan*/ *calloc(size_t, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ free(int /*<<< orphan*/ *);
scalar_t__ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
long get_file_length_and_rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ ltob(scalar_t__, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char const *);
scalar_t__ safe_fread(int /*<<< orphan*/ *, long, int /*<<< orphan*/ *);
scalar_t__ safe_fwrite(int /*<<< orphan*/ *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int main(int argc, const char *argv[]) {
  size_t min_sz = 2 * 1024 * 1024;
  uint8_t *buffer, out[8];
  uint32_t crc[2], c_crc[2];
  long fsz;
  int status;
  FILE *f;
  if (argc != 3) {
    printf("Usage: %s <header> <filename>\n", argv[0]);
    return EXIT_SUCCESS;
  }
  if ((buffer = calloc(min_sz, 1)) == NULL) {
    perror("calloc");
    return EXIT_FAILURE;
  }
  if ((f = fopen(argv[1], "rb")) == NULL) {
    perror("fopen");
    free(buffer);
    return EXIT_FAILURE;
  }
  if (safe_fread(buffer, 0x00001000, f)) {
    fprintf(stderr, "Unable to read contents of: %s.\n", argv[1]);
    free(buffer);
    fclose(f);
    return EXIT_FAILURE;
  }
  fclose(f);
  if ((f = fopen(argv[2], "rb")) == NULL) {
    perror("fopen");
    free(buffer);
    return EXIT_FAILURE;
  }
  if ((fsz = get_file_length_and_rewind(f)) < 0) {
    fprintf(stderr, "Unable to determine file size of: %s.\n", argv[2]);
    free(buffer);
    fclose(f);
    return EXIT_FAILURE;
  }
  if (safe_fread(buffer + 0x00001000,
                 ((0x00100000 - 0x00001000) > fsz) ? fsz
                                                   : 0x00100000 - 0x00001000,
                 f)) {
    fprintf(stderr, "Unable to read contents of: %s.\n", argv[2]);
    free(buffer);
    fclose(f);
    return EXIT_FAILURE;
  }
  c_crc[0] = btol(buffer + 0x00000010);
  c_crc[1] = btol(buffer + 0x00000010 + 4);
  status = calculate_crc(buffer, crc);
  fclose(f);
  if (status) {
    free(buffer);
    return EXIT_FAILURE;
  }
  if ((c_crc[0] == crc[0] && c_crc[1] == crc[1]) && ((size_t)fsz >= min_sz))
    return EXIT_SUCCESS;
  ltob(crc[0], out);
  ltob(crc[1], out + 4);
  if ((f = fopen(argv[2], "rb+")) == NULL) {
    perror("fopen");
    free(buffer);
    return EXIT_FAILURE;
  }
  if (safe_fwrite(buffer, min_sz, f)) {
    fprintf(stderr, "Unable to write contents to: %s.\n", argv[2]);
    free(buffer);
    fclose(f);
    return EXIT_FAILURE;
  }
  free(buffer);
  if (fseek(f, 0x00000010, SEEK_SET)) {
    perror("fseek");
    fclose(f);
    return EXIT_FAILURE;
  }
  if (safe_fwrite(out, sizeof(out), f)) {
    fprintf(stderr, "Unable to write CRC to: %s.\n", argv[2]);
    fclose(f);
    return EXIT_FAILURE;
  }
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x200000,-0x18(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     122f <main+0x4f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xde7(%rip),%rdi
call   1070 <printf@plt>
mov    0x2da3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1664 <main+0x484>
mov    -0x18(%rbp),%rdi
mov    $0x1,%esi
call   1080 <calloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1268 <main+0x88>
lea    0xdcd(%rip),%rdi
call   10f0 <perror@plt>
mov    0x2d72(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1664 <main+0x484>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdaf(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x78(%rbp)
cmp    $0x0,%rax
jne    12b0 <main+0xd0>
lea    0xd98(%rip),%rdi
call   10f0 <perror@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    0x2d2a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1664 <main+0x484>
mov    -0x20(%rbp),%rdi
mov    -0x78(%rbp),%rdx
mov    $0x1000,%esi
call   1100 <safe_fread@plt>
cmp    $0x0,%rax
je     130c <main+0x12c>
mov    0x2d0d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xd4b(%rip),%rsi
call   10a0 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x78(%rbp),%rdi
call   1060 <fclose@plt>
mov    0x2cce(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1664 <main+0x484>
mov    -0x78(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xd02(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x78(%rbp)
cmp    $0x0,%rax
jne    135d <main+0x17d>
lea    0xceb(%rip),%rdi
call   10f0 <perror@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    0x2c7d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1664 <main+0x484>
mov    -0x78(%rbp),%rdi
call   1040 <get_file_length_and_rewind@plt>
mov    %rax,-0x68(%rbp)
cmp    $0x0,%rax
jge    13b4 <main+0x1d4>
mov    0x2c65(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xcc4(%rip),%rsi
call   10a0 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x78(%rbp),%rdi
call   1060 <fclose@plt>
mov    0x2c26(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1664 <main+0x484>
mov    -0x20(%rbp),%rax
add    $0x4000,%rax
mov    %rax,-0x80(%rbp)
mov    $0xff000,%eax
cmp    -0x68(%rbp),%rax
jle    13e1 <main+0x201>
mov    -0x68(%rbp),%rax
mov    %rax,-0x88(%rbp)
jmp    13f2 <main+0x212>
mov    $0xff000,%eax
mov    %rax,-0x88(%rbp)
jmp    13f2 <main+0x212>
mov    -0x80(%rbp),%rdi
mov    -0x88(%rbp),%rsi
mov    -0x78(%rbp),%rdx
call   1100 <safe_fread@plt>
cmp    $0x0,%rax
je     1450 <main+0x270>
mov    0x2bc9(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xc07(%rip),%rsi
call   10a0 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x78(%rbp),%rdi
call   1060 <fclose@plt>
mov    0x2b8a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1664 <main+0x484>
mov    -0x20(%rbp),%rdi
add    $0x40,%rdi
call   1090 <btol@plt>
mov    %rax,-0x60(%rbp)
mov    -0x20(%rbp),%rdi
add    $0x40,%rdi
add    $0x10,%rdi
call   1090 <btol@plt>
mov    %rax,-0x58(%rbp)
mov    -0x20(%rbp),%rdi
lea    -0x50(%rbp),%rsi
call   1050 <calculate_crc@plt>
mov    %eax,-0x6c(%rbp)
mov    -0x78(%rbp),%rdi
call   1060 <fclose@plt>
cmpl   $0x0,-0x6c(%rbp)
je     14b3 <main+0x2d3>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    0x2b27(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1664 <main+0x484>
mov    -0x60(%rbp),%rax
cmp    -0x50(%rbp),%rax
jne    14ee <main+0x30e>
mov    -0x58(%rbp),%rax
cmp    -0x48(%rbp),%rax
jne    14ee <main+0x30e>
mov    -0x68(%rbp),%rax
cmp    -0x18(%rbp),%rax
jb     14ee <main+0x30e>
mov    0x2ae4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1664 <main+0x484>
mov    -0x50(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   10b0 <ltob@plt>
mov    -0x48(%rbp),%rdi
lea    -0x40(%rbp),%rsi
add    $0x10,%rsi
call   10b0 <ltob@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xb5c(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x78(%rbp)
cmp    $0x0,%rax
jne    1554 <main+0x374>
lea    0xaf4(%rip),%rdi
call   10f0 <perror@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    0x2a86(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1664 <main+0x484>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    %eax,%esi
mov    -0x78(%rbp),%rdx
call   10d0 <safe_fwrite@plt>
cmp    $0x0,%rax
je     15b1 <main+0x3d1>
mov    0x2a68(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xaf2(%rip),%rsi
call   10a0 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x78(%rbp),%rdi
call   1060 <fclose@plt>
mov    0x2a29(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1664 <main+0x484>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x78(%rbp),%rdi
mov    0x2a13(%rip),%rax
mov    (%rax),%edx
mov    $0x10,%esi
call   10c0 <fseek@plt>
cmp    $0x0,%rax
je     1601 <main+0x421>
lea    0xabb(%rip),%rdi
call   10f0 <perror@plt>
mov    -0x78(%rbp),%rdi
call   1060 <fclose@plt>
mov    0x29d9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1664 <main+0x484>
lea    -0x40(%rbp),%rdi
mov    -0x78(%rbp),%rdx
mov    $0x20,%esi
call   10d0 <safe_fwrite@plt>
cmp    $0x0,%rax
je     1654 <main+0x474>
mov    0x29bc(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xa6e(%rip),%rsi
call   10a0 <fprintf@plt>
mov    -0x78(%rbp),%rdi
call   1060 <fclose@plt>
mov    0x2986(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1664 <main+0x484>
mov    -0x78(%rbp),%rdi
call   1060 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rsi,%r13
cmp    $0x3,%edi
jne    126b <main+0x8b>
mov    $0x200000,%edi
mov    $0x1,%esi
call   1080 <calloc@plt>
test   %rax,%rax
je     1406 <main+0x226>
mov    %rax,%r14
mov    0x8(%r13),%rdi
lea    0xe0a(%rip),%rsi
call   10e0 <fopen@plt>
test   %rax,%rax
je     13ed <main+0x20d>
mov    %rax,%rbx
mov    $0x1000,%esi
mov    %r14,%rdi
mov    %rax,%rdx
call   1100 <safe_fread@plt>
test   %rax,%rax
je     1287 <main+0xa7>
mov    0x2d97(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r13),%rdx
lea    0xdd9(%rip),%rsi
call   10a0 <fprintf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
jmp    1318 <main+0x138>
mov    0x0(%r13),%rsi
lea    0xd8a(%rip),%rdi
call   1070 <printf@plt>
mov    0x2d46(%rip),%rax
jmp    1324 <main+0x144>
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    0x10(%r13),%rdi
lea    0xd8c(%rip),%rsi
call   10e0 <fopen@plt>
test   %rax,%rax
je     13ed <main+0x20d>
mov    %rax,%r15
mov    %rax,%rdi
call   1040 <get_file_length_and_rewind@plt>
test   %rax,%rax
js     12f4 <main+0x114>
mov    %rax,%r12
lea    0x4000(%r14),%rdi
cmp    $0xff000,%rax
mov    $0xff000,%esi
cmovb  %rax,%rsi
mov    %r15,%rdx
call   1100 <safe_fread@plt>
test   %rax,%rax
je     1335 <main+0x155>
mov    0x2cfb(%rip),%rax
mov    (%rax),%edi
mov    0x10(%r13),%rdx
lea    0xd3d(%rip),%rsi
jmp    1308 <main+0x128>
mov    0x2ce5(%rip),%rax
mov    (%rax),%edi
mov    0x10(%r13),%rdx
lea    0xd48(%rip),%rsi
call   10a0 <fprintf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1060 <fclose@plt>
mov    0x2cac(%rip),%rax
mov    (%rax),%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x40(%r14),%rdi
call   1090 <btol@plt>
mov    %rax,0x18(%rsp)
mov    %r14,%rdi
add    $0x50,%rdi
call   1090 <btol@plt>
mov    %rax,%rbp
mov    %rsp,%rsi
mov    %r14,%rdi
call   1050 <calculate_crc@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1060 <fclose@plt>
test   %ebx,%ebx
jne    13f9 <main+0x219>
mov    (%rsp),%rdi
cmp    %rdi,0x18(%rsp)
jne    138e <main+0x1ae>
cmp    0x8(%rsp),%rbp
jne    138e <main+0x1ae>
cmp    $0x200000,%r12
jae    127b <main+0x9b>
lea    0x20(%rsp),%rsi
call   10b0 <ltob@plt>
mov    0x8(%rsp),%rdi
lea    0x30(%rsp),%rsi
call   10b0 <ltob@plt>
mov    0x10(%r13),%rdi
lea    0xcc5(%rip),%rsi
call   10e0 <fopen@plt>
test   %rax,%rax
je     13ed <main+0x20d>
mov    %rax,%r15
mov    %r14,%rdi
mov    $0x200000,%esi
mov    %rax,%rdx
call   10d0 <safe_fwrite@plt>
test   %rax,%rax
je     1417 <main+0x237>
mov    0x2c05(%rip),%rax
mov    (%rax),%edi
mov    0x10(%r13),%rdx
lea    0xc93(%rip),%rsi
jmp    1308 <main+0x128>
lea    0xc35(%rip),%rdi
call   10f0 <perror@plt>
mov    %r14,%rdi
call   1030 <free@plt>
jmp    131d <main+0x13d>
lea    0xc12(%rip),%rdi
call   10f0 <perror@plt>
jmp    131d <main+0x13d>
mov    %r14,%rdi
call   1030 <free@plt>
mov    0x2bb2(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
mov    $0x10,%esi
call   10c0 <fseek@plt>
test   %rax,%rax
jne    147e <main+0x29e>
lea    0x20(%rsp),%rdi
mov    $0x20,%esi
mov    %r15,%rdx
call   10d0 <safe_fwrite@plt>
test   %rax,%rax
je     146f <main+0x28f>
mov    0x2b88(%rip),%rax
mov    (%rax),%edi
mov    0x10(%r13),%rdx
lea    0xc3e(%rip),%rsi
call   10a0 <fprintf@plt>
jmp    1315 <main+0x135>
mov    %r15,%rdi
call   1060 <fclose@plt>
xor    %eax,%eax
jmp    1326 <main+0x146>
lea    0xc18(%rip),%rdi
call   10f0 <perror@plt>
jmp    1315 <main+0x135>

LLVM IR (-O0):
@.str = [31 x i8] c"Usage: %s <header> <filename>\0A\00"
@EXIT_SUCCESS = global i32 0
@.str.1 = [7 x i8] c"calloc\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [6 x i8] c"fopen\00"
@stderr = global i32 0
@.str.4 = [33 x i8] c"Unable to read contents of: %s.\0A\00"
@.str.5 = [39 x i8] c"Unable to determine file size of: %s.\0A\00"
@.str.6 = [4 x i8] c"rb+\00"
@.str.7 = [34 x i8] c"Unable to write contents to: %s.\0A\00"
@SEEK_SET = global i32 0
@.str.8 = [6 x i8] c"fseek\00"
@.str.9 = [29 x i8] c"Unable to write CRC to: %s.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i32*
%8 = alloca [8 x i32]
%9 = alloca [2 x i64]
%10 = alloca [2 x i64]
%11 = alloca i64
%12 = alloca i32
%13 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 2097152, i64* %6
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 3
br i1 %15, label %16, label %22
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = load i32, i32* @EXIT_SUCCESS
store i32 %21, i32* %3
br label %214
22: ; preds = %2
%23 = load i64, i64* %6
%24 = call i32* @calloc(i64 %23, i32 1)
store i32* %24, i32** %7
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %29
26: ; preds = %22
%27 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%28 = load i32, i32* @EXIT_FAILURE
store i32 %28, i32* %3
br label %214
29: ; preds = %22
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = call i32* @fopen(i8* %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %33, i32** %13
%34 = icmp eq i32* %33, null
br i1 %34, label %35, label %40
35: ; preds = %29
%36 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%37 = load i32*, i32** %7
%38 = call i32 @free(i32* %37)
%39 = load i32, i32* @EXIT_FAILURE
store i32 %39, i32* %3
br label %214
40: ; preds = %29
%41 = load i32*, i32** %7
%42 = load i32*, i32** %13
%43 = call i64 @safe_fread(i32* %41, i64 4096, i32* %42)
%44 = icmp ne i64 %43, 0
br i1 %44, label %45, label %56
45: ; preds = %40
%46 = load i32, i32* @stderr
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 1
%49 = load i8*, i8** %48
%50 = call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i8* %49)
%51 = load i32*, i32** %7
%52 = call i32 @free(i32* %51)
%53 = load i32*, i32** %13
%54 = call i32 @fclose(i32* %53)
%55 = load i32, i32* @EXIT_FAILURE
store i32 %55, i32* %3
br label %214
56: ; preds = %40
%57 = load i32*, i32** %13
%58 = call i32 @fclose(i32* %57)
%59 = load i8**, i8*** %5
%60 = getelementptr inbounds i8*, i8** %59, i64 2
%61 = load i8*, i8** %60
%62 = call i32* @fopen(i8* %61, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %62, i32** %13
%63 = icmp eq i32* %62, null
br i1 %63, label %64, label %69
64: ; preds = %56
%65 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%66 = load i32*, i32** %7
%67 = call i32 @free(i32* %66)
%68 = load i32, i32* @EXIT_FAILURE
store i32 %68, i32* %3
br label %214
69: ; preds = %56
%70 = load i32*, i32** %13
%71 = call i64 @get_file_length_and_rewind(i32* %70)
store i64 %71, i64* %11
%72 = icmp slt i64 %71, 0
br i1 %72, label %73, label %84
73: ; preds = %69
%74 = load i32, i32* @stderr
%75 = load i8**, i8*** %5
%76 = getelementptr inbounds i8*, i8** %75, i64 2
%77 = load i8*, i8** %76
%78 = call i32 @fprintf(i32 %74, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0), i8* %77)
%79 = load i32*, i32** %7
%80 = call i32 @free(i32* %79)
%81 = load i32*, i32** %13
%82 = call i32 @fclose(i32* %81)
%83 = load i32, i32* @EXIT_FAILURE
store i32 %83, i32* %3
br label %214
84: ; preds = %69
%85 = load i32*, i32** %7
%86 = getelementptr inbounds i32, i32* %85, i64 4096
%87 = load i64, i64* %11
%88 = icmp sgt i64 1044480, %87
br i1 %88, label %89, label %91
89: ; preds = %84
%90 = load i64, i64* %11
br label %92
91: ; preds = %84
br label %92
92: ; preds = %91, %89
%93 = phi i64 [ %90, %89 ], [ 1044480, %91 ]
%94 = load i32*, i32** %13
%95 = call i64 @safe_fread(i32* %86, i64 %93, i32* %94)
%96 = icmp ne i64 %95, 0
br i1 %96, label %97, label %108
97: ; preds = %92
%98 = load i32, i32* @stderr
%99 = load i8**, i8*** %5
%100 = getelementptr inbounds i8*, i8** %99, i64 2
%101 = load i8*, i8** %100
%102 = call i32 @fprintf(i32 %98, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i8* %101)
%103 = load i32*, i32** %7
%104 = call i32 @free(i32* %103)
%105 = load i32*, i32** %13
%106 = call i32 @fclose(i32* %105)
%107 = load i32, i32* @EXIT_FAILURE
store i32 %107, i32* %3
br label %214
108: ; preds = %92
%109 = load i32*, i32** %7
%110 = getelementptr inbounds i32, i32* %109, i64 16
%111 = call i64 @btol(i32* %110)
%112 = getelementptr inbounds [2 x i64], [2 x i64]* %10, i64 0, i64 0
store i64 %111, i64* %112
%113 = load i32*, i32** %7
%114 = getelementptr inbounds i32, i32* %113, i64 16
%115 = getelementptr inbounds i32, i32* %114, i64 4
%116 = call i64 @btol(i32* %115)
%117 = getelementptr inbounds [2 x i64], [2 x i64]* %10, i64 0, i64 1
store i64 %116, i64* %117
%118 = load i32*, i32** %7
%119 = getelementptr inbounds [2 x i64], [2 x i64]* %9, i64 0, i64 0
%120 = call i32 @calculate_crc(i32* %118, i64* %119)
store i32 %120, i32* %12
%121 = load i32*, i32** %13
%122 = call i32 @fclose(i32* %121)
%123 = load i32, i32* %12
%124 = icmp ne i32 %123, 0
br i1 %124, label %125, label %129
125: ; preds = %108
%126 = load i32*, i32** %7
%127 = call i32 @free(i32* %126)
%128 = load i32, i32* @EXIT_FAILURE
store i32 %128, i32* %3
br label %214
129: ; preds = %108
%130 = getelementptr inbounds [2 x i64], [2 x i64]* %10, i64 0, i64 0
%131 = load i64, i64* %130
%132 = getelementptr inbounds [2 x i64], [2 x i64]* %9, i64 0, i64 0
%133 = load i64, i64* %132
%134 = icmp eq i64 %131, %133
br i1 %134, label %135, label %147
135: ; preds = %129
%136 = getelementptr inbounds [2 x i64], [2 x i64]* %10, i64 0, i64 1
%137 = load i64, i64* %136
%138 = getelementptr inbounds [2 x i64], [2 x i64]* %9, i64 0, i64 1
%139 = load i64, i64* %138
%140 = icmp eq i64 %137, %139
br i1 %140, label %141, label %147
141: ; preds = %135
%142 = load i64, i64* %11
%143 = load i64, i64* %6
%144 = icmp uge i64 %142, %143
br i1 %144, label %145, label %147
145: ; preds = %141
%146 = load i32, i32* @EXIT_SUCCESS
store i32 %146, i32* %3
br label %214
147: ; preds = %141, %135, %129
%148 = getelementptr inbounds [2 x i64], [2 x i64]* %9, i64 0, i64 0
%149 = load i64, i64* %148
%150 = getelementptr inbounds [8 x i32], [8 x i32]* %8, i64 0, i64 0
%151 = call i32 @ltob(i64 %149, i32* %150)
%152 = getelementptr inbounds [2 x i64], [2 x i64]* %9, i64 0, i64 1
%153 = load i64, i64* %152
%154 = getelementptr inbounds [8 x i32], [8 x i32]* %8, i64 0, i64 0
%155 = getelementptr inbounds i32, i32* %154, i64 4
%156 = call i32 @ltob(i64 %153, i32* %155)
%157 = load i8**, i8*** %5
%158 = getelementptr inbounds i8*, i8** %157, i64 2
%159 = load i8*, i8** %158
%160 = call i32* @fopen(i8* %159, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
store i32* %160, i32** %13
%161 = icmp eq i32* %160, null
br i1 %161, label %162, label %167
162: ; preds = %147
%163 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%164 = load i32*, i32** %7
%165 = call i32 @free(i32* %164)
%166 = load i32, i32* @EXIT_FAILURE
store i32 %166, i32* %3
br label %214
167: ; preds = %147
%168 = load i32*, i32** %7
%169 = load i64, i64* %6
%170 = trunc i64 %169 to i32
%171 = load i32*, i32** %13
%172 = call i64 @safe_fwrite(i32* %168, i32 %170, i32* %171)
%173 = icmp ne i64 %172, 0
br i1 %173, label %174, label %185
174: ; preds = %167
%175 = load i32, i32* @stderr
%176 = load i8**, i8*** %5
%177 = getelementptr inbounds i8*, i8** %176, i64 2
%178 = load i8*, i8** %177
%179 = call i32 @fprintf(i32 %175, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.7, i64 0, i64 0), i8* %178)
%180 = load i32*, i32** %7
%181 = call i32 @free(i32* %180)
%182 = load i32*, i32** %13
%183 = call i32 @fclose(i32* %182)
%184 = load i32, i32* @EXIT_FAILURE
store i32 %184, i32* %3
br label %214
185: ; preds = %167
%186 = load i32*, i32** %7
%187 = call i32 @free(i32* %186)
%188 = load i32*, i32** %13
%189 = load i32, i32* @SEEK_SET
%190 = call i64 @fseek(i32* %188, i32 16, i32 %189)
%191 = icmp ne i64 %190, 0
br i1 %191, label %192, label %197
192: ; preds = %185
%193 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
%194 = load i32*, i32** %13
%195 = call i32 @fclose(i32* %194)
%196 = load i32, i32* @EXIT_FAILURE
store i32 %196, i32* %3
br label %214
197: ; preds = %185
%198 = getelementptr inbounds [8 x i32], [8 x i32]* %8, i64 0, i64 0
%199 = load i32*, i32** %13
%200 = call i64 @safe_fwrite(i32* %198, i32 32, i32* %199)
%201 = icmp ne i64 %200, 0
br i1 %201, label %202, label %211
202: ; preds = %197
%203 = load i32, i32* @stderr
%204 = load i8**, i8*** %5
%205 = getelementptr inbounds i8*, i8** %204, i64 2
%206 = load i8*, i8** %205
%207 = call i32 @fprintf(i32 %203, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.9, i64 0, i64 0), i8* %206)
%208 = load i32*, i32** %13
%209 = call i32 @fclose(i32* %208)
%210 = load i32, i32* @EXIT_FAILURE
store i32 %210, i32* %3
br label %214
211: ; preds = %197
%212 = load i32*, i32** %13
%213 = call i32 @fclose(i32* %212)
store i32 0, i32* %3
br label %214
214: ; preds = %211, %202, %192, %174, %162, %145, %125, %97, %73, %64, %45, %35, %26, %16
%215 = load i32, i32* %3
ret i32 %215
}

LLVM IR (-O2):
@.str = [31 x i8] c"Usage: %s <header> <filename>\0A\00"
@EXIT_SUCCESS = global i32 0
@.str.1 = [7 x i8] c"calloc\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [6 x i8] c"fopen\00"
@stderr = global i32 0
@.str.4 = [33 x i8] c"Unable to read contents of: %s.\0A\00"
@.str.5 = [39 x i8] c"Unable to determine file size of: %s.\0A\00"
@.str.6 = [4 x i8] c"rb+\00"
@.str.7 = [34 x i8] c"Unable to write contents to: %s.\0A\00"
@SEEK_SET = global i32 0
@.str.8 = [6 x i8] c"fseek\00"
@.str.9 = [29 x i8] c"Unable to write CRC to: %s.\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [8 x i32]
%4 = alloca [2 x i64]
%5 = bitcast [8 x i32]* %3 to i8*
%6 = bitcast [2 x i64]* %4 to i8*
%7 = icmp eq i32 %0, 3
br i1 %7, label %12, label %8
8: ; preds = %2
%9 = load i8*, i8** %1
%10 = tail call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = load i32, i32* @EXIT_SUCCESS
br label %136
12: ; preds = %2
%13 = tail call i32* @calloc(i64 2097152, i32 1)
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%17 = load i32, i32* @EXIT_FAILURE
br label %136
18: ; preds = %12
%19 = getelementptr inbounds i8*, i8** %1, i64 1
%20 = load i8*, i8** %19
%21 = tail call i32* @fopen(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %27
23: ; preds = %18
%24 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%25 = tail call i32 @free(i32* %13)
%26 = load i32, i32* @EXIT_FAILURE
br label %136
27: ; preds = %18
%28 = tail call i64 @safe_fread(i32* %13, i64 4096, i32* %21)
%29 = icmp eq i64 %28, 0
br i1 %29, label %37, label %30
30: ; preds = %27
%31 = load i32, i32* @stderr
%32 = load i8*, i8** %19
%33 = tail call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i8* %32)
%34 = tail call i32 @free(i32* %13)
%35 = tail call i32 @fclose(i32* %21)
%36 = load i32, i32* @EXIT_FAILURE
br label %136
37: ; preds = %27
%38 = tail call i32 @fclose(i32* %21)
%39 = getelementptr inbounds i8*, i8** %1, i64 2
%40 = load i8*, i8** %39
%41 = tail call i32* @fopen(i8* %40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%42 = icmp eq i32* %41, null
br i1 %42, label %43, label %47
43: ; preds = %37
%44 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%45 = tail call i32 @free(i32* %13)
%46 = load i32, i32* @EXIT_FAILURE
br label %136
47: ; preds = %37
%48 = tail call i64 @get_file_length_and_rewind(i32* %41)
%49 = icmp slt i64 %48, 0
br i1 %49, label %50, label %57
50: ; preds = %47
%51 = load i32, i32* @stderr
%52 = load i8*, i8** %39
%53 = tail call i32 @fprintf(i32 %51, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0), i8* %52)
%54 = tail call i32 @free(i32* %13)
%55 = tail call i32 @fclose(i32* %41)
%56 = load i32, i32* @EXIT_FAILURE
br label %136
57: ; preds = %47
%58 = getelementptr inbounds i32, i32* %13, i64 4096
%59 = icmp ult i64 %48, 1044480
%60 = select i1 %59, i64 %48, i64 1044480
%61 = tail call i64 @safe_fread(i32* %58, i64 %60, i32* %41)
%62 = icmp eq i64 %61, 0
br i1 %62, label %70, label %63
63: ; preds = %57
%64 = load i32, i32* @stderr
%65 = load i8*, i8** %39
%66 = tail call i32 @fprintf(i32 %64, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i8* %65)
%67 = tail call i32 @free(i32* %13)
%68 = tail call i32 @fclose(i32* %41)
%69 = load i32, i32* @EXIT_FAILURE
br label %136
70: ; preds = %57
%71 = getelementptr inbounds i32, i32* %13, i64 16
%72 = tail call i64 @btol(i32* %71)
%73 = getelementptr inbounds i32, i32* %13, i64 20
%74 = tail call i64 @btol(i32* %73)
%75 = getelementptr inbounds [2 x i64], [2 x i64]* %4, i64 0, i64 0
%76 = call i32 @calculate_crc(i32* %13, i64* %75)
%77 = call i32 @fclose(i32* %41)
%78 = icmp eq i32 %76, 0
br i1 %78, label %82, label %79
79: ; preds = %70
%80 = call i32 @free(i32* %13)
%81 = load i32, i32* @EXIT_FAILURE
br label %136
82: ; preds = %70
%83 = load i64, i64* %75
%84 = icmp eq i64 %72, %83
%85 = getelementptr inbounds [2 x i64], [2 x i64]* %4, i64 0, i64 1
%86 = load i64, i64* %85
%87 = icmp eq i64 %74, %86
%88 = select i1 %84, i1 %87, i1 false
%89 = icmp ugt i64 %48, 2097151
%90 = select i1 %88, i1 %89, i1 false
br i1 %90, label %91, label %93
91: ; preds = %82
%92 = load i32, i32* @EXIT_SUCCESS
br label %136
93: ; preds = %82
%94 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 0
%95 = call i32 @ltob(i64 %83, i32* %94)
%96 = load i64, i64* %85
%97 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 4
%98 = call i32 @ltob(i64 %96, i32* %97)
%99 = load i8*, i8** %39
%100 = call i32* @fopen(i8* %99, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%101 = icmp eq i32* %100, null
br i1 %101, label %102, label %106
102: ; preds = %93
%103 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%104 = call i32 @free(i32* %13)
%105 = load i32, i32* @EXIT_FAILURE
br label %136
106: ; preds = %93
%107 = call i64 @safe_fwrite(i32* %13, i32 2097152, i32* %100)
%108 = icmp eq i64 %107, 0
br i1 %108, label %116, label %109
109: ; preds = %106
%110 = load i32, i32* @stderr
%111 = load i8*, i8** %39
%112 = call i32 @fprintf(i32 %110, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.7, i64 0, i64 0), i8* %111)
%113 = call i32 @free(i32* %13)
%114 = call i32 @fclose(i32* %100)
%115 = load i32, i32* @EXIT_FAILURE
br label %136
116: ; preds = %106
%117 = call i32 @free(i32* %13)
%118 = load i32, i32* @SEEK_SET
%119 = call i64 @fseek(i32* %100, i32 16, i32 %118)
%120 = icmp eq i64 %119, 0
br i1 %120, label %125, label %121
121: ; preds = %116
%122 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
%123 = call i32 @fclose(i32* %100)
%124 = load i32, i32* @EXIT_FAILURE
br label %136
125: ; preds = %116
%126 = call i64 @safe_fwrite(i32* %94, i32 32, i32* %100)
%127 = icmp eq i64 %126, 0
br i1 %127, label %134, label %128
128: ; preds = %125
%129 = load i32, i32* @stderr
%130 = load i8*, i8** %39
%131 = call i32 @fprintf(i32 %129, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.9, i64 0, i64 0), i8* %130)
%132 = call i32 @fclose(i32* %100)
%133 = load i32, i32* @EXIT_FAILURE
br label %136
134: ; preds = %125
%135 = call i32 @fclose(i32* %100)
br label %136
136: ; preds = %134, %128, %121, %109, %102, %91, %79, %63, %50, %43, %30, %23, %15, %8
%137 = phi i32 [ %11, %8 ], [ %17, %15 ], [ %26, %23 ], [ %36, %30 ], [ %46, %43 ], [ %56, %50 ], [ %69, %63 ], [ %81, %79 ], [ %92, %91 ], [ %105, %102 ], [ %115, %109 ], [ %124, %121 ], [ %133, %128 ], [ 0, %134 ]
ret i32 %137
}