#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 */
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int EOF;
int fgetc(int /*<<< orphan*/);
char *malloc(int);
int /*<<< orphan*/ printf(char *);
char *realloc(char *, int);
int /*<<< orphan*/ stdin;
char *Input(char *buffer) {
  unsigned int size = 10;
  unsigned int len = 0;
  int ch;
  buffer = malloc(sizeof(char) * size);
  if (!buffer) {
    printf("Error allocating memory");
    return buffer;
  }
  while ((ch = fgetc(stdin)) != EOF && ch != '\n') {
    buffer[len] = ch;
    if (len == size - 1) {
      size = size << 4;
      buffer = realloc(buffer, sizeof(char) * size);
      if (!buffer) {
        printf("Error reallocating memory");
        return buffer;
      }
    }
    len++;
  }
  buffer[len] = '\0';
  buffer = realloc(buffer, sizeof(buffer));
  return buffer;
}


x86 assembly (clang, -O0):
<Input>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0xa,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x14(%rbp),%eax
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1190 <Input+0x50>
lea    0xe82(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1271 <Input+0x131>
jmp    1195 <Input+0x55>
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
call   1040 <fgetc@plt>
mov    %eax,%ecx
mov    %ecx,-0x1c(%rbp)
xor    %eax,%eax
mov    0x2e2f(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x1d(%rbp)
je     11c6 <Input+0x86>
cmpl   $0xa,-0x1c(%rbp)
setne  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    11d6 <Input+0x96>
jmp    124c <Input+0x10c>
mov    -0x1c(%rbp),%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    123e <Input+0xfe>
mov    -0x14(%rbp),%eax
shl    $0x4,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%eax
shl    $0x0,%rax
mov    %eax,%esi
call   1060 <realloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1239 <Input+0xf9>
lea    0xdf1(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1271 <Input+0x131>
jmp    123e <Input+0xfe>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1195 <Input+0x55>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
mov    $0x8,%esi
call   1060 <realloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Input>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    $0xa,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11e4 <Input+0xa4>
mov    %rax,%r14
mov    0x2e83(%rip),%r15
mov    (%r15),%edi
call   1040 <fgetc@plt>
xor    %ecx,%ecx
cmp    $0xa,%eax
je     11ca <Input+0x8a>
mov    0x2e65(%rip),%r12
cmp    (%r12),%eax
je     11ca <Input+0x8a>
mov    $0xa,%ebx
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
mov    %ebp,%ecx
mov    %al,(%r14,%rcx,1)
lea    -0x1(%rbx),%eax
cmp    %eax,%ebp
jne    11b2 <Input+0x72>
shl    $0x4,%ebx
mov    %r14,%rdi
mov    %ebx,%esi
call   1060 <realloc@plt>
mov    %rax,%r14
test   %rax,%rax
je     11ed <Input+0xad>
add    $0x1,%ebp
mov    (%r15),%edi
call   1040 <fgetc@plt>
cmp    $0xa,%eax
je     11c8 <Input+0x88>
cmp    (%r12),%eax
jne    1190 <Input+0x50>
mov    %ebp,%ecx
movb   $0x0,(%r14,%rcx,1)
mov    %r14,%rdi
mov    $0x8,%esi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <realloc@plt>
lea    0xe15(%rip),%rdi
jmp    11f4 <Input+0xb4>
lea    0xe24(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"Error allocating memory\00"
@stdin = global i32 0
@EOF = global i32 0
@.str.1 = [26 x i8] c"Error reallocating memory\00"
define i8* @Input(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i32 10, i32* %4
store i32 0, i32* %5
%7 = load i32, i32* %4
%8 = zext i32 %7 to i64
%9 = mul i64 1, %8
%10 = trunc i64 %9 to i32
%11 = call i8* @malloc(i32 %10)
store i8* %11, i8** %3
%12 = load i8*, i8** %3
%13 = icmp ne i8* %12, null
br i1 %13, label %17, label %14
14: ; preds = %1
%15 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%16 = load i8*, i8** %3
store i8* %16, i8** %2
br label %65
17: ; preds = %1
br label %18
18: ; preds = %54, %17
%19 = load i32, i32* @stdin
%20 = call i32 @fgetc(i32 %19)
store i32 %20, i32* %6
%21 = load i32, i32* @EOF
%22 = icmp ne i32 %20, %21
br i1 %22, label %23, label %26
23: ; preds = %18
%24 = load i32, i32* %6
%25 = icmp ne i32 %24, 10
br label %26
26: ; preds = %23, %18
%27 = phi i1 [ false, %18 ], [ %25, %23 ]
br i1 %27, label %28, label %57
28: ; preds = %26
%29 = load i32, i32* %6
%30 = trunc i32 %29 to i8
%31 = load i8*, i8** %3
%32 = load i32, i32* %5
%33 = zext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
store i8 %30, i8* %34
%35 = load i32, i32* %5
%36 = load i32, i32* %4
%37 = sub i32 %36, 1
%38 = icmp eq i32 %35, %37
br i1 %38, label %39, label %54
39: ; preds = %28
%40 = load i32, i32* %4
%41 = shl i32 %40, 4
store i32 %41, i32* %4
%42 = load i8*, i8** %3
%43 = load i32, i32* %4
%44 = zext i32 %43 to i64
%45 = mul i64 1, %44
%46 = trunc i64 %45 to i32
%47 = call i8* @realloc(i8* %42, i32 %46)
store i8* %47, i8** %3
%48 = load i8*, i8** %3
%49 = icmp ne i8* %48, null
br i1 %49, label %53, label %50
50: ; preds = %39
%51 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%52 = load i8*, i8** %3
store i8* %52, i8** %2
br label %65
53: ; preds = %39
br label %54
54: ; preds = %53, %28
%55 = load i32, i32* %5
%56 = add i32 %55, 1
store i32 %56, i32* %5
br label %18
57: ; preds = %26
%58 = load i8*, i8** %3
%59 = load i32, i32* %5
%60 = zext i32 %59 to i64
%61 = getelementptr inbounds i8, i8* %58, i64 %60
store i8 0, i8* %61
%62 = load i8*, i8** %3
%63 = call i8* @realloc(i8* %62, i32 8)
store i8* %63, i8** %3
%64 = load i8*, i8** %3
store i8* %64, i8** %2
br label %65
65: ; preds = %57, %50, %14
%66 = load i8*, i8** %2
ret i8* %66
}

LLVM IR (-O2):
@.str = [24 x i8] c"Error allocating memory\00"
@stdin = global i32 0
@EOF = global i32 0
@.str.1 = [26 x i8] c"Error reallocating memory\00"
define i8* @Input(i8* nocapture readnone %0) {
%2 = tail call dereferenceable_or_null(10) i8* @malloc(i32 10)
%3 = icmp eq i8* %2, null
br i1 %3, label %11, label %4
4: ; preds = %1
%5 = load i32, i32* @stdin
%6 = tail call i32 @fgetc(i32 %5)
%7 = load i32, i32* @EOF
%8 = icmp ne i32 %6, %7
%9 = icmp ne i32 %6, 10
%10 = and i1 %9, %8
br i1 %10, label %13, label %41
11: ; preds = %1
%12 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %46
13: ; preds = %4, %29
%14 = phi i32 [ %34, %29 ], [ %6, %4 ]
%15 = phi i32 [ %32, %29 ], [ 0, %4 ]
%16 = phi i32 [ %31, %29 ], [ 10, %4 ]
%17 = phi i8* [ %30, %29 ], [ %2, %4 ]
%18 = trunc i32 %14 to i8
%19 = zext i32 %15 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
store i8 %18, i8* %20
%21 = add i32 %16, -1
%22 = icmp eq i32 %15, %21
br i1 %22, label %23, label %29
23: ; preds = %13
%24 = shl i32 %16, 4
%25 = tail call i8* @realloc(i8* %17, i32 %24)
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %29
27: ; preds = %23
%28 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %46
29: ; preds = %23, %13
%30 = phi i8* [ %25, %23 ], [ %17, %13 ]
%31 = phi i32 [ %24, %23 ], [ %16, %13 ]
%32 = add i32 %15, 1
%33 = load i32, i32* @stdin
%34 = tail call i32 @fgetc(i32 %33)
%35 = load i32, i32* @EOF
%36 = icmp ne i32 %34, %35
%37 = icmp ne i32 %34, 10
%38 = and i1 %37, %36
br i1 %38, label %13, label %39
39: ; preds = %29
%40 = zext i32 %32 to i64
br label %41
41: ; preds = %39, %4
%42 = phi i8* [ %2, %4 ], [ %30, %39 ]
%43 = phi i64 [ 0, %4 ], [ %40, %39 ]
%44 = getelementptr inbounds i8, i8* %42, i64 %43
store i8 0, i8* %44
%45 = tail call i8* @realloc(i8* %42, i32 8)
br label %46
46: ; preds = %41, %27, %11
%47 = phi i8* [ null, %27 ], [ %45, %41 ], [ null, %11 ]
ret i8* %47
}