#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*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int length, i, j, key;
  printf("Enter the length of the array: ");
  scanf("%d", &length);
  int array[length];
  printf("Enter the elements of the array: \n");
  for (i = 0; i < length; i++)
    scanf(" %d", &array[i]);
  for (i = 1; i < length; i++) {
    key = array[i];
    j = i;
    while (j-- >= 0 && array[j] > key)
      array[j + 1] = array[j];
    array[j + 1] = key;
  }
  printf("Sorted array: \n");
  for (i = 0; i < length; i++)
    printf("%d ", array[i]);
  printf("\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xf00(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
lea    0xea5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11be <main+0x9e>
mov    -0x30(%rbp),%rsi
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe98(%rip),%rdi
call   1040 <scanf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1189 <main+0x69>
movl   $0x1,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    125f <main+0x13f>
mov    -0x30(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%ecx
mov    %ecx,%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x31(%rbp)
jl     1212 <main+0xf2>
mov    -0x30(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x14(%rbp),%eax
setg   %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    1222 <main+0x102>
jmp    123e <main+0x11e>
mov    -0x30(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x10(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
jmp    11e5 <main+0xc5>
mov    -0x30(%rbp),%rax
mov    -0x14(%rbp),%edx
mov    -0x10(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11c5 <main+0xa5>
lea    0xde1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12a7 <main+0x187>
mov    -0x30(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xdc5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1274 <main+0x154>
lea    0xda7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xeab(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xebe(%rip),%rdi
lea    -0x2c(%rbp),%rsi
call   1060 <scanf@plt>
mov    %rsp,%r15
mov    -0x2c(%rbp),%eax
mov    %rsp,%r12
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
lea    0xe9a(%rip),%rdi
call   1040 <puts@plt>
cmpl   $0x0,-0x2c(%rbp)
jle    1225 <main+0xe5>
xor    %r13d,%r13d
lea    0xe79(%rip),%r14
mov    %r12,%rbx
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <scanf@plt>
add    $0x1,%r13
movslq -0x2c(%rbp),%rax
add    $0x4,%rbx
cmp    %rax,%r13
jl     11b0 <main+0x70>
mov    %eax,%eax
cmp    $0x2,%eax
jl     1225 <main+0xe5>
mov    $0x1,%ecx
jmp    11f0 <main+0xb0>
nopw   0x0(%rax,%rax,1)
movslq %esi,%rsi
mov    %edx,(%r12,%rsi,4)
add    $0x1,%rcx
cmp    %rax,%rcx
je     1225 <main+0xe5>
mov    (%r12,%rcx,4),%edx
mov    %rcx,%rsi
nopw   0x0(%rax,%rax,1)
mov    -0x4(%r12,%rsi,4),%edi
cmp    %edx,%edi
jle    11e0 <main+0xa0>
mov    %esi,%ebx
add    $0xffffffffffffffff,%rsi
mov    %edi,(%r12,%rbx,4)
lea    0x1(%rsi),%rdi
test   %rdi,%rdi
jg     1200 <main+0xc0>
mov    $0xffffffffffffffff,%rsi
jmp    11e0 <main+0xa0>
lea    0xe1e(%rip),%rdi
call   1040 <puts@plt>
cmpl   $0x0,-0x2c(%rbp)
jle    125b <main+0x11b>
lea    0xde6(%rip),%r14
xor    %ebx,%ebx
mov    (%r12,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
movslq -0x2c(%rbp),%rax
cmp    %rax,%rbx
jl     1240 <main+0x100>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r15,%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [32 x i8] c"Enter the length of the array: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [35 x i8] c"Enter the elements of the array: \0A\00"
@.str.3 = [4 x i8] c" %d\00"
@.str.4 = [16 x i8] c"Sorted array: \0A\00"
@.str.5 = [4 x i8] c"%d \00"
@.str.6 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
store i32 0, i32* %1
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%10 = load i32, i32* %2
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %6
%13 = alloca i32, i64 %11
store i64 %11, i64* %7
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %15
15: ; preds = %24, %0
%16 = load i32, i32* %3
%17 = load i32, i32* %2
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %27
19: ; preds = %15
%20 = load i32, i32* %3
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %13, i64 %21
%23 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32* %22)
br label %24
24: ; preds = %19
%25 = load i32, i32* %3
%26 = add nsw i32 %25, 1
store i32 %26, i32* %3
br label %15
27: ; preds = %15
store i32 1, i32* %3
br label %28
28: ; preds = %66, %27
%29 = load i32, i32* %3
%30 = load i32, i32* %2
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %69
32: ; preds = %28
%33 = load i32, i32* %3
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i32, i32* %13, i64 %34
%36 = load i32, i32* %35
store i32 %36, i32* %5
%37 = load i32, i32* %3
store i32 %37, i32* %4
br label %38
38: ; preds = %51, %32
%39 = load i32, i32* %4
%40 = add nsw i32 %39, -1
store i32 %40, i32* %4
%41 = icmp sge i32 %39, 0
br i1 %41, label %42, label %49
42: ; preds = %38
%43 = load i32, i32* %4
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i32, i32* %13, i64 %44
%46 = load i32, i32* %45
%47 = load i32, i32* %5
%48 = icmp sgt i32 %46, %47
br label %49
49: ; preds = %42, %38
%50 = phi i1 [ false, %38 ], [ %48, %42 ]
br i1 %50, label %51, label %60
51: ; preds = %49
%52 = load i32, i32* %4
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i32, i32* %13, i64 %53
%55 = load i32, i32* %54
%56 = load i32, i32* %4
%57 = add nsw i32 %56, 1
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i32, i32* %13, i64 %58
store i32 %55, i32* %59
br label %38
60: ; preds = %49
%61 = load i32, i32* %5
%62 = load i32, i32* %4
%63 = add nsw i32 %62, 1
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i32, i32* %13, i64 %64
store i32 %61, i32* %65
br label %66
66: ; preds = %60
%67 = load i32, i32* %3
%68 = add nsw i32 %67, 1
store i32 %68, i32* %3
br label %28
69: ; preds = %28
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %3
br label %71
71: ; preds = %81, %69
%72 = load i32, i32* %3
%73 = load i32, i32* %2
%74 = icmp slt i32 %72, %73
br i1 %74, label %75, label %84
75: ; preds = %71
%76 = load i32, i32* %3
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds i32, i32* %13, i64 %77
%79 = load i32, i32* %78
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %79)
br label %81
81: ; preds = %75
%82 = load i32, i32* %3
%83 = add nsw i32 %82, 1
store i32 %83, i32* %3
br label %71
84: ; preds = %71
%85 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%86 = load i8*, i8** %6
%87 = load i32, i32* %1
ret i32 %87
}

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