#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 s, i, j, temp, a[20];
  printf("Enter total elements: ");
  scanf("%d", &s);
  printf("Enter %d elements: ", s);
  for (i = 0; i < s; i++)
    scanf("%d", &a[i]);
  for (i = 0; i < s; i++) {
    for (j = i + 1; j < s; j++) {
      if (a[i] > a[j]) {
        temp = a[i];
        a[i] = a[j];
        a[j] = temp;
      }
    }
  }
  printf("After sorting is: ");
  for (i = 0; i < s; i++)
    printf(" %d", a[i]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xefb(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x8(%rbp),%esi
lea    0xec0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    119a <main+0x7a>
movslq -0xc(%rbp),%rax
lea    -0x70(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xeb8(%rip),%rdi
call   1040 <scanf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1165 <main+0x45>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1224 <main+0x104>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1211 <main+0xf1>
movslq -0xc(%rbp),%rax
mov    -0x70(%rbp,%rax,4),%eax
movslq -0x10(%rbp),%rcx
cmp    -0x70(%rbp,%rcx,4),%eax
jle    11fe <main+0xde>
movslq -0xc(%rbp),%rax
mov    -0x70(%rbp,%rax,4),%eax
mov    %eax,-0x14(%rbp)
movslq -0x10(%rbp),%rax
mov    -0x70(%rbp,%rax,4),%ecx
movslq -0xc(%rbp),%rax
mov    %ecx,-0x70(%rbp,%rax,4)
mov    -0x14(%rbp),%ecx
movslq -0x10(%rbp),%rax
mov    %ecx,-0x70(%rbp,%rax,4)
jmp    1203 <main+0xe3>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11b6 <main+0x96>
jmp    1216 <main+0xf6>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11a1 <main+0x81>
lea    0xe00(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1269 <main+0x149>
movslq -0xc(%rbp),%rax
mov    -0x70(%rbp,%rax,4),%esi
lea    0xdea(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1239 <main+0x119>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x60,%rsp
lea    0xed0(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xf01(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1040 <scanf@plt>
mov    0xc(%rsp),%esi
lea    0xec4(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
cmpl   $0x0,0xc(%rsp)
jle    11fd <main+0xdd>
lea    0x10(%rsp),%r15
xor    %ebx,%ebx
lea    0xecc(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <scanf@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%rax
add    $0x4,%r15
cmp    %rax,%rbx
jl     1180 <main+0x60>
mov    %eax,%r8d
test   %r8d,%r8d
jle    11fd <main+0xdd>
lea    0x10(%rsp),%rcx
xor    %r9d,%r9d
mov    %r8,%rdx
jmp    11cd <main+0xad>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x4,%rcx
add    $0xffffffffffffffff,%rdx
cmp    %r8,%r9
je     11fd <main+0xdd>
mov    %r9,%rdi
add    $0x1,%r9
cmp    %r8,%r9
jae    11c0 <main+0xa0>
mov    $0x1,%ebx
jmp    11e9 <main+0xc9>
add    $0x1,%rbx
cmp    %rbx,%rdx
je     11c0 <main+0xa0>
mov    0x10(%rsp,%rdi,4),%eax
mov    (%rcx,%rbx,4),%esi
cmp    %esi,%eax
jle    11e0 <main+0xc0>
mov    %esi,0x10(%rsp,%rdi,4)
mov    %eax,(%rcx,%rbx,4)
jmp    11e0 <main+0xc0>
lea    0xe27(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
cmpl   $0x0,0xc(%rsp)
jle    123c <main+0x11c>
lea    0xe25(%rip),%r14
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    0x10(%rsp,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%rax
cmp    %rax,%rbx
jl     1220 <main+0x100>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [23 x i8] c"Enter total elements: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [20 x i8] c"Enter %d elements: \00"
@.str.3 = [19 x i8] c"After sorting is: \00"
@.str.4 = [4 x i8] c" %d\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 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 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 = load i32, i32* %1
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %7)
%9 = load i32, i32* %1
%10 = icmp sgt i32 %9, 0
br i1 %10, label %16, label %44
11: ; preds = %16
%12 = icmp sgt i32 %21, 0
br i1 %12, label %13, label %44
13: ; preds = %11
%14 = zext i32 %21 to i64
%15 = zext i32 %21 to i64
br label %27
16: ; preds = %0, %16
%17 = phi i64 [ %20, %16 ], [ 0, %0 ]
%18 = getelementptr inbounds [20 x i32], [20 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)
%20 = add nuw nsw i64 %17, 1
%21 = load i32, i32* %1
%22 = sext i32 %21 to i64
%23 = icmp slt i64 %20, %22
br i1 %23, label %16, label %11
24: ; preds = %41, %27
%25 = add nuw nsw i64 %29, 1
%26 = icmp eq i64 %30, %15
br i1 %26, label %44, label %27
27: ; preds = %13, %24
%28 = phi i64 [ 0, %13 ], [ %30, %24 ]
%29 = phi i64 [ 1, %13 ], [ %25, %24 ]
%30 = add nuw nsw i64 %28, 1
%31 = icmp ult i64 %30, %14
br i1 %31, label %32, label %24
32: ; preds = %27
%33 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 %28
br label %34
34: ; preds = %32, %41
%35 = phi i64 [ %29, %32 ], [ %42, %41 ]
%36 = load i32, i32* %33
%37 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 %35
%38 = load i32, i32* %37
%39 = icmp sgt i32 %36, %38
br i1 %39, label %40, label %41
40: ; preds = %34
store i32 %38, i32* %33
store i32 %36, i32* %37
br label %41
41: ; preds = %34, %40
%42 = add nuw nsw i64 %35, 1
%43 = icmp eq i64 %42, %15
br i1 %43, label %24, label %34
44: ; preds = %24, %0, %11
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%46 = load i32, i32* %1
%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 [20 x i32], [20 x i32]* %2, 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* %1
%55 = sext i32 %54 to i64
%56 = icmp slt i64 %53, %55
br i1 %56, label %48, label %57
57: ; preds = %48, %44
ret i32 0
}