#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*/ uint32_t;
struct stat {
  scalar_t__ st_size;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(char *, int, scalar_t__, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ get_buffer_crc(char *, scalar_t__);
char *malloc(scalar_t__);
int /*<<< orphan*/ stat(char *, struct stat *);
uint32_t get_file_crc(char *filename) {
  struct stat buf;
  stat(filename, &buf);
  char *filebuffer = malloc(buf.st_size + 10);
  FILE *fd = fopen(filename, "r");
  fread(filebuffer, 1, buf.st_size, fd);
  fclose(fd);
  uint32_t crc = get_buffer_crc(filebuffer, buf.st_size);
  free(filebuffer);
  return crc;
}


x86 assembly (clang, -O0):
<get_file_crc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1060 <stat@plt>
mov    -0x10(%rbp),%rdi
add    $0xa,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe5b(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1090 <get_buffer_crc@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_file_crc>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    %rsp,%rsi
call   1060 <stat@plt>
mov    (%rsp),%r15
lea    0xa(%r15),%rdi
call   1070 <malloc@plt>
mov    %rax,%r12
lea    0xe66(%rip),%rsi
mov    %r14,%rdi
call   1080 <fopen@plt>
mov    %rax,%rbx
mov    %r12,%rdi
mov    $0x1,%esi
mov    %r15,%rdx
mov    %rax,%rcx
call   1040 <fread@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    %r12,%rdi
mov    %r15,%rsi
call   1090 <get_buffer_crc@plt>
mov    %eax,%ebx
mov    %r12,%rdi
call   1030 <free@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.stat = type { i64 }
@.str = [2 x i8] c"r\00"
define i32 @get_file_crc(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.stat
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = call i32 @stat(i8* %7, %struct.stat* %3)
%9 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%10 = load i64, i64* %9
%11 = add nsw i64 %10, 10
%12 = call i8* @malloc(i64 %11)
store i8* %12, i8** %4
%13 = load i8*, i8** %2
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %14, i32** %5
%15 = load i8*, i8** %4
%16 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%17 = load i64, i64* %16
%18 = load i32*, i32** %5
%19 = call i32 @fread(i8* %15, i32 1, i64 %17, i32* %18)
%20 = load i32*, i32** %5
%21 = call i32 @fclose(i32* %20)
%22 = load i8*, i8** %4
%23 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%24 = load i64, i64* %23
%25 = call i32 @get_buffer_crc(i8* %22, i64 %24)
store i32 %25, i32* %6
%26 = load i8*, i8** %4
%27 = call i32 @free(i8* %26)
%28 = load i32, i32* %6
ret i32 %28
}

LLVM IR (-O2):
%struct.stat = type { i64 }
@.str = [2 x i8] c"r\00"
define i32 @get_file_crc(i8* nocapture %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = call i32 @stat(i8* %0, %struct.stat* %2)
%5 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%6 = load i64, i64* %5
%7 = add nsw i64 %6, 10
%8 = tail call i8* @malloc(i64 %7)
%9 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @fread(i8* %8, i32 1, i64 %6, i32* %9)
%11 = tail call i32 @fclose(i32* %9)
%12 = tail call i32 @get_buffer_crc(i8* %8, i64 %6)
%13 = tail call i32 @free(i8* %8)
ret i32 %12
}