#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);
int *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int *a, num, i;
  printf("Enter the size of array: ");
  scanf("%d", &num);
  a = malloc(sizeof(int) * num);
  for (i = 0; i < num; i++) {
    printf("Enter the value of %d Element: ", (i + 1));
    scanf(" %d", &a[i]);
  }
  insertion_sort(a, num);
  for (i = 0; i < num; i++)
    printf("the %d Element: %d.\n", (i + 1), a[i]);
  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    0xed7(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1050 <scanf@plt>
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11d0 <main+0x90>
mov    -0x18(%rbp),%esi
add    $0x1,%esi
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rsi
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe7d(%rip),%rdi
call   1050 <scanf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1187 <main+0x47>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1060 <insertion_sort@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    121c <main+0xdc>
mov    -0x18(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11e3 <main+0xa3>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xeae(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xedb(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x4(%rsp),%r13d
lea    0x0(,%r13,4),%edi
call   1040 <malloc@plt>
mov    %rax,%r12
test   %r13d,%r13d
jle    11c9 <main+0x89>
lea    0xe8f(%rip),%r14
lea    0xea8(%rip),%r15
mov    %r12,%rbx
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
add    $0x1,%rbp
mov    %r14,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
movslq 0x4(%rsp),%r13
add    $0x4,%rbx
cmp    %r13,%rbp
jl     11a0 <main+0x60>
mov    %r12,%rdi
mov    %r13d,%esi
call   1060 <insertion_sort@plt>
cmpl   $0x0,0x4(%rsp)
jle    120e <main+0xce>
lea    0xe5c(%rip),%rbx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%r12,%rbp,4),%edx
add    $0x1,%rbp
mov    %rbx,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1030 <printf@plt>
movslq 0x4(%rsp),%rax
cmp    %rax,%rbp
jl     11f0 <main+0xb0>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"Enter the size of array: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [32 x i8] c"Enter the value of %d Element: \00"
@.str.3 = [4 x i8] c" %d\00"
@.str.4 = [21 x i8] c"the %d Element: %d.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 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 4, %8
%10 = trunc i64 %9 to i32
%11 = call i32* @malloc(i32 %10)
store i32* %11, i32** %2
store i32 0, i32* %4
br label %12
12: ; preds = %25, %0
%13 = load i32, i32* %4
%14 = load i32, i32* %3
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %28
16: ; preds = %12
%17 = load i32, i32* %4
%18 = add nsw i32 %17, 1
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %18)
%20 = load i32*, i32** %2
%21 = load i32, i32* %4
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %20, i64 %22
%24 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32* %23)
br label %25
25: ; preds = %16
%26 = load i32, i32* %4
%27 = add nsw i32 %26, 1
store i32 %27, i32* %4
br label %12
28: ; preds = %12
%29 = load i32*, i32** %2
%30 = load i32, i32* %3
%31 = call i32 @insertion_sort(i32* %29, i32 %30)
store i32 0, i32* %4
br label %32
32: ; preds = %45, %28
%33 = load i32, i32* %4
%34 = load i32, i32* %3
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %48
36: ; preds = %32
%37 = load i32, i32* %4
%38 = add nsw i32 %37, 1
%39 = load i32*, i32** %2
%40 = load i32, i32* %4
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i32, i32* %39, i64 %41
%43 = load i32, i32* %42
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32 %38, i32 %43)
br label %45
45: ; preds = %36
%46 = load i32, i32* %4
%47 = add nsw i32 %46, 1
store i32 %47, i32* %4
br label %32
48: ; preds = %32
ret i32 0
}

LLVM IR (-O2):
@.str = [26 x i8] c"Enter the size of array: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [32 x i8] c"Enter the value of %d Element: \00"
@.str.3 = [4 x i8] c" %d\00"
@.str.4 = [21 x i8] c"the %d Element: %d.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 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 i32* @malloc(i32 %6)
%8 = icmp sgt i32 %5, 0
br i1 %8, label %9, label %19
9: ; preds = %0, %9
%10 = phi i64 [ %11, %9 ], [ 0, %0 ]
%11 = add nuw nsw i64 %10, 1
%12 = trunc i64 %11 to i32
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %12)
%14 = getelementptr inbounds i32, i32* %7, i64 %10
%15 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32* %14)
%16 = load i32, i32* %1
%17 = sext i32 %16 to i64
%18 = icmp slt i64 %11, %17
br i1 %18, label %9, label %19
19: ; preds = %9, %0
%20 = phi i32 [ %5, %0 ], [ %16, %9 ]
%21 = call i32 @insertion_sort(i32* %7, i32 %20)
%22 = load i32, i32* %1
%23 = icmp sgt i32 %22, 0
br i1 %23, label %24, label %34
24: ; preds = %19, %24
%25 = phi i64 [ %26, %24 ], [ 0, %19 ]
%26 = add nuw nsw i64 %25, 1
%27 = getelementptr inbounds i32, i32* %7, i64 %25
%28 = load i32, i32* %27
%29 = trunc i64 %26 to i32
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32 %29, i32 %28)
%31 = load i32, i32* %1
%32 = sext i32 %31 to i64
%33 = icmp slt i64 %26, %32
br i1 %33, label %24, label %34
34: ; preds = %24, %19
ret i32 0
}