#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 Crc32_ComputeFile(int /*<<< orphan*/ *, unsigned long *);
int EOF;
int /*<<< orphan*/ exit(int);
int fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ printf(char *, unsigned long, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
int crcmain(int argc, const char *argv[]) {
  FILE *file = NULL;
  const char *filename;
  int argIdx;
  unsigned long crc32;
  int err;
  if (argc < 2) {
    err = Crc32_ComputeFile(stdin, &crc32);
    if (err == -1)
      goto ERR_EXIT;
    printf("crc32 = 0x%08lX for (stdin)\n", crc32);
  } else {
    for (argIdx = 1; argIdx < argc; argIdx++) {
      filename = argv[argIdx];
      file = fopen(filename, "rb");
      if (file == NULL) {
        fprintf(stderr, "error opening file \"%s\"!\n", filename);
        goto ERR_EXIT;
      }
      err = Crc32_ComputeFile(file, &crc32);
      if (err == -1)
        goto ERR_EXIT;
      printf("crc32 = 0x%08lX for \"%s\"\n", crc32, filename);
      err = fclose(file);
      file = NULL;
      if (err == EOF) {
        fprintf(stderr, "error closing file \"%s\"!\n", filename);
        goto ERR_EXIT;
      }
    }
  }
  return (0);
ERR_EXIT:
  if (file != NULL)
    fclose(file);
  exit(1);
}


x86 assembly (clang, -O0):
<crcmain>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpl   $0x2,-0x4(%rbp)
jge    11bd <crcmain+0x5d>
mov    0x2e60(%rip),%rax
mov    (%rax),%rdi
lea    -0x30(%rbp),%rsi
call   1030 <Crc32_ComputeFile@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0xffffffff,-0x34(%rbp)
jne    11a6 <crcmain+0x46>
jmp    12b6 <crcmain+0x156>
mov    -0x30(%rbp),%rsi
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12ae <crcmain+0x14e>
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    12a9 <crcmain+0x149>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe32(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    121d <crcmain+0xbd>
mov    0x2dca(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xe0d(%rip),%rsi
call   1060 <fprintf@plt>
jmp    12b6 <crcmain+0x156>
mov    -0x18(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1030 <Crc32_ComputeFile@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0xffffffff,-0x34(%rbp)
jne    123c <crcmain+0xdc>
jmp    12b6 <crcmain+0x156>
mov    -0x30(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    0xdef(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    %eax,-0x34(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x34(%rbp),%eax
mov    0x2d70(%rip),%rcx
cmp    (%rcx),%eax
jne    1296 <crcmain+0x136>
mov    0x2d51(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xdc8(%rip),%rsi
call   1060 <fprintf@plt>
jmp    12b6 <crcmain+0x156>
jmp    129b <crcmain+0x13b>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11c4 <crcmain+0x64>
jmp    12ae <crcmain+0x14e>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret
cmpq   $0x0,-0x18(%rbp)
je     12ca <crcmain+0x16a>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<crcmain>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edi
jge    119f <crcmain+0x3f>
mov    0x2e71(%rip),%rax
mov    (%rax),%rdi
mov    %rsp,%rsi
call   1030 <Crc32_ComputeFile@plt>
cmp    $0xffffffff,%eax
je     1242 <crcmain+0xe2>
mov    (%rsp),%rsi
lea    0xe6a(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1217 <crcmain+0xb7>
mov    %rsi,%r12
mov    %edi,%r14d
mov    $0x1,%r15d
mov    0x2e2e(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%r12,%r15,8),%rbx
mov    %rbx,%rdi
lea    0xe4f(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1228 <crcmain+0xc8>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %rsp,%rsi
call   1030 <Crc32_ComputeFile@plt>
cmp    $0xffffffff,%eax
je     123a <crcmain+0xda>
mov    (%rsp),%rsi
lea    0xe44(%rip),%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbp,%rdi
call   1040 <fclose@plt>
cmp    0x0(%r13),%eax
je     124c <crcmain+0xec>
add    $0x1,%r15
cmp    %r15,%r14
jne    11c0 <crcmain+0x60>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2da1(%rip),%rax
mov    (%rax),%edi
lea    0xde8(%rip),%rsi
jmp    125c <crcmain+0xfc>
mov    %rbp,%rdi
call   1040 <fclose@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x2d7d(%rip),%rax
mov    (%rax),%edi
lea    0xdf8(%rip),%rsi
mov    %rbx,%rdx
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stdin = global i32* null
@.str = [29 x i8] c"crc32 = 0x%08lX for (stdin)\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.2 = [26 x i8] c"error opening file \22%s\22!\0A\00"
@.str.3 = [26 x i8] c"crc32 = 0x%08lX for \22%s\22\0A\00"
@EOF = global i32 0
@.str.4 = [26 x i8] c"error closing file \22%s\22!\0A\00"
define i32 @crcmain(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i64
%9 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
store i32* null, i32** %5
%10 = load i32, i32* %3
%11 = icmp slt i32 %10, 2
br i1 %11, label %12, label %21
12: ; preds = %2
%13 = load i32*, i32** @stdin
%14 = call i32 @Crc32_ComputeFile(i32* %13, i64* %8)
store i32 %14, i32* %9
%15 = load i32, i32* %9
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %18
17: ; preds = %12
br label %65
18: ; preds = %12
%19 = load i64, i64* %8
%20 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i64 %19)
br label %64
21: ; preds = %2
store i32 1, i32* %7
br label %22
22: ; preds = %60, %21
%23 = load i32, i32* %7
%24 = load i32, i32* %3
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %63
26: ; preds = %22
%27 = load i8**, i8*** %4
%28 = load i32, i32* %7
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8*, i8** %27, i64 %29
%31 = load i8*, i8** %30
store i8* %31, i8** %6
%32 = load i8*, i8** %6
%33 = call i32* @fopen(i8* %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %33, i32** %5
%34 = load i32*, i32** %5
%35 = icmp eq i32* %34, null
br i1 %35, label %36, label %40
36: ; preds = %26
%37 = load i32, i32* @stderr
%38 = load i8*, i8** %6
%39 = call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %38)
br label %65
40: ; preds = %26
%41 = load i32*, i32** %5
%42 = call i32 @Crc32_ComputeFile(i32* %41, i64* %8)
store i32 %42, i32* %9
%43 = load i32, i32* %9
%44 = icmp eq i32 %43, -1
br i1 %44, label %45, label %46
45: ; preds = %40
br label %65
46: ; preds = %40
%47 = load i64, i64* %8
%48 = load i8*, i8** %6
%49 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i64 %47, i8* %48)
%50 = load i32*, i32** %5
%51 = call i32 @fclose(i32* %50)
store i32 %51, i32* %9
store i32* null, i32** %5
%52 = load i32, i32* %9
%53 = load i32, i32* @EOF
%54 = icmp eq i32 %52, %53
br i1 %54, label %55, label %59
55: ; preds = %46
%56 = load i32, i32* @stderr
%57 = load i8*, i8** %6
%58 = call i32 @fprintf(i32 %56, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i8* %57)
br label %65
59: ; preds = %46
br label %60
60: ; preds = %59
%61 = load i32, i32* %7
%62 = add nsw i32 %61, 1
store i32 %62, i32* %7
br label %22
63: ; preds = %22
br label %64
64: ; preds = %63, %18
ret i32 0
65: ; preds = %55, %45, %36, %17
%66 = load i32*, i32** %5
%67 = icmp ne i32* %66, null
br i1 %67, label %68, label %71
68: ; preds = %65
%69 = load i32*, i32** %5
%70 = call i32 @fclose(i32* %69)
br label %71
71: ; preds = %68, %65
%72 = call i32 @exit(i32 1)
unreachable
}

LLVM IR (-O2):
@stdin = global i32* null
@.str = [29 x i8] c"crc32 = 0x%08lX for (stdin)\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.2 = [26 x i8] c"error opening file \22%s\22!\0A\00"
@.str.3 = [26 x i8] c"crc32 = 0x%08lX for \22%s\22\0A\00"
@EOF = global i32 0
@.str.4 = [26 x i8] c"error closing file \22%s\22!\0A\00"
define i32 @crcmain(i32 %0, i8** nocapture %1) {
%3 = alloca i64
%4 = bitcast i64* %3 to i8*
%5 = icmp slt i32 %0, 2
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = zext i32 %0 to i64
br label %17
8: ; preds = %2
%9 = load i32*, i32** @stdin
%10 = call i32 @Crc32_ComputeFile(i32* %9, i64* %3)
%11 = icmp eq i32 %10, -1
br i1 %11, label %42, label %12
12: ; preds = %8
%13 = load i64, i64* %3
%14 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i64 %13)
br label %39
15: ; preds = %29
%16 = icmp eq i64 %35, %7
br i1 %16, label %39, label %17
17: ; preds = %6, %15
%18 = phi i64 [ 1, %6 ], [ %35, %15 ]
%19 = getelementptr inbounds i8*, i8** %1, i64 %18
%20 = load i8*, i8** %19
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %26
23: ; preds = %17
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %20)
br label %42
26: ; preds = %17
%27 = call i32 @Crc32_ComputeFile(i32* %21, i64* %3)
%28 = icmp eq i32 %27, -1
br i1 %28, label %40, label %29
29: ; preds = %26
%30 = load i64, i64* %3
%31 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i64 %30, i8* %20)
%32 = call i32 @fclose(i32* %21)
%33 = load i32, i32* @EOF
%34 = icmp eq i32 %32, %33
%35 = add nuw nsw i64 %18, 1
br i1 %34, label %36, label %15
36: ; preds = %29
%37 = load i32, i32* @stderr
%38 = call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i8* %20)
br label %42
39: ; preds = %15, %12
ret i32 0
40: ; preds = %26
%41 = call i32 @fclose(i32* %21)
br label %42
42: ; preds = %36, %23, %8, %40
%43 = call i32 @exit(i32 1)
unreachable
}