#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 x[100], n, i, j, key;
  printf("Enter number of elements to be sorted ");
  scanf("%d", &n);
  printf("Enter %d elements ", n);
  for (i = 0; i < n; i++) {
    scanf("%d", &x[i]);
  }
  for (i = 1; i < n; i++) {
    key = x[i];
    j = i - 1;
    while (j >= 0 && x[j] > key) {
      x[j + 1] = x[j];
      j--;
    }
    x[j + 1] = key;
  }
  printf("Sorted elements in ascending order are: ");
  for (i = 0; i < n; i++) {
    printf("%d ", x[i]);
  }
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1c0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xec7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xee0(%rip),%rdi
lea    -0x1a4(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x1a4(%rbp),%esi
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1a8(%rbp)
mov    -0x1a8(%rbp),%eax
cmp    -0x1a4(%rbp),%eax
jge    11b8 <main+0x98>
movslq -0x1a8(%rbp),%rax
lea    -0x1a0(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe88(%rip),%rdi
call   1040 <scanf@plt>
mov    -0x1a8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1a8(%rbp)
jmp    1171 <main+0x51>
movl   $0x1,-0x1a8(%rbp)
mov    -0x1a8(%rbp),%eax
cmp    -0x1a4(%rbp),%eax
jge    129c <main+0x17c>
movslq -0x1a8(%rbp),%rax
mov    -0x1a0(%rbp,%rax,4),%eax
mov    %eax,-0x1b0(%rbp)
mov    -0x1a8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x1ac(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x1ac(%rbp)
mov    %al,-0x1b1(%rbp)
jl     1229 <main+0x109>
movslq -0x1ac(%rbp),%rax
mov    -0x1a0(%rbp,%rax,4),%eax
cmp    -0x1b0(%rbp),%eax
setg   %al
mov    %al,-0x1b1(%rbp)
mov    -0x1b1(%rbp),%al
test   $0x1,%al
jne    123c <main+0x11c>
jmp    1270 <main+0x150>
movslq -0x1ac(%rbp),%rax
mov    -0x1a0(%rbp,%rax,4),%ecx
mov    -0x1ac(%rbp),%eax
add    $0x1,%eax
cltq
mov    %ecx,-0x1a0(%rbp,%rax,4)
mov    -0x1ac(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1ac(%rbp)
jmp    11f7 <main+0xd7>
mov    -0x1b0(%rbp),%ecx
mov    -0x1ac(%rbp),%eax
add    $0x1,%eax
cltq
mov    %ecx,-0x1a0(%rbp,%rax,4)
mov    -0x1a8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1a8(%rbp)
jmp    11c2 <main+0xa2>
lea    0xd9a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1a8(%rbp)
mov    -0x1a8(%rbp),%eax
cmp    -0x1a4(%rbp),%eax
jge    12f6 <main+0x1d6>
movslq -0x1a8(%rbp),%rax
mov    -0x1a0(%rbp,%rax,4),%esi
lea    0xd8b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1a8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1a8(%rbp)
jmp    12b4 <main+0x194>
lea    0xd6d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x1c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x1a0,%rsp
lea    0xebd(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xed6(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%esi
lea    0xec4(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmpl   $0x0,0xc(%rsp)
jle    1203 <main+0xd3>
lea    0x10(%rsp),%r15
xor    %ebx,%ebx
lea    0xea1(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <scanf@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%rax
add    $0x4,%r15
cmp    %rax,%rbx
jl     1190 <main+0x60>
mov    %eax,%eax
cmp    $0x2,%eax
jl     1203 <main+0xd3>
mov    $0x1,%ecx
jmp    11d0 <main+0xa0>
nopl   0x0(%rax,%rax,1)
movslq %esi,%rsi
mov    %edx,0x10(%rsp,%rsi,4)
add    $0x1,%rcx
cmp    %rax,%rcx
je     1203 <main+0xd3>
mov    0x10(%rsp,%rcx,4),%edx
mov    %rcx,%rsi
nopw   0x0(%rax,%rax,1)
lea    -0x1(%rsi),%rdi
mov    %edi,%ebx
mov    0x10(%rsp,%rbx,4),%ebx
cmp    %edx,%ebx
jle    11c0 <main+0x90>
mov    %ebx,0x10(%rsp,%rsi,4)
lea    0x1(%rdi),%rbx
mov    %rdi,%rsi
cmp    $0x1,%rbx
jg     11e0 <main+0xb0>
xor    %esi,%esi
jmp    11c0 <main+0x90>
lea    0xe33(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmpl   $0x0,0xc(%rsp)
jle    124c <main+0x11c>
lea    0xe47(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x10(%rsp,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%rax
cmp    %rax,%rbx
jl     1230 <main+0x100>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x1a0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

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