#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 /*<<< orphan*/ free(char *);
int getchar();
char *malloc(int);
char *realloc(char *, size_t);
char *getstr() {
  int c;
  size_t n;
  char *s, *t;
  if (!(s = t = malloc(1)))
    return NULL;
  for (n = 0; (c = getchar()) != EOF && c - '\n' && (t = realloc(s, n + 2));
       s[n++] = c)
    s = t;
  if (!t) {
    free(s);
    return NULL;
  }
  s[n] = '\0';
  return s;
}


x86 assembly (clang, -O0):
<getstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1171 <getstr+0x31>
movq   $0x0,-0x8(%rbp)
jmp    1239 <getstr+0xf9>
movq   $0x0,-0x18(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,%ecx
mov    %ecx,-0xc(%rbp)
xor    %eax,%eax
mov    0x2e5a(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x29(%rbp)
je     11cc <getstr+0x8c>
mov    -0xc(%rbp),%ecx
sub    $0xa,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x29(%rbp)
je     11cc <getstr+0x8c>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
add    $0x2,%rsi
call   1060 <realloc@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
setne  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    11dc <getstr+0x9c>
jmp    1204 <getstr+0xc4>
mov    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0xc(%rbp),%eax
mov    %al,%dl
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %rcx,%rsi
add    $0x1,%rsi
mov    %rsi,-0x18(%rbp)
mov    %dl,(%rax,%rcx,1)
jmp    1179 <getstr+0x39>
cmpq   $0x0,-0x28(%rbp)
jne    1225 <getstr+0xe5>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    1239 <getstr+0xf9>
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getstr>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    $0x1,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11c7 <getstr+0x87>
mov    %rax,%r14
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    $0xa,%eax
je     11b5 <getstr+0x75>
mov    %eax,%ebp
mov    0x2e77(%rip),%r12
cmp    (%r12),%eax
je     11b5 <getstr+0x75>
xor    %ebx,%ebx
nopl   0x0(%rax)
lea    0x2(%rbx),%rsi
mov    %r14,%rdi
call   1060 <realloc@plt>
test   %rax,%rax
je     11bf <getstr+0x7f>
mov    %rax,%r15
mov    %bpl,(%rax,%rbx,1)
add    $0x1,%rbx
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    $0xa,%eax
je     11b8 <getstr+0x78>
mov    %eax,%ebp
mov    %r15,%r14
cmp    (%r12),%eax
jne    1180 <getstr+0x40>
jmp    11b8 <getstr+0x78>
mov    %r14,%r15
movb   $0x0,(%r15,%rbx,1)
jmp    11ca <getstr+0x8a>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %r15d,%r15d
mov    %r15,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@EOF = global i32 0
define i8* @getstr() {
%1 = tail call dereferenceable_or_null(1) i8* @malloc(i32 1)
%2 = icmp eq i8* %1, null
br i1 %2, label %31, label %3
3: ; preds = %0
%4 = tail call i32 (...) @getchar()
%5 = load i32, i32* @EOF
%6 = icmp eq i32 %4, %5
%7 = icmp eq i32 %4, 10
%8 = or i1 %7, %6
br i1 %8, label %27, label %9
9: ; preds = %3, %16
%10 = phi i32 [ %20, %16 ], [ %4, %3 ]
%11 = phi i8* [ %14, %16 ], [ %1, %3 ]
%12 = phi i64 [ %18, %16 ], [ 0, %3 ]
%13 = add i64 %12, 2
%14 = tail call i8* @realloc(i8* %11, i64 %13)
%15 = icmp eq i8* %14, null
br i1 %15, label %25, label %16
16: ; preds = %9
%17 = trunc i32 %10 to i8
%18 = add i64 %12, 1
%19 = getelementptr inbounds i8, i8* %14, i64 %12
store i8 %17, i8* %19
%20 = tail call i32 (...) @getchar()
%21 = load i32, i32* @EOF
%22 = icmp eq i32 %20, %21
%23 = icmp eq i32 %20, 10
%24 = or i1 %23, %22
br i1 %24, label %27, label %9
25: ; preds = %9
%26 = tail call i32 @free(i8* %11)
br label %31
27: ; preds = %16, %3
%28 = phi i64 [ 0, %3 ], [ %18, %16 ]
%29 = phi i8* [ %1, %3 ], [ %14, %16 ]
%30 = getelementptr inbounds i8, i8* %29, i64 %28
store i8 0, i8* %30
br label %31
31: ; preds = %0, %27, %25
%32 = phi i8* [ %29, %27 ], [ null, %25 ], [ null, %0 ]
ret i8* %32
}