#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 EOF;
int getchar();
char *realloc(char *, int);
char *readString() {
  char *result = 0;
  int size = 0;
  int c;
  while (c = getchar(), c != '\n' && c != EOF) {
    result = realloc(result, sizeof(*result) * (size + 2));
    result[size++] = c;
  }
  if (result) {
    result[size] = 0;
  }
  return result;
}


x86 assembly (clang, -O0):
<readString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movq   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    $0x0,%al
call   1030 <getchar@plt>
mov    %eax,-0x10(%rbp)
xor    %eax,%eax
cmpl   $0xa,-0x10(%rbp)
mov    %al,-0x11(%rbp)
je     1162 <readString+0x42>
mov    -0x10(%rbp),%eax
mov    0x2e8e(%rip),%rcx
cmp    (%rcx),%eax
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1172 <readString+0x52>
jmp    11ac <readString+0x8c>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%eax
add    $0x2,%eax
cltq
shl    $0x0,%rax
mov    %eax,%esi
call   1040 <realloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0xc(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1137 <readString+0x17>
cmpq   $0x0,-0x8(%rbp)
je     11c3 <readString+0xa3>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readString>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %r15d,%r15d
xor    %eax,%eax
call   1030 <getchar@plt>
cmp    $0xa,%eax
je     1180 <readString+0x60>
mov    %eax,%ebp
mov    0x2ea9(%rip),%r14
cmp    (%r14),%eax
je     1180 <readString+0x60>
xor    %ebx,%ebx
xor    %r15d,%r15d
nopl   0x0(%rax)
lea    0x2(%rbx),%esi
mov    %r15,%rdi
call   1040 <realloc@plt>
mov    %rax,%r15
mov    %bpl,(%rax,%rbx,1)
add    $0x1,%rbx
xor    %eax,%eax
call   1030 <getchar@plt>
cmp    $0xa,%eax
je     1179 <readString+0x59>
mov    %eax,%ebp
cmp    (%r14),%eax
jne    1150 <readString+0x30>
mov    %ebx,%eax
movb   $0x0,(%r15,%rax,1)
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@EOF = global i32 0
define i8* @readString() {
%1 = tail call i32 (...) @getchar()
%2 = icmp ne i32 %1, 10
%3 = load i32, i32* @EOF
%4 = icmp ne i32 %1, %3
%5 = select i1 %2, i1 %4, i1 false
br i1 %5, label %6, label %24
6: ; preds = %0, %6
%7 = phi i64 [ %14, %6 ], [ 0, %0 ]
%8 = phi i32 [ %16, %6 ], [ %1, %0 ]
%9 = phi i8* [ %12, %6 ], [ null, %0 ]
%10 = trunc i64 %7 to i32
%11 = add i32 %10, 2
%12 = tail call i8* @realloc(i8* %9, i32 %11)
%13 = trunc i32 %8 to i8
%14 = add nuw i64 %7, 1
%15 = getelementptr inbounds i8, i8* %12, i64 %7
store i8 %13, i8* %15
%16 = tail call i32 (...) @getchar()
%17 = icmp ne i32 %16, 10
%18 = load i32, i32* @EOF
%19 = icmp ne i32 %16, %18
%20 = select i1 %17, i1 %19, i1 false
br i1 %20, label %6, label %21
21: ; preds = %6
%22 = and i64 %14, 4294967295
%23 = getelementptr inbounds i8, i8* %12, i64 %22
store i8 0, i8* %23
br label %24
24: ; preds = %0, %21
%25 = phi i8* [ %12, %21 ], [ null, %0 ]
ret i8* %25
}