#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*/ ex1();
int /*<<< orphan*/ ex2();
int /*<<< orphan*/ ex3();
int /*<<< orphan*/ ex4();
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ system(char *);
int main(void) {
  int pick;
  do {
    puts("escolha exercicio 1 a 4");
    scanf("%d", &pick);
  } while (pick < 1 || pick > 4);
  switch (pick) {
  case 1:
    puts("\n\n");
    ex1();
    break;
  case 2:
    puts("\n\n");
    ex2();
    break;
  case 3:
    puts("\n\n");
    ex3();
    break;
  case 4:
    puts("\n\n");
    ex4();
    break;
  }
  system("pause");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
call   1050 <puts@plt>
lea    0xe96(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1090 <scanf@plt>
mov    $0x1,%al
cmpl   $0x1,-0x8(%rbp)
mov    %al,-0x9(%rbp)
jl     11b4 <main+0x44>
cmpl   $0x4,-0x8(%rbp)
setg   %al
mov    %al,-0x9(%rbp)
mov    -0x9(%rbp),%al
test   $0x1,%al
jne    117f <main+0xf>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x3,%eax
ja     1243 <main+0xd3>
mov    -0x18(%rbp),%rax
lea    0xe21(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xe3c(%rip),%rdi
call   1050 <puts@plt>
mov    $0x0,%al
call   1030 <ex1@plt>
jmp    1243 <main+0xd3>
lea    0xe24(%rip),%rdi
call   1050 <puts@plt>
mov    $0x0,%al
call   1080 <ex2@plt>
jmp    1243 <main+0xd3>
lea    0xe0c(%rip),%rdi
call   1050 <puts@plt>
mov    $0x0,%al
call   1040 <ex3@plt>
jmp    1243 <main+0xd3>
lea    0xdf4(%rip),%rdi
call   1050 <puts@plt>
mov    $0x0,%al
call   1070 <ex4@plt>
lea    0xde4(%rip),%rdi
call   1060 <system@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xe90(%rip),%r14
lea    0xea1(%rip),%r15
lea    0xc(%rsp),%rbx
nopl   0x0(%rax)
mov    %r14,%rdi
call   1050 <puts@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1090 <scanf@plt>
mov    0xc(%rsp),%eax
lea    -0x5(%rax),%ecx
cmp    $0xfffffffc,%ecx
jb     1190 <main+0x20>
add    $0xffffffff,%eax
cmp    $0x3,%eax
ja     1219 <main+0xa9>
lea    0xe42(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xe5d(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
call   1030 <ex1@plt>
jmp    1219 <main+0xa9>
lea    0xe48(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
call   1080 <ex2@plt>
jmp    1219 <main+0xa9>
lea    0xe33(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
call   1040 <ex3@plt>
jmp    1219 <main+0xa9>
lea    0xe1e(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
call   1070 <ex4@plt>
lea    0xe0e(%rip),%rdi
call   1060 <system@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [24 x i8] c"escolha exercicio 1 a 4\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [3 x i8] c"\0A\0A\00"
@.str.3 = [6 x i8] c"pause\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
br label %3
3: ; preds = %12, %0
%4 = call i32 @puts(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
br label %6
6: ; preds = %3
%7 = load i32, i32* %2
%8 = icmp slt i32 %7, 1
br i1 %8, label %12, label %9
9: ; preds = %6
%10 = load i32, i32* %2
%11 = icmp sgt i32 %10, 4
br label %12
12: ; preds = %9, %6
%13 = phi i1 [ true, %6 ], [ %11, %9 ]
br i1 %13, label %3, label %14
14: ; preds = %12
%15 = load i32, i32* %2
switch i32 %15, label %28 [
i32 1, label %16
i32 2, label %19
i32 3, label %22
i32 4, label %25
]
16: ; preds = %14
%17 = call i32 @puts(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%18 = call i32 (...) @ex1()
br label %28
19: ; preds = %14
%20 = call i32 @puts(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%21 = call i32 (...) @ex2()
br label %28
22: ; preds = %14
%23 = call i32 @puts(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%24 = call i32 (...) @ex3()
br label %28
25: ; preds = %14
%26 = call i32 @puts(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%27 = call i32 (...) @ex4()
br label %28
28: ; preds = %14, %25, %22, %19, %16
%29 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [24 x i8] c"escolha exercicio 1 a 4\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [3 x i8] c"\0A\0A\00"
@.str.3 = [6 x i8] c"pause\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
br label %3
3: ; preds = %3, %0
%4 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%6 = load i32, i32* %1
%7 = add i32 %6, -5
%8 = icmp ult i32 %7, -4
br i1 %8, label %3, label %9
9: ; preds = %3
switch i32 %6, label %22 [
i32 1, label %10
i32 2, label %13
i32 3, label %16
i32 4, label %19
]
10: ; preds = %9
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 (...) @ex1()
br label %22
13: ; preds = %9
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%15 = call i32 (...) @ex2()
br label %22
16: ; preds = %9
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%18 = call i32 (...) @ex3()
br label %22
19: ; preds = %9
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%21 = call i32 (...) @ex4()
br label %22
22: ; preds = %9, %19, %16, %13, %10
%23 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}