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

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
struct apesq_entry_st *apesq_parse_string(char *, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
char *malloc(int);
struct apesq_entry_st *apesq_parse_file(const char *path) {
  FILE *fp;
  int fsz;
  char *buf;
  struct apesq_entry_st *ret;
  if (!path) {
    return NULL;
  }
  fp = fopen(path, "r");
  if (!fp) {
    return NULL;
  }
  fseek(fp, 0L, SEEK_END);
  fsz = ftell(fp);
  if (fsz < 1) {
    fclose(fp);
    return NULL;
  }
  fseek(fp, 0L, SEEK_SET);
  buf = malloc(fsz + 1);
  buf[fsz] = '\0';
  if (fread(buf, 1, fsz, fp) == -1) {
    fclose(fp);
    return NULL;
  }
  fclose(fp);
  ret = apesq_parse_string(buf, fsz);
  free(buf);
  return ret;
}


x86 assembly (clang, -O0):
<apesq_parse_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a4 <apesq_parse_file+0x24>
movq   $0x0,-0x8(%rbp)
jmp    12a1 <apesq_parse_file+0x121>
mov    -0x10(%rbp),%rdi
lea    0xe51(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11d0 <apesq_parse_file+0x50>
movq   $0x0,-0x8(%rbp)
jmp    12a1 <apesq_parse_file+0x121>
mov    -0x18(%rbp),%rdi
mov    0x2e0d(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1090 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1060 <ftell@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
jge    1212 <apesq_parse_file+0x92>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
movq   $0x0,-0x8(%rbp)
jmp    12a1 <apesq_parse_file+0x121>
mov    -0x18(%rbp),%rdi
mov    0x2dbb(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1090 <fseek@plt>
mov    -0x1c(%rbp),%edi
add    $0x1,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
cmp    $0xffffffff,%eax
jne    1277 <apesq_parse_file+0xf7>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
movq   $0x0,-0x8(%rbp)
jmp    12a1 <apesq_parse_file+0x121>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1080 <apesq_parse_string@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<apesq_parse_file>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1236 <apesq_parse_file+0xb6>
lea    0xe69(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1236 <apesq_parse_file+0xb6>
mov    %rax,%rbx
mov    0x2e39(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    %rbx,%rdi
call   1060 <ftell@plt>
test   %eax,%eax
jle    122e <apesq_parse_file+0xae>
mov    %eax,%r14d
mov    0x2e07(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
lea    0x1(%r14),%edi
call   1070 <malloc@plt>
mov    %rax,%r15
mov    %r14d,%eax
movb   $0x0,(%r15,%rax,1)
mov    %r15,%rdi
mov    $0x1,%esi
mov    %r14d,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1050 <fclose@plt>
cmp    $0xffffffff,%ebp
je     1236 <apesq_parse_file+0xb6>
mov    %r15,%rdi
mov    %r14d,%esi
call   1080 <apesq_parse_string@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
jmp    1238 <apesq_parse_file+0xb8>
mov    %rbx,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.apesq_entry_st = type { i32 }
@.str = [2 x i8] c"r\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define %struct.apesq_entry_st* @apesq_parse_file(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %26, label %3
3: ; preds = %1
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %26, label %6
6: ; preds = %3
%7 = load i32, i32* @SEEK_END
%8 = tail call i32 @fseek(i32* %4, i64 0, i32 %7)
%9 = tail call i32 @ftell(i32* %4)
%10 = icmp slt i32 %9, 1
br i1 %10, label %11, label %13
11: ; preds = %6
%12 = tail call i32 @fclose(i32* %4)
br label %26
13: ; preds = %6
%14 = load i32, i32* @SEEK_SET
%15 = tail call i32 @fseek(i32* %4, i64 0, i32 %14)
%16 = add nuw nsw i32 %9, 1
%17 = tail call i8* @malloc(i32 %16)
%18 = zext i32 %9 to i64
%19 = getelementptr inbounds i8, i8* %17, i64 %18
store i8 0, i8* %19
%20 = tail call i32 @fread(i8* %17, i32 1, i32 %9, i32* %4)
%21 = icmp eq i32 %20, -1
%22 = tail call i32 @fclose(i32* %4)
br i1 %21, label %26, label %23
23: ; preds = %13
%24 = tail call %struct.apesq_entry_st* @apesq_parse_string(i8* %17, i32 %9)
%25 = tail call i32 @free(i8* %17)
br label %26
26: ; preds = %13, %3, %1, %23, %11
%27 = phi %struct.apesq_entry_st* [ null, %11 ], [ %24, %23 ], [ null, %1 ], [ null, %3 ], [ null, %13 ]
ret %struct.apesq_entry_st* %27
}