#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 */
struct vsofont {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(unsigned char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
unsigned char *malloc(int);
int /*<<< orphan*/ stderr;
int vsofont_read_font_from_memory(unsigned char *, struct vsofont **);
int vsofont_read_font_from_file(char *name, struct vsofont **font) {
  unsigned char *c;
  FILE *f;
  int i;
  if (name == NULL || font == NULL)
    return 0;
  f = fopen(name, "rb");
  if (f == NULL) {
    fprintf(stderr,
            "VSOFONT_READ_FONT_FROM_FILE: Could not open file \"%s\".\n", name);
    return 0;
  }
  fseek(f, 0, SEEK_END);
  i = ftell(f);
  fseek(f, 0, SEEK_SET);
  c = malloc(i + 1);
  if (c == NULL) {
    fprintf(stderr, "VSOFONT_READ_FONT_FROM_FILE: Out of memory error.\n");
    fclose(f);
    return 0;
  }
  fread(c, 1, i, f);
  fclose(f);
  c[i] = 0;
  i = vsofont_read_font_from_memory(c, font);
  free(c);
  return i;
}


x86 assembly (clang, -O0):
<vsofont_read_font_from_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11b6 <vsofont_read_font_from_file+0x26>
cmpq   $0x0,-0x18(%rbp)
jne    11c2 <vsofont_read_font_from_file+0x32>
movl   $0x0,-0x4(%rbp)
jmp    12cb <vsofont_read_font_from_file+0x13b>
mov    -0x10(%rbp),%rdi
lea    0xe33(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1208 <vsofont_read_font_from_file+0x78>
mov    0x2df0(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe0e(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12cb <vsofont_read_font_from_file+0x13b>
mov    -0x28(%rbp),%rdi
mov    0x2dd5(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
mov    -0x28(%rbp),%rdi
call   1070 <ftell@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
mov    0x2d9d(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
mov    -0x2c(%rbp),%edi
add    $0x1,%edi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1282 <vsofont_read_font_from_file+0xf2>
mov    0x2d7b(%rip),%rax
mov    (%rax),%edi
lea    0xdd5(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    12cb <vsofont_read_font_from_file+0x13b>
mov    -0x20(%rbp),%rdi
mov    -0x2c(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10a0 <vsofont_read_font_from_memory@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vsofont_read_font_from_file>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %rdi,%rdi
je     1280 <vsofont_read_font_from_file+0xf0>
mov    %rsi,%r14
test   %rsi,%rsi
je     1280 <vsofont_read_font_from_file+0xf0>
mov    %rdi,%rbx
lea    0xe49(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     1245 <vsofont_read_font_from_file+0xb5>
mov    %rax,%r12
mov    0x2e19(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    %r12,%rdi
call   1070 <ftell@plt>
mov    %eax,%r15d
mov    0x2de3(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
lea    0x1(%r15),%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     1261 <vsofont_read_font_from_file+0xd1>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x1,%esi
mov    %r15d,%edx
mov    %r12,%rcx
call   1040 <fread@plt>
mov    %r12,%rdi
call   1050 <fclose@plt>
movslq %r15d,%rax
movb   $0x0,(%rbx,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
call   10a0 <vsofont_read_font_from_memory@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
jmp    1282 <vsofont_read_font_from_file+0xf2>
mov    0x2d8c(%rip),%rax
mov    (%rax),%edi
lea    0xdae(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    1280 <vsofont_read_font_from_file+0xf0>
mov    0x2d70(%rip),%rax
mov    (%rax),%edi
lea    0xdca(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %r12,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.vsofont = type { i32 }
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [56 x i8] c"VSOFONT_READ_FONT_FROM_FILE: Could not open file \22%s\22.\0A\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.2 = [51 x i8] c"VSOFONT_READ_FONT_FROM_FILE: Out of memory error.\0A\00"
define i32 @vsofont_read_font_from_file(i8* %0, %struct.vsofont** %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca %struct.vsofont**
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32
store i8* %0, i8** %4
store %struct.vsofont** %1, %struct.vsofont*** %5
%9 = load i8*, i8** %4
%10 = icmp eq i8* %9, null
br i1 %10, label %14, label %11
11: ; preds = %2
%12 = load %struct.vsofont**, %struct.vsofont*** %5
%13 = icmp eq %struct.vsofont** %12, null
br i1 %13, label %14, label %15
14: ; preds = %11, %2
store i32 0, i32* %3
br label %60
15: ; preds = %11
%16 = load i8*, i8** %4
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %17, i32** %7
%18 = load i32*, i32** %7
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %24
20: ; preds = %15
%21 = load i32, i32* @stderr
%22 = load i8*, i8** %4
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0), i8* %22)
store i32 0, i32* %3
br label %60
24: ; preds = %15
%25 = load i32*, i32** %7
%26 = load i32, i32* @SEEK_END
%27 = call i32 @fseek(i32* %25, i32 0, i32 %26)
%28 = load i32*, i32** %7
%29 = call i32 @ftell(i32* %28)
store i32 %29, i32* %8
%30 = load i32*, i32** %7
%31 = load i32, i32* @SEEK_SET
%32 = call i32 @fseek(i32* %30, i32 0, i32 %31)
%33 = load i32, i32* %8
%34 = add nsw i32 %33, 1
%35 = call i8* @malloc(i32 %34)
store i8* %35, i8** %6
%36 = load i8*, i8** %6
%37 = icmp eq i8* %36, null
br i1 %37, label %38, label %43
38: ; preds = %24
%39 = load i32, i32* @stderr
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0))
%41 = load i32*, i32** %7
%42 = call i32 @fclose(i32* %41)
store i32 0, i32* %3
br label %60
43: ; preds = %24
%44 = load i8*, i8** %6
%45 = load i32, i32* %8
%46 = load i32*, i32** %7
%47 = call i32 @fread(i8* %44, i32 1, i32 %45, i32* %46)
%48 = load i32*, i32** %7
%49 = call i32 @fclose(i32* %48)
%50 = load i8*, i8** %6
%51 = load i32, i32* %8
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %50, i64 %52
store i8 0, i8* %53
%54 = load i8*, i8** %6
%55 = load %struct.vsofont**, %struct.vsofont*** %5
%56 = call i32 @vsofont_read_font_from_memory(i8* %54, %struct.vsofont** %55)
store i32 %56, i32* %8
%57 = load i8*, i8** %6
%58 = call i32 @free(i8* %57)
%59 = load i32, i32* %8
store i32 %59, i32* %3
br label %60
60: ; preds = %43, %38, %20, %14
%61 = load i32, i32* %3
ret i32 %61
}

LLVM IR (-O2):
%struct.vsofont = type { i32 }
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [56 x i8] c"VSOFONT_READ_FONT_FROM_FILE: Could not open file \22%s\22.\0A\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.2 = [51 x i8] c"VSOFONT_READ_FONT_FROM_FILE: Out of memory error.\0A\00"
define i32 @vsofont_read_font_from_file(i8* %0, %struct.vsofont** %1) {
%3 = icmp eq i8* %0, null
%4 = icmp eq %struct.vsofont** %1, null
%5 = or i1 %3, %4
br i1 %5, label %32, label %6
6: ; preds = %2
%7 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %12
9: ; preds = %6
%10 = load i32, i32* @stderr
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %32
12: ; preds = %6
%13 = load i32, i32* @SEEK_END
%14 = tail call i32 @fseek(i32* %7, i32 0, i32 %13)
%15 = tail call i32 @ftell(i32* %7)
%16 = load i32, i32* @SEEK_SET
%17 = tail call i32 @fseek(i32* %7, i32 0, i32 %16)
%18 = add nsw i32 %15, 1
%19 = tail call i8* @malloc(i32 %18)
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %25
21: ; preds = %12
%22 = load i32, i32* @stderr
%23 = tail call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0))
%24 = tail call i32 @fclose(i32* %7)
br label %32
25: ; preds = %12
%26 = tail call i32 @fread(i8* %19, i32 1, i32 %15, i32* %7)
%27 = tail call i32 @fclose(i32* %7)
%28 = sext i32 %15 to i64
%29 = getelementptr inbounds i8, i8* %19, i64 %28
store i8 0, i8* %29
%30 = tail call i32 @vsofont_read_font_from_memory(i8* %19, %struct.vsofont** %1)
%31 = tail call i32 @free(i8* %19)
br label %32
32: ; preds = %2, %25, %21, %9
%33 = phi i32 [ 0, %9 ], [ 0, %21 ], [ %30, %25 ], [ 0, %2 ]
ret i32 %33
}