#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 stat {
  int st_size;
};

/* Variables and functions */
int /*<<< orphan*/ MAP_PRIVATE;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ PROT_READ;
int /*<<< orphan*/ append(char ***, int *, int *, char *);
int /*<<< orphan*/ die_errno(char *);
int fstat(int, struct stat *);
char **malloc(int);
char *mmap(int /*<<< orphan*/ *, int, int /*<<< orphan*/, int /*<<< orphan*/,
           int, int /*<<< orphan*/);
int /*<<< orphan*/ munmap(char *, int);
int open(char *, int /*<<< orphan*/);
char *strndup(char *, int);
char **load(char *path, int *count) {
  int alloc = 10;
  int used = 0;
  char **lines = malloc(sizeof(char *) * alloc);
  int fd = open(path, O_RDONLY);
  if (fd < 0) {
    die_errno("Failed to open file");
  }
  struct stat st;
  if (fstat(fd, &st) == -1)
    die_errno("Failed to stat file");
  char *data = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
  char *end = data + st.st_size;
  char *line_start = data;
  char *c;
  for (c = data; c < end; ++c) {
    if (*c == '\n') {
      int line_len = c - line_start;
      char *line = strndup(line_start, line_len);
      append(&lines, &alloc, &used, line);
      line_start = c + 1;
    }
  }
  if (line_start != c) {
    int line_len = c - line_start;
    char *line = strndup(line_start, line_len);
    append(&lines, &alloc, &used, line);
  }
  *count = used;
  append(&lines, &alloc, &used, NULL);
  munmap(data, st.st_size);
  return lines;
}


x86 assembly (clang, -O0):
<load>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xa,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e24(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    11dc <load+0x5c>
lea    0xe29(%rip),%rdi
call   1070 <die_errno@plt>
mov    -0x24(%rbp),%edi
lea    -0x28(%rbp),%rsi
call   10a0 <fstat@plt>
cmp    $0xffffffff,%eax
jne    11fd <load+0x7d>
lea    0xe1c(%rip),%rdi
call   1070 <die_errno@plt>
mov    -0x28(%rbp),%esi
mov    0x2df1(%rip),%rax
mov    (%rax),%edx
mov    0x2dc0(%rip),%rax
mov    (%rax),%ecx
mov    -0x24(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
movslq -0x28(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
cmp    -0x38(%rbp),%rax
jae    12b8 <load+0x138>
mov    -0x48(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    12a2 <load+0x122>
mov    -0x48(%rbp),%rax
mov    -0x40(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x4c(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x4c(%rbp),%esi
call   1050 <strndup@plt>
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rcx
lea    -0x20(%rbp),%rdi
lea    -0x14(%rbp),%rsi
lea    -0x18(%rbp),%rdx
call   1030 <append@plt>
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    12a7 <load+0x127>
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
jmp    1245 <load+0xc5>
mov    -0x40(%rbp),%rax
cmp    -0x48(%rbp),%rax
je     12f9 <load+0x179>
mov    -0x48(%rbp),%rax
mov    -0x40(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x5c(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x5c(%rbp),%esi
call   1050 <strndup@plt>
mov    %rax,-0x68(%rbp)
mov    -0x68(%rbp),%rcx
lea    -0x20(%rbp),%rdi
lea    -0x14(%rbp),%rsi
lea    -0x18(%rbp),%rdx
call   1030 <append@plt>
mov    -0x18(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
lea    -0x20(%rbp),%rdi
lea    -0x14(%rbp),%rsi
lea    -0x18(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%ecx
call   1030 <append@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%esi
call   1080 <munmap@plt>
mov    -0x20(%rbp),%rax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
movl   $0xa,0xc(%rsp)
movl   $0x0,0x8(%rsp)
mov    $0x50,%edi
call   1060 <malloc@plt>
mov    %rax,0x10(%rsp)
mov    0x2e26(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1090 <open@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    11d6 <load+0x56>
lea    0xe2f(%rip),%rdi
call   1070 <die_errno@plt>
lea    0x18(%rsp),%rsi
mov    %ebp,%edi
call   10a0 <fstat@plt>
cmp    $0xffffffff,%eax
jne    11f3 <load+0x73>
lea    0xe26(%rip),%rdi
call   1070 <die_errno@plt>
movslq 0x18(%rsp),%rbx
mov    0x2df9(%rip),%rax
mov    (%rax),%edx
mov    0x2dc8(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    %ebx,%esi
mov    %ebp,%r8d
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    %rax,%r15
test   %rbx,%rbx
jle    12c6 <load+0x146>
mov    %r14,0x30(%rsp)
mov    %r15,%r12
mov    %rbx,0x28(%rsp)
add    %rbx,%r12
lea    0x10(%rsp),%r13
lea    0xc(%rsp),%rbx
lea    0x8(%rsp),%r14
mov    %r15d,%ebp
mov    %r15,%rdi
mov    %r15,0x20(%rsp)
jmp    126c <load+0xec>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%r15
add    $0x1,%ebp
cmp    %r12,%r15
jae    1292 <load+0x112>
cmpb   $0xa,(%r15)
jne    1260 <load+0xe0>
mov    %ebp,%esi
sub    %edi,%esi
call   1050 <strndup@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
mov    %rax,%rcx
call   1030 <append@plt>
lea    0x1(%r15),%rdi
jmp    1260 <load+0xe0>
cmp    %rdi,%r15
mov    0x30(%rsp),%r14
mov    0x28(%rsp),%rbx
mov    0x20(%rsp),%r15
je     12c6 <load+0x146>
sub    %edi,%ebp
mov    %ebp,%esi
call   1050 <strndup@plt>
lea    0x10(%rsp),%rdi
lea    0xc(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    %rax,%rcx
call   1030 <append@plt>
mov    0x8(%rsp),%eax
mov    %eax,(%r14)
lea    0x10(%rsp),%rdi
lea    0xc(%rsp),%rsi
lea    0x8(%rsp),%rdx
xor    %ecx,%ecx
call   1030 <append@plt>
mov    %r15,%rdi
mov    %ebx,%esi
call   1080 <munmap@plt>
mov    0x10(%rsp),%rax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@O_RDONLY = global i32 0
@.str = [20 x i8] c"Failed to open file\00"
@.str.1 = [20 x i8] c"Failed to stat file\00"
@PROT_READ = global i32 0
@MAP_PRIVATE = global i32 0
define i8** @load(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8**
%8 = alloca i32
%9 = alloca %struct.stat
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i32
%15 = alloca i8*
%16 = alloca i32
%17 = alloca i8*
store i8* %0, i8** %3
store i32* %1, i32** %4
store i32 10, i32* %5
store i32 0, i32* %6
%18 = load i32, i32* %5
%19 = sext i32 %18 to i64
%20 = mul i64 8, %19
%21 = trunc i64 %20 to i32
%22 = call i8** @malloc(i32 %21)
store i8** %22, i8*** %7
%23 = load i8*, i8** %3
%24 = load i32, i32* @O_RDONLY
%25 = call i32 @open(i8* %23, i32 %24)
store i32 %25, i32* %8
%26 = load i32, i32* %8
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %2
%29 = call i32 @die_errno(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %30
30: ; preds = %28, %2
%31 = load i32, i32* %8
%32 = call i32 @fstat(i32 %31, %struct.stat* %9)
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %36
34: ; preds = %30
%35 = call i32 @die_errno(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %36
36: ; preds = %34, %30
%37 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%38 = load i32, i32* %37
%39 = load i32, i32* @PROT_READ
%40 = load i32, i32* @MAP_PRIVATE
%41 = load i32, i32* %8
%42 = call i8* @mmap(i32* null, i32 %38, i32 %39, i32 %40, i32 %41, i32 0)
store i8* %42, i8** %10
%43 = load i8*, i8** %10
%44 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%45 = load i32, i32* %44
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %43, i64 %46
store i8* %47, i8** %11
%48 = load i8*, i8** %10
store i8* %48, i8** %12
%49 = load i8*, i8** %10
store i8* %49, i8** %13
br label %50
50: ; preds = %74, %36
%51 = load i8*, i8** %13
%52 = load i8*, i8** %11
%53 = icmp ult i8* %51, %52
br i1 %53, label %54, label %77
54: ; preds = %50
%55 = load i8*, i8** %13
%56 = load i8, i8* %55
%57 = sext i8 %56 to i32
%58 = icmp eq i32 %57, 10
br i1 %58, label %59, label %73
59: ; preds = %54
%60 = load i8*, i8** %13
%61 = load i8*, i8** %12
%62 = ptrtoint i8* %60 to i64
%63 = ptrtoint i8* %61 to i64
%64 = sub i64 %62, %63
%65 = trunc i64 %64 to i32
store i32 %65, i32* %14
%66 = load i8*, i8** %12
%67 = load i32, i32* %14
%68 = call i8* @strndup(i8* %66, i32 %67)
store i8* %68, i8** %15
%69 = load i8*, i8** %15
%70 = call i32 @append(i8*** %7, i32* %5, i32* %6, i8* %69)
%71 = load i8*, i8** %13
%72 = getelementptr inbounds i8, i8* %71, i64 1
store i8* %72, i8** %12
br label %73
73: ; preds = %59, %54
br label %74
74: ; preds = %73
%75 = load i8*, i8** %13
%76 = getelementptr inbounds i8, i8* %75, i32 1
store i8* %76, i8** %13
br label %50
77: ; preds = %50
%78 = load i8*, i8** %12
%79 = load i8*, i8** %13
%80 = icmp ne i8* %78, %79
br i1 %80, label %81, label %93
81: ; preds = %77
%82 = load i8*, i8** %13
%83 = load i8*, i8** %12
%84 = ptrtoint i8* %82 to i64
%85 = ptrtoint i8* %83 to i64
%86 = sub i64 %84, %85
%87 = trunc i64 %86 to i32
store i32 %87, i32* %16
%88 = load i8*, i8** %12
%89 = load i32, i32* %16
%90 = call i8* @strndup(i8* %88, i32 %89)
store i8* %90, i8** %17
%91 = load i8*, i8** %17
%92 = call i32 @append(i8*** %7, i32* %5, i32* %6, i8* %91)
br label %93
93: ; preds = %81, %77
%94 = load i32, i32* %6
%95 = load i32*, i32** %4
store i32 %94, i32* %95
%96 = call i32 @append(i8*** %7, i32* %5, i32* %6, i8* null)
%97 = load i8*, i8** %10
%98 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%99 = load i32, i32* %98
%100 = call i32 @munmap(i8* %97, i32 %99)
%101 = load i8**, i8*** %7
ret i8** %101
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@O_RDONLY = global i32 0
@.str = [20 x i8] c"Failed to open file\00"
@.str.1 = [20 x i8] c"Failed to stat file\00"
@PROT_READ = global i32 0
@MAP_PRIVATE = global i32 0
define i8** @load(i8* nocapture %0, i32* nocapture writeonly %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.stat
%7 = bitcast i32* %3 to i8*
store i32 10, i32* %3
%8 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%9 = bitcast i8*** %5 to i8*
%10 = tail call i8** @malloc(i32 80)
store i8** %10, i8*** %5
%11 = load i32, i32* @O_RDONLY
%12 = tail call i32 @open(i8* %0, i32 %11)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = tail call i32 @die_errno(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %14, %2
%17 = bitcast %struct.stat* %6 to i8*
%18 = call i32 @fstat(i32 %12, %struct.stat* %6)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = tail call i32 @die_errno(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %20, %16
%23 = getelementptr inbounds %struct.stat, %struct.stat* %6, i64 0, i32 0
%24 = load i32, i32* %23
%25 = load i32, i32* @PROT_READ
%26 = load i32, i32* @MAP_PRIVATE
%27 = tail call i8* @mmap(i32* null, i32 %24, i32 %25, i32 %26, i32 %12, i32 0)
%28 = sext i32 %24 to i64
%29 = getelementptr inbounds i8, i8* %27, i64 %28
%30 = icmp sgt i32 %24, 0
br i1 %30, label %31, label %57
31: ; preds = %22, %44
%32 = phi i8* [ %45, %44 ], [ %27, %22 ]
%33 = phi i8* [ %46, %44 ], [ %27, %22 ]
%34 = load i8, i8* %33
%35 = icmp eq i8 %34, 10
br i1 %35, label %36, label %44
36: ; preds = %31
%37 = ptrtoint i8* %33 to i64
%38 = ptrtoint i8* %32 to i64
%39 = sub i64 %37, %38
%40 = trunc i64 %39 to i32
%41 = call i8* @strndup(i8* %32, i32 %40)
%42 = call i32 @append(i8*** %5, i32* %3, i32* %4, i8* %41)
%43 = getelementptr inbounds i8, i8* %33, i64 1
br label %44
44: ; preds = %31, %36
%45 = phi i8* [ %43, %36 ], [ %32, %31 ]
%46 = getelementptr inbounds i8, i8* %33, i64 1
%47 = icmp ult i8* %46, %29
br i1 %47, label %31, label %48
48: ; preds = %44
%49 = icmp eq i8* %45, %46
br i1 %49, label %57, label %50
50: ; preds = %48
%51 = ptrtoint i8* %46 to i64
%52 = ptrtoint i8* %45 to i64
%53 = sub i64 %51, %52
%54 = trunc i64 %53 to i32
%55 = call i8* @strndup(i8* %45, i32 %54)
%56 = call i32 @append(i8*** %5, i32* %3, i32* %4, i8* %55)
br label %57
57: ; preds = %22, %50, %48
%58 = load i32, i32* %4
store i32 %58, i32* %1
%59 = call i32 @append(i8*** %5, i32* %3, i32* %4, i8* null)
%60 = call i32 @munmap(i8* %27, i32 %24)
%61 = load i8**, i8*** %5
ret i8** %61
}