#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 get_choice();
float get_flt();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int main(void) {
  int mode;
  float num1, num2;
  mode = get_choice();
  while (mode != 0) {
    printf("Enter first number: ");
    num1 = get_flt();
    printf("Enter second number: ");
    num2 = get_flt();
    switch (mode) {
    case 1:
      printf("%g + %g = %g\n", num1, num2, num1 + num2);
      break;
    case 2:
      printf("%g - %g = %g\n", num1, num2, num1 - num2);
      break;
    case 3:
      printf("%g * %g = %g\n", num1, num2, num1 * num2);
      break;
    case 4:
      while (num2 == 0) {
        printf("Enter a number other than 0: ");
        num2 = get_flt();
      }
      printf("%g / %g = %g\n", num1, num2, num1 / num2);
      break;
    default:
      printf("Error\n");
    }
    mode = get_choice();
  }
  puts("Bye.");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1060 <get_choice@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     12ea <main+0x1aa>
lea    0xea6(%rip),%rdi
xor    %eax,%eax
mov    %al,-0x19(%rbp)
call   1040 <printf@plt>
mov    -0x19(%rbp),%al
call   1050 <get_flt@plt>
mov    -0x19(%rbp),%al
movss  %xmm0,-0xc(%rbp)
lea    0xe9a(%rip),%rdi
call   1040 <printf@plt>
mov    -0x19(%rbp),%al
call   1050 <get_flt@plt>
movss  %xmm0,-0x10(%rbp)
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x3,%eax
ja     12cd <main+0x18d>
mov    -0x18(%rbp),%rax
lea    0xe43(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movss  -0x10(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
movss  -0xc(%rbp),%xmm2
addss  -0x10(%rbp),%xmm2
cvtss2sd %xmm2,%xmm2
lea    0xe4e(%rip),%rdi
mov    $0x3,%al
call   1040 <printf@plt>
jmp    12db <main+0x19b>
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movss  -0x10(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
movss  -0xc(%rbp),%xmm2
subss  -0x10(%rbp),%xmm2
cvtss2sd %xmm2,%xmm2
lea    0xe29(%rip),%rdi
mov    $0x3,%al
call   1040 <printf@plt>
jmp    12db <main+0x19b>
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movss  -0x10(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
movss  -0xc(%rbp),%xmm2
mulss  -0x10(%rbp),%xmm2
cvtss2sd %xmm2,%xmm2
lea    0xe04(%rip),%rdi
mov    $0x3,%al
call   1040 <printf@plt>
jmp    12db <main+0x19b>
jmp    1264 <main+0x124>
movss  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    129a <main+0x15a>
jp     129a <main+0x15a>
lea    0xde3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <get_flt@plt>
movss  %xmm0,-0x10(%rbp)
jmp    1264 <main+0x124>
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movss  -0x10(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
movss  -0xc(%rbp),%xmm2
divss  -0x10(%rbp),%xmm2
cvtss2sd %xmm2,%xmm2
lea    0xdc2(%rip),%rdi
mov    $0x3,%al
call   1040 <printf@plt>
jmp    12db <main+0x19b>
lea    0xdbd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <get_choice@plt>
mov    %eax,-0x8(%rbp)
jmp    1159 <main+0x19>
lea    0xda7(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   1060 <get_choice@plt>
test   %eax,%eax
je     12c4 <main+0x184>
mov    %eax,%r13d
lea    0xeac(%rip),%r14
lea    0xeba(%rip),%rbx
lea    0xe8e(%rip),%rbp
lea    0xeec(%rip),%r15
lea    0xf03(%rip),%r12
jmp    11cf <main+0x8f>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movss  0x4(%rsp),%xmm2
xorps  %xmm3,%xmm3
cvtss2sd %xmm2,%xmm3
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
addss  %xmm0,%xmm2
cvtss2sd %xmm2,%xmm2
lea    0xe88(%rip),%rdi
movaps %xmm3,%xmm0
mov    $0x3,%al
call   1040 <printf@plt>
xor    %eax,%eax
call   1060 <get_choice@plt>
mov    %eax,%r13d
test   %eax,%eax
je     12c4 <main+0x184>
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <get_flt@plt>
movss  %xmm0,0x4(%rsp)
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <get_flt@plt>
add    $0xffffffff,%r13d
cmp    $0x3,%r13d
ja     1250 <main+0x110>
movslq 0x0(%rbp,%r13,4),%rax
add    %rbp,%rax
jmp    *%rax
movss  0x4(%rsp),%xmm2
xorps  %xmm3,%xmm3
cvtss2sd %xmm2,%xmm3
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
subss  %xmm0,%xmm2
cvtss2sd %xmm2,%xmm2
lea    0xe1b(%rip),%rdi
jmp    11b3 <main+0x73>
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    12a0 <main+0x160>
jp     12a0 <main+0x160>
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <get_flt@plt>
jmp    1230 <main+0xf0>
nopl   (%rax)
lea    0xe3f(%rip),%rdi
call   1030 <puts@plt>
jmp    11bd <main+0x7d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movss  0x4(%rsp),%xmm2
xorps  %xmm3,%xmm3
cvtss2sd %xmm2,%xmm3
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
mulss  %xmm0,%xmm2
cvtss2sd %xmm2,%xmm2
lea    0xdc4(%rip),%rdi
jmp    11b3 <main+0x73>
nopl   0x0(%rax,%rax,1)
movss  0x4(%rsp),%xmm2
xorps  %xmm3,%xmm3
cvtss2sd %xmm2,%xmm3
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
divss  %xmm0,%xmm2
cvtss2sd %xmm2,%xmm2
mov    %r12,%rdi
jmp    11b3 <main+0x73>
lea    0xdc6(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [21 x i8] c"Enter first number: \00"
@.str.1 = [22 x i8] c"Enter second number: \00"
@.str.2 = [14 x i8] c"%g + %g = %g\0A\00"
@.str.3 = [14 x i8] c"%g - %g = %g\0A\00"
@.str.4 = [14 x i8] c"%g * %g = %g\0A\00"
@.str.5 = [30 x i8] c"Enter a number other than 0: \00"
@.str.6 = [14 x i8] c"%g / %g = %g\0A\00"
@.str.7 = [7 x i8] c"Error\0A\00"
@.str.8 = [5 x i8] c"Bye.\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca float
%4 = alloca float
store i32 0, i32* %1
%5 = call i32 (...) @get_choice()
store i32 %5, i32* %2
br label %6
6: ; preds = %64, %0
%7 = load i32, i32* %2
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %66
9: ; preds = %6
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%11 = call float (...) @get_flt()
store float %11, float* %3
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%13 = call float (...) @get_flt()
store float %13, float* %4
%14 = load i32, i32* %2
switch i32 %14, label %62 [
i32 1, label %15
i32 2, label %25
i32 3, label %35
i32 4, label %45
]
15: ; preds = %9
%16 = load float, float* %3
%17 = fpext float %16 to double
%18 = load float, float* %4
%19 = fpext float %18 to double
%20 = load float, float* %3
%21 = load float, float* %4
%22 = fadd float %20, %21
%23 = fpext float %22 to double
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), double %17, double %19, double %23)
br label %64
25: ; preds = %9
%26 = load float, float* %3
%27 = fpext float %26 to double
%28 = load float, float* %4
%29 = fpext float %28 to double
%30 = load float, float* %3
%31 = load float, float* %4
%32 = fsub float %30, %31
%33 = fpext float %32 to double
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), double %27, double %29, double %33)
br label %64
35: ; preds = %9
%36 = load float, float* %3
%37 = fpext float %36 to double
%38 = load float, float* %4
%39 = fpext float %38 to double
%40 = load float, float* %3
%41 = load float, float* %4
%42 = fmul float %40, %41
%43 = fpext float %42 to double
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), double %37, double %39, double %43)
br label %64
45: ; preds = %9
br label %46
46: ; preds = %49, %45
%47 = load float, float* %4
%48 = fcmp oeq float %47, 0.000000e+00
br i1 %48, label %49, label %52
49: ; preds = %46
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0))
%51 = call float (...) @get_flt()
store float %51, float* %4
br label %46
52: ; preds = %46
%53 = load float, float* %3
%54 = fpext float %53 to double
%55 = load float, float* %4
%56 = fpext float %55 to double
%57 = load float, float* %3
%58 = load float, float* %4
%59 = fdiv float %57, %58
%60 = fpext float %59 to double
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), double %54, double %56, double %60)
br label %64
62: ; preds = %9
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
br label %64
64: ; preds = %62, %52, %35, %25, %15
%65 = call i32 (...) @get_choice()
store i32 %65, i32* %2
br label %6
66: ; preds = %6
%67 = call i32 @puts(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [21 x i8] c"Enter first number: \00"
@.str.1 = [22 x i8] c"Enter second number: \00"
@.str.2 = [14 x i8] c"%g + %g = %g\0A\00"
@.str.3 = [14 x i8] c"%g - %g = %g\0A\00"
@.str.4 = [14 x i8] c"%g * %g = %g\0A\00"
@.str.5 = [30 x i8] c"Enter a number other than 0: \00"
@.str.6 = [14 x i8] c"%g / %g = %g\0A\00"
@.str.8 = [5 x i8] c"Bye.\00"
@str = [6 x i8] c"Error\00"
define i32 @main() {
%1 = tail call i32 (...) @get_choice()
%2 = icmp eq i32 %1, 0
br i1 %2, label %45, label %3
3: ; preds = %0, %42
%4 = phi i32 [ %43, %42 ], [ %1, %0 ]
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%6 = tail call float (...) @get_flt()
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call float (...) @get_flt()
switch i32 %4, label %40 [
i32 1, label %11
i32 2, label %17
i32 3, label %23
i32 4, label %9
]
9: ; preds = %3
%10 = fcmp oeq float %8, 0.000000e+00
br i1 %10, label %29, label %33
11: ; preds = %3
%12 = fpext float %6 to double
%13 = fpext float %8 to double
%14 = fadd float %6, %8
%15 = fpext float %14 to double
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), double %12, double %13, double %15)
br label %42
17: ; preds = %3
%18 = fpext float %6 to double
%19 = fpext float %8 to double
%20 = fsub float %6, %8
%21 = fpext float %20 to double
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), double %18, double %19, double %21)
br label %42
23: ; preds = %3
%24 = fpext float %6 to double
%25 = fpext float %8 to double
%26 = fmul float %6, %8
%27 = fpext float %26 to double
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), double %24, double %25, double %27)
br label %42
29: ; preds = %9, %29
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0))
%31 = tail call float (...) @get_flt()
%32 = fcmp oeq float %31, 0.000000e+00
br i1 %32, label %29, label %33
33: ; preds = %29, %9
%34 = phi float [ %8, %9 ], [ %31, %29 ]
%35 = fpext float %6 to double
%36 = fpext float %34 to double
%37 = fdiv float %6, %34
%38 = fpext float %37 to double
%39 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), double %35, double %36, double %38)
br label %42
40: ; preds = %3
%41 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
br label %42
42: ; preds = %40, %33, %23, %17, %11
%43 = tail call i32 (...) @get_choice()
%44 = icmp eq i32 %43, 0
br i1 %44, label %45, label %3
45: ; preds = %42, %0
%46 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
ret i32 0
}