#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 */
char *alloc(int);
int get_line(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ strcpy(char *, char *);
int read_lines(char *line_pointer_array[], FILE *test) {
  char line[1000], *line_pointer;
  int line_length, line_count = 0;
  while (line_length = get_line(line, 1000, test)) {
    if (line_count < 5000 && (line_pointer = alloc(line_length)) != NULL) {
      strcpy(line_pointer, line);
      line_pointer_array[line_count++] = line_pointer;
    } else
      return -1;
  }
  return line_count;
}


x86 assembly (clang, -O0):
<read_lines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x410(%rbp)
lea    -0x400(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x3e8,%esi
call   1040 <get_line@plt>
mov    %eax,-0x40c(%rbp)
cmp    $0x0,%eax
je     11e9 <read_lines+0xb9>
cmpl   $0x1388,-0x410(%rbp)
jge    11d8 <read_lines+0xa8>
mov    -0x40c(%rbp),%edi
call   1050 <alloc@plt>
mov    %rax,-0x408(%rbp)
cmp    $0x0,%rax
je     11d8 <read_lines+0xa8>
mov    -0x408(%rbp),%rdi
lea    -0x400(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x408(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    -0x410(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x410(%rbp)
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
jmp    11e4 <read_lines+0xb4>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f2 <read_lines+0xc2>
jmp    114d <read_lines+0x1d>
mov    -0x410(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_lines>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x3e8,%rsp
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsp,%rdi
mov    $0x3e8,%esi
mov    %r15,%rdx
call   1040 <get_line@plt>
test   %eax,%eax
je     11b4 <read_lines+0x84>
xor    %ebp,%ebp
mov    %rsp,%r12
mov    $0xffffffff,%r13d
cs nopw 0x0(%rax,%rax,1)
cmp    $0x1388,%rbp
je     11b7 <read_lines+0x87>
mov    %eax,%edi
call   1050 <alloc@plt>
test   %rax,%rax
je     11b7 <read_lines+0x87>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r12,%rsi
call   1030 <strcpy@plt>
mov    %rbx,(%r14,%rbp,8)
add    $0x1,%rbp
mov    %r12,%rdi
mov    $0x3e8,%esi
mov    %r15,%rdx
call   1040 <get_line@plt>
test   %eax,%eax
jne    1170 <read_lines+0x40>
mov    %ebp,%r13d
jmp    11b7 <read_lines+0x87>
xor    %r13d,%r13d
mov    %r13d,%eax
add    $0x3e8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @read_lines(i8** %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32*
%6 = alloca [1000 x i8]
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i8** %0, i8*** %4
store i32* %1, i32** %5
store i32 0, i32* %9
br label %10
10: ; preds = %33, %2
%11 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%12 = load i32*, i32** %5
%13 = call i32 @get_line(i8* %11, i32 1000, i32* %12)
store i32 %13, i32* %8
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %34
15: ; preds = %10
%16 = load i32, i32* %9
%17 = icmp slt i32 %16, 5000
br i1 %17, label %18, label %32
18: ; preds = %15
%19 = load i32, i32* %8
%20 = call i8* @alloc(i32 %19)
store i8* %20, i8** %7
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %32
22: ; preds = %18
%23 = load i8*, i8** %7
%24 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%25 = call i32 @strcpy(i8* %23, i8* %24)
%26 = load i8*, i8** %7
%27 = load i8**, i8*** %4
%28 = load i32, i32* %9
%29 = add nsw i32 %28, 1
store i32 %29, i32* %9
%30 = sext i32 %28 to i64
%31 = getelementptr inbounds i8*, i8** %27, i64 %30
store i8* %26, i8** %31
br label %33
32: ; preds = %18, %15
store i32 -1, i32* %3
br label %36
33: ; preds = %22
br label %10
34: ; preds = %10
%35 = load i32, i32* %9
store i32 %35, i32* %3
br label %36
36: ; preds = %34, %32
%37 = load i32, i32* %3
ret i32 %37
}

LLVM IR (-O2):
define i32 @read_lines(i8** nocapture writeonly %0, i32* %1) {
%3 = alloca [1000 x i8]
%4 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%5 = call i32 @get_line(i8* %4, i32 1000, i32* %1)
%6 = icmp eq i32 %5, 0
br i1 %6, label %22, label %7
7: ; preds = %2, %14
%8 = phi i64 [ %16, %14 ], [ 0, %2 ]
%9 = phi i32 [ %18, %14 ], [ %5, %2 ]
%10 = icmp eq i64 %8, 5000
br i1 %10, label %22, label %11
11: ; preds = %7
%12 = call i8* @alloc(i32 %9)
%13 = icmp eq i8* %12, null
br i1 %13, label %22, label %14
14: ; preds = %11
%15 = call i32 @strcpy(i8* %12, i8* %4)
%16 = add nuw nsw i64 %8, 1
%17 = getelementptr inbounds i8*, i8** %0, i64 %8
store i8* %12, i8** %17
%18 = call i32 @get_line(i8* %4, i32 1000, i32* %1)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %7
20: ; preds = %14
%21 = trunc i64 %16 to i32
br label %22
22: ; preds = %7, %11, %20, %2
%23 = phi i32 [ 0, %2 ], [ %21, %20 ], [ -1, %11 ], [ -1, %7 ]
ret i32 %23
}