#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 rand();
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int n, i, j, temp;
  printf("Enter number of elements in array\n");
  scanf("%d", &n);
  int A[n];
  printf("Array before sorting\n");
  for (i = 0; i < n; i++) {
    A[i] = rand() % 1000;
    printf("%d ", A[i]);
  }
  printf("\n");
  for (i = 0; i < n; i++) {
    for (j = n; j > i; j--) {
      if (A[j] < A[j - 1]) {
        temp = A[j];
        A[i] = A[i - 1];
        A[i - 1] = temp;
      }
    }
  }
  printf("Array after sorting\n");
  for (i = 0; i < n; i++)
    printf("%d ", A[i]);
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xecf(%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    0xe9b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11e2 <main+0xb2>
mov    $0x0,%al
call   1050 <rand@plt>
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    -0x30(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1199 <main+0x69>
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1288 <main+0x158>
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jle    1275 <main+0x145>
mov    -0x30(%rbp),%rcx
movslq -0x10(%rbp),%rax
mov    (%rcx,%rax,4),%eax
mov    -0x10(%rbp),%edx
sub    $0x1,%edx
movslq %edx,%rdx
cmp    (%rcx,%rdx,4),%eax
jge    1262 <main+0x132>
mov    -0x30(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
mov    %ecx,-0x14(%rbp)
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%edx
movslq -0xc(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x14(%rbp),%edx
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
jmp    1267 <main+0x137>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    1209 <main+0xd9>
jmp    127a <main+0x14a>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11f7 <main+0xc7>
lea    0xdb1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12d0 <main+0x1a0>
mov    -0x30(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xd81(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    129d <main+0x16d>
lea    0xd63(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
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   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xea1(%rip),%rdi
call   1040 <puts@plt>
lea    0xe8e(%rip),%rdi
lea    -0x24(%rbp),%rsi
call   1060 <scanf@plt>
mov    %rsp,%r14
mov    -0x24(%rbp),%eax
mov    %rsp,%rbx
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe8c(%rip),%rdi
call   1040 <puts@plt>
cmpl   $0x0,-0x24(%rbp)
jle    1201 <main+0xb1>
lea    0xe54(%rip),%r15
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1070 <rand@plt>
movslq %eax,%rsi
imul   $0x10624dd3,%rsi,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x26,%rax
add    %ecx,%eax
imul   $0x3e8,%eax,%eax
sub    %eax,%esi
mov    %esi,(%rbx,%r12,4)
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%r12
movslq -0x24(%rbp),%rax
cmp    %rax,%r12
jl     11c0 <main+0x70>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    -0x24(%rbp),%eax
test   %eax,%eax
jle    1252 <main+0x102>
xor    %ecx,%ecx
jmp    1229 <main+0xd9>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%rcx
cmp    %rax,%rcx
je     1252 <main+0x102>
mov    %rax,%rdx
jmp    1235 <main+0xe5>
xchg   %ax,%ax
cmp    %rcx,%rdx
jle    1220 <main+0xd0>
mov    %rdx,%rdi
mov    (%rbx,%rdx,4),%esi
add    $0xffffffffffffffff,%rdx
cmp    -0x4(%rbx,%rdi,4),%esi
jge    1230 <main+0xe0>
mov    -0x4(%rbx,%rcx,4),%edi
mov    %edi,(%rbx,%rcx,4)
mov    %esi,-0x4(%rbx,%rcx,4)
jmp    1230 <main+0xe0>
lea    0xde5(%rip),%rdi
call   1040 <puts@plt>
cmpl   $0x0,-0x24(%rbp)
jle    128b <main+0x13b>
lea    0xd98(%rip),%r15
xor    %r12d,%r12d
xchg   %ax,%ax
mov    (%rbx,%r12,4),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%r12
movslq -0x24(%rbp),%rax
cmp    %rax,%r12
jl     1270 <main+0x120>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r14,%rsp
xor    %eax,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [35 x i8] c"Enter number of elements in array\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [22 x i8] c"Array before sorting\0A\00"
@.str.3 = [4 x i8] c"%d \00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [21 x i8] c"Array after sorting\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 ([35 x i8], [35 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 ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %15
15: ; preds = %30, %0
%16 = load i32, i32* %3
%17 = load i32, i32* %2
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %33
19: ; preds = %15
%20 = call i32 (...) @rand()
%21 = srem i32 %20, 1000
%22 = load i32, i32* %3
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i32, i32* %13, i64 %23
store i32 %21, i32* %24
%25 = load i32, i32* %3
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i32, i32* %13, i64 %26
%28 = load i32, i32* %27
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %28)
br label %30
30: ; preds = %19
%31 = load i32, i32* %3
%32 = add nsw i32 %31, 1
store i32 %32, i32* %3
br label %15
33: ; preds = %15
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %3
br label %35
35: ; preds = %79, %33
%36 = load i32, i32* %3
%37 = load i32, i32* %2
%38 = icmp slt i32 %36, %37
br i1 %38, label %39, label %82
39: ; preds = %35
%40 = load i32, i32* %2
store i32 %40, i32* %4
br label %41
41: ; preds = %75, %39
%42 = load i32, i32* %4
%43 = load i32, i32* %3
%44 = icmp sgt i32 %42, %43
br i1 %44, label %45, label %78
45: ; preds = %41
%46 = load i32, i32* %4
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i32, i32* %13, i64 %47
%49 = load i32, i32* %48
%50 = load i32, i32* %4
%51 = sub nsw i32 %50, 1
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i32, i32* %13, i64 %52
%54 = load i32, i32* %53
%55 = icmp slt i32 %49, %54
br i1 %55, label %56, label %74
56: ; preds = %45
%57 = load i32, i32* %4
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i32, i32* %13, i64 %58
%60 = load i32, i32* %59
store i32 %60, i32* %5
%61 = load i32, i32* %3
%62 = sub nsw i32 %61, 1
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i32, i32* %13, i64 %63
%65 = load i32, i32* %64
%66 = load i32, i32* %3
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i32, i32* %13, i64 %67
store i32 %65, i32* %68
%69 = load i32, i32* %5
%70 = load i32, i32* %3
%71 = sub nsw i32 %70, 1
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds i32, i32* %13, i64 %72
store i32 %69, i32* %73
br label %74
74: ; preds = %56, %45
br label %75
75: ; preds = %74
%76 = load i32, i32* %4
%77 = add nsw i32 %76, -1
store i32 %77, i32* %4
br label %41
78: ; preds = %41
br label %79
79: ; preds = %78
%80 = load i32, i32* %3
%81 = add nsw i32 %80, 1
store i32 %81, i32* %3
br label %35
82: ; preds = %35
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %3
br label %84
84: ; preds = %94, %82
%85 = load i32, i32* %3
%86 = load i32, i32* %2
%87 = icmp slt i32 %85, %86
br i1 %87, label %88, label %97
88: ; preds = %84
%89 = load i32, i32* %3
%90 = sext i32 %89 to i64
%91 = getelementptr inbounds i32, i32* %13, i64 %90
%92 = load i32, i32* %91
%93 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %92)
br label %94
94: ; preds = %88
%95 = load i32, i32* %3
%96 = add nsw i32 %95, 1
store i32 %96, i32* %3
br label %84
97: ; preds = %84
%98 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %1
%99 = load i8*, i8** %6
%100 = load i32, i32* %1
ret i32 %100
}

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