#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 *, int);
char *stpcpy(char *, char *);
int read_lines(char *line_pointer_array[], char *lines_buffer) {
  char line[1000], *lines_buffer_start = lines_buffer;
  int line_length, lines_count = 0;
  while (line_length = get_line(line, 1000)) {
    if (lines_count < 5000 &&
        lines_buffer_start + 5000 * 1000 > lines_buffer + line_length) {
      line_pointer_array[lines_count++] = lines_buffer;
      lines_buffer = stpcpy(lines_buffer, line);
      ++lines_buffer;
    } else
      return -1;
  }
  return lines_count;
}


x86 assembly (clang, -O0):
<read_lines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x408(%rbp)
movl   $0x0,-0x410(%rbp)
lea    -0x400(%rbp),%rdi
mov    $0x3e8,%esi
call   1030 <get_line@plt>
mov    %eax,-0x40c(%rbp)
cmp    $0x0,%eax
je     11f2 <read_lines+0xd2>
cmpl   $0x1388,-0x410(%rbp)
jge    11e1 <read_lines+0xc1>
mov    -0x408(%rbp),%rax
add    $0x4c4b40,%rax
mov    -0x18(%rbp),%rcx
movslq -0x40c(%rbp),%rdx
add    %rdx,%rcx
cmp    %rcx,%rax
jbe    11e1 <read_lines+0xc1>
mov    -0x18(%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)
mov    -0x18(%rbp),%rdi
lea    -0x400(%rbp),%rsi
call   1040 <stpcpy@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11ed <read_lines+0xcd>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fb <read_lines+0xdb>
jmp    1148 <read_lines+0x28>
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   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x3f0,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsp,%rdi
mov    $0x3e8,%esi
call   1030 <get_line@plt>
test   %eax,%eax
je     11a8 <read_lines+0x88>
lea    0x4c4b40(%rbx),%r13
xor    %r12d,%r12d
mov    %rsp,%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    $0xffffffff,%ecx
cmp    $0x1387,%r12
ja     11aa <read_lines+0x8a>
cltq
add    %rbx,%rax
cmp    %rax,%r13
jbe    11aa <read_lines+0x8a>
mov    %rbx,(%r14,%r12,8)
add    $0x1,%r12
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <stpcpy@plt>
mov    %rax,%rbx
add    $0x1,%rbx
mov    %r15,%rdi
mov    $0x3e8,%esi
call   1030 <get_line@plt>
test   %eax,%eax
jne    1160 <read_lines+0x40>
mov    %r12d,%ecx
jmp    11aa <read_lines+0x8a>
xor    %ecx,%ecx
mov    %ecx,%eax
add    $0x3f0,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i32 @read_lines(i8** nocapture writeonly %0, i8* %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)
%6 = icmp eq i32 %5, 0
br i1 %6, label %27, label %7
7: ; preds = %2
%8 = getelementptr inbounds i8, i8* %1, i64 5000000
br label %9
9: ; preds = %7, %18
%10 = phi i64 [ 0, %7 ], [ %19, %18 ]
%11 = phi i32 [ %5, %7 ], [ %23, %18 ]
%12 = phi i8* [ %1, %7 ], [ %22, %18 ]
%13 = icmp ult i64 %10, 5000
%14 = sext i32 %11 to i64
%15 = getelementptr inbounds i8, i8* %12, i64 %14
%16 = icmp ugt i8* %8, %15
%17 = select i1 %13, i1 %16, i1 false
br i1 %17, label %18, label %27
18: ; preds = %9
%19 = add nuw nsw i64 %10, 1
%20 = getelementptr inbounds i8*, i8** %0, i64 %10
store i8* %12, i8** %20
%21 = call i8* @stpcpy(i8* %12, i8* %4)
%22 = getelementptr inbounds i8, i8* %21, i64 1
%23 = call i32 @get_line(i8* %4, i32 1000)
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %9
25: ; preds = %18
%26 = trunc i64 %19 to i32
br label %27
27: ; preds = %9, %25, %2
%28 = phi i32 [ 0, %2 ], [ %26, %25 ], [ -1, %9 ]
ret i32 %28
}