#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 addSpace(int **, int, int, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ free(int *);
int getchar();
scalar_t__ malloc(int);
int /*<<< orphan*/ printData(int *, int);
int /*<<< orphan*/ printf(char *);
int main(void) {
  int *data;
  int characterInput;
  int arraySize = 5;
  int dataIndex = 0;
  data = (int *)malloc(5 * sizeof(int));
  if (!data) {
    printf("Memory allocation failed (malloc)");
    exit(0);
  }
  printf("Please enter you input, stopping at EOF:\n");
  while ((characterInput = getchar()) != EOF) {
    arraySize = addSpace(&data, dataIndex, characterInput, arraySize);
    if (arraySize == -1) {
      printf("Memory allocation failed by realloc");
      exit(0);
    }
    dataIndex++;
  }
  printf("Input received. You entered:\n");
  printData(data, dataIndex);
  free(data);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x5,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    $0x14,%edi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11b9 <main+0x49>
lea    0xe53(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
lea    0xe62(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <getchar@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e12(%rip),%rcx
cmp    (%rcx),%eax
je     121e <main+0xae>
mov    -0x1c(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    -0x10(%rbp),%rdi
call   1050 <addSpace@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    1210 <main+0xa0>
lea    0xe48(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11c5 <main+0x55>
lea    0xe4b(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1080 <printData@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0x14,%edi
call   1080 <malloc@plt>
mov    %rax,(%rsp)
test   %rax,%rax
je     1234 <main+0xb4>
lea    0xea1(%rip),%rdi
call   1040 <puts@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1070 <getchar@plt>
mov    0x2e2e(%rip),%r15
cmp    (%r15),%eax
je     11f4 <main+0x74>
mov    $0x5,%ebp
mov    %rsp,%r14
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %ebx,%esi
mov    %eax,%edx
mov    %ebp,%ecx
call   1060 <addSpace@plt>
cmp    $0xffffffff,%eax
je     1221 <main+0xa1>
mov    %eax,%ebp
add    $0x1,%ebx
xor    %eax,%eax
call   1070 <getchar@plt>
cmp    (%r15),%eax
jne    11d0 <main+0x50>
lea    0xe74(%rip),%rdi
call   1040 <puts@plt>
mov    (%rsp),%rdi
mov    %ebx,%esi
call   1090 <printData@plt>
mov    (%rsp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdfa(%rip),%rdi
call   1050 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
lea    0xdc5(%rip),%rdi
jmp    1228 <main+0xa8>

LLVM IR (-O0):
@.str = [34 x i8] c"Memory allocation failed (malloc)\00"
@.str.1 = [42 x i8] c"Please enter you input, stopping at EOF:\0A\00"
@EOF = global i32 0
@.str.2 = [36 x i8] c"Memory allocation failed by realloc\00"
@.str.3 = [30 x i8] c"Input received. You entered:\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 5, i32* %4
store i32 0, i32* %5
%6 = call i64 @malloc(i32 20)
%7 = inttoptr i64 %6 to i32*
store i32* %7, i32** %2
%8 = load i32*, i32** %2
%9 = icmp ne i32* %8, null
br i1 %9, label %13, label %10
10: ; preds = %0
%11 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @exit(i32 0)
unreachable
13: ; preds = %0
%14 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %29, %13
%16 = call i32 (...) @getchar()
store i32 %16, i32* %3
%17 = load i32, i32* @EOF
%18 = icmp ne i32 %16, %17
br i1 %18, label %19, label %32
19: ; preds = %15
%20 = load i32, i32* %5
%21 = load i32, i32* %3
%22 = load i32, i32* %4
%23 = call i32 @addSpace(i32** %2, i32 %20, i32 %21, i32 %22)
store i32 %23, i32* %4
%24 = load i32, i32* %4
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %29
26: ; preds = %19
%27 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
%28 = call i32 @exit(i32 0)
unreachable
29: ; preds = %19
%30 = load i32, i32* %5
%31 = add nsw i32 %30, 1
store i32 %31, i32* %5
br label %15
32: ; preds = %15
%33 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
%34 = load i32*, i32** %2
%35 = load i32, i32* %5
%36 = call i32 @printData(i32* %34, i32 %35)
%37 = load i32*, i32** %2
%38 = call i32 @free(i32* %37)
ret i32 0
}

LLVM IR (-O2):
@.str = [34 x i8] c"Memory allocation failed (malloc)\00"
@EOF = global i32 0
@.str.2 = [36 x i8] c"Memory allocation failed by realloc\00"
@str = [41 x i8] c"Please enter you input, stopping at EOF:\00"
@str.4 = [29 x i8] c"Input received. You entered:\00"
define i32 @main() {
%1 = alloca i32*
%2 = bitcast i32** %1 to i8*
%3 = tail call i64 @malloc(i32 20)
%4 = inttoptr i64 %3 to i32*
store i32* %4, i32** %1
%5 = icmp eq i64 %3, 0
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 0)
unreachable
9: ; preds = %0
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str, i64 0, i64 0))
%11 = call i32 (...) @getchar()
%12 = load i32, i32* @EOF
%13 = icmp eq i32 %11, %12
br i1 %13, label %28, label %14
14: ; preds = %9, %23
%15 = phi i32 [ %25, %23 ], [ %11, %9 ]
%16 = phi i32 [ %24, %23 ], [ 0, %9 ]
%17 = phi i32 [ %18, %23 ], [ 5, %9 ]
%18 = call i32 @addSpace(i32** %1, i32 %16, i32 %15, i32 %17)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %23
20: ; preds = %14
%21 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
%22 = call i32 @exit(i32 0)
unreachable
23: ; preds = %14
%24 = add nuw nsw i32 %16, 1
%25 = call i32 (...) @getchar()
%26 = load i32, i32* @EOF
%27 = icmp eq i32 %25, %26
br i1 %27, label %28, label %14
28: ; preds = %23, %9
%29 = phi i32 [ 0, %9 ], [ %24, %23 ]
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.4, i64 0, i64 0))
%31 = load i32*, i32** %1
%32 = call i32 @printData(i32* %31, i32 %29)
%33 = load i32*, i32** %1
%34 = call i32 @free(i32* %33)
ret i32 0
}