#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 /*<<< orphan*/ printf(char *, ...);
int readlines(char **, char *, int, int);
int main() {
  char *lineptr[100];
  char p[1000 * 100];
  int i, j;
  printf("Reading lines, terminate with EOF...\n");
  j = readlines(lineptr, p, 1000 * 100, 100);
  printf("Dumping lines...\n");
  for (i = 0; i < j; i++)
    printf("%s\n", lineptr[i]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x189e0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xec7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x330(%rbp),%rdi
lea    -0x189d0(%rbp),%rsi
mov    $0x186a0,%edx
mov    $0x64,%ecx
call   1040 <readlines@plt>
mov    %eax,-0x189d8(%rbp)
lea    0xebc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x189d4(%rbp)
mov    -0x189d4(%rbp),%eax
cmp    -0x189d8(%rbp),%eax
jge    11be <main+0x9e>
movslq -0x189d4(%rbp),%rax
mov    -0x330(%rbp,%rax,8),%rsi
ff
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x189d4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x189d4(%rbp)
jmp    117b <main+0x5b>
xor    %eax,%eax
add    $0x189e0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x189c8,%rsp
lea    0xecf(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rdi
lea    0x320(%rsp),%rsi
mov    $0x186a0,%edx
mov    $0x64,%ecx
call   1040 <readlines@plt>
mov    %eax,%ebx
lea    0xecc(%rip),%rdi
call   1030 <puts@plt>
test   %ebx,%ebx
jle    1182 <main+0x62>
mov    %ebx,%r14d
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    (%rsp,%rbx,8),%rdi
call   1030 <puts@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1170 <main+0x50>
xor    %eax,%eax
add    $0x189c8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [38 x i8] c"Reading lines, terminate with EOF...\0A\00"
@.str.1 = [18 x i8] c"Dumping lines...\0A\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i8*]
%3 = alloca [100000 x i8]
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds [100 x i8*], [100 x i8*]* %2, i64 0, i64 0
%8 = getelementptr inbounds [100000 x i8], [100000 x i8]* %3, i64 0, i64 0
%9 = call i32 @readlines(i8** %7, i8* %8, i32 100000, i32 100)
store i32 %9, i32* %5
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %4
br label %11
11: ; preds = %21, %0
%12 = load i32, i32* %4
%13 = load i32, i32* %5
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %24
15: ; preds = %11
%16 = load i32, i32* %4
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [100 x i8*], [100 x i8*]* %2, i64 0, i64 %17
%19 = load i8*, i8** %18
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %19)
br label %21
21: ; preds = %15
%22 = load i32, i32* %4
%23 = add nsw i32 %22, 1
store i32 %23, i32* %4
br label %11
24: ; preds = %11
ret i32 0
}

LLVM IR (-O2):
@str = [37 x i8] c"Reading lines, terminate with EOF...\00"
@str.3 = [17 x i8] c"Dumping lines...\00"
define i32 @main() {
%1 = alloca [100 x i8*]
%2 = alloca [100000 x i8]
%3 = bitcast [100 x i8*]* %1 to i8*
%4 = getelementptr inbounds [100000 x i8], [100000 x i8]* %2, i64 0, i64 0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str, i64 0, i64 0))
%6 = getelementptr inbounds [100 x i8*], [100 x i8*]* %1, i64 0, i64 0
%7 = call i32 @readlines(i8** %6, i8* %4, i32 100000, i32 100)
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.3, i64 0, i64 0))
%9 = icmp sgt i32 %7, 0
br i1 %9, label %10, label %19
10: ; preds = %0
%11 = zext i32 %7 to i64
br label %12
12: ; preds = %10, %12
%13 = phi i64 [ 0, %10 ], [ %17, %12 ]
%14 = getelementptr inbounds [100 x i8*], [100 x i8*]* %1, i64 0, i64 %13
%15 = load i8*, i8** %14
%16 = call i32 @puts(i8* dereferenceable(1) %15)
%17 = add nuw nsw i64 %13, 1
%18 = icmp eq i64 %17, %11
br i1 %18, label %19, label %12
19: ; preds = %12, %0
ret i32 0
}