#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 get_line(char *, int, int /*<<< orphan*/ *);
char *stpcpy(char *, char *);
int read_lines(char *line_pointer_array[], char *lines_buffer, FILE *test) {
  char line[1000], *lines_buffer_start = lines_buffer;
  int line_length, lines_count = 0;
  while (line_length = get_line(line, 1000, test)) {
    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    $0x420,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x418(%rbp)
movl   $0x0,-0x420(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x3e8,%esi
call   1030 <get_line@plt>
mov    %eax,-0x41c(%rbp)
cmp    $0x0,%eax
je     11fa <read_lines+0xda>
cmpl   $0x1388,-0x420(%rbp)
jge    11e9 <read_lines+0xc9>
mov    -0x418(%rbp),%rax
add    $0x4c4b40,%rax
mov    -0x18(%rbp),%rcx
movslq -0x41c(%rbp),%rdx
add    %rdx,%rcx
cmp    %rcx,%rax
jbe    11e9 <read_lines+0xc9>
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    -0x420(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x420(%rbp)
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%rdi
lea    -0x410(%rbp),%rsi
call   1040 <stpcpy@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11f5 <read_lines+0xd5>
movl   $0xffffffff,-0x4(%rbp)
jmp    1203 <read_lines+0xe3>
jmp    114c <read_lines+0x2c>
mov    -0x420(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x420,%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    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsp,%rdi
mov    $0x3e8,%esi
call   1030 <get_line@plt>
test   %eax,%eax
je     11ab <read_lines+0x8b>
lea    0x4c4b40(%rbx),%rbp
xor    %r13d,%r13d
mov    %rsp,%r12
nopl   0x0(%rax,%rax,1)
mov    $0xffffffff,%ecx
cmp    $0x1387,%r13
ja     11ad <read_lines+0x8d>
cltq
add    %rbx,%rax
cmp    %rax,%rbp
jbe    11ad <read_lines+0x8d>
mov    %rbx,(%r14,%r13,8)
add    $0x1,%r13
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <stpcpy@plt>
mov    %rax,%rbx
add    $0x1,%rbx
mov    %r12,%rdi
mov    $0x3e8,%esi
mov    %r15,%rdx
call   1030 <get_line@plt>
test   %eax,%eax
jne    1160 <read_lines+0x40>
mov    %r13d,%ecx
jmp    11ad <read_lines+0x8d>
xor    %ecx,%ecx
mov    %ecx,%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, i8* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca [1000 x i8]
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
store i8** %0, i8*** %5
store i8* %1, i8** %6
store i32* %2, i32** %7
%12 = load i8*, i8** %6
store i8* %12, i8** %9
store i32 0, i32* %11
br label %13
13: ; preds = %42, %3
%14 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%15 = load i32*, i32** %7
%16 = call i32 @get_line(i8* %14, i32 1000, i32* %15)
store i32 %16, i32* %10
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %43
18: ; preds = %13
%19 = load i32, i32* %11
%20 = icmp slt i32 %19, 5000
br i1 %20, label %21, label %41
21: ; preds = %18
%22 = load i8*, i8** %9
%23 = getelementptr inbounds i8, i8* %22, i64 5000000
%24 = load i8*, i8** %6
%25 = load i32, i32* %10
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = icmp ugt i8* %23, %27
br i1 %28, label %29, label %41
29: ; preds = %21
%30 = load i8*, i8** %6
%31 = load i8**, i8*** %5
%32 = load i32, i32* %11
%33 = add nsw i32 %32, 1
store i32 %33, i32* %11
%34 = sext i32 %32 to i64
%35 = getelementptr inbounds i8*, i8** %31, i64 %34
store i8* %30, i8** %35
%36 = load i8*, i8** %6
%37 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%38 = call i8* @stpcpy(i8* %36, i8* %37)
store i8* %38, i8** %6
%39 = load i8*, i8** %6
%40 = getelementptr inbounds i8, i8* %39, i32 1
store i8* %40, i8** %6
br label %42
41: ; preds = %21, %18
store i32 -1, i32* %4
br label %45
42: ; preds = %29
br label %13
43: ; preds = %13
%44 = load i32, i32* %11
store i32 %44, i32* %4
br label %45
45: ; preds = %43, %41
%46 = load i32, i32* %4
ret i32 %46
}

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