#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*/ accept(int *, unsigned int *);
int /*<<< orphan*/ display(int *, unsigned int);
int /*<<< orphan*/ mrgsort(int *, unsigned int);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ qiksort(int *, unsigned int);
int /*<<< orphan*/ scanf(char *, unsigned int *);
int main() {
  unsigned ch, n = 0;
  int a[50];
  do {
    puts("What would you like to do?");
    puts(" ( 0) Exit");
    puts(" ( 1) Populate Array");
    puts(" ( 2) Print");
    puts(" ( 3) Quick Sort");
    puts(" ( 4) Merge Sort");
    scanf(" %u%*c", &ch);
    switch (ch) {
    case 0:
      puts("Bye!");
      break;
    case 1:
      accept(a, &n);
      putchar('\n');
      break;
    case 2:
      display(a, n);
      putchar('\n');
      break;
    case 3:
      qiksort(a, n);
      display(a, n);
      putchar('\n');
      break;
    case 4:
      mrgsort(a, n);
      display(a, n);
      putchar('\n');
      break;
    default:
      puts("Incorrect Choice!");
      break;
    }
  } while (ch);
  putchar('\n');
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xe84(%rip),%rdi
call   1040 <puts@plt>
lea    0xe93(%rip),%rdi
call   1040 <puts@plt>
lea    0xe92(%rip),%rdi
call   1040 <puts@plt>
lea    0xe9b(%rip),%rdi
call   1040 <puts@plt>
lea    0xe9b(%rip),%rdi
call   1040 <puts@plt>
lea    0xea0(%rip),%rdi
call   1040 <puts@plt>
lea    0xea5(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1070 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %rax,-0xe8(%rbp)
sub    $0x4,%rax
ja     12b4 <main+0x144>
mov    -0xe8(%rbp),%rax
lea    0xdfd(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xe71(%rip),%rdi
call   1040 <puts@plt>
jmp    12c0 <main+0x150>
lea    -0xe0(%rbp),%rdi
lea    -0xc(%rbp),%rsi
call   1080 <accept@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    12c0 <main+0x150>
lea    -0xe0(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1050 <display@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    12c0 <main+0x150>
lea    -0xe0(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1090 <qiksort@plt>
lea    -0xe0(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1050 <display@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    12c0 <main+0x150>
lea    -0xe0(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1060 <mrgsort@plt>
lea    -0xe0(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1050 <display@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    12c0 <main+0x150>
lea    0xdce(%rip),%rdi
call   1040 <puts@plt>
jmp    12c5 <main+0x155>
cmpl   $0x0,-0x8(%rbp)
jne    1189 <main+0x19>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xd8,%rsp
movl   $0x0,0x8(%rsp)
lea    0xecb(%rip),%rbx
lea    0xed5(%rip),%rbp
lea    0xedf(%rip),%r14
lea    0xc(%rsp),%r15
lea    0xe56(%rip),%r13
lea    0x10(%rsp),%r12
jmp    11c8 <main+0x58>
lea    0xed1(%rip),%rdi
call   1040 <puts@plt>
cmpl   $0x0,0xc(%rsp)
je     127a <main+0x10a>
lea    0xe45(%rip),%rdi
call   1040 <puts@plt>
lea    0xe54(%rip),%rdi
call   1040 <puts@plt>
lea    0xe53(%rip),%rdi
call   1040 <puts@plt>
lea    0xe5c(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1040 <puts@plt>
mov    %rbp,%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1070 <scanf@plt>
mov    0xc(%rsp),%eax
cmp    $0x4,%rax
ja     11b1 <main+0x41>
movslq 0x0(%r13,%rax,4),%rax
add    %r13,%rax
jmp    *%rax
lea    0xe56(%rip),%rdi
jmp    11b8 <main+0x48>
mov    %r12,%rdi
lea    0x8(%rsp),%rsi
call   1080 <accept@plt>
jmp    1265 <main+0xf5>
mov    0x8(%rsp),%esi
mov    %r12,%rdi
call   1090 <qiksort@plt>
jmp    1259 <main+0xe9>
mov    0x8(%rsp),%esi
mov    %r12,%rdi
call   1060 <mrgsort@plt>
mov    0x8(%rsp),%esi
mov    %r12,%rdi
call   1050 <display@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
cmpl   $0x0,0xc(%rsp)
jne    11c8 <main+0x58>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0xd8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [27 x i8] c"What would you like to do?\00"
@.str.1 = [11 x i8] c" ( 0) Exit\00"
@.str.2 = [21 x i8] c" ( 1) Populate Array\00"
@.str.3 = [12 x i8] c" ( 2) Print\00"
@.str.4 = [17 x i8] c" ( 3) Quick Sort\00"
@.str.5 = [17 x i8] c" ( 4) Merge Sort\00"
@.str.6 = [7 x i8] c" %u%*c\00"
@.str.7 = [5 x i8] c"Bye!\00"
@.str.8 = [18 x i8] c"Incorrect Choice!\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [50 x i32]
store i32 0, i32* %1
store i32 0, i32* %3
br label %5
5: ; preds = %44, %0
%6 = call i32 @puts(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @puts(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 @puts(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%9 = call i32 @puts(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%10 = call i32 @puts(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%11 = call i32 @puts(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
%12 = call i32 @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32* %2)
%13 = load i32, i32* %2
switch i32 %13, label %41 [
i32 0, label %14
i32 1, label %16
i32 2, label %20
i32 3, label %25
i32 4, label %33
]
14: ; preds = %5
%15 = call i32 @puts(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
br label %43
16: ; preds = %5
%17 = getelementptr inbounds [50 x i32], [50 x i32]* %4, i64 0, i64 0
%18 = call i32 @accept(i32* %17, i32* %3)
%19 = call i32 @putchar(i8 signext 10)
br label %43
20: ; preds = %5
%21 = getelementptr inbounds [50 x i32], [50 x i32]* %4, i64 0, i64 0
%22 = load i32, i32* %3
%23 = call i32 @display(i32* %21, i32 %22)
%24 = call i32 @putchar(i8 signext 10)
br label %43
25: ; preds = %5
%26 = getelementptr inbounds [50 x i32], [50 x i32]* %4, i64 0, i64 0
%27 = load i32, i32* %3
%28 = call i32 @qiksort(i32* %26, i32 %27)
%29 = getelementptr inbounds [50 x i32], [50 x i32]* %4, i64 0, i64 0
%30 = load i32, i32* %3
%31 = call i32 @display(i32* %29, i32 %30)
%32 = call i32 @putchar(i8 signext 10)
br label %43
33: ; preds = %5
%34 = getelementptr inbounds [50 x i32], [50 x i32]* %4, i64 0, i64 0
%35 = load i32, i32* %3
%36 = call i32 @mrgsort(i32* %34, i32 %35)
%37 = getelementptr inbounds [50 x i32], [50 x i32]* %4, i64 0, i64 0
%38 = load i32, i32* %3
%39 = call i32 @display(i32* %37, i32 %38)
%40 = call i32 @putchar(i8 signext 10)
br label %43
41: ; preds = %5
%42 = call i32 @puts(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.8, i64 0, i64 0))
br label %43
43: ; preds = %41, %33, %25, %20, %16, %14
br label %44
44: ; preds = %43
%45 = load i32, i32* %2
%46 = icmp ne i32 %45, 0
br i1 %46, label %5, label %47
47: ; preds = %44
%48 = call i32 @putchar(i8 signext 10)
ret i32 0
}

LLVM IR (-O2):
@.str = [27 x i8] c"What would you like to do?\00"
@.str.1 = [11 x i8] c" ( 0) Exit\00"
@.str.2 = [21 x i8] c" ( 1) Populate Array\00"
@.str.3 = [12 x i8] c" ( 2) Print\00"
@.str.4 = [17 x i8] c" ( 3) Quick Sort\00"
@.str.5 = [17 x i8] c" ( 4) Merge Sort\00"
@.str.6 = [7 x i8] c" %u%*c\00"
@.str.7 = [5 x i8] c"Bye!\00"
@.str.8 = [18 x i8] c"Incorrect Choice!\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [50 x i32]
%4 = bitcast i32* %1 to i8*
%5 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%6 = bitcast [50 x i32]* %3 to i8*
%7 = getelementptr inbounds [50 x i32], [50 x i32]* %3, i64 0, i64 0
br label %8
8: ; preds = %40, %0
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
%15 = call i32 @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32* %1)
%16 = load i32, i32* %1
switch i32 %16, label %38 [
i32 0, label %17
i32 1, label %19
i32 2, label %22
i32 3, label %26
i32 4, label %32
]
17: ; preds = %8
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
br label %40
19: ; preds = %8
%20 = call i32 @accept(i32* %7, i32* %2)
%21 = call i32 @putchar(i8 signext 10)
br label %40
22: ; preds = %8
%23 = load i32, i32* %2
%24 = call i32 @display(i32* %7, i32 %23)
%25 = call i32 @putchar(i8 signext 10)
br label %40
26: ; preds = %8
%27 = load i32, i32* %2
%28 = call i32 @qiksort(i32* %7, i32 %27)
%29 = load i32, i32* %2
%30 = call i32 @display(i32* %7, i32 %29)
%31 = call i32 @putchar(i8 signext 10)
br label %40
32: ; preds = %8
%33 = load i32, i32* %2
%34 = call i32 @mrgsort(i32* %7, i32 %33)
%35 = load i32, i32* %2
%36 = call i32 @display(i32* %7, i32 %35)
%37 = call i32 @putchar(i8 signext 10)
br label %40
38: ; preds = %8
%39 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.8, i64 0, i64 0))
br label %40
40: ; preds = %17, %19, %22, %26, %32, %38
%41 = load i32, i32* %1
%42 = icmp eq i32 %41, 0
br i1 %42, label %43, label %8
43: ; preds = %40
%44 = call i32 @putchar(i8 signext 10)
ret i32 0
}