#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*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ getch();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ system(char *);
int menu(void) {
  int opcao;
  do {
    system("cls");
    printf("\n\n\tMENU DE OPCOES\n");
    printf("\nOpcaoes disponiveis.\n");
    printf("\n[1] - BubbleSort");
    printf("\n[2] - SelectionSort");
    printf("\n[3] - InsertionSort");
    printf("\n[4] - QuickSort");
    printf("\n[0] - Sair");
    printf("\n\nInforme sua opcao: ");
    fflush(stdin);
    scanf("%d", &opcao);
    if (opcao < 0 || opcao > 4) {
      printf("\n\nOpcao invalida. VERIFIQUE!");
      printf("\nPressione qualquer tecla para continuar...");
      getch();
      continue;
    }
  } while (opcao < 0 || opcao > 4);
  return opcao;
}


x86 assembly (clang, -O0):
<menu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xea1(%rip),%rdi
call   1030 <system@plt>
lea    0xe99(%rip),%rdi
call   1040 <printf@plt>
lea    0xea0(%rip),%rdi
call   1040 <printf@plt>
lea    0xeab(%rip),%rdi
call   1040 <printf@plt>
lea    0xeb1(%rip),%rdi
call   1040 <printf@plt>
lea    0xeba(%rip),%rdi
call   1040 <printf@plt>
lea    0xec3(%rip),%rdi
call   1040 <printf@plt>
lea    0xec8(%rip),%rdi
call   1040 <printf@plt>
lea    0xec8(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
lea    0xec4(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1060 <scanf@plt>
cmpl   $0x0,-0x4(%rbp)
jl     11f6 <menu+0xa6>
cmpl   $0x4,-0x4(%rbp)
jle    121a <menu+0xca>
lea    0xea3(%rip),%rdi
call   1040 <printf@plt>
lea    0xeb4(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1070 <getch@plt>
jmp    121f <menu+0xcf>
jmp    121f <menu+0xcf>
mov    $0x1,%al
cmpl   $0x0,-0x4(%rbp)
mov    %al,-0x5(%rbp)
jl     1238 <menu+0xe8>
cmpl   $0x4,-0x4(%rbp)
setg   %al
mov    %al,-0x5(%rbp)
mov    -0x5(%rbp),%al
test   $0x1,%al
jne    1158 <menu+0x8>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<menu>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xeeb(%rip),%r12
mov    0x2e6f(%rip),%r15
lea    0xef3(%rip),%r13
lea    0x4(%rsp),%rbx
lea    0xeea(%rip),%rbp
lea    0xf00(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    0xe59(%rip),%rdi
call   1040 <system@plt>
lea    0xf0c(%rip),%rdi
call   1030 <puts@plt>
lea    0xf12(%rip),%rdi
call   1030 <puts@plt>
lea    0xe39(%rip),%rdi
call   1050 <printf@plt>
lea    0xe3f(%rip),%rdi
call   1050 <printf@plt>
lea    0xe48(%rip),%rdi
call   1050 <printf@plt>
lea    0xe51(%rip),%rdi
call   1050 <printf@plt>
lea    0xe56(%rip),%rdi
call   1050 <printf@plt>
mov    %r12,%rdi
call   1050 <printf@plt>
mov    (%r15),%edi
call   1060 <fflush@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
call   1070 <scanf@plt>
mov    0x4(%rsp),%eax
cmp    $0x5,%eax
jb     1248 <menu+0xe8>
mov    %rbp,%rdi
call   1050 <printf@plt>
mov    %r14,%rdi
call   1050 <printf@plt>
xor    %eax,%eax
call   1080 <getch@plt>
mov    0x4(%rsp),%eax
cmp    $0x4,%eax
ja     11a0 <menu+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"cls\00"
@.str.1 = [19 x i8] c"\0A\0A\09MENU DE OPCOES\0A\00"
@.str.2 = [23 x i8] c"\0AOpcaoes disponiveis.\0A\00"
@.str.3 = [18 x i8] c"\0A[1] - BubbleSort\00"
@.str.4 = [21 x i8] c"\0A[2] - SelectionSort\00"
@.str.5 = [21 x i8] c"\0A[3] - InsertionSort\00"
@.str.6 = [17 x i8] c"\0A[4] - QuickSort\00"
@.str.7 = [12 x i8] c"\0A[0] - Sair\00"
@.str.8 = [22 x i8] c"\0A\0AInforme sua opcao: \00"
@stdin = global i32 0
@.str.9 = [3 x i8] c"%d\00"
@.str.10 = [29 x i8] c"\0A\0AOpcao invalida. VERIFIQUE!\00"
@.str.11 = [44 x i8] c"\0APressione qualquer tecla para continuar...\00"
define i32 @menu() {
%1 = alloca i32
br label %2
2: ; preds = %31, %0
%3 = call i32 @system(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%5 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%6 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%7 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
%8 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
%9 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0))
%10 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
%11 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0))
%12 = load i32, i32* @stdin
%13 = call i32 @fflush(i32 %12)
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i32* %1)
%15 = load i32, i32* %1
%16 = icmp slt i32 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %2
%18 = load i32, i32* %1
%19 = icmp sgt i32 %18, 4
br i1 %19, label %20, label %24
20: ; preds = %17, %2
%21 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.10, i64 0, i64 0))
%22 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.11, i64 0, i64 0))
%23 = call i32 (...) @getch()
br label %25
24: ; preds = %17
br label %25
25: ; preds = %24, %20
%26 = load i32, i32* %1
%27 = icmp slt i32 %26, 0
br i1 %27, label %31, label %28
28: ; preds = %25
%29 = load i32, i32* %1
%30 = icmp sgt i32 %29, 4
br label %31
31: ; preds = %28, %25
%32 = phi i1 [ true, %25 ], [ %30, %28 ]
br i1 %32, label %2, label %33
33: ; preds = %31
%34 = load i32, i32* %1
ret i32 %34
}

LLVM IR (-O2):
@.str = [4 x i8] c"cls\00"
@.str.3 = [18 x i8] c"\0A[1] - BubbleSort\00"
@.str.4 = [21 x i8] c"\0A[2] - SelectionSort\00"
@.str.5 = [21 x i8] c"\0A[3] - InsertionSort\00"
@.str.6 = [17 x i8] c"\0A[4] - QuickSort\00"
@.str.7 = [12 x i8] c"\0A[0] - Sair\00"
@.str.8 = [22 x i8] c"\0A\0AInforme sua opcao: \00"
@stdin = global i32 0
@.str.9 = [3 x i8] c"%d\00"
@.str.10 = [29 x i8] c"\0A\0AOpcao invalida. VERIFIQUE!\00"
@.str.11 = [44 x i8] c"\0APressione qualquer tecla para continuar...\00"
@str = [18 x i8] c"\0A\0A\09MENU DE OPCOES\00"
@str.12 = [22 x i8] c"\0AOpcaoes disponiveis.\00"
define i32 @menu() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
br label %3
3: ; preds = %18, %0
%4 = call i32 @system(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%6 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.12, i64 0, i64 0))
%7 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%8 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
%9 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
%10 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0))
%11 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
%12 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0))
%13 = load i32, i32* @stdin
%14 = call i32 @fflush(i32 %13)
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i32* %1)
%16 = load i32, i32* %1
%17 = icmp ugt i32 %16, 4
br i1 %17, label %18, label %24
18: ; preds = %3
%19 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.10, i64 0, i64 0))
%20 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.11, i64 0, i64 0))
%21 = call i32 (...) @getch()
%22 = load i32, i32* %1
%23 = icmp ugt i32 %22, 4
br i1 %23, label %3, label %24
24: ; preds = %3, %18
%25 = phi i32 [ %22, %18 ], [ %16, %3 ]
ret i32 %25
}