#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*/ uint64_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fread(unsigned char *, size_t, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(unsigned char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
size_t ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ getCrc64(int, unsigned char *, size_t);
scalar_t__ malloc(size_t);
uint64_t crc64(const char *filename) {
  unsigned char *buf = 0;
  size_t size = 0;
  uint64_t res = 0;
  const char *fname = filename;
  FILE *fileptr = fopen(fname, "rb");
  if (fileptr == NULL) {
    return 0;
  }
  fseek(fileptr, 0, SEEK_END);
  size = ftell(fileptr);
  fseek(fileptr, 0, SEEK_SET);
  buf = (unsigned char *)malloc(size);
  fread(buf, size, 1, fileptr);
  res = getCrc64((0xffffffffULL), buf, size);
  free(buf);
  return res;
}


x86 assembly (clang, -O0):
<crc64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xe5a(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11c6 <crc64+0x56>
movl   $0x0,-0x4(%rbp)
jmp    1242 <crc64+0xd2>
mov    -0x38(%rbp),%rdi
mov    0x2e17(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
mov    -0x38(%rbp),%rdi
call   1060 <ftell@plt>
mov    %rax,-0x20(%rbp)
mov    -0x38(%rbp),%rdi
mov    0x2de6(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
mov    -0x20(%rbp),%rdi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x38(%rbp),%rcx
mov    $0x1,%edx
call   1040 <fread@plt>
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    $0xffffffff,%edi
call   1050 <getCrc64@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<crc64>:
push   %r15
push   %r14
push   %rbx
lea    0xe84(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     11f6 <crc64+0x86>
mov    %rax,%rbx
mov    0x2e58(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    %rbx,%rdi
call   1060 <ftell@plt>
mov    %rax,%r14
mov    0x2e2a(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    %r14,%rdi
call   1070 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r14,%rsi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
mov    $0xffffffff,%edi
mov    %r15,%rsi
mov    %r14,%rdx
call   1050 <getCrc64@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1030 <free@plt>
mov    %ebx,%eax
jmp    11f8 <crc64+0x88>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i32 @crc64(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32*
store i8* %0, i8** %3
store i8* null, i8** %4
store i64 0, i64* %5
store i32 0, i32* %6
%9 = load i8*, i8** %3
store i8* %9, i8** %7
%10 = load i8*, i8** %7
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %8
%12 = load i32*, i32** %8
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %15
14: ; preds = %1
store i32 0, i32* %2
br label %37
15: ; preds = %1
%16 = load i32*, i32** %8
%17 = load i32, i32* @SEEK_END
%18 = call i32 @fseek(i32* %16, i32 0, i32 %17)
%19 = load i32*, i32** %8
%20 = call i64 @ftell(i32* %19)
store i64 %20, i64* %5
%21 = load i32*, i32** %8
%22 = load i32, i32* @SEEK_SET
%23 = call i32 @fseek(i32* %21, i32 0, i32 %22)
%24 = load i64, i64* %5
%25 = call i64 @malloc(i64 %24)
%26 = inttoptr i64 %25 to i8*
store i8* %26, i8** %4
%27 = load i8*, i8** %4
%28 = load i64, i64* %5
%29 = load i32*, i32** %8
%30 = call i32 @fread(i8* %27, i64 %28, i32 1, i32* %29)
%31 = load i8*, i8** %4
%32 = load i64, i64* %5
%33 = call i32 @getCrc64(i32 -1, i8* %31, i64 %32)
store i32 %33, i32* %6
%34 = load i8*, i8** %4
%35 = call i32 @free(i8* %34)
%36 = load i32, i32* %6
store i32 %36, i32* %2
br label %37
37: ; preds = %15, %14
%38 = load i32, i32* %2
ret i32 %38
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i32 @crc64(i8* nocapture %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %15, label %4
4: ; preds = %1
%5 = load i32, i32* @SEEK_END
%6 = tail call i32 @fseek(i32* %2, i32 0, i32 %5)
%7 = tail call i64 @ftell(i32* %2)
%8 = load i32, i32* @SEEK_SET
%9 = tail call i32 @fseek(i32* %2, i32 0, i32 %8)
%10 = tail call i64 @malloc(i64 %7)
%11 = inttoptr i64 %10 to i8*
%12 = tail call i32 @fread(i8* %11, i64 %7, i32 1, i32* %2)
%13 = tail call i32 @getCrc64(i32 -1, i8* %11, i64 %7)
%14 = tail call i32 @free(i8* %11)
br label %15
15: ; preds = %1, %4
%16 = phi i32 [ %13, %4 ], [ 0, %1 ]
ret i32 %16
}