#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 /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *);
unsigned char *load_model() {
  FILE *modelfile = fopen("model1.stl", "rb");
  if (modelfile == NULL) {
    printf("couldn't open modelfile\n");
    return NULL;
  }
  fseek(modelfile, 0, SEEK_END);
  int modelfile_bytes = ftell(modelfile);
  fseek(modelfile, 0, SEEK_SET);
  unsigned char *model = (unsigned char *)malloc(modelfile_bytes);
  fread(model, 1, modelfile_bytes, modelfile);
  return model;
}


x86 assembly (clang, -O0):
<load_model>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xe91(%rip),%rdi
lea    0xe95(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a3 <load_model+0x43>
lea    0xe7d(%rip),%rdi
call   1040 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1200 <load_model+0xa0>
mov    -0x10(%rbp),%rdi
mov    0x2e3a(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1070 <fseek@plt>
mov    -0x10(%rbp),%rdi
call   1050 <ftell@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e0a(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1070 <fseek@plt>
mov    -0x14(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_model>:
push   %rbp
push   %r14
push   %rbx
lea    0xe95(%rip),%rdi
lea    0xe99(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11cd <load_model+0x6d>
mov    %rax,%rbx
mov    0x2e62(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1070 <fseek@plt>
mov    %rbx,%rdi
call   1050 <ftell@plt>
mov    %eax,%ebp
mov    0x2e35(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1070 <fseek@plt>
mov    %ebp,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    $0x1,%esi
mov    %ebp,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
jmp    11dc <load_model+0x7c>
lea    0xe3a(%rip),%rdi
call   1030 <puts@plt>
xor    %r14d,%r14d
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"model1.stl\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [25 x i8] c"couldn't open modelfile\0A\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i8* @load_model() {
%1 = alloca i8*
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i8*
%5 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %2
%6 = load i32*, i32** %2
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
store i8* null, i8** %1
br label %27
10: ; preds = %0
%11 = load i32*, i32** %2
%12 = load i32, i32* @SEEK_END
%13 = call i32 @fseek(i32* %11, i32 0, i32 %12)
%14 = load i32*, i32** %2
%15 = call i32 @ftell(i32* %14)
store i32 %15, i32* %3
%16 = load i32*, i32** %2
%17 = load i32, i32* @SEEK_SET
%18 = call i32 @fseek(i32* %16, i32 0, i32 %17)
%19 = load i32, i32* %3
%20 = call i64 @malloc(i32 %19)
%21 = inttoptr i64 %20 to i8*
store i8* %21, i8** %4
%22 = load i8*, i8** %4
%23 = load i32, i32* %3
%24 = load i32*, i32** %2
%25 = call i32 @fread(i8* %22, i32 1, i32 %23, i32* %24)
%26 = load i8*, i8** %4
store i8* %26, i8** %1
br label %27
27: ; preds = %10, %8
%28 = load i8*, i8** %1
ret i8* %28
}

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