#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, i, a[50], j, f;
  printf("enter the no of array elements\n");
  scanf("%d", &n);
  printf("enter the elements\n");
  for (i = 0; i < n; i++)
    scanf("%d", &a[i]);
  for (i = 1; i < n; i++) {
    f = a[i];
    j = i - 1;
    while (j >= 0 && a[j] > f) {
      a[j + 1] = a[j];
      j = j - 1;
    }
    a[j + 1] = f;
  }
  printf("elemets after sorting\n");
  for (i = 0; i < n; i++)
    printf("%d\n", a[i]);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xec7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed9(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xecc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    119d <main+0x7d>
movslq -0xc(%rbp),%rax
lea    -0xe0(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe96(%rip),%rdi
call   1040 <scanf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1165 <main+0x45>
movl   $0x1,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    126c <main+0x14c>
movslq -0xc(%rbp),%rax
mov    -0xe0(%rbp,%rax,4),%eax
mov    %eax,-0xe8(%rbp)
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0xe4(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0xe4(%rbp)
mov    %al,-0xe9(%rbp)
jl     11ff <main+0xdf>
movslq -0xe4(%rbp),%rax
mov    -0xe0(%rbp,%rax,4),%eax
cmp    -0xe8(%rbp),%eax
setg   %al
mov    %al,-0xe9(%rbp)
mov    -0xe9(%rbp),%al
test   $0x1,%al
jne    1212 <main+0xf2>
jmp    1246 <main+0x126>
movslq -0xe4(%rbp),%rax
mov    -0xe0(%rbp,%rax,4),%ecx
mov    -0xe4(%rbp),%eax
add    $0x1,%eax
cltq
mov    %ecx,-0xe0(%rbp,%rax,4)
mov    -0xe4(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0xe4(%rbp)
jmp    11cd <main+0xad>
mov    -0xe8(%rbp),%ecx
mov    -0xe4(%rbp),%eax
add    $0x1,%eax
cltq
mov    %ecx,-0xe0(%rbp,%rax,4)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11a4 <main+0x84>
lea    0xdc4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12b4 <main+0x194>
movslq -0xc(%rbp),%rax
mov    -0xe0(%rbp,%rax,4),%esi
lea    0xdaf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1281 <main+0x161>
mov    -0x4(%rbp),%eax
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0xe0,%rsp
lea    0xec4(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb1(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
lea    0xec6(%rip),%rdi
call   1030 <puts@plt>
cmpl   $0x0,0xc(%rsp)
jle    11f3 <main+0xc3>
lea    0x10(%rsp),%r15
xor    %ebx,%ebx
lea    0xe82(%rip),%r14
xchg   %ax,%ax
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <scanf@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%rax
add    $0x4,%r15
cmp    %rax,%rbx
jl     1180 <main+0x50>
mov    %eax,%eax
cmp    $0x2,%eax
jl     11f3 <main+0xc3>
mov    $0x1,%ecx
jmp    11c0 <main+0x90>
nopl   0x0(%rax,%rax,1)
movslq %esi,%rsi
mov    %edx,0x10(%rsp,%rsi,4)
add    $0x1,%rcx
cmp    %rax,%rcx
je     11f3 <main+0xc3>
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    11b0 <main+0x80>
mov    %ebx,0x10(%rsp,%rsi,4)
lea    0x1(%rdi),%rbx
mov    %rdi,%rsi
cmp    $0x1,%rbx
jg     11d0 <main+0xa0>
xor    %esi,%esi
jmp    11b0 <main+0x80>
lea    0xe3f(%rip),%rdi
call   1030 <puts@plt>
cmpl   $0x0,0xc(%rsp)
jle    122c <main+0xfc>
lea    0xdf6(%rip),%r14
xor    %ebx,%ebx
nop
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     1210 <main+0xe0>
xor    %eax,%eax
add    $0xe0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

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