#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*/ stdin;
int x_getline(char **, int /*<<< orphan*/);
char **x_realloc(char **, size_t);
char **read_lines(size_t *count) {
  size_t used = 0;
  size_t allocated = 0;
  char **lines = NULL;
  char *line = NULL;
  while ((x_getline(&line, stdin)) != -1) {
    if (used >= allocated) {
      allocated += 1;
      allocated *= 2;
      lines = x_realloc(lines, allocated * sizeof(char *));
    }
    lines[used++] = line;
  }
  *count = used;
  return lines;
}


x86 assembly (clang, -O0):
<read_lines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    0x2e95(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1030 <x_getline@plt>
cmp    $0xffffffff,%eax
je     11c2 <read_lines+0xa2>
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jb     11a2 <read_lines+0x82>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
shl    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
shl    $0x3,%rsi
call   1040 <x_realloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rdx
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    %rcx,%rsi
add    $0x1,%rsi
mov    %rsi,-0x10(%rbp)
mov    %rdx,(%rax,%rcx,8)
jmp    114c <read_lines+0x2c>
mov    -0x10(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_lines>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
movq   $0x0,(%rsp)
mov    0x2eab(%rip),%r12
mov    (%r12),%esi
mov    %rsp,%rdi
call   1030 <x_getline@plt>
cmp    $0xffffffff,%eax
je     11a5 <read_lines+0x85>
xor    %r13d,%r13d
mov    %rsp,%r15
xor    %ebp,%ebp
xor    %ebx,%ebx
jmp    117e <read_lines+0x5e>
nopw   0x0(%rax,%rax,1)
mov    (%rsp),%rax
mov    %rax,0x0(%r13,%rbx,8)
add    $0x1,%rbx
mov    (%r12),%esi
mov    %r15,%rdi
call   1030 <x_getline@plt>
cmp    $0xffffffff,%eax
je     11aa <read_lines+0x8a>
cmp    %rbp,%rbx
jb     1160 <read_lines+0x40>
mov    %rbp,%rax
add    %rbp,%rax
add    %rbp,%rbp
add    $0x2,%rbp
lea    0x10(,%rax,8),%rsi
mov    %r13,%rdi
call   1040 <x_realloc@plt>
mov    %rax,%r13
jmp    1160 <read_lines+0x40>
xor    %ebx,%ebx
xor    %r13d,%r13d
mov    %rbx,(%r14)
mov    %r13,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
define i8** @read_lines(i64* %0) {
%2 = alloca i64*
%3 = alloca i64
%4 = alloca i64
%5 = alloca i8**
%6 = alloca i8*
store i64* %0, i64** %2
store i64 0, i64* %3
store i64 0, i64* %4
store i8** null, i8*** %5
store i8* null, i8** %6
br label %7
7: ; preds = %24, %1
%8 = load i32, i32* @stdin
%9 = call i32 @x_getline(i8** %6, i32 %8)
%10 = icmp ne i32 %9, -1
br i1 %10, label %11, label %30
11: ; preds = %7
%12 = load i64, i64* %3
%13 = load i64, i64* %4
%14 = icmp uge i64 %12, %13
br i1 %14, label %15, label %24
15: ; preds = %11
%16 = load i64, i64* %4
%17 = add i64 %16, 1
store i64 %17, i64* %4
%18 = load i64, i64* %4
%19 = mul i64 %18, 2
store i64 %19, i64* %4
%20 = load i8**, i8*** %5
%21 = load i64, i64* %4
%22 = mul i64 %21, 8
%23 = call i8** @x_realloc(i8** %20, i64 %22)
store i8** %23, i8*** %5
br label %24
24: ; preds = %15, %11
%25 = load i8*, i8** %6
%26 = load i8**, i8*** %5
%27 = load i64, i64* %3
%28 = add i64 %27, 1
store i64 %28, i64* %3
%29 = getelementptr inbounds i8*, i8** %26, i64 %27
store i8* %25, i8** %29
br label %7
30: ; preds = %7
%31 = load i64, i64* %3
%32 = load i64*, i64** %2
store i64 %31, i64* %32
%33 = load i8**, i8*** %5
ret i8** %33
}

LLVM IR (-O2):
@stdin = global i32 0
define i8** @read_lines(i64* nocapture writeonly %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
store i8* null, i8** %2
%4 = load i32, i32* @stdin
%5 = call i32 @x_getline(i8** %2, i32 %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %26, label %7
7: ; preds = %1, %17
%8 = phi i8** [ %19, %17 ], [ null, %1 ]
%9 = phi i64 [ %18, %17 ], [ 0, %1 ]
%10 = phi i64 [ %21, %17 ], [ 0, %1 ]
%11 = icmp ult i64 %10, %9
br i1 %11, label %17, label %12
12: ; preds = %7
%13 = shl i64 %9, 1
%14 = add i64 %13, 2
%15 = shl i64 %14, 3
%16 = call i8** @x_realloc(i8** %8, i64 %15)
br label %17
17: ; preds = %12, %7
%18 = phi i64 [ %14, %12 ], [ %9, %7 ]
%19 = phi i8** [ %16, %12 ], [ %8, %7 ]
%20 = load i8*, i8** %2
%21 = add i64 %10, 1
%22 = getelementptr inbounds i8*, i8** %19, i64 %10
store i8* %20, i8** %22
%23 = load i32, i32* @stdin
%24 = call i32 @x_getline(i8** %2, i32 %23)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %7
26: ; preds = %17, %1
%27 = phi i64 [ 0, %1 ], [ %21, %17 ]
%28 = phi i8** [ null, %1 ], [ %19, %17 ]
store i64 %27, i64* %0
ret i8** %28
}