#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 */
char *calloc(int, int);
int /*<<< orphan*/ feof(int /*<<< orphan*/);
char getchar();
char *realloc(char *, int);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
char *bufferedInput() {
  char *input = calloc(1, 1);
  char *realloc_ptr = NULL;
  char buffer[16];
  char c = 0;
  int count = 0;
  while (!feof(stdin) && c != '\n') {
    c = getchar();
    buffer[count++] = c;
    buffer[count] = '\0';
    if (strlen(buffer) >= 16 - 1) {
      realloc_ptr = realloc(input, strlen(input) + strlen(buffer) + 1);
      if (!realloc_ptr)
        return input;
      input = realloc_ptr;
      strcat(input, buffer);
      buffer[0] = '\0';
      count = 0;
    }
  }
  if (strlen(buffer) > 0) {
    realloc_ptr = realloc(input, strlen(input) + strlen(buffer) + 1);
    if (!realloc_ptr)
      return input;
    input = realloc_ptr;
    strcat(input, buffer);
  }
  return input;
}


x86 assembly (clang, -O0):
<bufferedInput>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    $0x1,%esi
mov    %esi,%edi
call   1040 <calloc@plt>
mov    %rax,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movb   $0x0,-0x31(%rbp)
movl   $0x0,-0x38(%rbp)
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
call   1060 <feof@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x39(%rbp)
jne    11b6 <bufferedInput+0x56>
movsbl -0x31(%rbp),%eax
cmp    $0xa,%eax
setne  %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    11c6 <bufferedInput+0x66>
jmp    126e <bufferedInput+0x10e>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%cl
mov    -0x38(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x38(%rbp)
cltq
mov    %cl,-0x30(%rbp,%rax,1)
movslq -0x38(%rbp),%rax
movb   $0x0,-0x30(%rbp,%rax,1)
lea    -0x30(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0xf,%eax
jl     1269 <bufferedInput+0x109>
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x4c(%rbp)
lea    -0x30(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x4c(%rbp),%esi
mov    -0x48(%rbp),%rdi
add    %eax,%esi
add    $0x1,%esi
call   1070 <realloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1249 <bufferedInput+0xe9>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12e7 <bufferedInput+0x187>
mov    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1080 <strcat@plt>
movb   $0x0,-0x30(%rbp)
movl   $0x0,-0x38(%rbp)
jmp    118b <bufferedInput+0x2b>
lea    -0x30(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%eax
jle    12df <bufferedInput+0x17f>
mov    -0x10(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x5c(%rbp)
lea    -0x30(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x5c(%rbp),%esi
mov    -0x58(%rbp),%rdi
add    %eax,%esi
add    $0x1,%esi
call   1070 <realloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    12ca <bufferedInput+0x16a>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12e7 <bufferedInput+0x187>
mov    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bufferedInput>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    $0x1,%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,%r15
mov    0x2e61(%rip),%r12
mov    (%r12),%edi
call   1060 <feof@plt>
test   %eax,%eax
je     11e8 <bufferedInput+0x88>
mov    %rsp,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    11d6 <bufferedInput+0x76>
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebx
mov    %rsp,%rdi
call   1030 <strlen@plt>
lea    (%rbx,%rax,1),%esi
add    $0x1,%esi
mov    %r15,%rdi
call   1070 <realloc@plt>
test   %rax,%rax
je     11d6 <bufferedInput+0x76>
mov    %rax,%rbx
mov    %rsp,%rsi
mov    %rax,%rdi
call   1080 <strcat@plt>
mov    %rbx,%r15
mov    %r15,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rsp,%r14
xor    %ebp,%ebp
nopl   (%rax)
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %eax,%r13d
movslq %ebp,%rbp
mov    %al,(%rsp,%rbp,1)
movb   $0x0,0x1(%rsp,%rbp,1)
mov    %r14,%rdi
call   1030 <strlen@plt>
cmp    $0xf,%eax
jl     1250 <bufferedInput+0xf0>
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1030 <strlen@plt>
lea    (%rbx,%rax,1),%esi
add    $0x1,%esi
mov    %r15,%rdi
call   1070 <realloc@plt>
test   %rax,%rax
je     11d6 <bufferedInput+0x76>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1080 <strcat@plt>
movb   $0x0,(%rsp)
xor    %ebp,%ebp
mov    %rbx,%r15
jmp    1254 <bufferedInput+0xf4>
add    $0x1,%rbp
mov    (%r12),%edi
call   1060 <feof@plt>
cmp    $0xa,%r13b
je     1194 <bufferedInput+0x34>
test   %eax,%eax
je     11f0 <bufferedInput+0x90>
jmp    1194 <bufferedInput+0x34>

LLVM IR (-O0):
@stdin = global i32 0
define i8* @bufferedInput() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca [16 x i8]
%5 = alloca i8
%6 = alloca i32
%7 = call i8* @calloc(i32 1, i32 1)
store i8* %7, i8** %2
store i8* null, i8** %3
store i8 0, i8* %5
store i32 0, i32* %6
br label %8
8: ; preds = %50, %0
%9 = load i32, i32* @stdin
%10 = call i32 @feof(i32 %9)
%11 = icmp ne i32 %10, 0
br i1 %11, label %16, label %12
12: ; preds = %8
%13 = load i8, i8* %5
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 10
br label %16
16: ; preds = %12, %8
%17 = phi i1 [ false, %8 ], [ %15, %12 ]
br i1 %17, label %18, label %51
18: ; preds = %16
%19 = call signext i8 (...) @getchar()
store i8 %19, i8* %5
%20 = load i8, i8* %5
%21 = load i32, i32* %6
%22 = add nsw i32 %21, 1
store i32 %22, i32* %6
%23 = sext i32 %21 to i64
%24 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 %23
store i8 %20, i8* %24
%25 = load i32, i32* %6
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 %26
store i8 0, i8* %27
%28 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%29 = call i32 @strlen(i8* %28)
%30 = icmp sge i32 %29, 15
br i1 %30, label %31, label %50
31: ; preds = %18
%32 = load i8*, i8** %2
%33 = load i8*, i8** %2
%34 = call i32 @strlen(i8* %33)
%35 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%36 = call i32 @strlen(i8* %35)
%37 = add nsw i32 %34, %36
%38 = add nsw i32 %37, 1
%39 = call i8* @realloc(i8* %32, i32 %38)
store i8* %39, i8** %3
%40 = load i8*, i8** %3
%41 = icmp ne i8* %40, null
br i1 %41, label %44, label %42
42: ; preds = %31
%43 = load i8*, i8** %2
store i8* %43, i8** %1
br label %75
44: ; preds = %31
%45 = load i8*, i8** %3
store i8* %45, i8** %2
%46 = load i8*, i8** %2
%47 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%48 = call i32 @strcat(i8* %46, i8* %47)
%49 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
store i8 0, i8* %49
store i32 0, i32* %6
br label %50
50: ; preds = %44, %18
br label %8
51: ; preds = %16
%52 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%53 = call i32 @strlen(i8* %52)
%54 = icmp sgt i32 %53, 0
br i1 %54, label %55, label %73
55: ; preds = %51
%56 = load i8*, i8** %2
%57 = load i8*, i8** %2
%58 = call i32 @strlen(i8* %57)
%59 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%60 = call i32 @strlen(i8* %59)
%61 = add nsw i32 %58, %60
%62 = add nsw i32 %61, 1
%63 = call i8* @realloc(i8* %56, i32 %62)
store i8* %63, i8** %3
%64 = load i8*, i8** %3
%65 = icmp ne i8* %64, null
br i1 %65, label %68, label %66
66: ; preds = %55
%67 = load i8*, i8** %2
store i8* %67, i8** %1
br label %75
68: ; preds = %55
%69 = load i8*, i8** %3
store i8* %69, i8** %2
%70 = load i8*, i8** %2
%71 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%72 = call i32 @strcat(i8* %70, i8* %71)
br label %73
73: ; preds = %68, %51
%74 = load i8*, i8** %2
store i8* %74, i8** %1
br label %75
75: ; preds = %73, %66, %42
%76 = load i8*, i8** %1
ret i8* %76
}

LLVM IR (-O2):
@stdin = global i32 0
define i8* @bufferedInput() {
%1 = alloca [16 x i8]
%2 = tail call dereferenceable_or_null(1) i8* @calloc(i32 1, i32 1)
%3 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 0
%4 = load i32, i32* @stdin
%5 = call i32 @feof(i32 %4)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %35
7: ; preds = %0, %27
%8 = phi i32 [ %29, %27 ], [ 0, %0 ]
%9 = phi i8* [ %28, %27 ], [ %2, %0 ]
%10 = call signext i8 (...) @getchar()
%11 = add nsw i32 %8, 1
%12 = sext i32 %8 to i64
%13 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 %12
store i8 %10, i8* %13
%14 = sext i32 %11 to i64
%15 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 %14
store i8 0, i8* %15
%16 = call i32 @strlen(i8* %3)
%17 = icmp sgt i32 %16, 14
br i1 %17, label %18, label %27
18: ; preds = %7
%19 = call i32 @strlen(i8* %9)
%20 = call i32 @strlen(i8* %3)
%21 = add i32 %19, 1
%22 = add i32 %21, %20
%23 = call i8* @realloc(i8* %9, i32 %22)
%24 = icmp eq i8* %23, null
br i1 %24, label %48, label %25
25: ; preds = %18
%26 = call i32 @strcat(i8* %23, i8* %3)
store i8 0, i8* %3
br label %27
27: ; preds = %25, %7
%28 = phi i8* [ %23, %25 ], [ %9, %7 ]
%29 = phi i32 [ 0, %25 ], [ %11, %7 ]
%30 = load i32, i32* @stdin
%31 = call i32 @feof(i32 %30)
%32 = icmp eq i32 %31, 0
%33 = icmp ne i8 %10, 10
%34 = and i1 %33, %32
br i1 %34, label %7, label %35
35: ; preds = %27, %0
%36 = phi i8* [ %2, %0 ], [ %28, %27 ]
%37 = call i32 @strlen(i8* %3)
%38 = icmp sgt i32 %37, 0
br i1 %38, label %39, label %48
39: ; preds = %35
%40 = call i32 @strlen(i8* %36)
%41 = call i32 @strlen(i8* %3)
%42 = add i32 %40, 1
%43 = add i32 %42, %41
%44 = call i8* @realloc(i8* %36, i32 %43)
%45 = icmp eq i8* %44, null
br i1 %45, label %48, label %46
46: ; preds = %39
%47 = call i32 @strcat(i8* %44, i8* %3)
br label %48
48: ; preds = %18, %35, %46, %39
%49 = phi i8* [ %36, %39 ], [ %44, %46 ], [ %36, %35 ], [ %9, %18 ]
ret i8* %49
}