#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*/ SEEK_SET;
char **calloc(int, int);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
char *strdup(char *);
int strlen(char *);
char **file_read_lines(FILE *file, int *count) {
  int nl_count = 0;
  char c;
  char **lines;
  char buffer[1024];
  if (!file)
    return 0;
  fseek(file, 0, SEEK_SET);
  while (!feof(file)) {
    fread(&c, sizeof(char), 1, file);
    if (c == 10)
      nl_count++;
  }
  fseek(file, 0, SEEK_SET);
  nl_count++;
  lines = calloc(nl_count, sizeof(char *));
  *count = 0;
  while (!feof(file)) {
    if (!fgets(buffer, 1023, file))
      break;
    if (buffer[0] == 10)
      continue;
    buffer[strlen(buffer) - 1] = 0;
    lines[*count] = strdup(buffer);
    (*count)++;
  }
  return lines;
}


x86 assembly (clang, -O0):
<file_read_lines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a2 <file_read_lines+0x32>
movq   $0x0,-0x8(%rbp)
jmp    12e0 <file_read_lines+0x170>
mov    -0x10(%rbp),%rdi
mov    0x2e33(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
mov    -0x10(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11d4 <file_read_lines+0x64>
jmp    1203 <file_read_lines+0x93>
mov    -0x10(%rbp),%rcx
lea    -0x1d(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
movsbl -0x1d(%rbp),%eax
cmp    $0xa,%eax
jne    11fe <file_read_lines+0x8e>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11b6 <file_read_lines+0x46>
mov    -0x10(%rbp),%rdi
mov    0x2dd2(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
mov    $0x8,%esi
call   1060 <calloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1259 <file_read_lines+0xe9>
jmp    12d8 <file_read_lines+0x168>
lea    -0x430(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x3ff,%esi
call   1050 <fgets@plt>
cmp    $0x0,%eax
jne    127c <file_read_lines+0x10c>
jmp    12d8 <file_read_lines+0x168>
movsbl -0x430(%rbp),%eax
cmp    $0xa,%eax
jne    1291 <file_read_lines+0x121>
jmp    123b <file_read_lines+0xcb>
lea    -0x430(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x430(%rbp,%rax,1)
lea    -0x430(%rbp),%rdi
call   1090 <strdup@plt>
mov    %rax,%rdx
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
movslq (%rcx),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
jmp    123b <file_read_lines+0xcb>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_read_lines>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x410,%rsp
test   %rdi,%rdi
je     127e <file_read_lines+0x10e>
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x2e4b(%rip),%r12
mov    (%r12),%edx
xor    %ebp,%ebp
xor    %esi,%esi
call   1080 <fseek@plt>
mov    %rbx,%rdi
call   1070 <feof@plt>
mov    $0x1,%r15d
test   %eax,%eax
jne    11f3 <file_read_lines+0x83>
lea    0xf(%rsp),%r15
nopl   0x0(%rax)
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
xor    %eax,%eax
cmpb   $0xa,0xf(%rsp)
sete   %al
add    %eax,%ebp
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %eax,%eax
je     11c0 <file_read_lines+0x50>
add    $0x1,%ebp
mov    %ebp,%r15d
mov    (%r12),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    %r15d,%edi
mov    $0x8,%esi
call   1060 <calloc@plt>
mov    %rax,%r15
movl   $0x0,(%r14)
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    1281 <file_read_lines+0x111>
lea    0x10(%rsp),%r12
jmp    123c <file_read_lines+0xcc>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    1281 <file_read_lines+0x111>
mov    %r12,%rdi
mov    $0x3ff,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
test   %eax,%eax
je     1281 <file_read_lines+0x111>
cmpb   $0xa,0x10(%rsp)
je     1230 <file_read_lines+0xc0>
mov    %r12,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r12,1)
mov    %r12,%rdi
call   1090 <strdup@plt>
movslq (%r14),%rcx
mov    %rax,(%r15,%rcx,8)
lea    0x1(%rcx),%eax
mov    %eax,(%r14)
jmp    1230 <file_read_lines+0xc0>
xor    %r15d,%r15d
mov    %r15,%rax
add    $0x410,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
define i8** @file_read_lines(i32* %0, i32* %1) {
%3 = alloca i8**
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i8
%8 = alloca i8**
%9 = alloca [1024 x i8]
store i32* %0, i32** %4
store i32* %1, i32** %5
store i32 0, i32* %6
%10 = load i32*, i32** %4
%11 = icmp ne i32* %10, null
br i1 %11, label %13, label %12
12: ; preds = %2
store i8** null, i8*** %3
br label %76
13: ; preds = %2
%14 = load i32*, i32** %4
%15 = load i32, i32* @SEEK_SET
%16 = call i32 @fseek(i32* %14, i32 0, i32 %15)
br label %17
17: ; preds = %31, %13
%18 = load i32*, i32** %4
%19 = call i32 @feof(i32* %18)
%20 = icmp ne i32 %19, 0
%21 = xor i1 %20, true
br i1 %21, label %22, label %32
22: ; preds = %17
%23 = load i32*, i32** %4
%24 = call i32 @fread(i8* %7, i32 1, i32 1, i32* %23)
%25 = load i8, i8* %7
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 10
br i1 %27, label %28, label %31
28: ; preds = %22
%29 = load i32, i32* %6
%30 = add nsw i32 %29, 1
store i32 %30, i32* %6
br label %31
31: ; preds = %28, %22
br label %17
32: ; preds = %17
%33 = load i32*, i32** %4
%34 = load i32, i32* @SEEK_SET
%35 = call i32 @fseek(i32* %33, i32 0, i32 %34)
%36 = load i32, i32* %6
%37 = add nsw i32 %36, 1
store i32 %37, i32* %6
%38 = load i32, i32* %6
%39 = call i8** @calloc(i32 %38, i32 8)
store i8** %39, i8*** %8
%40 = load i32*, i32** %5
store i32 0, i32* %40
br label %41
41: ; preds = %58, %57, %32
%42 = load i32*, i32** %4
%43 = call i32 @feof(i32* %42)
%44 = icmp ne i32 %43, 0
%45 = xor i1 %44, true
br i1 %45, label %46, label %74
46: ; preds = %41
%47 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%48 = load i32*, i32** %4
%49 = call i32 @fgets(i8* %47, i32 1023, i32* %48)
%50 = icmp ne i32 %49, 0
br i1 %50, label %52, label %51
51: ; preds = %46
br label %74
52: ; preds = %46
%53 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%54 = load i8, i8* %53
%55 = sext i8 %54 to i32
%56 = icmp eq i32 %55, 10
br i1 %56, label %57, label %58
57: ; preds = %52
br label %41
58: ; preds = %52
%59 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%60 = call i32 @strlen(i8* %59)
%61 = sub nsw i32 %60, 1
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 %62
store i8 0, i8* %63
%64 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%65 = call i8* @strdup(i8* %64)
%66 = load i8**, i8*** %8
%67 = load i32*, i32** %5
%68 = load i32, i32* %67
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds i8*, i8** %66, i64 %69
store i8* %65, i8** %70
%71 = load i32*, i32** %5
%72 = load i32, i32* %71
%73 = add nsw i32 %72, 1
store i32 %73, i32* %71
br label %41
74: ; preds = %51, %41
%75 = load i8**, i8*** %8
store i8** %75, i8*** %3
br label %76
76: ; preds = %74, %12
%77 = load i8**, i8*** %3
ret i8** %77
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
define noalias i8** @file_read_lines(i32* %0, i32* nocapture %1) {
%3 = alloca i8
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%6 = icmp eq i32* %0, null
br i1 %6, label %49, label %7
7: ; preds = %2
%8 = load i32, i32* @SEEK_SET
%9 = tail call i32 @fseek(i32* %0, i32 0, i32 %8)
%10 = tail call i32 @feof(i32* %0)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %23
12: ; preds = %7, %12
%13 = phi i32 [ %18, %12 ], [ 0, %7 ]
%14 = call i32 @fread(i8* %3, i32 1, i32 1, i32* %0)
%15 = load i8, i8* %3
%16 = icmp eq i8 %15, 10
%17 = zext i1 %16 to i32
%18 = add nuw nsw i32 %13, %17
%19 = tail call i32 @feof(i32* %0)
%20 = icmp eq i32 %19, 0
br i1 %20, label %12, label %21
21: ; preds = %12
%22 = add nuw i32 %18, 1
br label %23
23: ; preds = %21, %7
%24 = phi i32 [ 1, %7 ], [ %22, %21 ]
%25 = load i32, i32* @SEEK_SET
%26 = tail call i32 @fseek(i32* %0, i32 0, i32 %25)
%27 = tail call i8** @calloc(i32 %24, i32 8)
store i32 0, i32* %1
%28 = call i32 @feof(i32* %0)
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %49
30: ; preds = %23, %46
%31 = call i32 @fgets(i8* %5, i32 1023, i32* %0)
%32 = icmp eq i32 %31, 0
br i1 %32, label %49, label %33
33: ; preds = %30
%34 = load i8, i8* %5
%35 = icmp eq i8 %34, 10
br i1 %35, label %46, label %36
36: ; preds = %33
%37 = call i32 @strlen(i8* %5)
%38 = add nsw i32 %37, -1
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %39
store i8 0, i8* %40
%41 = call i8* @strdup(i8* %5)
%42 = load i32, i32* %1
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8*, i8** %27, i64 %43
store i8* %41, i8** %44
%45 = add nsw i32 %42, 1
store i32 %45, i32* %1
br label %46
46: ; preds = %36, %33
%47 = call i32 @feof(i32* %0)
%48 = icmp eq i32 %47, 0
br i1 %48, label %30, label %49
49: ; preds = %30, %46, %23, %2
%50 = phi i8** [ null, %2 ], [ %27, %23 ], [ %27, %46 ], [ %27, %30 ]
ret i8** %50
}