#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*/ R_OK;
int /*<<< orphan*/ SEEK_END;
scalar_t__ access(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
scalar_t__ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/, int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
scalar_t__ malloc_mem(int);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int read_file(char **line_list, const char *file_name) {
  if (NULL == line_list || NULL == file_name) {
    return -1;
  }
  if (access(file_name, R_OK) != 0) {
    return -1;
  }
  FILE *fp = fopen(file_name, "r");
  if (NULL == fp) {
    return -1;
  }
  if (fseek(fp, 0, SEEK_END) != 0) {
    fclose(fp);
    return -1;
  }
  int len = ftell(fp);
  if (-1 == len) {
    fclose(fp);
    return -1;
  }
  rewind(fp);
  *line_list = (char *)malloc_mem(sizeof(char) * (len + 1));
  if (NULL == *line_list) {
    fclose(fp);
    return -1;
  }
  fread(*line_list, 1, len, fp);
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<read_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
je     11a8 <read_file+0x28>
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
jne    11b4 <read_file+0x34>
movl   $0xffffffff,-0x4(%rbp)
jmp    12dc <read_file+0x15c>
mov    -0x18(%rbp),%rdi
mov    0x2e19(%rip),%rax
mov    (%rax),%esi
call   1090 <access@plt>
cmp    $0x0,%rax
je     11dc <read_file+0x5c>
movl   $0xffffffff,-0x4(%rbp)
jmp    12dc <read_file+0x15c>
mov    -0x18(%rbp),%rdi
lea    0xe19(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmp    -0x20(%rbp),%rax
jne    1208 <read_file+0x88>
movl   $0xffffffff,-0x4(%rbp)
jmp    12dc <read_file+0x15c>
mov    -0x20(%rbp),%rdi
mov    0x2dd5(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
cmp    $0x0,%rax
je     123b <read_file+0xbb>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12dc <read_file+0x15c>
mov    -0x20(%rbp),%rdi
call   1070 <ftell@plt>
mov    %eax,-0x24(%rbp)
mov    $0xffffffff,%eax
cmp    -0x24(%rbp),%eax
jne    126a <read_file+0xea>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12dc <read_file+0x15c>
mov    -0x20(%rbp),%rdi
call   1050 <rewind@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc_mem@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rcx
xor    %eax,%eax
cmp    (%rcx),%rax
jne    12b4 <read_file+0x134>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12dc <read_file+0x15c>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x24(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_file>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    $0xffffffff,%r12d
test   %rdi,%rdi
je     1238 <read_file+0xb8>
mov    %rsi,%rbp
test   %rsi,%rsi
je     1238 <read_file+0xb8>
mov    %rdi,%rbx
mov    0x2e2b(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
call   1090 <access@plt>
test   %rax,%rax
jne    1238 <read_file+0xb8>
lea    0xe3d(%rip),%rsi
mov    %rbp,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1238 <read_file+0xb8>
mov    %rax,%r14
mov    0x2e0e(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    $0xffffffff,%r12d
test   %rax,%rax
jne    1230 <read_file+0xb0>
mov    %r14,%rdi
call   1070 <ftell@plt>
cmp    $0xffffffff,%eax
je     1230 <read_file+0xb0>
mov    %eax,%r15d
mov    %r14,%rdi
call   1050 <rewind@plt>
lea    0x1(%r15),%edi
call   1060 <malloc_mem@plt>
mov    %rax,(%rbx)
test   %rax,%rax
je     1230 <read_file+0xb0>
mov    %rax,%rdi
mov    $0x1,%esi
mov    %r15d,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
xor    %r12d,%r12d
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %r12d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@R_OK = global i32 0
@.str = [2 x i8] c"r\00"
@SEEK_END = global i32 0
define i32 @read_file(i8** writeonly %0, i8* %1) {
%3 = icmp eq i8** %0, null
%4 = icmp eq i8* %1, null
%5 = or i1 %3, %4
br i1 %5, label %31, label %6
6: ; preds = %2
%7 = load i32, i32* @R_OK
%8 = tail call i64 @access(i8* %1, i32 %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %31
10: ; preds = %6
%11 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %31, label %13
13: ; preds = %10
%14 = load i32, i32* @SEEK_END
%15 = tail call i64 @fseek(i32* %11, i32 0, i32 %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %28
17: ; preds = %13
%18 = tail call i32 @ftell(i32* %11)
%19 = icmp eq i32 %18, -1
br i1 %19, label %28, label %20
20: ; preds = %17
%21 = tail call i32 @rewind(i32* %11)
%22 = add nuw nsw i32 %18, 1
%23 = tail call i64 @malloc_mem(i32 %22)
%24 = inttoptr i64 %23 to i8*
store i8* %24, i8** %0
%25 = icmp eq i64 %23, 0
br i1 %25, label %28, label %26
26: ; preds = %20
%27 = tail call i32 @fread(i8* %24, i32 1, i32 %18, i32* %11)
br label %28
28: ; preds = %20, %17, %13, %26
%29 = phi i32 [ 0, %26 ], [ -1, %13 ], [ -1, %17 ], [ -1, %20 ]
%30 = tail call i32 @fclose(i32* %11)
br label %31
31: ; preds = %28, %10, %6, %2
%32 = phi i32 [ -1, %2 ], [ -1, %6 ], [ -1, %10 ], [ %29, %28 ]
ret i32 %32
}