#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*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
char *malloc(scalar_t__);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
void load_aphorisms(char filename[], char *sayings[]) {
  char line[1024];
  int i = 0;
  FILE *infile;
  if ((infile = fopen(filename, "r")) == NULL) {
    printf("Could not open aphorisms file %s\n", filename);
    return;
  }
  while (fgets(line, 1024, infile)) {
    sayings[i] = malloc(strlen(line) + 1);
    strcpy(sayings[i], line);
    i++;
  }
  fclose(infile);
}


x86 assembly (clang, -O0):
<load_aphorisms>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x414(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe68(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x420(%rbp)
cmp    $0x0,%rax
jne    11c3 <load_aphorisms+0x53>
mov    -0x8(%rbp),%rsi
lea    0xe49(%rip),%rdi
call   1060 <printf@plt>
jmp    124f <load_aphorisms+0xdf>
jmp    11c8 <load_aphorisms+0x58>
lea    -0x410(%rbp),%rdi
mov    -0x420(%rbp),%rdx
mov    $0x400,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     1243 <load_aphorisms+0xd3>
lea    -0x410(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1080 <malloc@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
movslq -0x414(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
movslq -0x414(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    -0x410(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x414(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x414(%rbp)
jmp    11c8 <load_aphorisms+0x58>
mov    -0x420(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_aphorisms>:
push   %r15
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %rsi,%rbx
mov    %rdi,%r15
lea    0xe77(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     11fd <load_aphorisms+0x8d>
mov    %rax,%r14
mov    %rsp,%rdi
mov    $0x400,%esi
mov    %rax,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     11e8 <load_aphorisms+0x78>
mov    %rsp,%r15
xchg   %ax,%ax
mov    %r15,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rdi
call   1080 <malloc@plt>
mov    %rax,(%rbx)
mov    %rax,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
mov    %r15,%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   1070 <fgets@plt>
add    $0x8,%rbx
test   %rax,%rax
jne    11b0 <load_aphorisms+0x40>
mov    %r14,%rdi
call   1040 <fclose@plt>
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xdfe(%rip),%rdi
mov    %r15,%rsi
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1060 <printf@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [34 x i8] c"Could not open aphorisms file %s\0A\00"
define void @load_aphorisms(i8* %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca [1024 x i8]
%6 = alloca i32
%7 = alloca i32*
store i8* %0, i8** %3
store i8** %1, i8*** %4
store i32 0, i32* %6
%8 = load i8*, i8** %3
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %7
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i8*, i8** %3
%13 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %12)
br label %41
14: ; preds = %2
br label %15
15: ; preds = %20, %14
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%17 = load i32*, i32** %7
%18 = call i64 @fgets(i8* %16, i32 1024, i32* %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %38
20: ; preds = %15
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%22 = call i64 @strlen(i8* %21)
%23 = add nsw i64 %22, 1
%24 = call i8* @malloc(i64 %23)
%25 = load i8**, i8*** %4
%26 = load i32, i32* %6
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8*, i8** %25, i64 %27
store i8* %24, i8** %28
%29 = load i8**, i8*** %4
%30 = load i32, i32* %6
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8*, i8** %29, i64 %31
%33 = load i8*, i8** %32
%34 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%35 = call i32 @strcpy(i8* %33, i8* %34)
%36 = load i32, i32* %6
%37 = add nsw i32 %36, 1
store i32 %37, i32* %6
br label %15
38: ; preds = %15
%39 = load i32*, i32** %7
%40 = call i32 @fclose(i32* %39)
br label %41
41: ; preds = %38, %11
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [34 x i8] c"Could not open aphorisms file %s\0A\00"
define void @load_aphorisms(i8* %0, i8** nocapture writeonly %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = call i64 @fgets(i8* %4, i32 1024, i32* %5)
%9 = icmp eq i64 %8, 0
br i1 %9, label %22, label %12
10: ; preds = %2
%11 = tail call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %24
12: ; preds = %7, %12
%13 = phi i64 [ %19, %12 ], [ 0, %7 ]
%14 = call i64 @strlen(i8* %4)
%15 = add nsw i64 %14, 1
%16 = call i8* @malloc(i64 %15)
%17 = getelementptr inbounds i8*, i8** %1, i64 %13
store i8* %16, i8** %17
%18 = call i32 @strcpy(i8* %16, i8* %4)
%19 = add nuw i64 %13, 1
%20 = call i64 @fgets(i8* %4, i32 1024, i32* %5)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %12
22: ; preds = %12, %7
%23 = call i32 @fclose(i32* %5)
br label %24
24: ; preds = %22, %10
ret void
}