#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*/ feof(int /*<<< orphan*/ *);
char *get_line(int /*<<< orphan*/ *);
scalar_t__ malloc(int);
scalar_t__ realloc(char **, int);
char **get_all_lines(FILE *fp, int *num_line) {
  char *buffer = NULL;
  int count = 0;
  char **data = 0;
  data = (char **)malloc(sizeof(char *));
  do {
    buffer = get_line(fp);
    if (buffer == NULL)
      continue;
    if (count == 0) {
      data[count] = buffer;
    } else {
      data = (char **)realloc(data, (sizeof(char *) * (count + 1)));
      data[count] = buffer;
    }
    count++;
  } while (!feof(fp));
  *num_line = (count - 1);
  return data;
}


x86 assembly (clang, -O0):
<get_all_lines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movq   $0x0,-0x28(%rbp)
mov    $0x8,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <get_line@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1192 <get_all_lines+0x52>
jmp    11e5 <get_all_lines+0xa5>
cmpl   $0x0,-0x1c(%rbp)
jne    11b1 <get_all_lines+0x71>
mov    -0x18(%rbp),%rdx
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
jmp    11dc <get_all_lines+0x9c>
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%esi
call   1060 <realloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdx
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1175 <get_all_lines+0x35>
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_all_lines>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x8,%edi
call   1050 <malloc@plt>
mov    %rax,%r12
xor    %r13d,%r13d
jmp    119e <get_all_lines+0x5e>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0x8(,%r13,8),%esi
mov    %r12,%rdi
call   1060 <realloc@plt>
movslq %r13d,%rcx
lea    (%rax,%rcx,8),%r12
mov    %rbx,(%r12)
add    $0x1,%r13d
mov    %rax,%r12
mov    %r15,%rdi
call   1040 <feof@plt>
test   %eax,%eax
jne    11b8 <get_all_lines+0x78>
mov    %r15,%rdi
call   1030 <get_line@plt>
test   %rax,%rax
je     1192 <get_all_lines+0x52>
mov    %rax,%rbx
test   %r13d,%r13d
jne    1170 <get_all_lines+0x30>
mov    %r12,%rax
jmp    1187 <get_all_lines+0x47>
add    $0xffffffff,%r13d
mov    %r13d,(%r14)
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8** @get_all_lines(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8**
store i32* %0, i32** %3
store i32* %1, i32** %4
store i8* null, i8** %5
store i32 0, i32* %6
store i8** null, i8*** %7
%8 = call i64 @malloc(i32 8)
%9 = inttoptr i64 %8 to i8**
store i8** %9, i8*** %7
br label %10
10: ; preds = %42, %2
%11 = load i32*, i32** %3
%12 = call i8* @get_line(i32* %11)
store i8* %12, i8** %5
%13 = load i8*, i8** %5
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %16
15: ; preds = %10
br label %42
16: ; preds = %10
%17 = load i32, i32* %6
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %16
%20 = load i8*, i8** %5
%21 = load i8**, i8*** %7
%22 = load i32, i32* %6
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8*, i8** %21, i64 %23
store i8* %20, i8** %24
br label %39
25: ; preds = %16
%26 = load i8**, i8*** %7
%27 = load i32, i32* %6
%28 = add nsw i32 %27, 1
%29 = sext i32 %28 to i64
%30 = mul i64 8, %29
%31 = trunc i64 %30 to i32
%32 = call i64 @realloc(i8** %26, i32 %31)
%33 = inttoptr i64 %32 to i8**
store i8** %33, i8*** %7
%34 = load i8*, i8** %5
%35 = load i8**, i8*** %7
%36 = load i32, i32* %6
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8*, i8** %35, i64 %37
store i8* %34, i8** %38
br label %39
39: ; preds = %25, %19
%40 = load i32, i32* %6
%41 = add nsw i32 %40, 1
store i32 %41, i32* %6
br label %42
42: ; preds = %39, %15
%43 = load i32*, i32** %3
%44 = call i32 @feof(i32* %43)
%45 = icmp ne i32 %44, 0
%46 = xor i1 %45, true
br i1 %46, label %10, label %47
47: ; preds = %42
%48 = load i32, i32* %6
%49 = sub nsw i32 %48, 1
%50 = load i32*, i32** %4
store i32 %49, i32* %50
%51 = load i8**, i8*** %7
ret i8** %51
}

LLVM IR (-O2):
define i8** @get_all_lines(i32* %0, i32* nocapture writeonly %1) {
%3 = tail call i64 @malloc(i32 8)
%4 = inttoptr i64 %3 to i8**
br label %5
5: ; preds = %23, %2
%6 = phi i32 [ 0, %2 ], [ %24, %23 ]
%7 = phi i8** [ %4, %2 ], [ %25, %23 ]
%8 = tail call i8* @get_line(i32* %0)
%9 = icmp eq i8* %8, null
br i1 %9, label %23, label %10
10: ; preds = %5
%11 = icmp eq i32 %6, 0
br i1 %11, label %19, label %12
12: ; preds = %10
%13 = shl i32 %6, 3
%14 = add i32 %13, 8
%15 = tail call i64 @realloc(i8** %7, i32 %14)
%16 = inttoptr i64 %15 to i8**
%17 = sext i32 %6 to i64
%18 = getelementptr inbounds i8*, i8** %16, i64 %17
br label %19
19: ; preds = %10, %12
%20 = phi i8** [ %18, %12 ], [ %7, %10 ]
%21 = phi i8** [ %16, %12 ], [ %7, %10 ]
store i8* %8, i8** %20
%22 = add nsw i32 %6, 1
br label %23
23: ; preds = %5, %19
%24 = phi i32 [ %6, %5 ], [ %22, %19 ]
%25 = phi i8** [ %7, %5 ], [ %21, %19 ]
%26 = tail call i32 @feof(i32* %0)
%27 = icmp eq i32 %26, 0
br i1 %27, label %5, label %28
28: ; preds = %23
%29 = add nsw i32 %24, -1
store i32 %29, i32* %1
ret i8** %25
}