#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 n;
  printf("Enter value of n = ");
  scanf("%d", &n);
  int seq[n];
  printf("\n Enter %d elements \n\t", n);
  for (int i = 0; i < n; i++) {
    printf("\n Element %d = ", i + 1);
    scanf("%d", &seq[i]);
  }
  printf("\n Initial List: ");
  for (int i = 0; i < n; i++) {
    printf("%d ", seq[i]);
  }
  for (int j = 1; j <= (n - 1); j++) {
    int key = seq[j];
    int i = j - 1;
    while ((i >= 0) && (seq[i] > key)) {
      seq[i + 1] = seq[i];
      i = i - 1;
    }
    seq[i + 1] = key;
  }
  printf("\n The Sorted List: ");
  for (int i = 0; i < n; i++) {
    printf("\t%d", seq[i]);
  }
  return 0;
}


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    0xf21(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11d5 <main+0xb5>
mov    -0x1c(%rbp),%esi
add    $0x1,%esi
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%rsi
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xea3(%rip),%rdi
call   1040 <scanf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    118c <main+0x6c>
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    121d <main+0xfd>
mov    -0x38(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11ea <main+0xca>
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jg     12c5 <main+0x1a5>
mov    -0x38(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x2c(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x2c(%rbp)
mov    %al,-0x39(%rbp)
jl     126f <main+0x14f>
mov    -0x38(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x28(%rbp),%eax
setg   %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    127f <main+0x15f>
jmp    12a4 <main+0x184>
mov    -0x38(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x2c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x2c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    124c <main+0x12c>
mov    -0x38(%rbp),%rax
mov    -0x28(%rbp),%edx
mov    -0x2c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1224 <main+0x104>
lea    0xd84(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    130d <main+0x1ed>
mov    -0x38(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xd6c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    12da <main+0x1ba>
movl   $0x0,-0x4(%rbp)
mov    -0x10(%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
sub    $0x18,%rsp
lea    0xec8(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xf1f(%rip),%rdi
lea    -0x2c(%rbp),%rsi
call   1040 <scanf@plt>
mov    %rsp,-0x38(%rbp)
mov    -0x2c(%rbp),%eax
mov    %rsp,%r13
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
mov    -0x2c(%rbp),%esi
lea    0xe9f(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
cmpl   $0x0,-0x2c(%rbp)
jle    11c8 <main+0xa8>
lea    0xea2(%rip),%r14
lea    0xed5(%rip),%r15
mov    %r13,%r12
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%rbx
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1040 <scanf@plt>
movslq -0x2c(%rbp),%rax
add    $0x4,%r12
cmp    %rax,%rbx
jl     11a0 <main+0x80>
lea    0xe6c(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
cmpl   $0x0,-0x2c(%rbp)
jle    1265 <main+0x145>
lea    0xe65(%rip),%r14
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    0x0(%r13,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%rbx
movslq -0x2c(%rbp),%rax
cmp    %rax,%rbx
jl     11f0 <main+0xd0>
mov    %eax,%eax
cmp    $0x2,%eax
jl     1265 <main+0x145>
mov    $0x1,%ecx
jmp    1231 <main+0x111>
nopw   0x0(%rax,%rax,1)
movslq %esi,%rsi
mov    %edx,0x0(%r13,%rsi,4)
add    $0x1,%rcx
cmp    %rax,%rcx
je     1265 <main+0x145>
mov    0x0(%r13,%rcx,4),%edx
mov    %rcx,%rsi
nopl   0x0(%rax)
lea    -0x1(%rsi),%rdi
mov    %edi,%ebx
mov    0x0(%r13,%rbx,4),%ebx
cmp    %edx,%ebx
jle    1220 <main+0x100>
mov    %ebx,0x0(%r13,%rsi,4)
lea    0x1(%rdi),%rbx
mov    %rdi,%rsi
cmp    $0x1,%rbx
jg     1240 <main+0x120>
xor    %esi,%esi
jmp    1220 <main+0x100>
lea    0xde4(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
cmpl   $0x0,-0x2c(%rbp)
jle    12ac <main+0x18c>
lea    0xde4(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x0(%r13,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%rbx
movslq -0x2c(%rbp),%rax
cmp    %rax,%rbx
jl     1290 <main+0x170>
mov    -0x38(%rbp),%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 = [20 x i8] c"Enter value of n = \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [23 x i8] c"\0A Enter %d elements \0A\09\00"
@.str.3 = [16 x i8] c"\0A Element %d = \00"
@.str.4 = [17 x i8] c"\0A Initial List: \00"
@.str.5 = [4 x i8] c"%d \00"
@.str.6 = [20 x i8] c"\0A The Sorted List: \00"
@.str.7 = [4 x i8] c"\09%d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %1
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%13 = load i32, i32* %2
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %3
%16 = alloca i32, i64 %14
store i64 %14, i64* %4
%17 = load i32, i32* %2
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %17)
store i32 0, i32* %5
br label %19
19: ; preds = %31, %0
%20 = load i32, i32* %5
%21 = load i32, i32* %2
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %34
23: ; preds = %19
%24 = load i32, i32* %5
%25 = add nsw i32 %24, 1
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %25)
%27 = load i32, i32* %5
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %16, i64 %28
%30 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %29)
br label %31
31: ; preds = %23
%32 = load i32, i32* %5
%33 = add nsw i32 %32, 1
store i32 %33, i32* %5
br label %19
34: ; preds = %19
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %6
br label %36
36: ; preds = %46, %34
%37 = load i32, i32* %6
%38 = load i32, i32* %2
%39 = icmp slt i32 %37, %38
br i1 %39, label %40, label %49
40: ; preds = %36
%41 = load i32, i32* %6
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i32, i32* %16, i64 %42
%44 = load i32, i32* %43
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %44)
br label %46
46: ; preds = %40
%47 = load i32, i32* %6
%48 = add nsw i32 %47, 1
store i32 %48, i32* %6
br label %36
49: ; preds = %36
store i32 1, i32* %7
br label %50
50: ; preds = %91, %49
%51 = load i32, i32* %7
%52 = load i32, i32* %2
%53 = sub nsw i32 %52, 1
%54 = icmp sle i32 %51, %53
br i1 %54, label %55, label %94
55: ; preds = %50
%56 = load i32, i32* %7
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i32, i32* %16, i64 %57
%59 = load i32, i32* %58
store i32 %59, i32* %8
%60 = load i32, i32* %7
%61 = sub nsw i32 %60, 1
store i32 %61, i32* %9
br label %62
62: ; preds = %74, %55
%63 = load i32, i32* %9
%64 = icmp sge i32 %63, 0
br i1 %64, label %65, label %72
65: ; preds = %62
%66 = load i32, i32* %9
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i32, i32* %16, i64 %67
%69 = load i32, i32* %68
%70 = load i32, i32* %8
%71 = icmp sgt i32 %69, %70
br label %72
72: ; preds = %65, %62
%73 = phi i1 [ false, %62 ], [ %71, %65 ]
br i1 %73, label %74, label %85
74: ; preds = %72
%75 = load i32, i32* %9
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds i32, i32* %16, i64 %76
%78 = load i32, i32* %77
%79 = load i32, i32* %9
%80 = add nsw i32 %79, 1
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds i32, i32* %16, i64 %81
store i32 %78, i32* %82
%83 = load i32, i32* %9
%84 = sub nsw i32 %83, 1
store i32 %84, i32* %9
br label %62
85: ; preds = %72
%86 = load i32, i32* %8
%87 = load i32, i32* %9
%88 = add nsw i32 %87, 1
%89 = sext i32 %88 to i64
%90 = getelementptr inbounds i32, i32* %16, i64 %89
store i32 %86, i32* %90
br label %91
91: ; preds = %85
%92 = load i32, i32* %7
%93 = add nsw i32 %92, 1
store i32 %93, i32* %7
br label %50
94: ; preds = %50
%95 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %10
br label %96
96: ; preds = %106, %94
%97 = load i32, i32* %10
%98 = load i32, i32* %2
%99 = icmp slt i32 %97, %98
br i1 %99, label %100, label %109
100: ; preds = %96
%101 = load i32, i32* %10
%102 = sext i32 %101 to i64
%103 = getelementptr inbounds i32, i32* %16, i64 %102
%104 = load i32, i32* %103
%105 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i32 %104)
br label %106
106: ; preds = %100
%107 = load i32, i32* %10
%108 = add nsw i32 %107, 1
store i32 %108, i32* %10
br label %96
109: ; preds = %96
store i32 0, i32* %1
%110 = load i8*, i8** %3
%111 = load i32, i32* %1
ret i32 %111
}

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