#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 EOF;
char fgetc(int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
char *malloc(int);
char *realloc(char *, int);
int /*<<< orphan*/ stdin;
char *readKeyboardInput() {
  char *userInput;
  char *temp;
  char inputChar = 0;
  int size = sizeof(char);
  int index = 0;
  int memBlock = 10;
  userInput = malloc(sizeof(char));
  if (userInput == NULL)
    return NULL;
  while (inputChar != '\n' && inputChar != EOF) {
    inputChar = fgetc(stdin);
    if (index > size) {
      size += memBlock;
      temp = realloc(userInput, size);
      if (temp == NULL) {
        free(userInput);
        return NULL;
      }
      userInput = temp;
    }
    userInput[index++] = inputChar;
  }
  return userInput;
}


x86 assembly (clang, -O0):
<readKeyboardInput>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movb   $0x0,-0x19(%rbp)
movl   $0x1,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0xa,-0x28(%rbp)
mov    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1187 <readKeyboardInput+0x47>
movq   $0x0,-0x8(%rbp)
jmp    1248 <readKeyboardInput+0x108>
jmp    118c <readKeyboardInput+0x4c>
movsbl -0x19(%rbp),%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x29(%rbp)
je     11b4 <readKeyboardInput+0x74>
movsbl -0x19(%rbp),%eax
mov    0x2e37(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
setne  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    11c4 <readKeyboardInput+0x84>
jmp    1240 <readKeyboardInput+0x100>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
call   1040 <fgetc@plt>
mov    %al,-0x19(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x20(%rbp),%eax
jle    1223 <readKeyboardInput+0xe3>
mov    -0x28(%rbp),%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%esi
call   1060 <realloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    121b <readKeyboardInput+0xdb>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    1248 <readKeyboardInput+0x108>
mov    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x19(%rbp),%dl
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x24(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    118c <readKeyboardInput+0x4c>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readKeyboardInput>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x1,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11d6 <readKeyboardInput+0x96>
mov    %rax,%r14
mov    0x2e7c(%rip),%r15
cmpb   $0x0,(%r15)
je     11c9 <readKeyboardInput+0x89>
mov    $0x1,%r12d
xor    %ebp,%ebp
mov    0x2e6f(%rip),%r13
nopl   0x0(%rax)
mov    0x0(%r13),%edi
call   1040 <fgetc@plt>
mov    %eax,%ebx
movslq %r12d,%rax
cmp    %rax,%rbp
jle    11b0 <readKeyboardInput+0x70>
add    $0xa,%r12d
mov    %r14,%rdi
mov    %r12d,%esi
call   1060 <realloc@plt>
test   %rax,%rax
jne    11b3 <readKeyboardInput+0x73>
jmp    11ce <readKeyboardInput+0x8e>
nopl   0x0(%rax)
mov    %r14,%rax
mov    %bl,(%rax,%rbp,1)
cmp    $0xa,%bl
je     11d8 <readKeyboardInput+0x98>
add    $0x1,%rbp
mov    %rax,%r14
cmp    (%r15),%bl
jne    1180 <readKeyboardInput+0x40>
jmp    11d8 <readKeyboardInput+0x98>
mov    %r14,%rax
jmp    11d8 <readKeyboardInput+0x98>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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