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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ string_chomp(char *);
int /*<<< orphan*/ text_list_append(struct text_list *, char *);
struct text_list *text_list_create();
struct text_list *text_list_load(const char *path) {
  char line[1024];
  FILE *file = fopen(path, "r");
  if (!file)
    return 0;
  struct text_list *t = text_list_create();
  while (fgets(line, sizeof(line), file)) {
    string_chomp(line);
    text_list_append(t, line);
  }
  fclose(file);
  return t;
}


x86 assembly (clang, -O0):
<text_list_load>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe86(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x418(%rbp)
cmpq   $0x0,-0x418(%rbp)
jne    11a1 <text_list_load+0x41>
movq   $0x0,-0x8(%rbp)
jmp    120c <text_list_load+0xac>
mov    $0x0,%al
call   1080 <text_list_create@plt>
mov    %rax,-0x420(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x418(%rbp),%rdx
mov    $0x400,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     11f5 <text_list_load+0x95>
lea    -0x410(%rbp),%rdi
call   1050 <string_chomp@plt>
mov    -0x420(%rbp),%rdi
lea    -0x410(%rbp),%rsi
call   1040 <text_list_append@plt>
jmp    11af <text_list_load+0x4f>
mov    -0x418(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x420(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<text_list_load>:
push   %r15
push   %r14
push   %rbx
sub    $0x400,%rsp
lea    0xe8d(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11e2 <text_list_load+0x82>
mov    %rax,%r15
xor    %eax,%eax
call   1080 <text_list_create@plt>
mov    %rax,%r14
mov    %rsp,%rdi
mov    $0x400,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11d8 <text_list_load+0x78>
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1050 <string_chomp@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <text_list_append@plt>
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
jne    11b0 <text_list_load+0x50>
mov    %r15,%rdi
call   1030 <fclose@plt>
jmp    11e5 <text_list_load+0x85>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.text_list = type { i32 }
@.str = [2 x i8] c"r\00"
define %struct.text_list* @text_list_load(i8* %0) {
%2 = alloca %struct.text_list*
%3 = alloca i8*
%4 = alloca [1024 x i8]
%5 = alloca i32*
%6 = alloca %struct.text_list*
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %5
%9 = load i32*, i32** %5
%10 = icmp ne i32* %9, null
br i1 %10, label %12, label %11
11: ; preds = %1
store %struct.text_list* null, %struct.text_list** %2
br label %29
12: ; preds = %1
%13 = call %struct.text_list* (...) @text_list_create()
store %struct.text_list* %13, %struct.text_list** %6
br label %14
14: ; preds = %19, %12
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%16 = load i32*, i32** %5
%17 = call i64 @fgets(i8* %15, i32 1024, i32* %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %14
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%21 = call i32 @string_chomp(i8* %20)
%22 = load %struct.text_list*, %struct.text_list** %6
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%24 = call i32 @text_list_append(%struct.text_list* %22, i8* %23)
br label %14
25: ; preds = %14
%26 = load i32*, i32** %5
%27 = call i32 @fclose(i32* %26)
%28 = load %struct.text_list*, %struct.text_list** %6
store %struct.text_list* %28, %struct.text_list** %2
br label %29
29: ; preds = %25, %11
%30 = load %struct.text_list*, %struct.text_list** %2
ret %struct.text_list* %30
}

LLVM IR (-O2):
%struct.text_list = type { i32 }
@.str = [2 x i8] c"r\00"
define %struct.text_list* @text_list_load(i8* nocapture %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%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 %17, label %6
6: ; preds = %1
%7 = tail call %struct.text_list* (...) @text_list_create()
%8 = call i64 @fgets(i8* %3, i32 1024, i32* %4)
%9 = icmp eq i64 %8, 0
br i1 %9, label %15, label %10
10: ; preds = %6, %10
%11 = call i32 @string_chomp(i8* %3)
%12 = call i32 @text_list_append(%struct.text_list* %7, i8* %3)
%13 = call i64 @fgets(i8* %3, i32 1024, i32* %4)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %10
15: ; preds = %10, %6
%16 = call i32 @fclose(i32* %4)
br label %17
17: ; preds = %1, %15
%18 = phi %struct.text_list* [ %7, %15 ], [ null, %1 ]
ret %struct.text_list* %18
}