#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
unsigned int crc32buf(unsigned char *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ showUsage(char const *);
int main(int argc, const char *argv[]) {
  FILE *pFile;
  unsigned char inBuffer[0x3F000];
  unsigned char outBuffer[0x40000];
  unsigned int crcValue = 0xFFFFFFFF, nbytes;
  printf("CRC32 calculator. Embed the result in bin file at offset 0x3FDFC.\n");
  if (argc != 3) {
    showUsage(argv[0]);
    exit(1);
  }
  pFile = fopen(argv[1], "rb");
  if (pFile == NULL) {
    printf("File open error.\n");
    exit(1);
  }
  fseek(pFile, 0, SEEK_END);
  if (ftell(pFile) != 262144) {
    printf("File size error.\n");
    exit(1);
  }
  fseek(pFile, 0, SEEK_SET);
  fread(inBuffer, 1, 0x3F000, pFile);
  fseek(pFile, 0, SEEK_SET);
  fread(outBuffer, 1, 0x40000, pFile);
  fclose(pFile);
  crcValue = crc32buf(inBuffer, 0x3F000);
  outBuffer[0x3FDFC] = crcValue & 0xFF;
  outBuffer[0x3FDFD] = (crcValue >> 8) & 0xFF;
  outBuffer[0x3FDFE] = (crcValue >> 16) & 0xFF;
  outBuffer[0x3FDFF] = (crcValue >> 24) & 0xFF;
  pFile = fopen(argv[2], "wb");
  if (pFile == NULL) {
    printf("File creation error.\n");
    exit(1);
  }
  fwrite(outBuffer, 1, 0x40000, pFile);
  printf("Done.  CRC32 value is 0x%08X\n", crcValue);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x7f030,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x7f024(%rbp)
ff ff ff
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
cmpl   $0x3,-0x8(%rbp)
je     11f1 <main+0x51>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1050 <showUsage@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe43(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    122c <main+0x8c>
lea    0xe2b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x18(%rbp),%rdi
mov    0x2db1(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1080 <ftell@plt>
cmp    $0x40000,%eax
je     126c <main+0xcc>
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x18(%rbp),%rdi
mov    0x2d61(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
lea    -0x3f020(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x3f000,%edx
call   1030 <fread@plt>
mov    -0x18(%rbp),%rdi
mov    0x2d33(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
lea    -0x7f020(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x40000,%edx
call   1030 <fread@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
lea    -0x3f020(%rbp),%rdi
mov    $0x3f000,%esi
call   1070 <crc32buf@plt>
mov    %eax,-0x7f024(%rbp)
mov    -0x7f024(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x3f224(%rbp)
mov    -0x7f024(%rbp),%eax
shr    $0x8,%eax
and    $0xff,%eax
mov    %al,-0x3f223(%rbp)
mov    -0x7f024(%rbp),%eax
shr    $0x10,%eax
and    $0xff,%eax
mov    %al,-0x3f222(%rbp)
mov    -0x7f024(%rbp),%eax
shr    $0x18,%eax
and    $0xff,%eax
mov    %al,-0x3f221(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xd26(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1370 <main+0x1d0>
lea    0xd0e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    -0x7f020(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x40000,%edx
call   10c0 <fwrite@plt>
mov    -0x7f024(%rbp),%esi
lea    0xcec(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x7f008,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
lea    0xe5a(%rip),%rdi
call   1030 <puts@plt>
cmp    $0x3,%ebx
jne    11f5 <main+0x45>
mov    0x8(%r14),%rdi
lea    0xe21(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
jne    1207 <main+0x57>
lea    0xe9c(%rip),%rdi
jmp    12c8 <main+0x118>
mov    (%r14),%rdi
call   1060 <showUsage@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    %rax,%rbx
mov    0x2dd7(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    %rbx,%rdi
call   1090 <ftell@plt>
cmp    $0x40000,%eax
jne    12c1 <main+0x111>
mov    0x2da1(%rip),%r12
mov    (%r12),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
lea    0x40000(%rsp),%r15
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x3f000,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
mov    (%r12),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x40000,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    %r15,%rdi
mov    $0x3f000,%esi
call   1080 <crc32buf@plt>
mov    %eax,%ebx
mov    %eax,0x3fdfc(%rsp)
mov    0x10(%r14),%rdi
lea    0xd55(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
jne    12d7 <main+0x127>
lea    0xda7(%rip),%rdi
jmp    12c8 <main+0x118>
lea    0xdb3(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x40000,%edx
mov    %rax,%rcx
call   10d0 <fwrite@plt>
lea    0xd13(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %edi,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [67 x i8] c"CRC32 calculator. Embed the result in bin file at offset 0x3FDFC.\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [18 x i8] c"File open error.\0A\00"
@SEEK_END = global i32 0
@.str.3 = [18 x i8] c"File size error.\0A\00"
@SEEK_SET = global i32 0
@.str.4 = [3 x i8] c"wb\00"
@.str.5 = [22 x i8] c"File creation error.\0A\00"
@.str.6 = [30 x i8] c"Done. CRC32 value is 0x%08X\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [258048 x i8]
%8 = alloca [262144 x i8]
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -1, i32* %9
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 3
br i1 %13, label %14, label %20
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 @showUsage(i8* %17)
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %24, i32** %6
%25 = load i32*, i32** %6
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %30
27: ; preds = %20
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %20
%31 = load i32*, i32** %6
%32 = load i32, i32* @SEEK_END
%33 = call i32 @fseek(i32* %31, i32 0, i32 %32)
%34 = load i32*, i32** %6
%35 = call i32 @ftell(i32* %34)
%36 = icmp ne i32 %35, 262144
br i1 %36, label %37, label %40
37: ; preds = %30
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%39 = call i32 @exit(i32 1)
unreachable
40: ; preds = %30
%41 = load i32*, i32** %6
%42 = load i32, i32* @SEEK_SET
%43 = call i32 @fseek(i32* %41, i32 0, i32 %42)
%44 = getelementptr inbounds [258048 x i8], [258048 x i8]* %7, i64 0, i64 0
%45 = load i32*, i32** %6
%46 = call i32 @fread(i8* %44, i32 1, i32 258048, i32* %45)
%47 = load i32*, i32** %6
%48 = load i32, i32* @SEEK_SET
%49 = call i32 @fseek(i32* %47, i32 0, i32 %48)
%50 = getelementptr inbounds [262144 x i8], [262144 x i8]* %8, i64 0, i64 0
%51 = load i32*, i32** %6
%52 = call i32 @fread(i8* %50, i32 1, i32 262144, i32* %51)
%53 = load i32*, i32** %6
%54 = call i32 @fclose(i32* %53)
%55 = getelementptr inbounds [258048 x i8], [258048 x i8]* %7, i64 0, i64 0
%56 = call i32 @crc32buf(i8* %55, i32 258048)
store i32 %56, i32* %9
%57 = load i32, i32* %9
%58 = and i32 %57, 255
%59 = trunc i32 %58 to i8
%60 = getelementptr inbounds [262144 x i8], [262144 x i8]* %8, i64 0, i64 261628
store i8 %59, i8* %60
%61 = load i32, i32* %9
%62 = lshr i32 %61, 8
%63 = and i32 %62, 255
%64 = trunc i32 %63 to i8
%65 = getelementptr inbounds [262144 x i8], [262144 x i8]* %8, i64 0, i64 261629
store i8 %64, i8* %65
%66 = load i32, i32* %9
%67 = lshr i32 %66, 16
%68 = and i32 %67, 255
%69 = trunc i32 %68 to i8
%70 = getelementptr inbounds [262144 x i8], [262144 x i8]* %8, i64 0, i64 261630
store i8 %69, i8* %70
%71 = load i32, i32* %9
%72 = lshr i32 %71, 24
%73 = and i32 %72, 255
%74 = trunc i32 %73 to i8
%75 = getelementptr inbounds [262144 x i8], [262144 x i8]* %8, i64 0, i64 261631
store i8 %74, i8* %75
%76 = load i8**, i8*** %5
%77 = getelementptr inbounds i8*, i8** %76, i64 2
%78 = load i8*, i8** %77
%79 = call i32* @fopen(i8* %78, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %79, i32** %6
%80 = load i32*, i32** %6
%81 = icmp eq i32* %80, null
br i1 %81, label %82, label %85
82: ; preds = %40
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
%84 = call i32 @exit(i32 1)
unreachable
85: ; preds = %40
%86 = getelementptr inbounds [262144 x i8], [262144 x i8]* %8, i64 0, i64 0
%87 = load i32*, i32** %6
%88 = call i32 @fwrite(i8* %86, i32 1, i32 262144, i32* %87)
%89 = load i32, i32* %9
%90 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0), i32 %89)
%91 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.4 = [3 x i8] c"wb\00"
@.str.6 = [30 x i8] c"Done. CRC32 value is 0x%08X\0A\00"
@str = [66 x i8] c"CRC32 calculator. Embed the result in bin file at offset 0x3FDFC.\00"
@str.7 = [21 x i8] c"File creation error.\00"
@str.8 = [17 x i8] c"File size error.\00"
@str.9 = [17 x i8] c"File open error.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [258048 x i8]
%4 = alloca [262144 x i8]
%5 = getelementptr inbounds [258048 x i8], [258048 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [262144 x i8], [262144 x i8]* %4, i64 0, i64 0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([66 x i8], [66 x i8]* @str, i64 0, i64 0))
%8 = icmp eq i32 %0, 3
br i1 %8, label %13, label %9
9: ; preds = %2
%10 = load i8*, i8** %1
%11 = tail call i32 @showUsage(i8* %10)
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = tail call i32* @fopen(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %21
18: ; preds = %13
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.9, i64 0, i64 0))
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %13
%22 = load i32, i32* @SEEK_END
%23 = tail call i32 @fseek(i32* %16, i32 0, i32 %22)
%24 = tail call i32 @ftell(i32* %16)
%25 = icmp eq i32 %24, 262144
br i1 %25, label %29, label %26
26: ; preds = %21
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.8, i64 0, i64 0))
%28 = tail call i32 @exit(i32 1)
unreachable
29: ; preds = %21
%30 = load i32, i32* @SEEK_SET
%31 = tail call i32 @fseek(i32* %16, i32 0, i32 %30)
%32 = call i32 @fread(i8* %5, i32 1, i32 258048, i32* %16)
%33 = load i32, i32* @SEEK_SET
%34 = tail call i32 @fseek(i32* %16, i32 0, i32 %33)
%35 = call i32 @fread(i8* %6, i32 1, i32 262144, i32* %16)
%36 = tail call i32 @fclose(i32* %16)
%37 = call i32 @crc32buf(i8* %5, i32 258048)
%38 = trunc i32 %37 to i8
%39 = getelementptr inbounds [262144 x i8], [262144 x i8]* %4, i64 0, i64 261628
store i8 %38, i8* %39
%40 = lshr i32 %37, 8
%41 = trunc i32 %40 to i8
%42 = getelementptr inbounds [262144 x i8], [262144 x i8]* %4, i64 0, i64 261629
store i8 %41, i8* %42
%43 = lshr i32 %37, 16
%44 = trunc i32 %43 to i8
%45 = getelementptr inbounds [262144 x i8], [262144 x i8]* %4, i64 0, i64 261630
store i8 %44, i8* %45
%46 = lshr i32 %37, 24
%47 = trunc i32 %46 to i8
%48 = getelementptr inbounds [262144 x i8], [262144 x i8]* %4, i64 0, i64 261631
store i8 %47, i8* %48
%49 = getelementptr inbounds i8*, i8** %1, i64 2
%50 = load i8*, i8** %49
%51 = call i32* @fopen(i8* %50, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%52 = icmp eq i32* %51, null
br i1 %52, label %53, label %56
53: ; preds = %29
%54 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.7, i64 0, i64 0))
%55 = call i32 @exit(i32 1)
unreachable
56: ; preds = %29
%57 = call i32 @fwrite(i8* %6, i32 1, i32 262144, i32* %51)
%58 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0), i32 %37)
%59 = call i32 @exit(i32 0)
unreachable
}