#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*/ insertion_sort(int *, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int n, m;
  int *array;
  printf("Enter number of elements: ");
  scanf("%d", &n);
  array = (int *)malloc(sizeof(int) * n);
  int j;
  for (j = 0; j < n; j++) {
    printf("> ");
    scanf("%d", &m);
    array[j] = m;
  }
  int i;
  for (i = 0; i < n; i++)
    printf("%d%s", array[i], i == n - 1 ? "\n" : " ");
  insertion_sort(array, n);
  for (i = 0; i < n; i++)
    printf("%d%s", array[i], i == n - 1 ? "\n" : " ");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb7(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11cd <main+0x8d>
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe73(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0xc(%rbp),%edx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1187 <main+0x47>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1224 <main+0xe4>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
mov    -0x20(%rbp),%ecx
mov    -0x8(%rbp),%edi
sub    $0x1,%edi
lea    0xe1e(%rip),%rdx
lea    0xe24(%rip),%rax
cmp    %edi,%ecx
cmove  %rax,%rdx
lea    0xe12(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11d4 <main+0x94>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1060 <insertion_sort@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1287 <main+0x147>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
mov    -0x20(%rbp),%ecx
mov    -0x8(%rbp),%edi
sub    $0x1,%edi
lea    0xdbb(%rip),%rdx
lea    0xdc1(%rip),%rax
cmp    %edi,%ecx
cmove  %rax,%rdx
lea    0xdaf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1237 <main+0xf7>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xeac(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xeb9(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x8(%rsp),%edi
shl    $0x2,%edi
call   1040 <malloc@plt>
mov    %rax,%r13
mov    0x8(%rsp),%esi
test   %esi,%esi
jle    121c <main+0xdc>
lea    0xe90(%rip),%r14
lea    0xe86(%rip),%r15
lea    0xc(%rsp),%r12
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%eax
mov    %eax,0x0(%r13,%rbx,4)
add    $0x1,%rbx
movslq 0x8(%rsp),%rsi
cmp    %rsi,%rbx
jl     11a0 <main+0x60>
test   %esi,%esi
jle    121c <main+0xdc>
lea    0xe4f(%rip),%r15
lea    0xe3b(%rip),%r12
lea    0xe3c(%rip),%r14
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    0x0(%r13,%rbx,4),%eax
add    $0xffffffff,%esi
cmp    %rsi,%rbx
mov    %r12,%rdx
cmove  %r15,%rdx
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%rbx
movslq 0x8(%rsp),%rsi
cmp    %rsi,%rbx
jl     11f0 <main+0xb0>
mov    %r13,%rdi
call   1060 <insertion_sort@plt>
mov    0x8(%rsp),%eax
test   %eax,%eax
jle    127a <main+0x13a>
lea    0xdf3(%rip),%r15
lea    0xddf(%rip),%r12
lea    0xde0(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x0(%r13,%rbx,4),%esi
add    $0xffffffff,%eax
cmp    %rax,%rbx
mov    %r12,%rdx
cmove  %r15,%rdx
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%rbx
movslq 0x8(%rsp),%rax
cmp    %rax,%rbx
jl     1250 <main+0x110>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [27 x i8] c"Enter number of elements: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [3 x i8] c"> \00"
@.str.3 = [5 x i8] c"%d%s\00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [2 x i8] c" \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
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%9 = load i32, i32* %2
%10 = sext i32 %9 to i64
%11 = mul i64 4, %10
%12 = trunc i64 %11 to i32
%13 = call i64 @malloc(i32 %12)
%14 = inttoptr i64 %13 to i32*
store i32* %14, i32** %4
store i32 0, i32* %5
br label %15
15: ; preds = %27, %0
%16 = load i32, i32* %5
%17 = load i32, i32* %2
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %30
19: ; preds = %15
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%21 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%22 = load i32, i32* %3
%23 = load i32*, i32** %4
%24 = load i32, i32* %5
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32, i32* %23, i64 %25
store i32 %22, i32* %26
br label %27
27: ; preds = %19
%28 = load i32, i32* %5
%29 = add nsw i32 %28, 1
store i32 %29, i32* %5
br label %15
30: ; preds = %15
store i32 0, i32* %6
br label %31
31: ; preds = %48, %30
%32 = load i32, i32* %6
%33 = load i32, i32* %2
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %51
35: ; preds = %31
%36 = load i32*, i32** %4
%37 = load i32, i32* %6
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i32, i32* %36, i64 %38
%40 = load i32, i32* %39
%41 = load i32, i32* %6
%42 = load i32, i32* %2
%43 = sub nsw i32 %42, 1
%44 = icmp eq i32 %41, %43
%45 = zext i1 %44 to i64
%46 = select i1 %44, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0)
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %40, i8* %46)
br label %48
48: ; preds = %35
%49 = load i32, i32* %6
%50 = add nsw i32 %49, 1
store i32 %50, i32* %6
br label %31
51: ; preds = %31
%52 = load i32*, i32** %4
%53 = load i32, i32* %2
%54 = call i32 @insertion_sort(i32* %52, i32 %53)
store i32 0, i32* %6
br label %55
55: ; preds = %72, %51
%56 = load i32, i32* %6
%57 = load i32, i32* %2
%58 = icmp slt i32 %56, %57
br i1 %58, label %59, label %75
59: ; preds = %55
%60 = load i32*, i32** %4
%61 = load i32, i32* %6
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i32, i32* %60, i64 %62
%64 = load i32, i32* %63
%65 = load i32, i32* %6
%66 = load i32, i32* %2
%67 = sub nsw i32 %66, 1
%68 = icmp eq i32 %65, %67
%69 = zext i1 %68 to i64
%70 = select i1 %68, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0)
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %64, i8* %70)
br label %72
72: ; preds = %59
%73 = load i32, i32* %6
%74 = add nsw i32 %73, 1
store i32 %74, i32* %6
br label %55
75: ; preds = %55
ret i32 0
}

LLVM IR (-O2):
@.str = [27 x i8] c"Enter number of elements: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [3 x i8] c"> \00"
@.str.3 = [5 x i8] c"%d%s\00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [2 x i8] c" \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 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 = shl i32 %7, 2
%9 = call i64 @malloc(i32 %8)
%10 = inttoptr i64 %9 to i32*
%11 = load i32, i32* %1
%12 = icmp sgt i32 %11, 0
br i1 %12, label %15, label %39
13: ; preds = %15
%14 = icmp sgt i32 %22, 0
br i1 %14, label %25, label %39
15: ; preds = %0, %15
%16 = phi i64 [ %21, %15 ], [ 0, %0 ]
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%18 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%19 = load i32, i32* %2
%20 = getelementptr inbounds i32, i32* %10, i64 %16
store i32 %19, i32* %20
%21 = add nuw nsw i64 %16, 1
%22 = load i32, i32* %1
%23 = sext i32 %22 to i64
%24 = icmp slt i64 %21, %23
br i1 %24, label %15, label %13
25: ; preds = %13, %25
%26 = phi i64 [ %35, %25 ], [ 0, %13 ]
%27 = phi i32 [ %36, %25 ], [ %22, %13 ]
%28 = getelementptr inbounds i32, i32* %10, i64 %26
%29 = load i32, i32* %28
%30 = add nsw i32 %27, -1
%31 = zext i32 %30 to i64
%32 = icmp eq i64 %26, %31
%33 = select i1 %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0)
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %29, i8* %33)
%35 = add nuw nsw i64 %26, 1
%36 = load i32, i32* %1
%37 = sext i32 %36 to i64
%38 = icmp slt i64 %35, %37
br i1 %38, label %25, label %39
39: ; preds = %25, %0, %13
%40 = phi i32 [ %22, %13 ], [ %11, %0 ], [ %36, %25 ]
%41 = call i32 @insertion_sort(i32* %10, i32 %40)
%42 = load i32, i32* %1
%43 = icmp sgt i32 %42, 0
br i1 %43, label %44, label %58
44: ; preds = %39, %44
%45 = phi i64 [ %54, %44 ], [ 0, %39 ]
%46 = phi i32 [ %55, %44 ], [ %42, %39 ]
%47 = getelementptr inbounds i32, i32* %10, i64 %45
%48 = load i32, i32* %47
%49 = add nsw i32 %46, -1
%50 = zext i32 %49 to i64
%51 = icmp eq i64 %45, %50
%52 = select i1 %51, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0)
%53 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %48, i8* %52)
%54 = add nuw nsw i64 %45, 1
%55 = load i32, i32* %1
%56 = sext i32 %55 to i64
%57 = icmp slt i64 %54, %56
br i1 %57, label %44, label %58
58: ; preds = %44, %39
ret i32 0
}