#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 *, double *, char *, double *);
void main() {
  double num1, num2;
  char op;
  printf("Enter the calculation:\n");
  scanf("%lf%c%lf", &num1, &op, &num2);
  switch (op) {
  case '+':
    printf("=%lf\n", num1 + num2);
    break;
  case '-':
    printf("=%lf\n", num1 - num2);
    break;
  case '*':
    printf("=%lf\n", num1 * num2);
    break;
  case '/':
    if (num2 == 0) {
      printf("Division by zero error!\n");
    } else {
      printf("=%lf\n", num1 / num2);
    }
    break;
  case '%':
    printf("=%l\n", (long)num1 % (long)num2);
    break;
  default:
    printf("Invalid Operator\n");
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xefd(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xf07(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0x11(%rbp),%rdx
lea    -0x10(%rbp),%rcx
call   1040 <scanf@plt>
movsbl -0x11(%rbp),%eax
add    $0xffffffdb,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0xa,%eax
ja     123e <main+0x11e>
mov    -0x20(%rbp),%rax
lea    0xe91(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movsd  -0x8(%rbp),%xmm0
addsd  -0x10(%rbp),%xmm0
lea    0xec4(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    124c <main+0x12c>
movsd  -0x8(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
lea    0xea7(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    124c <main+0x12c>
movsd  -0x8(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm0
lea    0xe8a(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    124c <main+0x12c>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11fa <main+0xda>
jp     11fa <main+0xda>
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1212 <main+0xf2>
movsd  -0x8(%rbp),%xmm0
divsd  -0x10(%rbp),%xmm0
lea    0xe42(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    124c <main+0x12c>
cvttsd2si -0x8(%rbp),%rax
cvttsd2si -0x10(%rbp),%rcx
cqto
idiv   %rcx
mov    %rdx,%rsi
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    124c <main+0x12c>
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
lea    0xf05(%rip),%rdi
call   1030 <puts@plt>
lea    0xee5(%rip),%rdi
lea    0x10(%rsp),%rsi
lea    0x7(%rsp),%rdx
lea    0x8(%rsp),%rcx
call   1050 <scanf@plt>
movsbl 0x7(%rsp),%eax
add    $0xffffffdb,%eax
cmp    $0xa,%eax
ja     1199 <main+0x69>
lea    0xe91(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
cvttsd2si 0x10(%rsp),%rax
cvttsd2si 0x8(%rsp),%rcx
mov    %rax,%rdx
or     %rcx,%rdx
shr    $0x20,%rdx
je     11ef <main+0xbf>
cqto
idiv   %rcx
jmp    11f3 <main+0xc3>
lea    0xecf(%rip),%rdi
jmp    11e5 <main+0xb5>
movsd  0x10(%rsp),%xmm0
mulsd  0x8(%rsp),%xmm0
jmp    1213 <main+0xe3>
movsd  0x10(%rsp),%xmm0
addsd  0x8(%rsp),%xmm0
jmp    1213 <main+0xe3>
movsd  0x10(%rsp),%xmm0
subsd  0x8(%rsp),%xmm0
jmp    1213 <main+0xe3>
movsd  0x8(%rsp),%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jne    1209 <main+0xd9>
jp     1209 <main+0xd9>
lea    0xe72(%rip),%rdi
call   1030 <puts@plt>
add    $0x18,%rsp
ret
xor    %edx,%edx
div    %ecx
lea    0xe41(%rip),%rdi
mov    %rdx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x18,%rsp
ret
movsd  0x10(%rsp),%xmm0
divsd  %xmm1,%xmm0
lea    0xe1b(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"Enter the calculation:\0A\00"
@.str.1 = [9 x i8] c"%lf%c%lf\00"
@.str.2 = [6 x i8] c"=%lf\0A\00"
@.str.3 = [25 x i8] c"Division by zero error!\0A\00"
@.str.4 = [5 x i8] c"=%l\0A\00"
@.str.5 = [18 x i8] c"Invalid Operator\0A\00"
define void @main() {
%1 = alloca double
%2 = alloca double
%3 = alloca i8
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([9 x i8], [9 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
switch i32 %7, label %41 [
i32 43, label %8
i32 45, label %13
i32 42, label %18
i32 47, label %23
i32 37, label %34
]
8: ; preds = %0
%9 = load double, double* %1
%10 = load double, double* %2
%11 = fadd double %9, %10
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), double %11)
br label %43
13: ; preds = %0
%14 = load double, double* %1
%15 = load double, double* %2
%16 = fsub double %14, %15
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), double %16)
br label %43
18: ; preds = %0
%19 = load double, double* %1
%20 = load double, double* %2
%21 = fmul double %19, %20
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), double %21)
br label %43
23: ; preds = %0
%24 = load double, double* %2
%25 = fcmp oeq double %24, 0.000000e+00
br i1 %25, label %26, label %28
26: ; preds = %23
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
br label %33
28: ; preds = %23
%29 = load double, double* %1
%30 = load double, double* %2
%31 = fdiv double %29, %30
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), double %31)
br label %33
33: ; preds = %28, %26
br label %43
34: ; preds = %0
%35 = load double, double* %1
%36 = fptosi double %35 to i64
%37 = load double, double* %2
%38 = fptosi double %37 to i64
%39 = srem i64 %36, %38
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i64 %39)
br label %43
41: ; preds = %0
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
br label %43
43: ; preds = %41, %34, %33, %18, %13, %8
ret void
}

LLVM IR (-O2):
@.str.1 = [9 x i8] c"%lf%c%lf\00"
@.str.2 = [6 x i8] c"=%lf\0A\00"
@.str.4 = [5 x i8] c"=%l\0A\00"
@str = [23 x i8] c"Enter the calculation:\00"
@str.6 = [24 x i8] c"Division by zero error!\00"
@str.7 = [17 x i8] c"Invalid Operator\00"
define void @main() {
%1 = alloca double
%2 = alloca double
%3 = alloca i8
%4 = bitcast double* %1 to i8*
%5 = bitcast double* %2 to i8*
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), double* %1, i8* %3, double* %2)
%8 = load i8, i8* %3
%9 = sext i8 %8 to i32
switch i32 %9, label %41 [
i32 43, label %10
i32 45, label %15
i32 42, label %20
i32 47, label %25
i32 37, label %34
]
10: ; preds = %0
%11 = load double, double* %1
%12 = load double, double* %2
%13 = fadd double %11, %12
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), double %13)
br label %43
15: ; preds = %0
%16 = load double, double* %1
%17 = load double, double* %2
%18 = fsub double %16, %17
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), double %18)
br label %43
20: ; preds = %0
%21 = load double, double* %1
%22 = load double, double* %2
%23 = fmul double %21, %22
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), double %23)
br label %43
25: ; preds = %0
%26 = load double, double* %2
%27 = fcmp oeq double %26, 0.000000e+00
br i1 %27, label %28, label %30
28: ; preds = %25
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.6, i64 0, i64 0))
br label %43
30: ; preds = %25
%31 = load double, double* %1
%32 = fdiv double %31, %26
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), double %32)
br label %43
34: ; preds = %0
%35 = load double, double* %1
%36 = fptosi double %35 to i64
%37 = load double, double* %2
%38 = fptosi double %37 to i64
%39 = srem i64 %36, %38
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i64 %39)
br label %43
41: ; preds = %0
%42 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.7, i64 0, i64 0))
br label %43
43: ; preds = %28, %30, %41, %34, %20, %15, %10
ret void
}