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

/* Variables and functions */
int /*<<< orphan*/ assert(int);
scalar_t__ feof(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
char *malloc(int);
char **realloc(char **, int);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int load_lines(FILE *file, char ***bufs, unsigned int *lines_size) {
  char line[512];
  *bufs = NULL;
  *lines_size = 0;
  while (!feof(file)) {
    if (fgets(line, (sizeof(line) / sizeof(*line)), file) == NULL) {
      if (ferror(file))
        return -1;
      else
        return 0;
    }
    assert(strlen(line) < (sizeof(line) / sizeof(*line)) || feof(file));
    *bufs = realloc(*bufs, 2012);
    (*bufs)[*lines_size] = malloc(2012);
    strcpy((*bufs)[*lines_size], line);
    (*lines_size)++;
  }
  return 0;
}


x86 assembly (clang, -O0):
<load_lines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11cb <load_lines+0x4b>
jmp    12c5 <load_lines+0x145>
lea    -0x220(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x200,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
jne    1215 <load_lines+0x95>
mov    -0x10(%rbp),%rdi
call   1040 <ferror@plt>
cmp    $0x0,%rax
je     1209 <load_lines+0x89>
movl   $0xffffffff,-0x4(%rbp)
jmp    12cc <load_lines+0x14c>
movl   $0x0,-0x4(%rbp)
jmp    12cc <load_lines+0x14c>
lea    -0x220(%rbp),%rdi
call   1050 <strlen@plt>
movslq %eax,%rcx
mov    $0x1,%al
cmp    $0x200,%rcx
mov    %al,-0x221(%rbp)
jb     124f <load_lines+0xcf>
mov    -0x10(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x221(%rbp)
mov    -0x221(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    $0x7dc,%esi
call   10a0 <realloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    $0x7dc,%edi
call   1090 <malloc@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    -0x20(%rbp),%rcx
mov    (%rcx),%ecx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    -0x20(%rbp),%rcx
mov    (%rcx),%ecx
mov    (%rax,%rcx,8),%rdi
lea    -0x220(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
jmp    11ac <load_lines+0x2c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_lines>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x208,%rsp
mov    %rdx,%r14
mov    %rsi,%rbp
mov    %rdi,%r13
movq   $0x0,(%rsi)
movl   $0x0,(%rdx)
call   1080 <feof@plt>
xor    %r15d,%r15d
test   %rax,%rax
jne    1256 <load_lines+0xd6>
mov    %rsp,%r12
jmp    120f <load_lines+0x8f>
nopl   (%rax)
movzbl %cl,%edi
call   1070 <assert@plt>
mov    0x0(%rbp),%rdi
mov    $0x7dc,%esi
call   10a0 <realloc@plt>
mov    %rax,%rbx
mov    %rax,0x0(%rbp)
mov    $0x7dc,%edi
call   1090 <malloc@plt>
mov    (%r14),%ecx
mov    %rax,(%rbx,%rcx,8)
mov    0x0(%rbp),%rax
mov    (%rax,%rcx,8),%rdi
mov    %r12,%rsi
call   1030 <strcpy@plt>
addl   $0x1,(%r14)
mov    %r13,%rdi
call   1080 <feof@plt>
test   %rax,%rax
jne    1256 <load_lines+0xd6>
mov    %r12,%rdi
mov    $0x200,%esi
mov    %r13,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1248 <load_lines+0xc8>
mov    %r12,%rdi
call   1050 <strlen@plt>
mov    $0x1,%cl
cmp    $0x200,%eax
jb     11c0 <load_lines+0x40>
mov    %r13,%rdi
call   1080 <feof@plt>
test   %rax,%rax
setne  %cl
jmp    11c0 <load_lines+0x40>
mov    %r13,%rdi
call   1040 <ferror@plt>
neg    %rax
sbb    %r15d,%r15d
mov    %r15d,%eax
add    $0x208,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @load_lines(i32* %0, i8*** %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8***
%7 = alloca i32*
%8 = alloca [512 x i8]
store i32* %0, i32** %5
store i8*** %1, i8**** %6
store i32* %2, i32** %7
%9 = load i8***, i8**** %6
store i8** null, i8*** %9
%10 = load i32*, i32** %7
store i32 0, i32* %10
br label %11
11: ; preds = %36, %3
%12 = load i32*, i32** %5
%13 = call i64 @feof(i32* %12)
%14 = icmp ne i64 %13, 0
%15 = xor i1 %14, true
br i1 %15, label %16, label %63
16: ; preds = %11
%17 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%18 = load i32*, i32** %5
%19 = call i32* @fgets(i8* %17, i32 512, i32* %18)
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %27
21: ; preds = %16
%22 = load i32*, i32** %5
%23 = call i64 @ferror(i32* %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %21
store i32 -1, i32* %4
br label %64
26: ; preds = %21
store i32 0, i32* %4
br label %64
27: ; preds = %16
%28 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%29 = call i32 @strlen(i8* %28)
%30 = sext i32 %29 to i64
%31 = icmp ult i64 %30, 512
br i1 %31, label %36, label %32
32: ; preds = %27
%33 = load i32*, i32** %5
%34 = call i64 @feof(i32* %33)
%35 = icmp ne i64 %34, 0
br label %36
36: ; preds = %32, %27
%37 = phi i1 [ true, %27 ], [ %35, %32 ]
%38 = zext i1 %37 to i32
%39 = call i32 @assert(i32 %38)
%40 = load i8***, i8**** %6
%41 = load i8**, i8*** %40
%42 = call i8** @realloc(i8** %41, i32 2012)
%43 = load i8***, i8**** %6
store i8** %42, i8*** %43
%44 = call i8* @malloc(i32 2012)
%45 = load i8***, i8**** %6
%46 = load i8**, i8*** %45
%47 = load i32*, i32** %7
%48 = load i32, i32* %47
%49 = zext i32 %48 to i64
%50 = getelementptr inbounds i8*, i8** %46, i64 %49
store i8* %44, i8** %50
%51 = load i8***, i8**** %6
%52 = load i8**, i8*** %51
%53 = load i32*, i32** %7
%54 = load i32, i32* %53
%55 = zext i32 %54 to i64
%56 = getelementptr inbounds i8*, i8** %52, i64 %55
%57 = load i8*, i8** %56
%58 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%59 = call i32 @strcpy(i8* %57, i8* %58)
%60 = load i32*, i32** %7
%61 = load i32, i32* %60
%62 = add i32 %61, 1
store i32 %62, i32* %60
br label %11
63: ; preds = %11
store i32 0, i32* %4
br label %64
64: ; preds = %63, %26, %25
%65 = load i32, i32* %4
ret i32 %65
}

LLVM IR (-O2):
define i32 @load_lines(i32* nocapture %0, i8*** nocapture %1, i32* nocapture %2) {
%4 = alloca [512 x i8]
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
store i8** null, i8*** %1
store i32 0, i32* %2
%6 = call i64 @feof(i32* %0)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %39
8: ; preds = %3, %21
%9 = call i32* @fgets(i8* %5, i32 512, i32* %0)
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %15
11: ; preds = %8
%12 = call i64 @ferror(i32* %0)
%13 = icmp ne i64 %12, 0
%14 = sext i1 %13 to i32
br label %39
15: ; preds = %8
%16 = call i32 @strlen(i8* %5)
%17 = icmp ult i32 %16, 512
br i1 %17, label %21, label %18
18: ; preds = %15
%19 = call i64 @feof(i32* %0)
%20 = icmp ne i64 %19, 0
br label %21
21: ; preds = %18, %15
%22 = phi i1 [ true, %15 ], [ %20, %18 ]
%23 = zext i1 %22 to i32
%24 = call i32 @assert(i32 %23)
%25 = load i8**, i8*** %1
%26 = call i8** @realloc(i8** %25, i32 2012)
store i8** %26, i8*** %1
%27 = call dereferenceable_or_null(2012) i8* @malloc(i32 2012)
%28 = load i32, i32* %2
%29 = zext i32 %28 to i64
%30 = getelementptr inbounds i8*, i8** %26, i64 %29
store i8* %27, i8** %30
%31 = load i8**, i8*** %1
%32 = getelementptr inbounds i8*, i8** %31, i64 %29
%33 = load i8*, i8** %32
%34 = call i32 @strcpy(i8* %33, i8* %5)
%35 = load i32, i32* %2
%36 = add i32 %35, 1
store i32 %36, i32* %2
%37 = call i64 @feof(i32* %0)
%38 = icmp eq i64 %37, 0
br i1 %38, label %8, label %39
39: ; preds = %21, %3, %11
%40 = phi i32 [ %14, %11 ], [ 0, %3 ], [ 0, %21 ]
ret i32 %40
}