#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*/ BubbleSort(int *, int);
int /*<<< orphan*/ InsertionSort(int *, int);
int /*<<< orphan*/ MergeSort(int *, int /*<<< orphan*/, int);
int /*<<< orphan*/ Print(int *, int);
int /*<<< orphan*/ Quicksort(int *, int /*<<< orphan*/, int);
int /*<<< orphan*/ SelectionSort(int *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int n;
  do {
    int A[] = {9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
    printf("1. Bubble Sort\n");
    printf("2. Selection Sort\n");
    printf("3. Insertion Sort\n");
    printf("4. Merge Sort\n");
    printf("5. Quicksort\n");
    printf("0. Exit\n");
    printf("Enter Input: ");
    scanf("%d", &n);
    switch (n) {
    case 1:
      BubbleSort(A, 10);
      Print(A, 10);
      break;
    case 2:
      SelectionSort(A, 10);
      Print(A, 10);
      break;
    case 3:
      InsertionSort(A, 10);
      Print(A, 10);
      break;
    case 4:
      MergeSort(A, 0, 9);
      Print(A, 10);
      break;
    case 5:
      Quicksort(A, 0, 9);
      Print(A, 10);
      break;
    case 0:
      break;
    default:
      printf("Invalid Input. Try Again.\n");
    }
  } while (n != 0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeaa(%rip),%rax
mov    %rax,-0x10(%rbp)
movaps 0xe8f(%rip),%xmm0
movaps %xmm0,-0x20(%rbp)
movaps 0xe74(%rip),%xmm0
movaps %xmm0,-0x30(%rbp)
lea    0xe91(%rip),%rdi
call   1050 <printf@plt>
lea    0xe95(%rip),%rdi
call   1050 <printf@plt>
lea    0xe9c(%rip),%rdi
call   1050 <printf@plt>
lea    0xea3(%rip),%rdi
call   1050 <printf@plt>
lea    0xea6(%rip),%rdi
call   1050 <printf@plt>
lea    0xea8(%rip),%rdi
call   1050 <printf@plt>
lea    0xea5(%rip),%rdi
call   1050 <printf@plt>
lea    0xea7(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1070 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %rax,-0x38(%rbp)
sub    $0x5,%rax
ja     12e7 <main+0x167>
mov    -0x38(%rbp),%rax
lea    0xdd0(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    -0x30(%rbp),%rdi
mov    $0xa,%esi
call   1090 <BubbleSort@plt>
lea    -0x30(%rbp),%rdi
mov    $0xa,%esi
call   10a0 <Print@plt>
jmp    12f3 <main+0x173>
lea    -0x30(%rbp),%rdi
mov    $0xa,%esi
call   1030 <SelectionSort@plt>
lea    -0x30(%rbp),%rdi
mov    $0xa,%esi
call   10a0 <Print@plt>
jmp    12f3 <main+0x173>
lea    -0x30(%rbp),%rdi
mov    $0xa,%esi
call   1060 <InsertionSort@plt>
lea    -0x30(%rbp),%rdi
mov    $0xa,%esi
call   10a0 <Print@plt>
jmp    12f3 <main+0x173>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x9,%edx
call   1080 <MergeSort@plt>
lea    -0x30(%rbp),%rdi
mov    $0xa,%esi
call   10a0 <Print@plt>
jmp    12f3 <main+0x173>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x9,%edx
call   1040 <Quicksort@plt>
lea    -0x30(%rbp),%rdi
mov    $0xa,%esi
call   10a0 <Print@plt>
jmp    12f3 <main+0x173>
jmp    12f3 <main+0x173>
lea    0xdc7(%rip),%rdi
call   1050 <printf@plt>
jmp    12f8 <main+0x178>
cmpl   $0x0,-0x8(%rbp)
jne    118f <main+0xf>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
lea    0xf02(%rip),%rbp
lea    0xe9c(%rip),%r14
lea    0xea3(%rip),%r15
lea    0xc(%rsp),%r12
lea    0xe41(%rip),%rbx
lea    0x10(%rsp),%r13
jmp    11f8 <main+0x68>
mov    %r13,%rdi
mov    $0xa,%esi
call   10a0 <BubbleSort@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r13,%rdi
mov    $0xa,%esi
call   10b0 <Print@plt>
cmpl   $0x0,0xc(%rsp)
je     12eb <main+0x15b>
mov    0xe41(%rip),%rax
mov    %rax,0x30(%rsp)
movaps 0xe25(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe09(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
lea    0xe36(%rip),%rdi
call   1030 <puts@plt>
lea    0xe39(%rip),%rdi
call   1030 <puts@plt>
lea    0xe3f(%rip),%rdi
call   1030 <puts@plt>
lea    0xe45(%rip),%rdi
call   1030 <puts@plt>
lea    0xe47(%rip),%rdi
call   1030 <puts@plt>
mov    %rbp,%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
call   1060 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1080 <scanf@plt>
mov    0xc(%rsp),%eax
cmp    $0x5,%rax
ja     1298 <main+0x108>
movslq (%rbx,%rax,4),%rax
add    %rbx,%rax
jmp    *%rax
mov    %r13,%rdi
mov    $0xa,%esi
call   1040 <SelectionSort@plt>
jmp    11e0 <main+0x50>
lea    0xe10(%rip),%rdi
call   1030 <puts@plt>
cmpl   $0x0,0xc(%rsp)
jne    11f8 <main+0x68>
jmp    12eb <main+0x15b>
mov    %r13,%rdi
mov    $0xa,%esi
call   1070 <InsertionSort@plt>
jmp    11e0 <main+0x50>
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x9,%edx
call   1090 <MergeSort@plt>
jmp    11e0 <main+0x50>
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x9,%edx
call   1050 <Quicksort@plt>
jmp    11e0 <main+0x50>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.A = [10 x i32] [i32 9, i32 8, i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0]
@.str = [16 x i8] c"1. Bubble Sort\0A\00"
@.str.1 = [19 x i8] c"2. Selection Sort\0A\00"
@.str.2 = [19 x i8] c"3. Insertion Sort\0A\00"
@.str.3 = [15 x i8] c"4. Merge Sort\0A\00"
@.str.4 = [14 x i8] c"5. Quicksort\0A\00"
@.str.5 = [9 x i8] c"0. Exit\0A\00"
@.str.6 = [14 x i8] c"Enter Input: \00"
@.str.7 = [3 x i8] c"%d\00"
@.str.8 = [27 x i8] c"Invalid Input. Try Again.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [10 x i32]
store i32 0, i32* %1
br label %4
4: ; preds = %44, %0
%5 = bitcast [10 x i32]* %3 to i8*
%6 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%9 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%10 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%11 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%12 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32* %2)
%14 = load i32, i32* %2
switch i32 %14, label %41 [
i32 1, label %15
i32 2, label %20
i32 3, label %25
i32 4, label %30
i32 5, label %35
i32 0, label %40
]
15: ; preds = %4
%16 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 0
%17 = call i32 @BubbleSort(i32* %16, i32 10)
%18 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 0
%19 = call i32 @Print(i32* %18, i32 10)
br label %43
20: ; preds = %4
%21 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 0
%22 = call i32 @SelectionSort(i32* %21, i32 10)
%23 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 0
%24 = call i32 @Print(i32* %23, i32 10)
br label %43
25: ; preds = %4
%26 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 0
%27 = call i32 @InsertionSort(i32* %26, i32 10)
%28 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 0
%29 = call i32 @Print(i32* %28, i32 10)
br label %43
30: ; preds = %4
%31 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 0
%32 = call i32 @MergeSort(i32* %31, i32 0, i32 9)
%33 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 0
%34 = call i32 @Print(i32* %33, i32 10)
br label %43
35: ; preds = %4
%36 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 0
%37 = call i32 @Quicksort(i32* %36, i32 0, i32 9)
%38 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 0
%39 = call i32 @Print(i32* %38, i32 10)
br label %43
40: ; preds = %4
br label %43
41: ; preds = %4
%42 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0))
br label %43
43: ; preds = %41, %40, %35, %30, %25, %20, %15
br label %44
44: ; preds = %43
%45 = load i32, i32* %2
%46 = icmp ne i32 %45, 0
br i1 %46, label %4, label %47
47: ; preds = %44
%48 = load i32, i32* %1
ret i32 %48
}

LLVM IR (-O2):
@__const.main.A = [10 x i32] [i32 9, i32 8, i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0]
@.str.6 = [14 x i8] c"Enter Input: \00"
@.str.7 = [3 x i8] c"%d\00"
@str = [15 x i8] c"1. Bubble Sort\00"
@str.9 = [18 x i8] c"2. Selection Sort\00"
@str.10 = [18 x i8] c"3. Insertion Sort\00"
@str.11 = [14 x i8] c"4. Merge Sort\00"
@str.12 = [13 x i8] c"5. Quicksort\00"
@str.13 = [8 x i8] c"0. Exit\00"
@str.14 = [26 x i8] c"Invalid Input. Try Again.\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x i32]
%3 = bitcast i32* %1 to i8*
%4 = bitcast [10 x i32]* %2 to i8*
%5 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 0
br label %6
6: ; preds = %34, %0
%7 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.9, i64 0, i64 0))
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.10, i64 0, i64 0))
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.11, i64 0, i64 0))
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.12, i64 0, i64 0))
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.13, i64 0, i64 0))
%13 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32* %1)
%15 = load i32, i32* %1
switch i32 %15, label %32 [
i32 1, label %17
i32 2, label %20
i32 3, label %23
i32 4, label %26
i32 5, label %29
i32 0, label %16
]
16: ; preds = %6
br label %37
17: ; preds = %6
%18 = call i32 @BubbleSort(i32* %5, i32 10)
%19 = call i32 @Print(i32* %5, i32 10)
br label %34
20: ; preds = %6
%21 = call i32 @SelectionSort(i32* %5, i32 10)
%22 = call i32 @Print(i32* %5, i32 10)
br label %34
23: ; preds = %6
%24 = call i32 @InsertionSort(i32* %5, i32 10)
%25 = call i32 @Print(i32* %5, i32 10)
br label %34
26: ; preds = %6
%27 = call i32 @MergeSort(i32* %5, i32 0, i32 9)
%28 = call i32 @Print(i32* %5, i32 10)
br label %34
29: ; preds = %6
%30 = call i32 @Quicksort(i32* %5, i32 0, i32 9)
%31 = call i32 @Print(i32* %5, i32 10)
br label %34
32: ; preds = %6
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.14, i64 0, i64 0))
br label %34
34: ; preds = %32, %29, %26, %23, %20, %17
%35 = load i32, i32* %1
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %6
37: ; preds = %34, %16
ret i32 0
}