#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 getchar();
char *malloc(int);
char *helpReadLine(int soFar) {
  int ch;
  char *rtnVal;
  ch = getchar();
  if (ch < 0 && soFar == 0) {
    return NULL;
  } else if (ch == '\n') {
    rtnVal = malloc(soFar + 1);
    ch = 0;
  } else {
    rtnVal = helpReadLine(soFar + 1);
  }
  rtnVal[soFar] = ch;
  return rtnVal;
}


x86 assembly (clang, -O0):
<helpReadLine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    1166 <helpReadLine+0x36>
cmpl   $0x0,-0xc(%rbp)
jne    1166 <helpReadLine+0x36>
movq   $0x0,-0x8(%rbp)
jmp    11b7 <helpReadLine+0x87>
cmpl   $0xa,-0x10(%rbp)
jne    118b <helpReadLine+0x5b>
mov    -0xc(%rbp),%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x10(%rbp)
jmp    119a <helpReadLine+0x6a>
mov    -0xc(%rbp),%edi
add    $0x1,%edi
call   1030 <helpReadLine@plt>
mov    %rax,-0x18(%rbp)
jmp    119f <helpReadLine+0x6f>
mov    -0x10(%rbp),%eax
mov    %al,%dl
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<helpReadLine>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%r14d
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %eax,%ebp
test   %r14d,%r14d
jne    114b <helpReadLine+0x1b>
test   %ebp,%ebp
js     116f <helpReadLine+0x3f>
lea    0x1(%r14),%edi
cmp    $0xa,%ebp
jne    1160 <helpReadLine+0x30>
call   1050 <malloc@plt>
mov    %rax,%rbx
xor    %ebp,%ebp
jmp    1168 <helpReadLine+0x38>
call   1030 <helpReadLine@plt>
mov    %rax,%rbx
movslq %r14d,%rax
mov    %bpl,(%rbx,%rax,1)
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define noalias i8* @helpReadLine(i32 %0) {
%2 = tail call i32 (...) @getchar()
%3 = icmp slt i32 %2, 0
%4 = icmp eq i32 %0, 0
%5 = and i1 %4, %3
br i1 %5, label %19, label %6
6: ; preds = %1
%7 = icmp eq i32 %2, 10
%8 = add nsw i32 %0, 1
br i1 %7, label %9, label %11
9: ; preds = %6
%10 = tail call i8* @malloc(i32 %8)
br label %14
11: ; preds = %6
%12 = tail call i8* @helpReadLine(i32 %8)
%13 = trunc i32 %2 to i8
br label %14
14: ; preds = %9, %11
%15 = phi i8 [ 0, %9 ], [ %13, %11 ]
%16 = phi i8* [ %10, %9 ], [ %12, %11 ]
%17 = sext i32 %0 to i64
%18 = getelementptr inbounds i8, i8* %16, i64 %17
store i8 %15, i8* %18
br label %19
19: ; preds = %1, %14
%20 = phi i8* [ %16, %14 ], [ null, %1 ]
ret i8* %20
}