#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 */
int get_line(char *);
char *stpcpy(char *, char *);
int read_lines(char *line_pointer_array[]) {
  char line[1000], *line_pointer = line_pointer_array[0];
  int line_length, line_number = 0;
  while ((line_length = get_line(line)) > 0 && line_number < 5000)
    line_pointer = line_pointer_array[++line_number] =
        stpcpy(line_pointer, line) + 1;
  return (line_number < 5000) ? line_number : -1;
}


x86 assembly (clang, -O0):
<read_lines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x3f8(%rbp)
movl   $0x0,-0x400(%rbp)
lea    -0x3f0(%rbp),%rdi
call   1030 <get_line@plt>
mov    %eax,%ecx
mov    %ecx,-0x3fc(%rbp)
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x401(%rbp)
jle    117f <read_lines+0x5f>
cmpl   $0x1388,-0x400(%rbp)
setl   %al
mov    %al,-0x401(%rbp)
mov    -0x401(%rbp),%al
test   $0x1,%al
jne    1192 <read_lines+0x72>
jmp    11cf <read_lines+0xaf>
mov    -0x3f8(%rbp),%rdi
lea    -0x3f0(%rbp),%rsi
call   1040 <stpcpy@plt>
add    $0x1,%rax
mov    -0x8(%rbp),%rcx
mov    -0x400(%rbp),%edx
add    $0x1,%edx
mov    %edx,-0x400(%rbp)
movslq %edx,%rdx
mov    %rax,(%rcx,%rdx,8)
mov    %rax,-0x3f8(%rbp)
jmp    1147 <read_lines+0x27>
cmpl   $0x1388,-0x400(%rbp)
jge    11f0 <read_lines+0xd0>
mov    -0x400(%rbp),%eax
mov    %eax,-0x408(%rbp)
jmp    1200 <read_lines+0xe0>
mov    $0xffffffff,%eax
mov    %eax,-0x408(%rbp)
jmp    1200 <read_lines+0xe0>
mov    -0x408(%rbp),%eax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_lines>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x3f0,%rsp
mov    %rdi,%r14
mov    (%rdi),%rbx
mov    %rsp,%rdi
call   1030 <get_line@plt>
test   %eax,%eax
jle    1195 <read_lines+0x75>
xor    %r12d,%r12d
mov    %rsp,%r15
nopl   0x0(%rax,%rax,1)
mov    %r12,%r13
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <stpcpy@plt>
mov    %rax,%rbx
add    $0x1,%rbx
add    $0x1,%r12
mov    %rbx,0x8(%r14,%r13,8)
mov    %r15,%rdi
call   1030 <get_line@plt>
test   %eax,%eax
jle    1183 <read_lines+0x63>
cmp    $0x1387,%r13
jb     1150 <read_lines+0x30>
cmp    $0x1387,%r13
mov    $0xffffffff,%eax
cmovb  %r12d,%eax
jmp    1197 <read_lines+0x77>
xor    %eax,%eax
add    $0x3f0,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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