#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 */
double dividir(double, double);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ getchar();
int menu();
double multiplicar(double, double);
int /*<<< orphan*/ printf(char *, ...);
double restar(double, double);
int /*<<< orphan*/ scanf(char *, double *);
int /*<<< orphan*/ stdin;
double sumar(double, double);
main() {
  double dato1 = 0, dato2 = 0, resultado = 0;
  int operacion = 0;
  while (1) {
    operacion = menu();
    if (operacion != 5) {
      printf("Dato 1: ");
      scanf("%lf", &dato1);
      printf("Dato 2: ");
      scanf("%lf", &dato2);
      fflush(stdin);
      switch (operacion) {
      case 1:
        resultado = sumar(dato1, dato2);
        break;
      case 2:
        resultado = restar(dato1, dato2);
        break;
      case 3:
        resultado = multiplicar(dato1, dato2);
        break;
      case 4:
        resultado = dividir(dato1, dato2);
        break;
      }
      printf("Resultado = %g\n", resultado);
      printf("Pulse <Entrar> para continuar ");
      getchar();
    } else
      break;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    $0x0,%al
call   1030 <menu@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x5,-0x24(%rbp)
je     12d6 <main+0x146>
lea    0xe37(%rip),%rdi
xor    %eax,%eax
mov    %al,-0x39(%rbp)
call   1040 <printf@plt>
lea    0xe2f(%rip),%rdi
mov    %rdi,-0x38(%rbp)
lea    -0x10(%rbp),%rsi
call   10a0 <scanf@plt>
mov    -0x39(%rbp),%al
lea    0xe1c(%rip),%rdi
call   1040 <printf@plt>
mov    -0x38(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   10a0 <scanf@plt>
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
mov    -0x24(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x30(%rbp)
sub    $0x3,%eax
ja     12a9 <main+0x119>
mov    -0x30(%rbp),%rax
lea    0xdbf(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
call   1050 <sumar@plt>
movsd  %xmm0,-0x20(%rbp)
jmp    12a9 <main+0x119>
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
call   1090 <restar@plt>
movsd  %xmm0,-0x20(%rbp)
jmp    12a9 <main+0x119>
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
call   1080 <multiplicar@plt>
movsd  %xmm0,-0x20(%rbp)
jmp    12a9 <main+0x119>
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
call   10b0 <dividir@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
lea    0xd71(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
lea    0xd73(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <getchar@plt>
jmp    12db <main+0x14b>
jmp    12e0 <main+0x150>
jmp    11be <main+0x2e>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
movq   $0x0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
xor    %eax,%eax
call   1030 <menu@plt>
cmp    $0x5,%eax
jne    11cd <main+0x3d>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%r15d
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rsp)
lea    0xe3a(%rip),%rbx
lea    0x8(%rsp),%r13
lea    0xe3b(%rip),%rbp
lea    0xe44(%rip),%r14
lea    0xe07(%rip),%r12
jmp    1249 <main+0xb9>
nopl   0x0(%rax,%rax,1)
movsd  0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
call   10b0 <dividir@plt>
movsd  %xmm0,(%rsp)
mov    %rbp,%rdi
movsd  (%rsp),%xmm0
mov    $0x1,%al
call   1040 <printf@plt>
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
xor    %eax,%eax
call   1030 <menu@plt>
mov    %eax,%r15d
cmp    $0x5,%eax
je     11bc <main+0x2c>
lea    0xdc0(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
lea    0x10(%rsp),%rsi
call   10a0 <scanf@plt>
lea    0xdb2(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   10a0 <scanf@plt>
mov    0x2d64(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
add    $0xffffffff,%r15d
cmp    $0x3,%r15d
ja     1216 <main+0x86>
movslq (%r12,%r15,4),%rax
add    %r12,%rax
jmp    *%rax
movsd  0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
call   1050 <sumar@plt>
jmp    1211 <main+0x81>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsd  0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
call   1090 <restar@plt>
jmp    1211 <main+0x81>
cs nopw 0x0(%rax,%rax,1)
movsd  0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
call   1080 <multiplicar@plt>
jmp    1211 <main+0x81>

LLVM IR (-O0):
@.str = [9 x i8] c"Dato 1: \00"
@.str.1 = [4 x i8] c"%lf\00"
@.str.2 = [9 x i8] c"Dato 2: \00"
@stdin = global i32 0
@.str.3 = [16 x i8] c"Resultado = %g\0A\00"
@.str.4 = [31 x i8] c"Pulse <Entrar> para continuar \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca i32
store i32 0, i32* %1
store double 0.000000e+00, double* %2
store double 0.000000e+00, double* %3
store double 0.000000e+00, double* %4
store i32 0, i32* %5
br label %6
6: ; preds = %0, %40
%7 = call i32 (...) @menu()
store i32 %7, i32* %5
%8 = load i32, i32* %5
%9 = icmp ne i32 %8, 5
br i1 %9, label %10, label %39
10: ; preds = %6
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %2)
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%14 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %3)
%15 = load i32, i32* @stdin
%16 = call i32 @fflush(i32 %15)
%17 = load i32, i32* %5
switch i32 %17, label %34 [
i32 1, label %18
i32 2, label %22
i32 3, label %26
i32 4, label %30
]
18: ; preds = %10
%19 = load double, double* %2
%20 = load double, double* %3
%21 = call double @sumar(double %19, double %20)
store double %21, double* %4
br label %34
22: ; preds = %10
%23 = load double, double* %2
%24 = load double, double* %3
%25 = call double @restar(double %23, double %24)
store double %25, double* %4
br label %34
26: ; preds = %10
%27 = load double, double* %2
%28 = load double, double* %3
%29 = call double @multiplicar(double %27, double %28)
store double %29, double* %4
br label %34
30: ; preds = %10
%31 = load double, double* %2
%32 = load double, double* %3
%33 = call double @dividir(double %31, double %32)
store double %33, double* %4
br label %34
34: ; preds = %10, %30, %26, %22, %18
%35 = load double, double* %4
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), double %35)
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
%38 = call i32 (...) @getchar()
br label %40
39: ; preds = %6
br label %41
40: ; preds = %34
br label %6
41: ; preds = %39
%42 = load i32, i32* %1
ret i32 %42
}

LLVM IR (-O2):
@.str = [9 x i8] c"Dato 1: \00"
@.str.1 = [4 x i8] c"%lf\00"
@.str.2 = [9 x i8] c"Dato 2: \00"
@stdin = global i32 0
@.str.3 = [16 x i8] c"Resultado = %g\0A\00"
@.str.4 = [31 x i8] c"Pulse <Entrar> para continuar \00"
define i32 @main() {
%1 = alloca double
%2 = alloca double
%3 = bitcast double* %1 to i8*
store double 0.000000e+00, double* %1
%4 = bitcast double* %2 to i8*
store double 0.000000e+00, double* %2
%5 = call i32 (...) @menu()
%6 = icmp eq i32 %5, 5
br i1 %6, label %39, label %7
7: ; preds = %0, %32
%8 = phi i32 [ %37, %32 ], [ %5, %0 ]
%9 = phi double [ %33, %32 ], [ 0.000000e+00, %0 ]
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %1)
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%13 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %2)
%14 = load i32, i32* @stdin
%15 = call i32 @fflush(i32 %14)
switch i32 %8, label %32 [
i32 1, label %16
i32 2, label %20
i32 3, label %24
i32 4, label %28
]
16: ; preds = %7
%17 = load double, double* %1
%18 = load double, double* %2
%19 = call double @sumar(double %17, double %18)
br label %32
20: ; preds = %7
%21 = load double, double* %1
%22 = load double, double* %2
%23 = call double @restar(double %21, double %22)
br label %32
24: ; preds = %7
%25 = load double, double* %1
%26 = load double, double* %2
%27 = call double @multiplicar(double %25, double %26)
br label %32
28: ; preds = %7
%29 = load double, double* %1
%30 = load double, double* %2
%31 = call double @dividir(double %29, double %30)
br label %32
32: ; preds = %7, %28, %24, %20, %16
%33 = phi double [ %9, %7 ], [ %31, %28 ], [ %27, %24 ], [ %23, %20 ], [ %19, %16 ]
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), double %33)
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
%36 = call i32 (...) @getchar()
%37 = call i32 (...) @menu()
%38 = icmp eq i32 %37, 5
br i1 %38, label %39, label %7
39: ; preds = %32, %0
ret i32 0
}