#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 */

/* Variables and functions */
char **malloc(int);
char *read_whole_file(char const *, size_t *);
char **text_to_lines(char *const, size_t, int *);
char **read_file_of_lines(const char filepath[], int *nlines) {
  size_t text_len;
  char *const text = read_whole_file(filepath, &text_len);
  char **list = (text == NULL) ? NULL : text_to_lines(text, text_len, nlines);
  if (list == NULL) {
    list = malloc(sizeof(*list));
    *nlines = 0;
  }
  return list;
}


x86 assembly (clang, -O0):
<read_file_of_lines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <read_whole_file@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1167 <read_file_of_lines+0x37>
xor    %eax,%eax
mov    %rax,-0x30(%rbp)
jmp    117c <read_file_of_lines+0x4c>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1040 <text_to_lines@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11a7 <read_file_of_lines+0x77>
mov    $0x8,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_file_of_lines>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
lea    0x8(%rsp),%rsi
call   1030 <read_whole_file@plt>
test   %rax,%rax
je     115c <read_file_of_lines+0x2c>
mov    0x8(%rsp),%rsi
mov    %rax,%rdi
mov    %rbx,%rdx
call   1040 <text_to_lines@plt>
test   %rax,%rax
jne    116c <read_file_of_lines+0x3c>
mov    $0x8,%edi
call   1050 <malloc@plt>
movl   $0x0,(%rbx)
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i8** @read_file_of_lines(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i8**
store i8* %0, i8** %3
store i32* %1, i32** %4
%8 = load i8*, i8** %3
%9 = call i8* @read_whole_file(i8* %8, i64* %5)
store i8* %9, i8** %6
%10 = load i8*, i8** %6
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %13
12: ; preds = %2
br label %18
13: ; preds = %2
%14 = load i8*, i8** %6
%15 = load i64, i64* %5
%16 = load i32*, i32** %4
%17 = call i8** @text_to_lines(i8* %14, i64 %15, i32* %16)
br label %18
18: ; preds = %13, %12
%19 = phi i8** [ null, %12 ], [ %17, %13 ]
store i8** %19, i8*** %7
%20 = load i8**, i8*** %7
%21 = icmp eq i8** %20, null
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = call i8** @malloc(i32 8)
store i8** %23, i8*** %7
%24 = load i32*, i32** %4
store i32 0, i32* %24
br label %25
25: ; preds = %22, %18
%26 = load i8**, i8*** %7
ret i8** %26
}

LLVM IR (-O2):
define i8** @read_file_of_lines(i8* %0, i32* %1) {
%3 = alloca i64
%4 = bitcast i64* %3 to i8*
%5 = call i8* @read_whole_file(i8* %0, i64* %3)
%6 = icmp eq i8* %5, null
br i1 %6, label %11, label %7
7: ; preds = %2
%8 = load i64, i64* %3
%9 = call i8** @text_to_lines(i8* %5, i64 %8, i32* %1)
%10 = icmp eq i8** %9, null
br i1 %10, label %11, label %13
11: ; preds = %2, %7
%12 = call i8** @malloc(i32 8)
store i32 0, i32* %1
br label %13
13: ; preds = %11, %7
%14 = phi i8** [ %12, %11 ], [ %9, %7 ]
ret i8** %14
}