#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ free(int *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int *numList = NULL;
  int maxNum = 0;
  int count = 0;
  printf("Enter the number of allocations: ");
  scanf("%d", &maxNum);
  numList = (int *)malloc(maxNum * sizeof(int));
  if (numList == NULL) {
    printf("\nmalloc() failed\n");
    return EXIT_FAILURE;
  }
  for (count = 0; count < maxNum; count++)
    numList[count] = count + 1;
  printf("\n\n");
  for (count = 0; count < maxNum; count++)
    printf("%d ", numList[count]);
  free(numList);
  numList = NULL;
  printf("\n\n");
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
lea    0xe94(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xea8(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1060 <scanf@plt>
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11c0 <main+0x80>
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2e2a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1265 <main+0x125>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11f2 <main+0xb2>
mov    -0x18(%rbp),%edx
add    $0x1,%edx
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11c7 <main+0x87>
lea    0xe3e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    123a <main+0xfa>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe15(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1207 <main+0xc7>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x10(%rbp)
lea    0xde5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2d78(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
movl   $0x0,0x4(%rsp)
lea    0xe99(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xead(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1070 <scanf@plt>
mov    0x4(%rsp),%edi
shl    $0x2,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     120d <main+0xbd>
mov    %rax,%r12
cmpl   $0x0,0x4(%rsp)
jle    11b5 <main+0x65>
xor    %eax,%eax
nopl   0x0(%rax)
lea    0x1(%rax),%rcx
mov    %ecx,(%r12,%rax,4)
movslq 0x4(%rsp),%rdx
mov    %rcx,%rax
cmp    %rdx,%rcx
jl     11a0 <main+0x50>
lea    0xe6d(%rip),%r14
mov    %r14,%rdi
call   1040 <puts@plt>
cmpl   $0x0,0x4(%rsp)
jle    11fc <main+0xac>
lea    0xe53(%rip),%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%r12,%rbx,4),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
movslq 0x4(%rsp),%rax
cmp    %rax,%rbx
jl     11e0 <main+0x90>
mov    %r12,%rdi
call   1030 <free@plt>
mov    0x2dcd(%rip),%rbx
jmp    121b <main+0xcb>
mov    0x2dcc(%rip),%rbx
lea    0xe10(%rip),%r14
mov    %r14,%rdi
call   1040 <puts@plt>
mov    (%rbx),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [34 x i8] c"Enter the number of allocations: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [18 x i8] c"\0Amalloc() failed\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [3 x i8] c"\0A\0A\00"
@.str.4 = [4 x i8] c"%d \00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32* null, i32** %2
store i32 0, i32* %3
store i32 0, i32* %4
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 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* %3)
%7 = load i32, i32* %3
%8 = sext i32 %7 to i64
%9 = mul i64 %8, 4
%10 = trunc i64 %9 to i32
%11 = call i64 @malloc(i32 %10)
%12 = inttoptr i64 %11 to i32*
store i32* %12, i32** %2
%13 = load i32*, i32** %2
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %18
15: ; preds = %0
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%17 = load i32, i32* @EXIT_FAILURE
store i32 %17, i32* %1
br label %54
18: ; preds = %0
store i32 0, i32* %4
br label %19
19: ; preds = %30, %18
%20 = load i32, i32* %4
%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* %4
%25 = add nsw i32 %24, 1
%26 = load i32*, i32** %2
%27 = load i32, i32* %4
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %26, i64 %28
store i32 %25, i32* %29
br label %30
30: ; preds = %23
%31 = load i32, i32* %4
%32 = add nsw i32 %31, 1
store i32 %32, i32* %4
br label %19
33: ; preds = %19
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %4
br label %35
35: ; preds = %46, %33
%36 = load i32, i32* %4
%37 = load i32, i32* %3
%38 = icmp slt i32 %36, %37
br i1 %38, label %39, label %49
39: ; preds = %35
%40 = load i32*, i32** %2
%41 = load i32, i32* %4
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i32, i32* %40, i64 %42
%44 = load i32, i32* %43
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %44)
br label %46
46: ; preds = %39
%47 = load i32, i32* %4
%48 = add nsw i32 %47, 1
store i32 %48, i32* %4
br label %35
49: ; preds = %35
%50 = load i32*, i32** %2
%51 = call i32 @free(i32* %50)
store i32* null, i32** %2
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%53 = load i32, i32* @EXIT_SUCCESS
store i32 %53, i32* %1
br label %54
54: ; preds = %49, %15
%55 = load i32, i32* %1
ret i32 %55
}

LLVM IR (-O2):
@.str = [34 x i8] c"Enter the number of allocations: \00"
@.str.1 = [3 x i8] c"%d\00"
@EXIT_FAILURE = global i32 0
@.str.4 = [4 x i8] c"%d \00"
@EXIT_SUCCESS = global i32 0
@str.5 = [2 x i8] c"\0A\00"
@str.6 = [17 x i8] c"\0Amalloc() failed\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = shl i32 %5, 2
%7 = call i64 @malloc(i32 %6)
%8 = inttoptr i64 %7 to i32*
%9 = icmp eq i64 %7, 0
br i1 %9, label %36, label %10
10: ; preds = %0
%11 = load i32, i32* %1
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %21
13: ; preds = %10, %13
%14 = phi i64 [ %15, %13 ], [ 0, %10 ]
%15 = add nuw nsw i64 %14, 1
%16 = getelementptr inbounds i32, i32* %8, i64 %14
%17 = trunc i64 %15 to i32
store i32 %17, i32* %16
%18 = load i32, i32* %1
%19 = sext i32 %18 to i64
%20 = icmp slt i64 %15, %19
br i1 %20, label %13, label %21
21: ; preds = %13, %10
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.5, i64 0, i64 0))
%23 = load i32, i32* %1
%24 = icmp sgt i32 %23, 0
br i1 %24, label %25, label %34
25: ; preds = %21, %25
%26 = phi i64 [ %30, %25 ], [ 0, %21 ]
%27 = getelementptr inbounds i32, i32* %8, i64 %26
%28 = load i32, i32* %27
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %28)
%30 = add nuw nsw i64 %26, 1
%31 = load i32, i32* %1
%32 = sext i32 %31 to i64
%33 = icmp slt i64 %30, %32
br i1 %33, label %25, label %34
34: ; preds = %25, %21
%35 = call i32 @free(i32* %8)
br label %36
36: ; preds = %0, %34
%37 = phi i8* [ getelementptr inbounds ([2 x i8], [2 x i8]* @str.5, i64 0, i64 0), %34 ], [ getelementptr inbounds ([17 x i8], [17 x i8]* @str.6, i64 0, i64 0), %0 ]
%38 = phi i32* [ @EXIT_SUCCESS, %34 ], [ @EXIT_FAILURE, %0 ]
%39 = call i32 @puts(i8* dereferenceable(1) %37)
%40 = load i32, i32* %38
ret i32 %40
}