#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 /*<<< orphan*/ insertionSort(int *, int);
int *malloc(int);
int /*<<< orphan*/ populateTheArray(int *, int);
int /*<<< orphan*/ printTheArray(int *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int arraySize;
  int *theArray;
  scanf("%d", &arraySize);
  if ((theArray = malloc(arraySize * sizeof(int))) == NULL) {
    printf("Failed to allocate memory. exit");
  }
  theArray = malloc(arraySize * sizeof(int));
  populateTheArray(theArray, arraySize);
  printTheArray(theArray, arraySize);
  insertionSort(theArray, arraySize);
  printTheArray(theArray, arraySize);
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1070 <scanf@plt>
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11a8 <main+0x48>
lea    0xe60(%rip),%rdi
call   1040 <printf@plt>
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1030 <populateTheArray@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1080 <printTheArray@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1060 <insertionSort@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1080 <printTheArray@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
lea    0xe96(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1070 <scanf@plt>
mov    0x4(%rsp),%ebx
lea    0x0(,%rbx,4),%ebp
mov    %ebp,%edi
call   1050 <malloc@plt>
test   %rax,%rax
jne    11a2 <main+0x42>
lea    0xe71(%rip),%rdi
call   1040 <printf@plt>
mov    0x4(%rsp),%ebx
lea    0x0(,%rbx,4),%ebp
mov    %ebp,%edi
call   1050 <malloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %ebx,%esi
call   1030 <populateTheArray@plt>
mov    0x4(%rsp),%esi
mov    %rbp,%rdi
call   1080 <printTheArray@plt>
mov    0x4(%rsp),%esi
mov    %rbp,%rdi
call   1060 <insertionSort@plt>
mov    0x4(%rsp),%esi
mov    %rbp,%rdi
call   1080 <printTheArray@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [32 x i8] c"Failed to allocate memory. exit\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
store i32 0, i32* %1
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%5 = load i32, i32* %2
%6 = sext i32 %5 to i64
%7 = mul i64 %6, 4
%8 = trunc i64 %7 to i32
%9 = call i32* @malloc(i32 %8)
store i32* %9, i32** %3
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %11, %0
%14 = load i32, i32* %2
%15 = sext i32 %14 to i64
%16 = mul i64 %15, 4
%17 = trunc i64 %16 to i32
%18 = call i32* @malloc(i32 %17)
store i32* %18, i32** %3
%19 = load i32*, i32** %3
%20 = load i32, i32* %2
%21 = call i32 @populateTheArray(i32* %19, i32 %20)
%22 = load i32*, i32** %3
%23 = load i32, i32* %2
%24 = call i32 @printTheArray(i32* %22, i32 %23)
%25 = load i32*, i32** %3
%26 = load i32, i32* %2
%27 = call i32 @insertionSort(i32* %25, i32 %26)
%28 = load i32*, i32** %3
%29 = load i32, i32* %2
%30 = call i32 @printTheArray(i32* %28, i32 %29)
ret i32 1
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [32 x i8] c"Failed to allocate memory. exit\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%4 = load i32, i32* %1
%5 = shl i32 %4, 2
%6 = call i32* @malloc(i32 %5)
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %12
8: ; preds = %0
%9 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
%10 = load i32, i32* %1
%11 = shl i32 %10, 2
br label %12
12: ; preds = %8, %0
%13 = phi i32 [ %11, %8 ], [ %5, %0 ]
%14 = phi i32 [ %10, %8 ], [ %4, %0 ]
%15 = call i32* @malloc(i32 %13)
%16 = call i32 @populateTheArray(i32* %15, i32 %14)
%17 = load i32, i32* %1
%18 = call i32 @printTheArray(i32* %15, i32 %17)
%19 = load i32, i32* %1
%20 = call i32 @insertionSort(i32* %15, i32 %19)
%21 = load i32, i32* %1
%22 = call i32 @printTheArray(i32* %15, i32 %21)
ret i32 1
}