#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 EXIT_FAILURE;
char *alloc(int);
int get_line(char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
int read_lines(char *pline[], int maxlines) {
  int len, nlines = 0;
  char *p, line[1000];
  while ((len = get_line(line, 1000)) > 0)
    if (nlines >= maxlines || (p = alloc(len)) == NULL)
      return (EXIT_FAILURE);
    else {
      line[len - 1] = '\0';
      strncpy(p, line, len);
      pline[nlines++] = p;
    }
  return nlines;
}


x86 assembly (clang, -O0):
<read_lines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    -0x410(%rbp),%rdi
mov    $0x3e8,%esi
call   1040 <get_line@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jle    11db <read_lines+0xab>
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1188 <read_lines+0x58>
mov    -0x18(%rbp),%edi
call   1050 <alloc@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1199 <read_lines+0x69>
mov    0x2e51(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11e1 <read_lines+0xb1>
mov    -0x18(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0x410(%rbp,%rax,1)
mov    -0x28(%rbp),%rdi
lea    -0x410(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x28(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x1c(%rbp)
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
jmp    1149 <read_lines+0x19>
mov    -0x1c(%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    %esi,%r15d
mov    %rdi,%r14
mov    %rsp,%rdi
mov    $0x3e8,%esi
call   1040 <get_line@plt>
test   %eax,%eax
jle    11c1 <read_lines+0x91>
mov    %eax,%ebx
xor    %r13d,%r13d
test   %r15d,%r15d
cmovle %r13d,%r15d
mov    %rsp,%r12
nopw   0x0(%rax,%rax,1)
cmp    %r13,%r15
je     11b5 <read_lines+0x85>
mov    %ebx,%edi
call   1050 <alloc@plt>
test   %rax,%rax
je     11b5 <read_lines+0x85>
mov    %rax,%rbp
lea    -0x1(%rbx),%eax
movb   $0x0,(%rsp,%rax,1)
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %ebx,%edx
call   1030 <strncpy@plt>
mov    %rbp,(%r14,%r13,8)
add    $0x1,%r13
mov    %r12,%rdi
mov    $0x3e8,%esi
call   1040 <get_line@plt>
mov    %eax,%ebx
test   %eax,%eax
jg     1170 <read_lines+0x40>
jmp    11c4 <read_lines+0x94>
mov    0x2e24(%rip),%rax
mov    (%rax),%r13d
jmp    11c4 <read_lines+0x94>
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):
@EXIT_FAILURE = global i32 0
define i32 @read_lines(i8** %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca [1000 x i8]
store i8** %0, i8*** %4
store i32 %1, i32* %5
store i32 0, i32* %7
br label %10
10: ; preds = %39, %2
%11 = getelementptr inbounds [1000 x i8], [1000 x i8]* %9, i64 0, i64 0
%12 = call i32 @get_line(i8* %11, i32 1000)
store i32 %12, i32* %6
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %40
14: ; preds = %10
%15 = load i32, i32* %7
%16 = load i32, i32* %5
%17 = icmp sge i32 %15, %16
br i1 %17, label %22, label %18
18: ; preds = %14
%19 = load i32, i32* %6
%20 = call i8* @alloc(i32 %19)
store i8* %20, i8** %8
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %24
22: ; preds = %18, %14
%23 = load i32, i32* @EXIT_FAILURE
store i32 %23, i32* %3
br label %42
24: ; preds = %18
%25 = load i32, i32* %6
%26 = sub nsw i32 %25, 1
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [1000 x i8], [1000 x i8]* %9, i64 0, i64 %27
store i8 0, i8* %28
%29 = load i8*, i8** %8
%30 = getelementptr inbounds [1000 x i8], [1000 x i8]* %9, i64 0, i64 0
%31 = load i32, i32* %6
%32 = call i32 @strncpy(i8* %29, i8* %30, i32 %31)
%33 = load i8*, i8** %8
%34 = load i8**, i8*** %4
%35 = load i32, i32* %7
%36 = add nsw i32 %35, 1
store i32 %36, i32* %7
%37 = sext i32 %35 to i64
%38 = getelementptr inbounds i8*, i8** %34, i64 %37
store i8* %33, i8** %38
br label %39
39: ; preds = %24
br label %10
40: ; preds = %10
%41 = load i32, i32* %7
store i32 %41, i32* %3
br label %42
42: ; preds = %40, %22
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
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)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %30
7: ; preds = %2
%8 = call i32 @llvm.smax.i32(i32 %1, i32 0)
%9 = zext i32 %8 to i64
br label %10
10: ; preds = %7, %19
%11 = phi i64 [ 0, %7 ], [ %24, %19 ]
%12 = phi i32 [ %5, %7 ], [ %26, %19 ]
%13 = icmp eq i64 %11, %9
br i1 %13, label %17, label %14
14: ; preds = %10
%15 = call i8* @alloc(i32 %12)
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %19
17: ; preds = %14, %10
%18 = load i32, i32* @EXIT_FAILURE
br label %30
19: ; preds = %14
%20 = add nsw i32 %12, -1
%21 = zext i32 %20 to i64
%22 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 %21
store i8 0, i8* %22
%23 = call i32 @strncpy(i8* %15, i8* %4, i32 %12)
%24 = add nuw nsw i64 %11, 1
%25 = getelementptr inbounds i8*, i8** %0, i64 %11
store i8* %15, i8** %25
%26 = call i32 @get_line(i8* %4, i32 1000)
%27 = icmp sgt i32 %26, 0
br i1 %27, label %10, label %28
28: ; preds = %19
%29 = trunc i64 %24 to i32
br label %30
30: ; preds = %28, %2, %17
%31 = phi i32 [ %18, %17 ], [ 0, %2 ], [ %29, %28 ]
ret i32 %31
}