#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 floor(double);
int /*<<< orphan*/ printf(char *, double);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ scanf(char *, double *, char *, double *);
void calculator() {
  double number1 = 0.0;
  double number2 = 0.0;
  char operation = 0;
  puts("\nEnter the calculation:\n");
  scanf("%lf %c %lf", &number1, &operation, &number2);
  if (operation == '+') {
    printf("Answer: %lf", number1 + number2);
  }
  if (operation == '-') {
    printf("Answer: %lf", number1 - number2);
  }
  if (operation == '*') {
    printf("Answer: %lf", number1 * number2);
  }
  if (operation == '/') {
    printf("Answer: %lf", number1 / number2);
  }
  if (operation == '%') {
    printf("Answer: %lf", number1 - floor(number1 / number2) * number2);
  }
}


x86 assembly (clang, -O0):
<calculator>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
movb   $0x0,-0x11(%rbp)
lea    0xe9d(%rip),%rdi
call   1030 <puts@plt>
lea    0xeaa(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0x11(%rbp),%rdx
lea    -0x10(%rbp),%rcx
call   1050 <scanf@plt>
movsbl -0x11(%rbp),%eax
cmp    $0x2b,%eax
jne    11a3 <calculator+0x63>
movsd  -0x8(%rbp),%xmm0
addsd  -0x10(%rbp),%xmm0
lea    0xe86(%rip),%rdi
call   1040 <printf@plt>
movsbl -0x11(%rbp),%eax
cmp    $0x2d,%eax
jne    11c6 <calculator+0x86>
movsd  -0x8(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
lea    0xe63(%rip),%rdi
call   1040 <printf@plt>
movsbl -0x11(%rbp),%eax
cmp    $0x2a,%eax
jne    11e9 <calculator+0xa9>
movsd  -0x8(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm0
lea    0xe40(%rip),%rdi
call   1040 <printf@plt>
movsbl -0x11(%rbp),%eax
cmp    $0x2f,%eax
jne    120c <calculator+0xcc>
movsd  -0x8(%rbp),%xmm0
divsd  -0x10(%rbp),%xmm0
lea    0xe1d(%rip),%rdi
call   1040 <printf@plt>
movsbl -0x11(%rbp),%eax
cmp    $0x25,%eax
jne    1267 <calculator+0x127>
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x8(%rbp),%xmm0
divsd  -0x10(%rbp),%xmm0
call   1060 <floor@plt>
movsd  -0x20(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
lea    0xdc2(%rip),%rdi
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calculator>:
sub    $0x28,%rsp
movq   $0x0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
movb   $0x0,0x7(%rsp)
lea    0xe9e(%rip),%rdi
call   1030 <puts@plt>
lea    0xeab(%rip),%rdi
lea    0x10(%rsp),%rsi
lea    0x7(%rsp),%rdx
lea    0x8(%rsp),%rcx
call   1050 <scanf@plt>
mov    0x7(%rsp),%al
cmp    $0x2b,%al
je     11a3 <calculator+0x63>
cmp    $0x2d,%al
je     11c3 <calculator+0x83>
cmp    $0x2a,%al
je     11e3 <calculator+0xa3>
cmp    $0x2f,%al
je     1203 <calculator+0xc3>
cmp    $0x25,%al
je     1227 <calculator+0xe7>
add    $0x28,%rsp
ret
movsd  0x10(%rsp),%xmm0
addsd  0x8(%rsp),%xmm0
lea    0xe6e(%rip),%rdi
call   1040 <printf@plt>
mov    0x7(%rsp),%al
cmp    $0x2d,%al
jne    118e <calculator+0x4e>
movsd  0x10(%rsp),%xmm0
subsd  0x8(%rsp),%xmm0
lea    0xe4e(%rip),%rdi
call   1040 <printf@plt>
mov    0x7(%rsp),%al
cmp    $0x2a,%al
jne    1192 <calculator+0x52>
movsd  0x10(%rsp),%xmm0
mulsd  0x8(%rsp),%xmm0
lea    0xe2e(%rip),%rdi
call   1040 <printf@plt>
mov    0x7(%rsp),%al
cmp    $0x2f,%al
jne    1196 <calculator+0x56>
movsd  0x10(%rsp),%xmm0
divsd  0x8(%rsp),%xmm0
lea    0xe0e(%rip),%rdi
call   1040 <printf@plt>
mov    0x7(%rsp),%al
cmp    $0x25,%al
jne    119e <calculator+0x5e>
movsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x20(%rsp)
movsd  0x8(%rsp),%xmm1
movsd  %xmm1,0x18(%rsp)
divsd  %xmm1,%xmm0
call   1060 <floor@plt>
mulsd  0x18(%rsp),%xmm0
movsd  0x20(%rsp),%xmm1
subsd  %xmm0,%xmm1
lea    0xdc5(%rip),%rdi
movapd %xmm1,%xmm0
call   1040 <printf@plt>
add    $0x28,%rsp
ret

LLVM IR (-O0):
@.str = [25 x i8] c"\0AEnter the calculation:\0A\00"
@.str.1 = [11 x i8] c"%lf %c %lf\00"
@.str.2 = [12 x i8] c"Answer: %lf\00"
define void @calculator() {
%1 = alloca double
%2 = alloca double
%3 = alloca i8
store double 0.000000e+00, double* %1
store double 0.000000e+00, double* %2
store i8 0, i8* %3
%4 = call i32 @puts(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), double* %1, i8* %3, double* %2)
%6 = load i8, i8* %3
%7 = sext i8 %6 to i32
%8 = icmp eq i32 %7, 43
br i1 %8, label %9, label %14
9: ; preds = %0
%10 = load double, double* %1
%11 = load double, double* %2
%12 = fadd double %10, %11
%13 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), double %12)
br label %14
14: ; preds = %9, %0
%15 = load i8, i8* %3
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 45
br i1 %17, label %18, label %23
18: ; preds = %14
%19 = load double, double* %1
%20 = load double, double* %2
%21 = fsub double %19, %20
%22 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), double %21)
br label %23
23: ; preds = %18, %14
%24 = load i8, i8* %3
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 42
br i1 %26, label %27, label %32
27: ; preds = %23
%28 = load double, double* %1
%29 = load double, double* %2
%30 = fmul double %28, %29
%31 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), double %30)
br label %32
32: ; preds = %27, %23
%33 = load i8, i8* %3
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 47
br i1 %35, label %36, label %41
36: ; preds = %32
%37 = load double, double* %1
%38 = load double, double* %2
%39 = fdiv double %37, %38
%40 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), double %39)
br label %41
41: ; preds = %36, %32
%42 = load i8, i8* %3
%43 = sext i8 %42 to i32
%44 = icmp eq i32 %43, 37
br i1 %44, label %45, label %55
45: ; preds = %41
%46 = load double, double* %1
%47 = load double, double* %1
%48 = load double, double* %2
%49 = fdiv double %47, %48
%50 = call double @llvm.floor.f64(double %49)
%51 = load double, double* %2
%52 = fneg double %50
%53 = call double @llvm.fmuladd.f64(double %52, double %51, double %46)
%54 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), double %53)
br label %55
55: ; preds = %45, %41
ret void
}

LLVM IR (-O2):
@.str = [25 x i8] c"\0AEnter the calculation:\0A\00"
@.str.1 = [11 x i8] c"%lf %c %lf\00"
@.str.2 = [12 x i8] c"Answer: %lf\00"
define void @calculator() {
%1 = alloca double
%2 = alloca double
%3 = alloca i8
%4 = bitcast double* %1 to i8*
store double 0.000000e+00, double* %1
%5 = bitcast double* %2 to i8*
store double 0.000000e+00, double* %2
store i8 0, i8* %3
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), double* %1, i8* %3, double* %2)
%8 = load i8, i8* %3
%9 = icmp eq i8 %8, 43
br i1 %9, label %10, label %16
10: ; preds = %0
%11 = load double, double* %1
%12 = load double, double* %2
%13 = fadd double %11, %12
%14 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), double %13)
%15 = load i8, i8* %3
br label %16
16: ; preds = %10, %0
%17 = phi i8 [ %15, %10 ], [ %8, %0 ]
%18 = icmp eq i8 %17, 45
br i1 %18, label %19, label %25
19: ; preds = %16
%20 = load double, double* %1
%21 = load double, double* %2
%22 = fsub double %20, %21
%23 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), double %22)
%24 = load i8, i8* %3
br label %25
25: ; preds = %19, %16
%26 = phi i8 [ %24, %19 ], [ %17, %16 ]
%27 = icmp eq i8 %26, 42
br i1 %27, label %28, label %34
28: ; preds = %25
%29 = load double, double* %1
%30 = load double, double* %2
%31 = fmul double %29, %30
%32 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), double %31)
%33 = load i8, i8* %3
br label %34
34: ; preds = %28, %25
%35 = phi i8 [ %33, %28 ], [ %26, %25 ]
%36 = icmp eq i8 %35, 47
br i1 %36, label %37, label %43
37: ; preds = %34
%38 = load double, double* %1
%39 = load double, double* %2
%40 = fdiv double %38, %39
%41 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), double %40)
%42 = load i8, i8* %3
br label %43
43: ; preds = %37, %34
%44 = phi i8 [ %42, %37 ], [ %35, %34 ]
%45 = icmp eq i8 %44, 37
br i1 %45, label %46, label %54
46: ; preds = %43
%47 = load double, double* %1
%48 = load double, double* %2
%49 = fdiv double %47, %48
%50 = call double @llvm.floor.f64(double %49)
%51 = fneg double %50
%52 = call double @llvm.fmuladd.f64(double %51, double %48, double %47)
%53 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), double %52)
br label %54
54: ; preds = %46, %43
ret void
}