#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*/ BSort(int, int);
int /*<<< orphan*/ CreateLUT();
int /*<<< orphan*/ PrintAll();
int /*<<< orphan*/ PrintIndex();
int /*<<< orphan*/ getchar();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
int sort_menu() {
  int sel, RowNum;
  printf("* * * * * * * * * * * * * * * * * *\n");
  printf("*             Sort Menu           *\n");
  printf("* 1. Sort in ascending order      *\n");
  printf("* 2. Sort in desecending order    *\n");
  printf("* 3. Flush current order          *\n");
  printf("* * * * * * * * * * * * * * * * * *\n");
  printf("Please enter your choice:");
  scanf("%d", &sel);
  getchar();
  PrintIndex();
  printf("Which row?");
  scanf("%d", &RowNum);
  switch (sel) {
  case 1:
    BSort(0, RowNum - 1);
    break;
  case 2:
    BSort(1, RowNum - 1);
    break;
  case 3:
    CreateLUT();
    break;
  }
  PrintAll();
}


x86 assembly (clang, -O0):
<sort_menu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xe81(%rip),%rdi
mov    %rdi,-0x28(%rbp)
call   1030 <printf@plt>
lea    0xe96(%rip),%rdi
call   1030 <printf@plt>
lea    0xeaf(%rip),%rdi
call   1030 <printf@plt>
lea    0xec8(%rip),%rdi
call   1030 <printf@plt>
lea    0xee1(%rip),%rdi
call   1030 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <printf@plt>
lea    0xef1(%rip),%rdi
call   1030 <printf@plt>
lea    0xeff(%rip),%rdi
mov    %rdi,-0x18(%rbp)
lea    -0x8(%rbp),%rsi
call   1080 <scanf@plt>
xor    %eax,%eax
mov    %al,-0x19(%rbp)
call   1050 <getchar@plt>
mov    -0x19(%rbp),%al
call   1090 <PrintIndex@plt>
lea    0xedc(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
lea    -0xc(%rbp),%rsi
call   1080 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
sub    $0x1,%eax
je     1242 <sort_menu+0xd2>
jmp    1220 <sort_menu+0xb0>
mov    -0x10(%rbp),%eax
sub    $0x2,%eax
je     1254 <sort_menu+0xe4>
jmp    1231 <sort_menu+0xc1>
mov    -0x10(%rbp),%eax
sub    $0x3,%eax
je     1269 <sort_menu+0xf9>
jmp    1270 <sort_menu+0x100>
mov    -0xc(%rbp),%esi
sub    $0x1,%esi
xor    %edi,%edi
call   1040 <BSort@plt>
jmp    1270 <sort_menu+0x100>
mov    -0xc(%rbp),%esi
sub    $0x1,%esi
mov    $0x1,%edi
call   1040 <BSort@plt>
jmp    1270 <sort_menu+0x100>
mov    $0x0,%al
call   1060 <CreateLUT@plt>
mov    $0x0,%al
call   1070 <PrintAll@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sort_menu>:
push   %rbx
sub    $0x10,%rsp
lea    0xf2c(%rip),%rbx
mov    %rbx,%rdi
call   1030 <puts@plt>
lea    0xe8d(%rip),%rdi
call   1030 <puts@plt>
lea    0xea5(%rip),%rdi
call   1030 <puts@plt>
lea    0xebd(%rip),%rdi
call   1030 <puts@plt>
lea    0xed5(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
lea    0xe2d(%rip),%rdi
call   1040 <printf@plt>
lea    0xe3b(%rip),%rbx
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
call   1090 <scanf@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
xor    %eax,%eax
call   10a0 <PrintIndex@plt>
lea    0xe1c(%rip),%rdi
call   1040 <printf@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1090 <scanf@plt>
mov    0xc(%rsp),%eax
cmp    $0x3,%eax
je     1231 <sort_menu+0xb1>
cmp    $0x2,%eax
je     123a <sort_menu+0xba>
cmp    $0x1,%eax
jne    124b <sort_menu+0xcb>
mov    0x8(%rsp),%esi
add    $0xffffffff,%esi
xor    %edi,%edi
jmp    1246 <sort_menu+0xc6>
xor    %eax,%eax
call   1070 <CreateLUT@plt>
jmp    124b <sort_menu+0xcb>
mov    0x8(%rsp),%esi
add    $0xffffffff,%esi
mov    $0x1,%edi
call   1050 <BSort@plt>
xor    %eax,%eax
call   1080 <PrintAll@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [37 x i8] c"* * * * * * * * * * * * * * * * * *\0A\00"
@.str.1 = [37 x i8] c"* Sort Menu *\0A\00"
@.str.2 = [37 x i8] c"* 1. Sort in ascending order *\0A\00"
@.str.3 = [37 x i8] c"* 2. Sort in desecending order *\0A\00"
@.str.4 = [37 x i8] c"* 3. Flush current order *\0A\00"
@.str.5 = [26 x i8] c"Please enter your choice:\00"
@.str.6 = [3 x i8] c"%d\00"
@.str.7 = [11 x i8] c"Which row?\00"
define i32 @sort_menu() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
%6 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
%7 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0))
%8 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
%9 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %2)
%12 = call i32 (...) @getchar()
%13 = call i32 (...) @PrintIndex()
%14 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %3)
%16 = load i32, i32* %2
switch i32 %16, label %27 [
i32 1, label %17
i32 2, label %21
i32 3, label %25
]
17: ; preds = %0
%18 = load i32, i32* %3
%19 = sub nsw i32 %18, 1
%20 = call i32 @BSort(i32 0, i32 %19)
br label %27
21: ; preds = %0
%22 = load i32, i32* %3
%23 = sub nsw i32 %22, 1
%24 = call i32 @BSort(i32 1, i32 %23)
br label %27
25: ; preds = %0
%26 = call i32 (...) @CreateLUT()
br label %27
27: ; preds = %0, %25, %21, %17
%28 = call i32 (...) @PrintAll()
%29 = load i32, i32* %1
ret i32 %29
}

LLVM IR (-O2):
@.str.5 = [26 x i8] c"Please enter your choice:\00"
@.str.6 = [3 x i8] c"%d\00"
@.str.7 = [11 x i8] c"Which row?\00"
@str.8 = [36 x i8] c"* Sort Menu *\00"
@str.9 = [36 x i8] c"* 1. Sort in ascending order *\00"
@str.10 = [36 x i8] c"* 2. Sort in desecending order *\00"
@str.11 = [36 x i8] c"* 3. Flush current order *\00"
@str.12 = [36 x i8] c"* * * * * * * * * * * * * * * * * *\00"
define i32 @sort_menu() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.12, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.8, i64 0, i64 0))
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.9, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.10, i64 0, i64 0))
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.11, i64 0, i64 0))
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.12, i64 0, i64 0))
%11 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0))
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %1)
%13 = call i32 (...) @getchar()
%14 = call i32 (...) @PrintIndex()
%15 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
%16 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %2)
%17 = load i32, i32* %1
switch i32 %17, label %28 [
i32 1, label %18
i32 2, label %22
i32 3, label %26
]
18: ; preds = %0
%19 = load i32, i32* %2
%20 = add nsw i32 %19, -1
%21 = call i32 @BSort(i32 0, i32 %20)
br label %28
22: ; preds = %0
%23 = load i32, i32* %2
%24 = add nsw i32 %23, -1
%25 = call i32 @BSort(i32 1, i32 %24)
br label %28
26: ; preds = %0
%27 = call i32 (...) @CreateLUT()
br label %28
28: ; preds = %0, %26, %22, %18
%29 = call i32 (...) @PrintAll()
ret i32 undef
}