#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 */
struct tnode {
  int dummy;
};

/* Variables and functions */
int getline(char **, size_t *, int /*<<< orphan*/);
char *malloc(int);
struct tnode *process_line(char *, int, struct tnode *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ treeprint_lines(struct tnode *);
int main() {
  size_t n = 10000;
  char *line = malloc(10000);
  struct tnode *root = NULL;
  int linecounter = 0;
  while (getline(&line, &n, stdin) != -1) {
    linecounter++;
    root = process_line(line, linecounter, root);
  }
  treeprint_lines(root);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x2710,-0x10(%rbp)
mov    $0x2710,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    0x2e6d(%rip),%rax
mov    (%rax),%edx
lea    -0x18(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1050 <getline@plt>
cmp    $0xffffffff,%eax
je     11b5 <main+0x75>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   1060 <process_line@plt>
mov    %rax,-0x20(%rbp)
jmp    1174 <main+0x34>
mov    -0x20(%rbp),%rdi
call   1030 <treeprint_lines@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
movq   $0x2710,0x8(%rsp)
mov    $0x2710,%edi
call   1040 <malloc@plt>
mov    %rax,(%rsp)
mov    0x2e7e(%rip),%r12
mov    (%r12),%edx
mov    %rsp,%rdi
lea    0x8(%rsp),%rsi
call   1050 <getline@plt>
cmp    $0xffffffff,%eax
je     11ba <main+0x7a>
mov    $0x1,%ebp
xor    %ebx,%ebx
mov    %rsp,%r14
lea    0x8(%rsp),%r15
nop
mov    (%rsp),%rdi
mov    %ebp,%esi
mov    %rbx,%rdx
call   1060 <process_line@plt>
mov    %rax,%rbx
mov    (%r12),%edx
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <getline@plt>
add    $0x1,%ebp
cmp    $0xffffffff,%eax
jne    1190 <main+0x50>
jmp    11bc <main+0x7c>
xor    %ebx,%ebx
mov    %rbx,%rdi
call   1030 <treeprint_lines@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tnode = type { i32 }
@stdin = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i8*
%4 = alloca %struct.tnode*
%5 = alloca i32
store i32 0, i32* %1
store i64 10000, i64* %2
%6 = call i8* @malloc(i32 10000)
store i8* %6, i8** %3
store %struct.tnode* null, %struct.tnode** %4
store i32 0, i32* %5
br label %7
7: ; preds = %11, %0
%8 = load i32, i32* @stdin
%9 = call i32 @getline(i8** %3, i64* %2, i32 %8)
%10 = icmp ne i32 %9, -1
br i1 %10, label %11, label %18
11: ; preds = %7
%12 = load i32, i32* %5
%13 = add nsw i32 %12, 1
store i32 %13, i32* %5
%14 = load i8*, i8** %3
%15 = load i32, i32* %5
%16 = load %struct.tnode*, %struct.tnode** %4
%17 = call %struct.tnode* @process_line(i8* %14, i32 %15, %struct.tnode* %16)
store %struct.tnode* %17, %struct.tnode** %4
br label %7
18: ; preds = %7
%19 = load %struct.tnode*, %struct.tnode** %4
%20 = call i32 @treeprint_lines(%struct.tnode* %19)
ret i32 0
}

LLVM IR (-O2):
%struct.tnode = type { i32 }
@stdin = global i32 0
define i32 @main() {
%1 = alloca i64
%2 = alloca i8*
%3 = bitcast i64* %1 to i8*
store i64 10000, i64* %1
%4 = bitcast i8** %2 to i8*
%5 = tail call dereferenceable_or_null(10000) i8* @malloc(i32 10000)
store i8* %5, i8** %2
%6 = load i32, i32* @stdin
%7 = call i32 @getline(i8** %2, i64* %1, i32 %6)
%8 = icmp eq i32 %7, -1
br i1 %8, label %18, label %9
9: ; preds = %0, %9
%10 = phi i32 [ %12, %9 ], [ 0, %0 ]
%11 = phi %struct.tnode* [ %14, %9 ], [ null, %0 ]
%12 = add nuw nsw i32 %10, 1
%13 = load i8*, i8** %2
%14 = call %struct.tnode* @process_line(i8* %13, i32 %12, %struct.tnode* %11)
%15 = load i32, i32* @stdin
%16 = call i32 @getline(i8** %2, i64* %1, i32 %15)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %9
18: ; preds = %9, %0
%19 = phi %struct.tnode* [ null, %0 ], [ %14, %9 ]
%20 = call i32 @treeprint_lines(%struct.tnode* %19)
ret i32 0
}