#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 int CRC32_Update(unsigned int, unsigned char *, size_t);
int feof(int /*<<< orphan*/ *);
size_t fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int CRC32_FromFile(FILE *f, unsigned int *result) {
  unsigned char buf[0x400];
  unsigned int crc = 0xffffffff;
  for (;;) {
    size_t len = fread(buf, 1, 0x400, f);
    crc = CRC32_Update(crc, buf, len);
    if (len < 0x400)
      break;
  }
  *result = ~crc;
  return feof(f);
}


x86 assembly (clang, -O0):
<CRC32_FromFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x414(%rbp)
ff ff ff
lea    -0x410(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
mov    $0x400,%edx
call   1030 <fread@plt>
mov    %rax,-0x420(%rbp)
mov    -0x414(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    -0x420(%rbp),%rdx
call   1050 <CRC32_Update@plt>
mov    %eax,-0x414(%rbp)
cmpq   $0x400,-0x420(%rbp)
jae    11a3 <CRC32_FromFile+0x73>
jmp    11a8 <CRC32_FromFile+0x78>
jmp    114d <CRC32_FromFile+0x1d>
mov    -0x414(%rbp),%ecx
xor    $0xffffffff,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rdi
call   1040 <feof@plt>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CRC32_FromFile>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x400,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0xffffffff,%ebp
mov    %rsp,%r12
nopl   (%rax)
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x400,%edx
mov    %r15,%rcx
call   1030 <fread@plt>
mov    %rax,%rbx
mov    %ebp,%edi
mov    %r12,%rsi
mov    %rax,%rdx
call   1050 <CRC32_Update@plt>
mov    %eax,%ebp
cmp    $0x3ff,%rbx
ja     1150 <CRC32_FromFile+0x20>
not    %ebp
mov    %ebp,(%r14)
mov    %r15,%rdi
call   1040 <feof@plt>
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @CRC32_FromFile(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca [1024 x i8]
%6 = alloca i32
%7 = alloca i64
store i32* %0, i32** %3
store i32* %1, i32** %4
store i32 -1, i32* %6
br label %8
8: ; preds = %19, %2
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%10 = load i32*, i32** %3
%11 = call i64 @fread(i8* %9, i32 1, i32 1024, i32* %10)
store i64 %11, i64* %7
%12 = load i32, i32* %6
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%14 = load i64, i64* %7
%15 = call i32 @CRC32_Update(i32 %12, i8* %13, i64 %14)
store i32 %15, i32* %6
%16 = load i64, i64* %7
%17 = icmp ult i64 %16, 1024
br i1 %17, label %18, label %19
18: ; preds = %8
br label %20
19: ; preds = %8
br label %8
20: ; preds = %18
%21 = load i32, i32* %6
%22 = xor i32 %21, -1
%23 = load i32*, i32** %4
store i32 %22, i32* %23
%24 = load i32*, i32** %3
%25 = call i32 @feof(i32* %24)
ret i32 %25
}

LLVM IR (-O2):
define i32 @CRC32_FromFile(i32* nocapture %0, i32* nocapture writeonly %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
br label %5
5: ; preds = %5, %2
%6 = phi i32 [ -1, %2 ], [ %8, %5 ]
%7 = call i64 @fread(i8* %4, i32 1, i32 1024, i32* %0)
%8 = call i32 @CRC32_Update(i32 %6, i8* %4, i64 %7)
%9 = icmp ult i64 %7, 1024
br i1 %9, label %10, label %5
10: ; preds = %5
%11 = xor i32 %8, -1
store i32 %11, i32* %1
%12 = call i32 @feof(i32* %0)
ret i32 %12
}