#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*/ exit(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main(void) {
  int arr[100];
  int num;
  int i;
  int j;
  int order;
  int min;
  printf("Enter the number of elements in the array: ");
  scanf("%d", &num);
  printf("Enter the array elements:\n");
  for (i = 0; i < num; i++) {
    scanf("%d", &arr[i]);
  }
  printf("Enter the order of sorting:\n");
  printf("1. Ascending Order\n2. Descending order\n");
  scanf("%d", &order);
  if ((order == 1) || (order == 2)) {
    for (i = 1; i < num; i++) {
      min = arr[i];
      for (j = (i - 1); j >= 0; j--) {
        if ((order == 1) && (arr[j] > min)) {
          arr[j + 1] = arr[j];
          arr[j] = min;
          ;
        } else if ((order == 2) && (arr[j] < min)) {
          arr[j + 1] = arr[j];
          arr[j] = min;
          ;
        } else {
          break;
        }
      }
    }
  } else {
    printf("Invalid input!\n");
    exit(1);
  }
  printf("Array after sorting:\n");
  for (i = 0; i < num; i++) {
    printf("%d\t", arr[i]);
  }
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1c0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeb7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed5(%rip),%rdi
lea    -0x1a4(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xec5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1a8(%rbp)
mov    -0x1a8(%rbp),%eax
cmp    -0x1a4(%rbp),%eax
jge    11c2 <main+0x92>
movslq -0x1a8(%rbp),%rax
lea    -0x1a0(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe83(%rip),%rdi
call   1040 <scanf@plt>
mov    -0x1a8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1a8(%rbp)
jmp    117b <main+0x4b>
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe47(%rip),%rdi
lea    -0x1b0(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x1,-0x1b0(%rbp)
je     120b <main+0xdb>
cmpl   $0x2,-0x1b0(%rbp)
jne    1358 <main+0x228>
movl   $0x1,-0x1a8(%rbp)
mov    -0x1a8(%rbp),%eax
cmp    -0x1a4(%rbp),%eax
jge    1353 <main+0x223>
movslq -0x1a8(%rbp),%rax
mov    -0x1a0(%rbp,%rax,4),%eax
mov    %eax,-0x1b4(%rbp)
mov    -0x1a8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x1ac(%rbp)
cmpl   $0x0,-0x1ac(%rbp)
jl     133a <main+0x20a>
cmpl   $0x1,-0x1b0(%rbp)
jne    12b7 <main+0x187>
movslq -0x1ac(%rbp),%rax
mov    -0x1a0(%rbp,%rax,4),%eax
cmp    -0x1b4(%rbp),%eax
jle    12b7 <main+0x187>
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    -0x1b4(%rbp),%ecx
movslq -0x1ac(%rbp),%rax
mov    %ecx,-0x1a0(%rbp,%rax,4)
jmp    1321 <main+0x1f1>
cmpl   $0x2,-0x1b0(%rbp)
jne    1317 <main+0x1e7>
movslq -0x1ac(%rbp),%rax
mov    -0x1a0(%rbp,%rax,4),%eax
cmp    -0x1b4(%rbp),%eax
jge    1317 <main+0x1e7>
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    -0x1b4(%rbp),%ecx
movslq -0x1ac(%rbp),%rax
mov    %ecx,-0x1a0(%rbp,%rax,4)
jmp    131c <main+0x1ec>
jmp    133a <main+0x20a>
jmp    1321 <main+0x1f1>
jmp    1326 <main+0x1f6>
mov    -0x1ac(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1ac(%rbp)
jmp    124a <main+0x11a>
jmp    133f <main+0x20f>
mov    -0x1a8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1a8(%rbp)
jmp    1215 <main+0xe5>
jmp    1370 <main+0x240>
lea    0xd30(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
lea    0xd28(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1a8(%rbp)
mov    -0x1a8(%rbp),%eax
cmp    -0x1a4(%rbp),%eax
jge    13ca <main+0x29a>
movslq -0x1a8(%rbp),%rax
mov    -0x1a0(%rbp,%rax,4),%esi
lea    0xd06(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1a8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1a8(%rbp)
jmp    1388 <main+0x258>
lea    0xccc(%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    0xe9d(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xebb(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1060 <scanf@plt>
lea    0xeb1(%rip),%rdi
call   1040 <puts@plt>
cmpl   $0x0,0x8(%rsp)
jle    11bd <main+0x6d>
lea    0x10(%rsp),%r15
xor    %ebx,%ebx
lea    0xe90(%rip),%r14
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %r15,%rsi
call   1060 <scanf@plt>
add    $0x1,%rbx
movslq 0x8(%rsp),%rax
add    $0x4,%r15
cmp    %rax,%rbx
jl     11a0 <main+0x50>
lea    0xe89(%rip),%rdi
call   1040 <puts@plt>
lea    0xe99(%rip),%rdi
call   1040 <puts@plt>
lea    0xe50(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1060 <scanf@plt>
mov    0xc(%rsp),%eax
lea    -0x1(%rax),%ecx
cmp    $0x1,%ecx
ja     12b5 <main+0x165>
mov    0x8(%rsp),%r8d
cmp    $0x2,%r8d
jl     125e <main+0x10e>
mov    $0x1,%edx
xor    %r9d,%r9d
jmp    121d <main+0xcd>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rdx
add    $0x1,%r9
cmp    %r8,%rdx
je     125e <main+0x10e>
mov    0x10(%rsp,%rdx,4),%edi
mov    %r9,%rsi
jmp    124d <main+0xfd>
cs nopw 0x0(%rax,%rax,1)
cmp    %edi,%ebx
jge    1210 <main+0xc0>
mov    %ebx,0x14(%rsp,%rsi,4)
mov    %edi,0x10(%rsp,%rcx,4)
lea    -0x1(%rsi),%rcx
add    $0x1,%rsi
cmp    $0x1,%rsi
mov    %rcx,%rsi
jle    1210 <main+0xc0>
mov    %esi,%ecx
mov    0x10(%rsp,%rcx,4),%ebx
cmp    $0x1,%eax
jne    1230 <main+0xe0>
cmp    %edi,%ebx
jg     1234 <main+0xe4>
jmp    1210 <main+0xc0>
lea    0xe3a(%rip),%rdi
call   1040 <puts@plt>
cmpl   $0x0,0x8(%rsp)
jle    129c <main+0x14c>
lea    0xdb7(%rip),%r14
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    0x10(%rsp,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
movslq 0x8(%rsp),%rax
cmp    %rax,%rbx
jl     1280 <main+0x130>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x1a0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xdd4(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [44 x i8] c"Enter the number of elements in the array: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [27 x i8] c"Enter the array elements:\0A\00"
@.str.3 = [29 x i8] c"Enter the order of sorting:\0A\00"
@.str.4 = [40 x i8] c"1. Ascending Order\0A2. Descending order\0A\00"
@.str.5 = [16 x i8] c"Invalid input!\0A\00"
@.str.6 = [22 x i8] c"Array after sorting:\0A\00"
@.str.7 = [4 x i8] c"%d\09\00"
@.str.8 = [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
%7 = alloca i32
store i32 0, i32* %1
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 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* %3)
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
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
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0))
%26 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%27 = load i32, i32* %6
%28 = icmp eq i32 %27, 1
br i1 %28, label %32, label %29
29: ; preds = %23
%30 = load i32, i32* %6
%31 = icmp eq i32 %30, 2
br i1 %31, label %32, label %104
32: ; preds = %29, %23
store i32 1, i32* %4
br label %33
33: ; preds = %100, %32
%34 = load i32, i32* %4
%35 = load i32, i32* %3
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %103
37: ; preds = %33
%38 = load i32, i32* %4
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 %39
%41 = load i32, i32* %40
store i32 %41, i32* %7
%42 = load i32, i32* %4
%43 = sub nsw i32 %42, 1
store i32 %43, i32* %5
br label %44
44: ; preds = %96, %37
%45 = load i32, i32* %5
%46 = icmp sge i32 %45, 0
br i1 %46, label %47, label %99
47: ; preds = %44
%48 = load i32, i32* %6
%49 = icmp eq i32 %48, 1
br i1 %49, label %50, label %70
50: ; preds = %47
%51 = load i32, i32* %5
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 %52
%54 = load i32, i32* %53
%55 = load i32, i32* %7
%56 = icmp sgt i32 %54, %55
br i1 %56, label %57, label %70
57: ; preds = %50
%58 = load i32, i32* %5
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 %59
%61 = load i32, i32* %60
%62 = load i32, i32* %5
%63 = add nsw i32 %62, 1
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 %64
store i32 %61, i32* %65
%66 = load i32, i32* %7
%67 = load i32, i32* %5
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 %68
store i32 %66, i32* %69
br label %95
70: ; preds = %50, %47
%71 = load i32, i32* %6
%72 = icmp eq i32 %71, 2
br i1 %72, label %73, label %93
73: ; preds = %70
%74 = load i32, i32* %5
%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 = load i32, i32* %7
%79 = icmp slt i32 %77, %78
br i1 %79, label %80, label %93
80: ; preds = %73
%81 = load i32, i32* %5
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 %82
%84 = load i32, i32* %83
%85 = load i32, i32* %5
%86 = add nsw i32 %85, 1
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 %87
store i32 %84, i32* %88
%89 = load i32, i32* %7
%90 = load i32, i32* %5
%91 = sext i32 %90 to i64
%92 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 %91
store i32 %89, i32* %92
br label %94
93: ; preds = %73, %70
br label %99
94: ; preds = %80
br label %95
95: ; preds = %94, %57
br label %96
96: ; preds = %95
%97 = load i32, i32* %5
%98 = add nsw i32 %97, -1
store i32 %98, i32* %5
br label %44
99: ; preds = %93, %44
br label %100
100: ; preds = %99
%101 = load i32, i32* %4
%102 = add nsw i32 %101, 1
store i32 %102, i32* %4
br label %33
103: ; preds = %33
br label %107
104: ; preds = %29
%105 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
%106 = call i32 @exit(i32 1)
unreachable
107: ; preds = %103
%108 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %4
br label %109
109: ; preds = %119, %107
%110 = load i32, i32* %4
%111 = load i32, i32* %3
%112 = icmp slt i32 %110, %111
br i1 %112, label %113, label %122
113: ; preds = %109
%114 = load i32, i32* %4
%115 = sext i32 %114 to i64
%116 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 %115
%117 = load i32, i32* %116
%118 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i32 %117)
br label %119
119: ; preds = %113
%120 = load i32, i32* %4
%121 = add nsw i32 %120, 1
store i32 %121, i32* %4
br label %109
122: ; preds = %109
%123 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
ret i32 0
}

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