#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*/ array;

/* Variables and functions */
int /*<<< orphan*/ free(int *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ realloc(int *, int);
int /*<<< orphan*/ scanf(char *, int *);
int main(void) {
  int arraysize = 5;
  int id = 0;
  int userInput = 0;
  int *array;
  array = (int *)malloc(sizeof(int) * arraysize);
  while (1) {
    printf("Input integer: ");
    scanf("%d", &userInput);
    if (userInput == -1) {
      int i = 0;
      for (i = 0; i < id; i++) {
        printf("%d", array[i]);
      }
      printf("\n");
      free(array);
      return 0;
    } else {
      arraysize = (int)sizeof(array) / sizeof(int);
      if (id < arraysize) {
        array[id] = userInput;
      } else {
        array = (int *)realloc(array, arraysize + 3);
        array[id] = userInput;
      }
      id++;
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x5,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe74(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1070 <scanf@plt>
cmpl   $0xffffffff,-0x10(%rbp)
jne    120f <main+0xbf>
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11f0 <main+0xa0>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11bd <main+0x6d>
lea    0xe1c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret
movl   $0x2,-0x8(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1235 <main+0xe5>
mov    -0x10(%rbp),%edx
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
jmp    1256 <main+0x106>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
add    $0x3,%esi
call   1060 <realloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%edx
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1187 <main+0x37>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
movl   $0x0,0xc(%rsp)
mov    $0x14,%edi
call   1060 <malloc@plt>
mov    %rax,%r13
lea    0xe77(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe79(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1080 <scanf@plt>
mov    0xc(%rsp),%eax
cmp    $0xffffffff,%eax
je     1298 <main+0x138>
mov    %eax,0x0(%r13)
lea    0xe47(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe49(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1080 <scanf@plt>
mov    0xc(%rsp),%eax
cmp    $0xffffffff,%eax
je     125f <main+0xff>
mov    %eax,0x4(%r13)
lea    0xe17(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe19(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1080 <scanf@plt>
cmpl   $0xffffffff,0xc(%rsp)
je     1266 <main+0x106>
mov    $0x2,%ebx
lea    0xdec(%rip),%r14
lea    0xdf5(%rip),%r15
lea    0xc(%rsp),%r12
mov    %r13,%rdi
mov    $0x5,%esi
call   1070 <realloc@plt>
mov    %rax,%r13
mov    0xc(%rsp),%eax
mov    %eax,0x0(%r13,%rbx,4)
add    $0x1,%rbx
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1080 <scanf@plt>
cmpl   $0xffffffff,0xc(%rsp)
jne    1220 <main+0xc0>
test   %ebx,%ebx
jne    126b <main+0x10b>
jmp    1298 <main+0x138>
mov    $0x1,%ebx
jmp    126b <main+0x10b>
mov    $0x2,%ebx
mov    %ebx,%r15d
lea    0xd9b(%rip),%r14
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    0x0(%r13,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1280 <main+0x120>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %r13,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [16 x i8] c"Input integer: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
store i32 0, i32* %1
store i32 5, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
%7 = load i32, i32* %2
%8 = sext i32 %7 to i64
%9 = mul i64 4, %8
%10 = trunc i64 %9 to i32
%11 = call i64 @malloc(i32 %10)
%12 = inttoptr i64 %11 to i32*
store i32* %12, i32** %5
br label %13
13: ; preds = %0, %61
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%16 = load i32, i32* %4
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %37
18: ; preds = %13
store i32 0, i32* %6
store i32 0, i32* %6
br label %19
19: ; preds = %30, %18
%20 = load i32, i32* %6
%21 = load i32, i32* %3
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %33
23: ; preds = %19
%24 = load i32*, i32** %5
%25 = load i32, i32* %6
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i32, i32* %24, i64 %26
%28 = load i32, i32* %27
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %28)
br label %30
30: ; preds = %23
%31 = load i32, i32* %6
%32 = add nsw i32 %31, 1
store i32 %32, i32* %6
br label %19
33: ; preds = %19
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%35 = load i32*, i32** %5
%36 = call i32 @free(i32* %35)
ret i32 0
37: ; preds = %13
store i32 2, i32* %2
%38 = load i32, i32* %3
%39 = load i32, i32* %2
%40 = icmp slt i32 %38, %39
br i1 %40, label %41, label %47
41: ; preds = %37
%42 = load i32, i32* %4
%43 = load i32*, i32** %5
%44 = load i32, i32* %3
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i32, i32* %43, i64 %45
store i32 %42, i32* %46
br label %58
47: ; preds = %37
%48 = load i32*, i32** %5
%49 = load i32, i32* %2
%50 = add nsw i32 %49, 3
%51 = call i64 @realloc(i32* %48, i32 %50)
%52 = inttoptr i64 %51 to i32*
store i32* %52, i32** %5
%53 = load i32, i32* %4
%54 = load i32*, i32** %5
%55 = load i32, i32* %3
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i32, i32* %54, i64 %56
store i32 %53, i32* %57
br label %58
58: ; preds = %47, %41
%59 = load i32, i32* %3
%60 = add nsw i32 %59, 1
store i32 %60, i32* %3
br label %61
61: ; preds = %58
br label %13
}

LLVM IR (-O2):
@.str = [16 x i8] c"Input integer: \00"
@.str.1 = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%3 = tail call i64 @malloc(i32 20)
%4 = inttoptr i64 %3 to i32*
%5 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%7 = load i32, i32* %1
%8 = icmp eq i32 %7, -1
br i1 %8, label %35, label %9
9: ; preds = %0
store i32 %7, i32* %4
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%12 = load i32, i32* %1
%13 = icmp eq i32 %12, -1
br i1 %13, label %24, label %14
14: ; preds = %9
%15 = getelementptr inbounds i32, i32* %4, i64 1
store i32 %12, i32* %15
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%18 = load i32, i32* %1
%19 = icmp eq i32 %18, -1
br i1 %19, label %24, label %39
20: ; preds = %39
%21 = inttoptr i64 %42 to i32*
%22 = trunc i64 %46 to i32
%23 = icmp eq i32 %22, 0
br i1 %23, label %35, label %24
24: ; preds = %14, %9, %20
%25 = phi i32* [ %21, %20 ], [ %4, %9 ], [ %4, %14 ]
%26 = phi i64 [ %46, %20 ], [ 1, %9 ], [ 2, %14 ]
%27 = and i64 %26, 4294967295
br label %28
28: ; preds = %24, %28
%29 = phi i64 [ 0, %24 ], [ %33, %28 ]
%30 = getelementptr inbounds i32, i32* %25, i64 %29
%31 = load i32, i32* %30
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %31)
%33 = add nuw nsw i64 %29, 1
%34 = icmp eq i64 %33, %27
br i1 %34, label %35, label %28
35: ; preds = %28, %0, %20
%36 = phi i32* [ %21, %20 ], [ %4, %0 ], [ %25, %28 ]
%37 = call i32 @putchar(i32 10)
%38 = call i32 @free(i32* %36)
ret i32 0
39: ; preds = %14, %39
%40 = phi i64 [ %46, %39 ], [ 2, %14 ]
%41 = phi i32* [ %43, %39 ], [ %4, %14 ]
%42 = call i64 @realloc(i32* %41, i32 5)
%43 = inttoptr i64 %42 to i32*
%44 = load i32, i32* %1
%45 = getelementptr inbounds i32, i32* %43, i64 %40
store i32 %44, i32* %45
%46 = add nuw i64 %40, 1
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%48 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%49 = load i32, i32* %1
%50 = icmp eq i32 %49, -1
br i1 %50, label %20, label %39
}