#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 i, j, n, t, a[20];
  printf("Enter the no. of elements\n");
  scanf("%d", &n);
  printf("Enter the elements\n");
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  for (i = 0; i <= n - 1; i++) {
    j = i;
    while (j > 0 && a[j] < a[j - 1]) {
      t = a[j];
      a[j] = a[j - 1];
      a[j - 1] = t;
      j--;
    }
  }
  printf("Sorted array:\n");
  for (i = 0; i < n; i++)
    printf("%d\n", a[i]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xec7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed4(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xec7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    119a <main+0x7a>
movslq -0x8(%rbp),%rax
lea    -0x70(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe94(%rip),%rdi
call   1040 <scanf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1165 <main+0x45>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jg     1241 <main+0x121>
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0xc(%rbp)
mov    %al,-0x71(%rbp)
jle    11e2 <main+0xc2>
movslq -0xc(%rbp),%rax
mov    -0x70(%rbp,%rax,4),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
cmp    -0x70(%rbp,%rcx,4),%eax
setl   %al
mov    %al,-0x71(%rbp)
mov    -0x71(%rbp),%al
test   $0x1,%al
jne    11f2 <main+0xd2>
jmp    122e <main+0x10e>
movslq -0xc(%rbp),%rax
mov    -0x70(%rbp,%rax,4),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
cltq
mov    -0x70(%rbp,%rax,4),%ecx
movslq -0xc(%rbp),%rax
mov    %ecx,-0x70(%rbp,%rax,4)
mov    -0x14(%rbp),%ecx
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
cltq
mov    %ecx,-0x70(%rbp,%rax,4)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    11b8 <main+0x98>
jmp    1233 <main+0x113>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11a1 <main+0x81>
lea    0xdea(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1286 <main+0x166>
movslq -0x8(%rbp),%rax
mov    -0x70(%rbp,%rax,4),%esi
lea    0xdd0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1256 <main+0x136>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x60,%rsp
lea    0xec7(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb4(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
lea    0xec4(%rip),%rdi
call   1030 <puts@plt>
cmpl   $0x0,0xc(%rsp)
jle    11ff <main+0xcf>
lea    0x10(%rsp),%r15
xor    %ebx,%ebx
lea    0xe85(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <scanf@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%r8
add    $0x4,%r15
cmp    %r8,%rbx
jl     1180 <main+0x50>
test   %r8d,%r8d
jle    11ff <main+0xcf>
xor    %ecx,%ecx
mov    $0x1,%r9d
lea    0x10(%rsp),%r10
jmp    11d0 <main+0xa0>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%ecx
add    $0x1,%r9d
add    $0x4,%r10
cmp    %r8d,%ecx
je     11ff <main+0xcf>
test   %ecx,%ecx
je     11c0 <main+0x90>
mov    %ecx,%eax
mov    0x10(%rsp,%rax,4),%edi
mov    %r10,%rsi
mov    %r9d,%eax
lea    -0x2(%rax),%edx
mov    0x10(%rsp,%rdx,4),%ebx
cmp    %ebx,%edi
jge    11c0 <main+0x90>
mov    %ebx,(%rsi)
mov    %edi,0x10(%rsp,%rdx,4)
add    $0xffffffff,%eax
add    $0xfffffffffffffffc,%rsi
cmp    $0x1,%eax
jg     11e0 <main+0xb0>
jmp    11c0 <main+0x90>
lea    0xe2e(%rip),%rdi
call   1030 <puts@plt>
cmpl   $0x0,0xc(%rsp)
jle    123c <main+0x10c>
lea    0xdea(%rip),%r14
xor    %ebx,%ebx
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     1220 <main+0xf0>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

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