#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);
scalar_t__ malloc(int);
int /*<<< orphan*/ strncpy(char *, char *, int);
int getlines(char *lines[], int maxlen) {
  char line[100];
  int lines_num = 0;
  int line_len;
  while ((line_len = getline(line, 100)) > 0) {
    lines[lines_num] = (char *)malloc(sizeof(char) * line_len);
    strncpy(lines[lines_num], line, line_len);
    lines_num++;
  }
  return lines_num;
}


x86 assembly (clang, -O0):
<getlines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x74(%rbp)
lea    -0x70(%rbp),%rdi
mov    $0x64,%esi
call   1050 <getline@plt>
mov    %eax,-0x78(%rbp)
cmp    $0x0,%eax
jle    11a7 <getlines+0x77>
movslq -0x78(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,%rdx
mov    -0x8(%rbp),%rax
movslq -0x74(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x8(%rbp),%rax
movslq -0x74(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    -0x70(%rbp),%rsi
mov    -0x78(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
jmp    1149 <getlines+0x19>
mov    -0x74(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getlines>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x68,%rsp
mov    %rdi,%r14
mov    %rsp,%rdi
mov    $0x64,%esi
call   1050 <getline@plt>
test   %eax,%eax
jle    1191 <getlines+0x61>
mov    %eax,%ebp
xor    %ebx,%ebx
mov    %rsp,%r15
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebp,%edi
call   1040 <malloc@plt>
mov    %rax,(%r14,%rbx,8)
mov    %rax,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
call   1030 <strncpy@plt>
add    $0x1,%rbx
mov    %r15,%rdi
mov    $0x64,%esi
call   1050 <getline@plt>
mov    %eax,%ebp
test   %eax,%eax
jg     1160 <getlines+0x30>
jmp    1193 <getlines+0x63>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @getlines(i8** nocapture writeonly %0, i32 %1) {
%3 = alloca [100 x i8]
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%5 = call i32 @getline(i8* %4, i32 100)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %19
7: ; preds = %2, %7
%8 = phi i64 [ %14, %7 ], [ 0, %2 ]
%9 = phi i32 [ %15, %7 ], [ %5, %2 ]
%10 = call i64 @malloc(i32 %9)
%11 = inttoptr i64 %10 to i8*
%12 = getelementptr inbounds i8*, i8** %0, i64 %8
store i8* %11, i8** %12
%13 = call i32 @strncpy(i8* %11, i8* %4, i32 %9)
%14 = add nuw i64 %8, 1
%15 = call i32 @getline(i8* %4, i32 100)
%16 = icmp sgt i32 %15, 0
br i1 %16, label %7, label %17
17: ; preds = %7
%18 = trunc i64 %14 to i32
br label %19
19: ; preds = %17, %2
%20 = phi i32 [ 0, %2 ], [ %18, %17 ]
ret i32 %20
}