#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 */

/* Variables and functions */
char *alloc(int);
int get_line(char *, int);
int /*<<< orphan*/ strcpy(char *, char *);
int read_lines(char *line_pointer_array[]) {
  char line[1000], *line_pointer;
  int line_length, line_count = 0;
  while (line_length = get_line(line, 1000)) {
    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)
movl   $0x0,-0x410(%rbp)
lea    -0x400(%rbp),%rdi
mov    $0x3e8,%esi
call   1040 <get_line@plt>
mov    %eax,-0x40c(%rbp)
cmp    $0x0,%eax
je     11e1 <read_lines+0xb1>
cmpl   $0x1388,-0x410(%rbp)
jge    11d0 <read_lines+0xa0>
mov    -0x40c(%rbp),%edi
call   1050 <alloc@plt>
mov    %rax,-0x408(%rbp)
cmp    $0x0,%rax
je     11d0 <read_lines+0xa0>
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    11dc <read_lines+0xac>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ea <read_lines+0xba>
jmp    1149 <read_lines+0x19>
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   %r12
push   %rbx
sub    $0x3f0,%rsp
mov    %rdi,%r14
mov    %rsp,%rdi
mov    $0x3e8,%esi
call   1040 <get_line@plt>
test   %eax,%eax
je     11a1 <read_lines+0x71>
xor    %ebp,%ebp
mov    %rsp,%r15
mov    $0xffffffff,%r12d
xchg   %ax,%ax
cmp    $0x1388,%rbp
je     11a4 <read_lines+0x74>
mov    %eax,%edi
call   1050 <alloc@plt>
test   %rax,%rax
je     11a4 <read_lines+0x74>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
mov    %rbx,(%r14,%rbp,8)
add    $0x1,%rbp
mov    %r15,%rdi
mov    $0x3e8,%esi
call   1040 <get_line@plt>
test   %eax,%eax
jne    1160 <read_lines+0x30>
mov    %ebp,%r12d
jmp    11a4 <read_lines+0x74>
xor    %r12d,%r12d
mov    %r12d,%eax
add    $0x3f0,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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