#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 */
unsigned long Crc32_ComputeBuf(unsigned long, unsigned char *, size_t);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
size_t fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int Crc32_ComputeFile(FILE *file, unsigned long *outCrc32) {
  unsigned char buf[8192];
  size_t bufLen;
  *outCrc32 = 0;
  while (1) {
    bufLen = fread(buf, 1, 8192, file);
    if (bufLen == 0) {
      if (ferror(file)) {
        fprintf(stderr, "error reading file\n");
        goto ERR_EXIT;
      }
      break;
    }
    *outCrc32 = Crc32_ComputeBuf(*outCrc32, buf, bufLen);
  }
  return (0);
ERR_EXIT:
  return (-1);
}


x86 assembly (clang, -O0):
<Crc32_ComputeFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2030,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
lea    -0x2020(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x2000,%edx
call   1040 <fread@plt>
mov    %rax,-0x2028(%rbp)
cmpq   $0x0,-0x2028(%rbp)
jne    11bf <Crc32_ComputeFile+0x7f>
mov    -0x10(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     11ba <Crc32_ComputeFile+0x7a>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
lea    0xe50(%rip),%rsi
call   1050 <fprintf@plt>
jmp    11f4 <Crc32_ComputeFile+0xb4>
jmp    11e8 <Crc32_ComputeFile+0xa8>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
lea    -0x2020(%rbp),%rsi
mov    -0x2028(%rbp),%rdx
call   1060 <Crc32_ComputeBuf@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
jmp    115e <Crc32_ComputeFile+0x1e>
movl   $0x0,-0x4(%rbp)
jmp    11fb <Crc32_ComputeFile+0xbb>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Crc32_ComputeFile>:
push   %r15
push   %r14
push   %rbx
sub    $0x2000,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
movq   $0x0,(%rsi)
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x2000,%edx
mov    %r14,%rcx
call   1040 <fread@plt>
test   %rax,%rax
je     11ab <Crc32_ComputeFile+0x6b>
mov    %rsp,%r15
cs nopw 0x0(%rax,%rax,1)
mov    (%rbx),%rdi
mov    %r15,%rsi
mov    %rax,%rdx
call   1060 <Crc32_ComputeBuf@plt>
mov    %rax,(%rbx)
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x2000,%edx
mov    %r14,%rcx
call   1040 <fread@plt>
test   %rax,%rax
jne    1180 <Crc32_ComputeFile+0x40>
mov    %r14,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
je     11d4 <Crc32_ComputeFile+0x94>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
lea    0xe38(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    11d6 <Crc32_ComputeFile+0x96>
xor    %eax,%eax
add    $0x2000,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [20 x i8] c"error reading file\0A\00"
define i32 @Crc32_ComputeFile(i32* %0, i64* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i64*
%6 = alloca [8192 x i8]
%7 = alloca i64
store i32* %0, i32** %4
store i64* %1, i64** %5
%8 = load i64*, i64** %5
store i64 0, i64* %8
br label %9
9: ; preds = %2, %23
%10 = getelementptr inbounds [8192 x i8], [8192 x i8]* %6, i64 0, i64 0
%11 = load i32*, i32** %4
%12 = call i64 @fread(i8* %10, i32 1, i32 8192, i32* %11)
store i64 %12, i64* %7
%13 = load i64, i64* %7
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %23
15: ; preds = %9
%16 = load i32*, i32** %4
%17 = call i64 @ferror(i32* %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %15
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %31
22: ; preds = %15
br label %30
23: ; preds = %9
%24 = load i64*, i64** %5
%25 = load i64, i64* %24
%26 = getelementptr inbounds [8192 x i8], [8192 x i8]* %6, i64 0, i64 0
%27 = load i64, i64* %7
%28 = call i64 @Crc32_ComputeBuf(i64 %25, i8* %26, i64 %27)
%29 = load i64*, i64** %5
store i64 %28, i64* %29
br label %9
30: ; preds = %22
store i32 0, i32* %3
br label %32
31: ; preds = %19
store i32 -1, i32* %3
br label %32
32: ; preds = %31, %30
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [20 x i8] c"error reading file\0A\00"
define i32 @Crc32_ComputeFile(i32* nocapture %0, i64* nocapture %1) {
%3 = alloca [8192 x i8]
%4 = getelementptr inbounds [8192 x i8], [8192 x i8]* %3, i64 0, i64 0
store i64 0, i64* %1
%5 = call i64 @fread(i8* %4, i32 1, i32 8192, i32* %0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %13
7: ; preds = %13, %2
%8 = call i64 @ferror(i32* %0)
%9 = icmp eq i64 %8, 0
br i1 %9, label %19, label %10
10: ; preds = %7
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %19
13: ; preds = %2, %13
%14 = phi i64 [ %17, %13 ], [ %5, %2 ]
%15 = load i64, i64* %1
%16 = call i64 @Crc32_ComputeBuf(i64 %15, i8* %4, i64 %14)
store i64 %16, i64* %1
%17 = call i64 @fread(i8* %4, i32 1, i32 8192, i32* %0)
%18 = icmp eq i64 %17, 0
br i1 %18, label %7, label %13
19: ; preds = %7, %10
%20 = phi i32 [ -1, %10 ], [ 0, %7 ]
ret i32 %20
}