#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*/ chamaMenu(int, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int op, atual, aux;
  aux = 0;
  atual = 0;
  printf("\t\tDigite valores entre 1 e 6 para mudar de menu\n");
  printf("\t\tCaso queira sair, digite 0\n");
  printf("\t\tPara voltar ao menu anterior, digite -1\n");
  printf("\n----------------------------------------------\n");
  while (1) {
    printf("\n\nSelecione o menu\n ");
    printf("\t> Menus         ~ 1 a 6\n");
    printf("\t> Menu anterior ~ -1\n");
    printf("\t> Sair          ~ 0\n");
    scanf("%d", &op);
    printf("\n");
    switch (op) {
    case -1:
      chamaMenu(aux, atual);
      op = aux;
      aux = atual;
      atual = op;
      break;
    case 0:
      printf("Voce saiu!");
      return 0;
      break;
    case 1:
      chamaMenu(op, atual);
      aux = atual;
      atual = op;
      break;
    case 2:
      chamaMenu(op, atual);
      aux = atual;
      atual = op;
      break;
    case 3:
      chamaMenu(op, atual);
      aux = atual;
      atual = op;
      break;
    case 4:
      chamaMenu(op, atual);
      aux = atual;
      atual = op;
      break;
    case 5:
      chamaMenu(op, atual);
      aux = atual;
      atual = op;
      break;
    case 6:
      chamaMenu(op, atual);
      aux = atual;
      atual = op;
      break;
    default:
      printf("Opcao invalida!\n");
      break;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xecc(%rip),%rdi
call   1030 <printf@plt>
lea    0xef1(%rip),%rdi
call   1030 <printf@plt>
lea    0xf03(%rip),%rdi
call   1030 <printf@plt>
lea    0xf22(%rip),%rdi
call   1030 <printf@plt>
lea    0xf47(%rip),%rdi
call   1030 <printf@plt>
lea    0xf50(%rip),%rdi
call   1030 <printf@plt>
lea    0xf5e(%rip),%rdi
call   1030 <printf@plt>
lea    0xf69(%rip),%rdi
call   1030 <printf@plt>
lea    0xf73(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
lea    0xf80(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x7,%eax
ja     12d0 <main+0x1a0>
mov    -0x18(%rbp),%rax
lea    0xe17(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1040 <chamaMenu@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    12dc <main+0x1ac>
lea    0xf0f(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1040 <chamaMenu@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    12dc <main+0x1ac>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1040 <chamaMenu@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    12dc <main+0x1ac>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1040 <chamaMenu@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    12dc <main+0x1ac>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1040 <chamaMenu@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    12dc <main+0x1ac>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1040 <chamaMenu@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    12dc <main+0x1ac>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1040 <chamaMenu@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    12dc <main+0x1ac>
lea    0xe5e(%rip),%rdi
call   1030 <printf@plt>
jmp    117d <main+0x4d>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xee1(%rip),%rdi
call   1040 <puts@plt>
lea    0xf05(%rip),%rdi
call   1040 <puts@plt>
lea    0xf16(%rip),%rdi
call   1040 <puts@plt>
lea    0xf34(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
lea    0xf85(%rip),%r13
lea    0xe9a(%rip),%rbx
lea    0x4(%rsp),%rbp
lea    0xe59(%rip),%r12
xor    %r15d,%r15d
jmp    11cf <main+0x7f>
mov    $0x1,%edi
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14d,%esi
call   1060 <chamaMenu@plt>
mov    0x4(%rsp),%eax
mov    %r14d,%r15d
mov    %eax,%r14d
lea    0xe47(%rip),%rdi
call   1050 <printf@plt>
lea    0xf05(%rip),%rdi
call   1040 <puts@plt>
lea    0xf12(%rip),%rdi
call   1040 <puts@plt>
mov    %r13,%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1070 <scanf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x4(%rsp),%eax
add    $0x1,%eax
cmp    $0x7,%eax
ja     1240 <main+0xf0>
movslq (%r12,%rax,4),%rax
add    %r12,%rax
jmp    *%rax
mov    %r15d,%edi
mov    %r14d,%esi
call   1060 <chamaMenu@plt>
mov    %r15d,0x4(%rsp)
mov    %r15d,%eax
mov    %r14d,%r15d
jmp    11cf <main+0x7f>
lea    0xee7(%rip),%rdi
call   1040 <puts@plt>
mov    %r14d,%eax
jmp    11cf <main+0x7f>
mov    $0x2,%edi
jmp    11c0 <main+0x70>
mov    $0x3,%edi
jmp    11c0 <main+0x70>
mov    $0x4,%edi
jmp    11c0 <main+0x70>
mov    $0x5,%edi
jmp    11c0 <main+0x70>
mov    $0x6,%edi
jmp    11c0 <main+0x70>
lea    0xdab(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [49 x i8] c"\09\09Digite valores entre 1 e 6 para mudar de menu\0A\00"
@.str.1 = [30 x i8] c"\09\09Caso queira sair, digite 0\0A\00"
@.str.2 = [43 x i8] c"\09\09Para voltar ao menu anterior, digite -1\0A\00"
@.str.3 = [49 x i8] c"\0A----------------------------------------------\0A\00"
@.str.4 = [21 x i8] c"\0A\0ASelecione o menu\0A \00"
@.str.5 = [26 x i8] c"\09> Menus ~ 1 a 6\0A\00"
@.str.6 = [23 x i8] c"\09> Menu anterior ~ -1\0A\00"
@.str.7 = [22 x i8] c"\09> Sair ~ 0\0A\00"
@.str.8 = [3 x i8] c"%d\00"
@.str.9 = [2 x i8] c"\0A\00"
@.str.10 = [11 x i8] c"Voce saiu!\00"
@.str.11 = [17 x i8] c"Opcao invalida!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %4
store i32 0, i32* %3
%5 = call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0))
%8 = call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.3, i64 0, i64 0))
br label %9
9: ; preds = %0, %64
%10 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
%11 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0))
%12 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0))
%13 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0))
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32* %2)
%15 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
%16 = load i32, i32* %2
switch i32 %16, label %62 [
i32 -1, label %17
i32 0, label %24
i32 1, label %26
i32 2, label %32
i32 3, label %38
i32 4, label %44
i32 5, label %50
i32 6, label %56
]
17: ; preds = %9
%18 = load i32, i32* %4
%19 = load i32, i32* %3
%20 = call i32 @chamaMenu(i32 %18, i32 %19)
%21 = load i32, i32* %4
store i32 %21, i32* %2
%22 = load i32, i32* %3
store i32 %22, i32* %4
%23 = load i32, i32* %2
store i32 %23, i32* %3
br label %64
24: ; preds = %9
%25 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.10, i64 0, i64 0))
ret i32 0
26: ; preds = %9
%27 = load i32, i32* %2
%28 = load i32, i32* %3
%29 = call i32 @chamaMenu(i32 %27, i32 %28)
%30 = load i32, i32* %3
store i32 %30, i32* %4
%31 = load i32, i32* %2
store i32 %31, i32* %3
br label %64
32: ; preds = %9
%33 = load i32, i32* %2
%34 = load i32, i32* %3
%35 = call i32 @chamaMenu(i32 %33, i32 %34)
%36 = load i32, i32* %3
store i32 %36, i32* %4
%37 = load i32, i32* %2
store i32 %37, i32* %3
br label %64
38: ; preds = %9
%39 = load i32, i32* %2
%40 = load i32, i32* %3
%41 = call i32 @chamaMenu(i32 %39, i32 %40)
%42 = load i32, i32* %3
store i32 %42, i32* %4
%43 = load i32, i32* %2
store i32 %43, i32* %3
br label %64
44: ; preds = %9
%45 = load i32, i32* %2
%46 = load i32, i32* %3
%47 = call i32 @chamaMenu(i32 %45, i32 %46)
%48 = load i32, i32* %3
store i32 %48, i32* %4
%49 = load i32, i32* %2
store i32 %49, i32* %3
br label %64
50: ; preds = %9
%51 = load i32, i32* %2
%52 = load i32, i32* %3
%53 = call i32 @chamaMenu(i32 %51, i32 %52)
%54 = load i32, i32* %3
store i32 %54, i32* %4
%55 = load i32, i32* %2
store i32 %55, i32* %3
br label %64
56: ; preds = %9
%57 = load i32, i32* %2
%58 = load i32, i32* %3
%59 = call i32 @chamaMenu(i32 %57, i32 %58)
%60 = load i32, i32* %3
store i32 %60, i32* %4
%61 = load i32, i32* %2
store i32 %61, i32* %3
br label %64
62: ; preds = %9
%63 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.11, i64 0, i64 0))
br label %64
64: ; preds = %62, %56, %50, %44, %38, %32, %26, %17
br label %9
}

LLVM IR (-O2):
@.str.4 = [21 x i8] c"\0A\0ASelecione o menu\0A \00"
@.str.8 = [3 x i8] c"%d\00"
@.str.10 = [11 x i8] c"Voce saiu!\00"
@str = [48 x i8] c"\09\09Digite valores entre 1 e 6 para mudar de menu\00"
@str.12 = [29 x i8] c"\09\09Caso queira sair, digite 0\00"
@str.13 = [42 x i8] c"\09\09Para voltar ao menu anterior, digite -1\00"
@str.14 = [48 x i8] c"\0A----------------------------------------------\00"
@str.15 = [25 x i8] c"\09> Menus ~ 1 a 6\00"
@str.16 = [22 x i8] c"\09> Menu anterior ~ -1\00"
@str.17 = [21 x i8] c"\09> Sair ~ 0\00"
@str.18 = [16 x i8] c"Opcao invalida!\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.12, i64 0, i64 0))
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str.13, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @str.14, i64 0, i64 0))
br label %7
7: ; preds = %41, %0
%8 = phi i32 [ 0, %0 ], [ %42, %41 ]
%9 = phi i32 [ 0, %0 ], [ %43, %41 ]
%10 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.15, i64 0, i64 0))
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.16, i64 0, i64 0))
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.17, i64 0, i64 0))
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32* %1)
%15 = call i32 @putchar(i32 10)
%16 = load i32, i32* %1
switch i32 %16, label %39 [
i32 -1, label %17
i32 0, label %19
i32 1, label %21
i32 2, label %24
i32 3, label %27
i32 4, label %30
i32 5, label %33
i32 6, label %36
]
17: ; preds = %7
%18 = call i32 @chamaMenu(i32 %9, i32 %8)
store i32 %9, i32* %1
br label %41
19: ; preds = %7
%20 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.10, i64 0, i64 0))
ret i32 0
21: ; preds = %7
%22 = call i32 @chamaMenu(i32 1, i32 %8)
%23 = load i32, i32* %1
br label %41
24: ; preds = %7
%25 = call i32 @chamaMenu(i32 2, i32 %8)
%26 = load i32, i32* %1
br label %41
27: ; preds = %7
%28 = call i32 @chamaMenu(i32 3, i32 %8)
%29 = load i32, i32* %1
br label %41
30: ; preds = %7
%31 = call i32 @chamaMenu(i32 4, i32 %8)
%32 = load i32, i32* %1
br label %41
33: ; preds = %7
%34 = call i32 @chamaMenu(i32 5, i32 %8)
%35 = load i32, i32* %1
br label %41
36: ; preds = %7
%37 = call i32 @chamaMenu(i32 6, i32 %8)
%38 = load i32, i32* %1
br label %41
39: ; preds = %7
%40 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.18, i64 0, i64 0))
br label %41
41: ; preds = %39, %36, %33, %30, %27, %24, %21, %17
%42 = phi i32 [ %8, %39 ], [ %38, %36 ], [ %35, %33 ], [ %32, %30 ], [ %29, %27 ], [ %26, %24 ], [ %23, %21 ], [ %9, %17 ]
%43 = phi i32 [ %9, %39 ], [ %8, %36 ], [ %8, %33 ], [ %8, %30 ], [ %8, %27 ], [ %8, %24 ], [ %8, %21 ], [ %8, %17 ]
br label %7
}