#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);
unsigned long crc32(int /*<<< orphan*/, unsigned char *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, unsigned long);
int /*<<< orphan*/ free(unsigned char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putchar(unsigned long);
int read(int, unsigned char *, int);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  int fd;
  unsigned char *mybuf;
  unsigned long checksum;
  if (argc != 2) {
    printf("a single argument is required !\n");
    exit(1);
  }
  if ((fd = open(argv[1], O_RDONLY)) == -1) {
    printf("Open %s Error!", argv[1]);
    exit(1);
  }
  if ((mybuf = (unsigned char *)malloc(0x200000)) == NULL) {
    printf("malloc error\n");
    exit(1);
  }
  memset(mybuf, 0, 0x200000);
  if (read(fd, mybuf, 0x200000) == -1) {
    printf("malloc error\n");
    exit(1);
  }
  checksum = crc32(0, mybuf, 0x200000);
  fprintf(stderr, "crc32 checksum of %s is :%08x\n", argv[1], checksum);
  putchar(checksum >> 24);
  putchar((checksum % 0x1000000) >> 16);
  putchar((checksum % 0x10000) >> 8);
  putchar(checksum % 0x100);
  free(mybuf);
  close(fd);
  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)
cmpl   $0x2,-0x8(%rbp)
je     11e8 <main+0x38>
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2df1(%rip),%rax
mov    (%rax),%esi
call   10c0 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    122a <main+0x7a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe08(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    $0x200000,%edi
call   10b0 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    125a <main+0xaa>
lea    0xde7(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x200000,%edx
call   1070 <memset@plt>
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    $0x200000,%edx
call   1090 <read@plt>
cmp    $0xffffffff,%eax
jne    129c <main+0xec>
lea    0xda5(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x20(%rbp),%rsi
xor    %edi,%edi
mov    $0x200000,%edx
call   1050 <crc32@plt>
mov    %rax,-0x28(%rbp)
mov    0x2d21(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
mov    -0x28(%rbp),%rcx
lea    0xd72(%rip),%rsi
call   10a0 <fprintf@plt>
mov    -0x28(%rbp),%rdi
shr    $0x18,%rdi
call   1040 <putchar@plt>
mov    -0x28(%rbp),%rdi
and    $0xffffff,%rdi
shr    $0x10,%rdi
call   1040 <putchar@plt>
mov    -0x28(%rbp),%rdi
and    $0xffff,%rdi
shr    $0x8,%rdi
call   1040 <putchar@plt>
mov    -0x28(%rbp),%rdi
and    $0xff,%rdi
call   1040 <putchar@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    12a8 <main+0xe8>
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
mov    0x2e0a(%rip),%rax
mov    (%rax),%esi
call   10d0 <open@plt>
cmp    $0xffffffff,%eax
je     12be <main+0xfe>
mov    %eax,%r15d
mov    $0x200000,%edi
call   10c0 <malloc@plt>
test   %rax,%rax
je     129f <main+0xdf>
mov    %rax,%rbp
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x200000,%edx
call   1080 <memset@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
mov    $0x200000,%edx
call   10a0 <read@plt>
cmp    $0xffffffff,%eax
je     129f <main+0xdf>
xor    %edi,%edi
mov    %rbp,%rsi
mov    $0x200000,%edx
call   1060 <crc32@plt>
mov    %rax,%rbx
mov    0x2d94(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r14),%rdx
lea    0xdbe(%rip),%rsi
mov    %rbx,%rcx
call   10b0 <fprintf@plt>
mov    %rbx,%rdi
shr    $0x18,%rdi
call   1040 <putchar@plt>
mov    %ebx,%eax
shr    $0x10,%eax
movzbl %al,%edi
call   1040 <putchar@plt>
movzbl %bh,%edi
call   1040 <putchar@plt>
movzbl %bl,%edi
call   1040 <putchar@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %r15d,%edi
call   1090 <close@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd88(%rip),%rdi
jmp    12af <main+0xef>
lea    0xd8c(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    0x8(%r14),%rsi
lea    0xd37(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
@.str = [33 x i8] c"a single argument is required !\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [15 x i8] c"Open %s Error!\00"
@.str.2 = [14 x i8] c"malloc error\0A\00"
@stderr = global i32 0
@.str.3 = [31 x i8] c"crc32 checksum of %s is :%08x\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = load i32, i32* @O_RDONLY
%19 = call i32 @open(i8* %17, i32 %18)
store i32 %19, i32* %6
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %27
21: ; preds = %14
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %24)
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %14
%28 = call i64 @malloc(i32 2097152)
%29 = inttoptr i64 %28 to i8*
store i8* %29, i8** %7
%30 = icmp eq i8* %29, null
br i1 %30, label %31, label %34
31: ; preds = %27
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %27
%35 = load i8*, i8** %7
%36 = call i32 @memset(i8* %35, i32 0, i32 2097152)
%37 = load i32, i32* %6
%38 = load i8*, i8** %7
%39 = call i32 @read(i32 %37, i8* %38, i32 2097152)
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %44
41: ; preds = %34
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %34
%45 = load i8*, i8** %7
%46 = call i64 @crc32(i32 0, i8* %45, i32 2097152)
store i64 %46, i64* %8
%47 = load i32, i32* @stderr
%48 = load i8**, i8*** %5
%49 = getelementptr inbounds i8*, i8** %48, i64 1
%50 = load i8*, i8** %49
%51 = load i64, i64* %8
%52 = call i32 @fprintf(i32 %47, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i8* %50, i64 %51)
%53 = load i64, i64* %8
%54 = lshr i64 %53, 24
%55 = call i32 @putchar(i64 %54)
%56 = load i64, i64* %8
%57 = urem i64 %56, 16777216
%58 = lshr i64 %57, 16
%59 = call i32 @putchar(i64 %58)
%60 = load i64, i64* %8
%61 = urem i64 %60, 65536
%62 = lshr i64 %61, 8
%63 = call i32 @putchar(i64 %62)
%64 = load i64, i64* %8
%65 = urem i64 %64, 256
%66 = call i32 @putchar(i64 %65)
%67 = load i8*, i8** %7
%68 = call i32 @free(i8* %67)
%69 = load i32, i32* %6
%70 = call i32 @close(i32 %69)
ret i32 0
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@.str.1 = [15 x i8] c"Open %s Error!\00"
@stderr = global i32 0
@.str.3 = [31 x i8] c"crc32 checksum of %s is :%08x\0A\00"
@str.4 = [13 x i8] c"malloc error\00"
@str.5 = [32 x i8] c"a single argument is required !\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.5, i64 0, i64 0))
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = load i32, i32* @O_RDONLY
%11 = tail call i32 @open(i8* %9, i32 %10)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %17
13: ; preds = %7
%14 = load i8*, i8** %8
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %7
%18 = tail call i64 @malloc(i32 2097152)
%19 = inttoptr i64 %18 to i8*
%20 = icmp eq i64 %18, 0
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.4, i64 0, i64 0))
%23 = tail call i32 @exit(i32 1)
unreachable
24: ; preds = %17
%25 = tail call i32 @memset(i8* %19, i32 0, i32 2097152)
%26 = tail call i32 @read(i32 %11, i8* %19, i32 2097152)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %31
28: ; preds = %24
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.4, i64 0, i64 0))
%30 = tail call i32 @exit(i32 1)
unreachable
31: ; preds = %24
%32 = tail call i64 @crc32(i32 0, i8* %19, i32 2097152)
%33 = load i32, i32* @stderr
%34 = load i8*, i8** %8
%35 = tail call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i8* %34, i64 %32)
%36 = lshr i64 %32, 24
%37 = tail call i32 @putchar(i64 %36)
%38 = lshr i64 %32, 16
%39 = and i64 %38, 255
%40 = tail call i32 @putchar(i64 %39)
%41 = lshr i64 %32, 8
%42 = and i64 %41, 255
%43 = tail call i32 @putchar(i64 %42)
%44 = and i64 %32, 255
%45 = tail call i32 @putchar(i64 %44)
%46 = tail call i32 @free(i8* %19)
%47 = tail call i32 @close(i32 %11)
ret i32 0
}