#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 getline(char *, int);
char *malloc(int);
int /*<<< orphan*/ strcpy(char *, char *);
int readlines(char *linesarray[]) {
  char line[80];
  int len;
  char *p;
  int numberlines;
  numberlines = 0;
  while ((len = getline(line, 80)) > 0) {
    if (numberlines >= 30 || (p = malloc(len)) == 0)
      return 0;
    else {
      line[len - 1] = '\0';
      strcpy(p, line);
      linesarray[numberlines++] = p;
    }
  }
  return numberlines;
}


x86 assembly (clang, -O0):
<readlines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x74(%rbp)
lea    -0x60(%rbp),%rdi
mov    $0x50,%esi
call   1050 <getline@plt>
mov    %eax,-0x64(%rbp)
cmp    $0x0,%eax
jle    11c5 <readlines+0x95>
cmpl   $0x1e,-0x74(%rbp)
jge    1180 <readlines+0x50>
mov    -0x64(%rbp),%edi
call   1040 <malloc@plt>
mov    %rax,-0x70(%rbp)
cmp    $0x0,%rax
jne    118c <readlines+0x5c>
movl   $0x0,-0x4(%rbp)
jmp    11cb <readlines+0x9b>
mov    -0x64(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0x60(%rbp,%rax,1)
mov    -0x70(%rbp),%rdi
lea    -0x60(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x70(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    -0x74(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x74(%rbp)
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
jmp    1146 <readlines+0x16>
mov    -0x74(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readlines>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %rdi,%r15
mov    %rsp,%rdi
mov    $0x50,%esi
call   1050 <getline@plt>
test   %eax,%eax
jle    11a7 <readlines+0x77>
mov    %eax,%ebx
xor    %r14d,%r14d
mov    %rsp,%r12
xor    %ebp,%ebp
nopl   0x0(%rax)
cmp    $0x1e,%rbp
je     11aa <readlines+0x7a>
mov    %ebx,%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     11aa <readlines+0x7a>
mov    %rax,%r13
add    $0xffffffff,%ebx
movb   $0x0,(%rsp,%rbx,1)
mov    %rax,%rdi
mov    %r12,%rsi
call   1030 <strcpy@plt>
mov    %r13,(%r15,%rbp,8)
add    $0x1,%rbp
mov    %r12,%rdi
mov    $0x50,%esi
call   1050 <getline@plt>
mov    %eax,%ebx
test   %eax,%eax
jg     1160 <readlines+0x30>
mov    %ebp,%r14d
jmp    11aa <readlines+0x7a>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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