#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 *);
int main(void) {
  int n1 = 0, n2 = 0;
  int opcao = 6;
  do {
    printf("\nEntre com a operacao desejada: \n(1)...Divisao\n(2)...Resto da "
           "Disisao\n(3)...Adicao\n(4)...Multiplicacao\n(0)...Sair\n");
    scanf("%d", &opcao);
    if ((opcao == 1) || (opcao == 2)) {
      printf("Digite o primeiro numero: \n");
      scanf("%d", &n1);
      do {
        printf("Digite o segundo numero: \n");
        scanf("%d", &n2);
        if (n2 == 0)
          printf("Impossivel realizar divisao por zero!\n");
      } while (n2 == 0);
    } else if ((opcao == 3) || (opcao == 4)) {
      printf("Digite o primeiro numero: \n");
      scanf("%d", &n1);
      printf("Digite o segundo numero: \n");
      scanf("%d", &n2);
    }
    switch (opcao) {
    case 1:
      printf("%d / %d = %d\n", n1, n2, (n1 / n2));
      break;
    case 2:
      printf("%d resto %d = %d\n", n1, n2, (n1 % n2));
      break;
    case 3:
      printf("%d + %d = %d\n", n1, n2, (n1 + n2));
      break;
    case 4:
      printf("%d * %d = %d\n", n1, n2, (n1 * n2));
      break;
    default:
      if (opcao == 0)
        printf("Voce escolheu sair!");
      else
        printf("Selecione uma opcao valida!\n");
    }
  } while (opcao != 0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x6,-0x10(%rbp)
lea    0xec5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf2a(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x1,-0x10(%rbp)
je     1176 <main+0x56>
cmpl   $0x2,-0x10(%rbp)
jne    11de <main+0xbe>
lea    0xf09(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xef8(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xf07(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeda(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x0,-0xc(%rbp)
jne    11ca <main+0xaa>
lea    0xefa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11cf <main+0xaf>
cmpl   $0x0,-0xc(%rbp)
je     1194 <main+0x74>
jmp    1233 <main+0x113>
cmpl   $0x3,-0x10(%rbp)
je     11f2 <main+0xd2>
cmpl   $0x4,-0x10(%rbp)
jne    122e <main+0x10e>
lea    0xe8d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe7c(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xe8b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe5e(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
jmp    1233 <main+0x113>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x3,%eax
ja     12eb <main+0x1cb>
mov    -0x18(%rbp),%rax
lea    0xdad(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
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    0xe6c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    131b <main+0x1fb>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%eax
cltd
idivl  -0xc(%rbp)
mov    %edx,%ecx
mov    -0x20(%rbp),%edx
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    131b <main+0x1fb>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x8(%rbp),%ecx
add    -0xc(%rbp),%ecx
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    131b <main+0x1fb>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x8(%rbp),%ecx
imul   -0xc(%rbp),%ecx
lea    0xe33(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    131b <main+0x1fb>
cmpl   $0x0,-0x10(%rbp)
jne    1308 <main+0x1e8>
lea    0xe24(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1316 <main+0x1f6>
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    131b <main+0x1fb>
jmp    1320 <main+0x200>
cmpl   $0x0,-0x10(%rbp)
jne    1144 <main+0x24>
mov    -0x4(%rbp),%eax
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
movl   $0x0,0x10(%rsp)
movl   $0x0,0xc(%rsp)
movl   $0x6,0x14(%rsp)
lea    0xeb7(%rip),%rbx
lea    0x14(%rsp),%r15
lea    0xfa7(%rip),%rbp
lea    0xc(%rsp),%r12
lea    0xfb5(%rip),%r13
lea    0xe84(%rip),%r14
jmp    11a4 <main+0x74>
mov    0x10(%rsp),%esi
mov    0xc(%rsp),%edx
mov    %edx,%ecx
imul   %esi,%ecx
lea    0xeb3(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmpl   $0x0,0x14(%rsp)
je     12cf <main+0x19f>
lea    0xebc(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <scanf@plt>
mov    0x14(%rsp),%eax
lea    -0x1(%rax),%ecx
cmp    $0x1,%ecx
ja     1210 <main+0xe0>
lea    0xf27(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
lea    0x10(%rsp),%rsi
call   1050 <scanf@plt>
mov    %rbp,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1050 <scanf@plt>
cmpl   $0x0,0xc(%rsp)
jne    1244 <main+0x114>
mov    %r13,%rdi
call   1030 <puts@plt>
cmpl   $0x0,0xc(%rsp)
je     11e0 <main+0xb0>
jmp    1244 <main+0x114>
nopl   0x0(%rax,%rax,1)
add    $0xfffffffd,%eax
cmp    $0x1,%eax
ja     1244 <main+0x114>
lea    0xed6(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
lea    0x10(%rsp),%rsi
call   1050 <scanf@plt>
mov    %rbp,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1050 <scanf@plt>
mov    0x14(%rsp),%eax
cmp    $0x4,%rax
ja     126a <main+0x13a>
movslq (%r14,%rax,4),%rax
add    %r14,%rax
jmp    *%rax
lea    0xdf5(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1199 <main+0x69>
lea    0xe68(%rip),%rdi
call   1030 <puts@plt>
jmp    1199 <main+0x69>
mov    0x10(%rsp),%esi
mov    0xc(%rsp),%ecx
mov    %esi,%eax
cltd
idiv   %ecx
lea    0xd88(%rip),%rdi
mov    %ecx,%edx
mov    %eax,%ecx
jmp    1192 <main+0x62>
mov    0x10(%rsp),%esi
mov    0xc(%rsp),%r8d
mov    %esi,%eax
cltd
idiv   %r8d
mov    %edx,%ecx
lea    0xd75(%rip),%rdi
mov    %r8d,%edx
jmp    1192 <main+0x62>
mov    0x10(%rsp),%esi
mov    0xc(%rsp),%edx
lea    (%rdx,%rsi,1),%ecx
lea    0xd6d(%rip),%rdi
jmp    1192 <main+0x62>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [115 x i8] c"\0AEntre com a operacao desejada: \0A(1)...Divisao\0A(2)...Resto da Disisao\0A(3)...Adicao\0A(4)...Multiplicacao\0A(0)...Sair\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [28 x i8] c"Digite o primeiro numero: \0A\00"
@.str.3 = [27 x i8] c"Digite o segundo numero: \0A\00"
@.str.4 = [39 x i8] c"Impossivel realizar divisao por zero!\0A\00"
@.str.5 = [14 x i8] c"%d / %d = %d\0A\00"
@.str.6 = [18 x i8] c"%d resto %d = %d\0A\00"
@.str.7 = [14 x i8] c"%d + %d = %d\0A\00"
@.str.8 = [14 x i8] c"%d * %d = %d\0A\00"
@.str.9 = [20 x i8] c"Voce escolheu sair!\00"
@.str.10 = [29 x i8] c"Selecione uma opcao valida!\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* %2
store i32 0, i32* %3
store i32 6, i32* %4
br label %5
5: ; preds = %79, %0
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([115 x i8], [115 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%8 = load i32, i32* %4
%9 = icmp eq i32 %8, 1
br i1 %9, label %13, label %10
10: ; preds = %5
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, 2
br i1 %12, label %13, label %28
13: ; preds = %10, %5
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
br label %16
16: ; preds = %24, %13
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%18 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%19 = load i32, i32* %3
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0))
br label %23
23: ; preds = %21, %16
br label %24
24: ; preds = %23
%25 = load i32, i32* %3
%26 = icmp eq i32 %25, 0
br i1 %26, label %16, label %27
27: ; preds = %24
br label %40
28: ; preds = %10
%29 = load i32, i32* %4
%30 = icmp eq i32 %29, 3
br i1 %30, label %34, label %31
31: ; preds = %28
%32 = load i32, i32* %4
%33 = icmp eq i32 %32, 4
br i1 %33, label %34, label %39
34: ; preds = %31, %28
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%36 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%38 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
br label %39
39: ; preds = %34, %31
br label %40
40: ; preds = %39, %27
%41 = load i32, i32* %4
switch i32 %41, label %70 [
i32 1, label %42
i32 2, label %49
i32 3, label %56
i32 4, label %63
]
42: ; preds = %40
%43 = load i32, i32* %2
%44 = load i32, i32* %3
%45 = load i32, i32* %2
%46 = load i32, i32* %3
%47 = sdiv i32 %45, %46
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i32 %43, i32 %44, i32 %47)
br label %78
49: ; preds = %40
%50 = load i32, i32* %2
%51 = load i32, i32* %3
%52 = load i32, i32* %2
%53 = load i32, i32* %3
%54 = srem i32 %52, %53
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i32 %50, i32 %51, i32 %54)
br label %78
56: ; preds = %40
%57 = load i32, i32* %2
%58 = load i32, i32* %3
%59 = load i32, i32* %2
%60 = load i32, i32* %3
%61 = add nsw i32 %59, %60
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i32 %57, i32 %58, i32 %61)
br label %78
63: ; preds = %40
%64 = load i32, i32* %2
%65 = load i32, i32* %3
%66 = load i32, i32* %2
%67 = load i32, i32* %3
%68 = mul nsw i32 %66, %67
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), i32 %64, i32 %65, i32 %68)
br label %78
70: ; preds = %40
%71 = load i32, i32* %4
%72 = icmp eq i32 %71, 0
br i1 %72, label %73, label %75
73: ; preds = %70
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.9, i64 0, i64 0))
br label %77
75: ; preds = %70
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.10, i64 0, i64 0))
br label %77
77: ; preds = %75, %73
br label %78
78: ; preds = %77, %63, %56, %49, %42
br label %79
79: ; preds = %78
%80 = load i32, i32* %4
%81 = icmp ne i32 %80, 0
br i1 %81, label %5, label %82
82: ; preds = %79
%83 = load i32, i32* %1
ret i32 %83
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.5 = [14 x i8] c"%d / %d = %d\0A\00"
@.str.6 = [18 x i8] c"%d resto %d = %d\0A\00"
@.str.7 = [14 x i8] c"%d + %d = %d\0A\00"
@.str.8 = [14 x i8] c"%d * %d = %d\0A\00"
@.str.9 = [20 x i8] c"Voce escolheu sair!\00"
@str = [114 x i8] c"\0AEntre com a operacao desejada: \0A(1)...Divisao\0A(2)...Resto da Disisao\0A(3)...Adicao\0A(4)...Multiplicacao\0A(0)...Sair\00"
@str.11 = [28 x i8] c"Selecione uma opcao valida!\00"
@str.14 = [27 x i8] c"Digite o primeiro numero: \00"
@str.15 = [26 x i8] c"Digite o segundo numero: \00"
@str.16 = [38 x i8] c"Impossivel realizar divisao por zero!\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%5 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%6 = bitcast i32* %3 to i8*
store i32 6, i32* %3
br label %7
7: ; preds = %59, %0
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([114 x i8], [114 x i8]* @str, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%10 = load i32, i32* %3
%11 = add i32 %10, -1
%12 = icmp ult i32 %11, 2
br i1 %12, label %13, label %25
13: ; preds = %7
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.14, i64 0, i64 0))
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
br label %16
16: ; preds = %21, %13
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.15, i64 0, i64 0))
%18 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%19 = load i32, i32* %2
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %33
21: ; preds = %16
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str.16, i64 0, i64 0))
%23 = load i32, i32* %2
%24 = icmp eq i32 %23, 0
br i1 %24, label %16, label %33
25: ; preds = %7
%26 = add i32 %10, -3
%27 = icmp ult i32 %26, 2
br i1 %27, label %28, label %33
28: ; preds = %25
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.14, i64 0, i64 0))
%30 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.15, i64 0, i64 0))
%32 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
br label %33
33: ; preds = %16, %21, %28, %25
%34 = load i32, i32* %3
switch i32 %34, label %57 [
i32 1, label %35
i32 2, label %40
i32 3, label %45
i32 4, label %50
i32 0, label %55
]
35: ; preds = %33
%36 = load i32, i32* %1
%37 = load i32, i32* %2
%38 = sdiv i32 %36, %37
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i32 %36, i32 %37, i32 %38)
br label %59
40: ; preds = %33
%41 = load i32, i32* %1
%42 = load i32, i32* %2
%43 = srem i32 %41, %42
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i32 %41, i32 %42, i32 %43)
br label %59
45: ; preds = %33
%46 = load i32, i32* %1
%47 = load i32, i32* %2
%48 = add nsw i32 %47, %46
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i32 %46, i32 %47, i32 %48)
br label %59
50: ; preds = %33
%51 = load i32, i32* %1
%52 = load i32, i32* %2
%53 = mul nsw i32 %52, %51
%54 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), i32 %51, i32 %52, i32 %53)
br label %59
55: ; preds = %33
%56 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.9, i64 0, i64 0))
br label %59
57: ; preds = %33
%58 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.11, i64 0, i64 0))
br label %59
59: ; preds = %35, %40, %45, %50, %57, %55
%60 = load i32, i32* %3
%61 = icmp eq i32 %60, 0
br i1 %61, label %62, label %7
62: ; preds = %59
ret i32 0
}