#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*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
void main() {
  int opcao, a, b;
  printf("----- CALCULADORA -----\n"
         "1. Soma\n"
         "2. Subtracao\n"
         "3. Multiplicacao\n"
         "4. Divisao\n\n");
  do {
    printf("Escolha uma opcao: ");
    scanf("%d", &opcao);
    switch (opcao) {
    case 1:
      printf("\nDigite o primeiro numero: ");
      scanf("%d", &a);
      printf("Digite o segundo numero: ");
      scanf("%d", &b);
      printf("\n%d + %d = %d\n", a, b, a + b);
      break;
    case 2:
      printf("\nDigite o primeiro numero: ");
      scanf("%d", &a);
      printf("Digite o segundo numero: ");
      scanf("%d", &b);
      printf("\n%d - %d = %d\n", a, b, a - b);
      break;
    case 3:
      printf("\nDigite o primeiro numero: ");
      scanf("%d", &a);
      printf("Digite o segundo numero: ");
      scanf("%d", &b);
      printf("\n%d * %d = %d\n", a, b, a * b);
      break;
    case 4:
      printf("\nDigite o primeiro numero: ");
      scanf("%d", &a);
      printf("Digite o segundo numero: ");
      scanf("%d", &b);
      printf("\n%d / %d = %d\n", a, b, a / b);
      break;
    default:
      printf("\nOpcao invalida. Tente novamente.\n");
    }
  } while (opcao < 1 || opcao > 4);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xee1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf1e(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xf24(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x3,%eax
ja     12f3 <main+0x1d3>
mov    -0x18(%rbp),%rax
lea    0xe8c(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xeee(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xedd(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xeec(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xebf(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x8(%rbp),%ecx
add    -0xc(%rbp),%ecx
lea    0xedc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1301 <main+0x1e1>
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe82(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe64(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x8(%rbp),%ecx
sub    -0xc(%rbp),%ecx
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1301 <main+0x1e1>
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe27(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe09(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x8(%rbp),%ecx
imul   -0xc(%rbp),%ecx
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1301 <main+0x1e1>
lea    0xddc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xdcb(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xdda(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xdad(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%eax
cltd
idivl  -0xc(%rbp)
mov    -0x1c(%rbp),%edx
mov    %eax,%ecx
lea    0xdee(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1301 <main+0x1e1>
lea    0xdea(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1306 <main+0x1e6>
mov    $0x1,%al
cmpl   $0x1,-0x4(%rbp)
mov    %al,-0x1d(%rbp)
jl     131f <main+0x1ff>
cmpl   $0x4,-0x4(%rbp)
setg   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    1136 <main+0x16>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xf54(%rip),%rdi
call   1030 <puts@plt>
lea    0xebf(%rip),%r14
lea    0xecc(%rip),%rbx
lea    0x14(%rsp),%r15
lea    0xe9c(%rip),%rbp
lea    0xed8(%rip),%r12
lea    0x10(%rsp),%r13
jmp    11da <main+0xaa>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0xea0(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%esi
mov    0x10(%rsp),%edx
mov    %esi,%ecx
sub    %edx,%ecx
lea    0xea9(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x14(%rsp),%eax
add    $0xfffffffb,%eax
cmp    $0xfffffffc,%eax
jae    130d <main+0x1dd>
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <scanf@plt>
mov    0x14(%rsp),%eax
add    $0xffffffff,%eax
cmp    $0x3,%eax
ja     1250 <main+0x120>
movslq 0x0(%rbp,%rax,4),%rax
add    %rbp,%rax
jmp    *%rax
lea    0xe1b(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%esi
mov    0x10(%rsp),%edx
lea    (%rdx,%rsi,1),%ecx
lea    0xe16(%rip),%rdi
jmp    11c3 <main+0x93>
nopl   0x0(%rax)
lea    0xe8c(%rip),%rdi
call   1030 <puts@plt>
jmp    11ca <main+0x9a>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0xdb0(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%esi
mov    0x10(%rsp),%edx
mov    %edx,%ecx
imul   %esi,%ecx
lea    0xdc7(%rip),%rdi
jmp    11c3 <main+0x93>
nopl   0x0(%rax)
lea    0xd60(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%esi
mov    0x10(%rsp),%ecx
mov    %esi,%eax
cltd
idiv   %ecx
lea    0xd86(%rip),%rdi
mov    %ecx,%edx
mov    %eax,%ecx
jmp    11c3 <main+0x93>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [75 x i8] c"----- CALCULADORA -----\0A1. Soma\0A2. Subtracao\0A3. Multiplicacao\0A4. Divisao\0A\0A\00"
@.str.1 = [20 x i8] c"Escolha uma opcao: \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [28 x i8] c"\0ADigite o primeiro numero: \00"
@.str.4 = [26 x i8] c"Digite o segundo numero: \00"
@.str.5 = [15 x i8] c"\0A%d + %d = %d\0A\00"
@.str.6 = [15 x i8] c"\0A%d - %d = %d\0A\00"
@.str.7 = [15 x i8] c"\0A%d * %d = %d\0A\00"
@.str.8 = [15 x i8] c"\0A%d / %d = %d\0A\00"
@.str.9 = [35 x i8] c"\0AOpcao invalida. Tente novamente.\0A\00"
define void @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str, i64 0, i64 0))
br label %5
5: ; preds = %62, %0
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%8 = load i32, i32* %1
switch i32 %8, label %53 [
i32 1, label %9
i32 2, label %20
i32 3, label %31
i32 4, label %42
]
9: ; preds = %5
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%14 = load i32, i32* %2
%15 = load i32, i32* %3
%16 = load i32, i32* %2
%17 = load i32, i32* %3
%18 = add nsw i32 %16, %17
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i32 %14, i32 %15, i32 %18)
br label %55
20: ; preds = %5
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
%22 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
%24 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%25 = load i32, i32* %2
%26 = load i32, i32* %3
%27 = load i32, i32* %2
%28 = load i32, i32* %3
%29 = sub nsw i32 %27, %28
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i32 %25, i32 %26, i32 %29)
br label %55
31: ; preds = %5
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
%33 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
%35 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%36 = load i32, i32* %2
%37 = load i32, i32* %3
%38 = load i32, i32* %2
%39 = load i32, i32* %3
%40 = mul nsw i32 %38, %39
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0), i32 %36, i32 %37, i32 %40)
br label %55
42: ; preds = %5
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
%44 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
%46 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%47 = load i32, i32* %2
%48 = load i32, i32* %3
%49 = load i32, i32* %2
%50 = load i32, i32* %3
%51 = sdiv i32 %49, %50
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0), i32 %47, i32 %48, i32 %51)
br label %55
53: ; preds = %5
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.9, i64 0, i64 0))
br label %55
55: ; preds = %53, %42, %31, %20, %9
br label %56
56: ; preds = %55
%57 = load i32, i32* %1
%58 = icmp slt i32 %57, 1
br i1 %58, label %62, label %59
59: ; preds = %56
%60 = load i32, i32* %1
%61 = icmp sgt i32 %60, 4
br label %62
62: ; preds = %59, %56
%63 = phi i1 [ true, %56 ], [ %61, %59 ]
br i1 %63, label %5, label %64
64: ; preds = %62
ret void
}

LLVM IR (-O2):
@.str.1 = [20 x i8] c"Escolha uma opcao: \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [28 x i8] c"\0ADigite o primeiro numero: \00"
@.str.4 = [26 x i8] c"Digite o segundo numero: \00"
@.str.5 = [15 x i8] c"\0A%d + %d = %d\0A\00"
@.str.6 = [15 x i8] c"\0A%d - %d = %d\0A\00"
@.str.7 = [15 x i8] c"\0A%d * %d = %d\0A\00"
@.str.8 = [15 x i8] c"\0A%d / %d = %d\0A\00"
@str = [74 x i8] c"----- CALCULADORA -----\0A1. Soma\0A2. Subtracao\0A3. Multiplicacao\0A4. Divisao\0A\00"
@str.10 = [34 x i8] c"\0AOpcao invalida. Tente novamente.\00"
define void @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([74 x i8], [74 x i8]* @str, i64 0, i64 0))
br label %8
8: ; preds = %50, %0
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%11 = load i32, i32* %1
switch i32 %11, label %48 [
i32 1, label %12
i32 2, label %21
i32 3, label %30
i32 4, label %39
]
12: ; preds = %8
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
%16 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%17 = load i32, i32* %2
%18 = load i32, i32* %3
%19 = add nsw i32 %18, %17
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i32 %17, i32 %18, i32 %19)
br label %50
21: ; preds = %8
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
%23 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
%25 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%26 = load i32, i32* %2
%27 = load i32, i32* %3
%28 = sub nsw i32 %26, %27
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i32 %26, i32 %27, i32 %28)
br label %50
30: ; preds = %8
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
%32 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
%34 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%35 = load i32, i32* %2
%36 = load i32, i32* %3
%37 = mul nsw i32 %36, %35
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0), i32 %35, i32 %36, i32 %37)
br label %50
39: ; preds = %8
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
%41 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
%43 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%44 = load i32, i32* %2
%45 = load i32, i32* %3
%46 = sdiv i32 %44, %45
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0), i32 %44, i32 %45, i32 %46)
br label %50
48: ; preds = %8
%49 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str.10, i64 0, i64 0))
br label %50
50: ; preds = %12, %21, %30, %39, %48
%51 = load i32, i32* %1
%52 = add i32 %51, -5
%53 = icmp ult i32 %52, -4
br i1 %53, label %8, label %54
54: ; preds = %50
ret void
}