#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 *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int *realloc(int *, int);
int scanf(char *, int *);
void his(void) {
  int *array;
  int size;
  int value;
  int count;
  size = 100;
  array = malloc(size + 1 * sizeof(int));
  if (array == NULL) {
    printf("ERROR: Not enough memory!");
    return;
  }
  puts("Enter some numbers separated by whitespaces:");
  while (scanf("%d", &value) == 1) {
    count += 1;
    if (count > size) {
      size += 100;
      array = realloc(array, size + 1 * sizeof(int));
      if (array == NULL) {
        printf("ERROR: Not enough memory!");
        return;
      }
    }
    array[count] = value;
  }
  if (count < size) {
    array = realloc(array, count + 1 * sizeof(int));
    if (array == NULL) {
      printf("ERROR: Not enough memory!");
      return;
    }
  }
  array[0] = count;
  puts("Your numbers, in a dynamic allocated int array would be..");
  printf("%d: ", array[0]);
  value = 1;
  while (value <= count) {
    printf("%d, ", array[value++]);
  }
  puts("\n");
}


x86 assembly (clang, -O0):
<his>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x64,-0xc(%rbp)
movslq -0xc(%rbp),%rax
add    $0x4,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1190 <his+0x40>
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12d6 <his+0x186>
lea    0xe83(%rip),%rdi
call   1030 <puts@plt>
lea    0xea4(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1070 <scanf@plt>
cmp    $0x1,%eax
jne    1220 <his+0xd0>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jle    120d <his+0xbd>
mov    -0xc(%rbp),%eax
add    $0x64,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0xc(%rbp),%rax
add    $0x4,%rax
mov    %eax,%esi
call   1060 <realloc@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1208 <his+0xb8>
lea    0xe04(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12d6 <his+0x186>
jmp    120d <his+0xbd>
mov    -0x10(%rbp),%edx
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
jmp    119c <his+0x4c>
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1266 <his+0x116>
mov    -0x8(%rbp),%rdi
movslq -0x14(%rbp),%rax
add    $0x4,%rax
mov    %eax,%esi
call   1060 <realloc@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1261 <his+0x111>
lea    0xdab(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12d6 <his+0x186>
jmp    1266 <his+0x116>
mov    -0x14(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
lea    0xdd4(%rip),%rdi
call   1030 <puts@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%esi
lea    0xdfc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     12ca <his+0x17a>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x10(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%esi
lea    0xdcb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1296 <his+0x146>
lea    0xdbd(%rip),%rdi
call   1030 <puts@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<his>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    $0x68,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11f3 <his+0xa3>
mov    %rax,%r12
lea    0xea0(%rip),%rdi
call   1030 <puts@plt>
lea    0xec1(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1070 <scanf@plt>
cmp    $0x1,%eax
jne    120e <his+0xbe>
mov    $0x64,%r13d
xor    %ebx,%ebx
lea    0xea3(%rip),%r14
lea    0xc(%rsp),%r15
jmp    11cd <his+0x7d>
nopl   0x0(%rax,%rax,1)
mov    0xc(%rsp),%eax
mov    %eax,0x4(%r12,%rbx,4)
mov    %r14,%rdi
mov    %r15,%rsi
call   1070 <scanf@plt>
add    $0x1,%rbx
cmp    $0x1,%eax
jne    1210 <his+0xc0>
movslq %r13d,%rax
cmp    %rax,%rbx
jl     11b0 <his+0x60>
lea    0x68(%r13),%esi
mov    %r12,%rdi
call   1060 <realloc@plt>
test   %rax,%rax
je     129d <his+0x14d>
mov    %rax,%r12
add    $0x64,%r13d
jmp    11b0 <his+0x60>
lea    0xe06(%rip),%rdi
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1040 <printf@plt>
jmp    1228 <his+0xd8>
cmp    %ebx,%r13d
jle    1228 <his+0xd8>
lea    0x4(%rbx),%esi
mov    %r12,%rdi
call   1060 <realloc@plt>
test   %rax,%rax
je     129d <his+0x14d>
mov    %rax,%r12
mov    %ebx,(%r12)
lea    0xe17(%rip),%rdi
call   1030 <puts@plt>
mov    (%r12),%esi
lea    0xe41(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movl   $0x1,0xc(%rsp)
test   %ebx,%ebx
jle    128f <his+0x13f>
mov    $0x1,%eax
lea    0xe27(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0x1(%rax),%ecx
mov    %ecx,0xc(%rsp)
cltq
mov    (%r12,%rax,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0xc(%rsp),%eax
cmp    %ebx,%eax
jle    1270 <his+0x120>
lea    0xdf8(%rip),%rdi
call   1030 <puts@plt>
jmp    12ab <his+0x15b>
lea    0xd5c(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [26 x i8] c"ERROR: Not enough memory!\00"
@.str.1 = [45 x i8] c"Enter some numbers separated by whitespaces:\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [58 x i8] c"Your numbers, in a dynamic allocated int array would be..\00"
@.str.4 = [5 x i8] c"%d: \00"
@.str.5 = [5 x i8] c"%d, \00"
@.str.6 = [2 x i8] c"\0A\00"
define void @his() {
%1 = alloca i32*
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 100, i32* %2
%5 = load i32, i32* %2
%6 = sext i32 %5 to i64
%7 = add i64 %6, 4
%8 = trunc i64 %7 to i32
%9 = call i32* @malloc(i32 %8)
store i32* %9, i32** %1
%10 = load i32*, i32** %1
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %84
14: ; preds = %0
%15 = call i32 @puts(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %39, %14
%17 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%18 = icmp eq i32 %17, 1
br i1 %18, label %19, label %45
19: ; preds = %16
%20 = load i32, i32* %4
%21 = add nsw i32 %20, 1
store i32 %21, i32* %4
%22 = load i32, i32* %4
%23 = load i32, i32* %2
%24 = icmp sgt i32 %22, %23
br i1 %24, label %25, label %39
25: ; preds = %19
%26 = load i32, i32* %2
%27 = add nsw i32 %26, 100
store i32 %27, i32* %2
%28 = load i32*, i32** %1
%29 = load i32, i32* %2
%30 = sext i32 %29 to i64
%31 = add i64 %30, 4
%32 = trunc i64 %31 to i32
%33 = call i32* @realloc(i32* %28, i32 %32)
store i32* %33, i32** %1
%34 = load i32*, i32** %1
%35 = icmp eq i32* %34, null
br i1 %35, label %36, label %38
36: ; preds = %25
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %84
38: ; preds = %25
br label %39
39: ; preds = %38, %19
%40 = load i32, i32* %3
%41 = load i32*, i32** %1
%42 = load i32, i32* %4
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i32, i32* %41, i64 %43
store i32 %40, i32* %44
br label %16
45: ; preds = %16
%46 = load i32, i32* %4
%47 = load i32, i32* %2
%48 = icmp slt i32 %46, %47
br i1 %48, label %49, label %61
49: ; preds = %45
%50 = load i32*, i32** %1
%51 = load i32, i32* %4
%52 = sext i32 %51 to i64
%53 = add i64 %52, 4
%54 = trunc i64 %53 to i32
%55 = call i32* @realloc(i32* %50, i32 %54)
store i32* %55, i32** %1
%56 = load i32*, i32** %1
%57 = icmp eq i32* %56, null
br i1 %57, label %58, label %60
58: ; preds = %49
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %84
60: ; preds = %49
br label %61
61: ; preds = %60, %45
%62 = load i32, i32* %4
%63 = load i32*, i32** %1
%64 = getelementptr inbounds i32, i32* %63, i64 0
store i32 %62, i32* %64
%65 = call i32 @puts(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.3, i64 0, i64 0))
%66 = load i32*, i32** %1
%67 = getelementptr inbounds i32, i32* %66, i64 0
%68 = load i32, i32* %67
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %68)
store i32 1, i32* %3
br label %70
70: ; preds = %74, %61
%71 = load i32, i32* %3
%72 = load i32, i32* %4
%73 = icmp sle i32 %71, %72
br i1 %73, label %74, label %82
74: ; preds = %70
%75 = load i32*, i32** %1
%76 = load i32, i32* %3
%77 = add nsw i32 %76, 1
store i32 %77, i32* %3
%78 = sext i32 %76 to i64
%79 = getelementptr inbounds i32, i32* %75, i64 %78
%80 = load i32, i32* %79
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %80)
br label %70
82: ; preds = %70
%83 = call i32 @puts(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %84
84: ; preds = %82, %58, %36, %12
ret void
}

LLVM IR (-O2):
@.str = [26 x i8] c"ERROR: Not enough memory!\00"
@.str.1 = [45 x i8] c"Enter some numbers separated by whitespaces:\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [58 x i8] c"Your numbers, in a dynamic allocated int array would be..\00"
@.str.4 = [5 x i8] c"%d: \00"
@.str.5 = [5 x i8] c"%d, \00"
@.str.6 = [2 x i8] c"\0A\00"
define void @his() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32* @malloc(i32 104)
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %59
7: ; preds = %0
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %41
11: ; preds = %7, %25
%12 = phi i64 [ %15, %25 ], [ 0, %7 ]
%13 = phi i32 [ %27, %25 ], [ 100, %7 ]
%14 = phi i32* [ %26, %25 ], [ %3, %7 ]
%15 = add i64 %12, 1
%16 = sext i32 %13 to i64
%17 = icmp slt i64 %12, %16
br i1 %17, label %25, label %18
18: ; preds = %11
%19 = add nsw i32 %13, 100
%20 = add i32 %13, 104
%21 = call i32* @realloc(i32* %14, i32 %20)
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %25
23: ; preds = %18
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %59
25: ; preds = %18, %11
%26 = phi i32* [ %21, %18 ], [ %14, %11 ]
%27 = phi i32 [ %19, %18 ], [ %13, %11 ]
%28 = load i32, i32* %1
%29 = getelementptr inbounds i32, i32* %26, i64 %15
store i32 %28, i32* %29
%30 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%31 = icmp eq i32 %30, 1
br i1 %31, label %11, label %32
32: ; preds = %25
%33 = trunc i64 %15 to i32
%34 = icmp sgt i32 %27, %33
br i1 %34, label %35, label %41
35: ; preds = %32
%36 = add i32 %33, 4
%37 = call i32* @realloc(i32* %26, i32 %36)
%38 = icmp eq i32* %37, null
br i1 %38, label %39, label %41
39: ; preds = %35
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %59
41: ; preds = %7, %35, %32
%42 = phi i32 [ %33, %35 ], [ %33, %32 ], [ undef, %7 ]
%43 = phi i32* [ %37, %35 ], [ %26, %32 ], [ %3, %7 ]
store i32 %42, i32* %43
%44 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @.str.3, i64 0, i64 0))
%45 = load i32, i32* %43
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %45)
store i32 1, i32* %1
%47 = icmp slt i32 %42, 1
br i1 %47, label %57, label %48
48: ; preds = %41, %48
%49 = phi i32 [ %55, %48 ], [ 1, %41 ]
%50 = add nsw i32 %49, 1
store i32 %50, i32* %1
%51 = sext i32 %49 to i64
%52 = getelementptr inbounds i32, i32* %43, i64 %51
%53 = load i32, i32* %52
%54 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %53)
%55 = load i32, i32* %1
%56 = icmp sgt i32 %55, %42
br i1 %56, label %57, label %48
57: ; preds = %48, %41
%58 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %59
59: ; preds = %57, %39, %23, %5
ret void
}