#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 *);
int main(void) {
  double number1 = 0.0;
  double number2 = 0.0;
  char operation = 0;
  printf("\nEnter the calculation\n");
  scanf("%lf %c %lf", &number1, &operation, &number2);
  switch (operation) {
  case '+':
    printf("= %lf\n", number1 + number2);
    break;
  case '-':
    printf("= %lf\n", number1 - number2);
    break;
  case '*':
    printf("= %lf\n", number1 * number2);
    break;
  case '/':
    if (number2 == 0)
      printf("\n\n\aDivision by zero error!\n");
    else
      printf("= %lf\n", number1 / number2);
    break;
  case '%':
    if (number2 == 0)
      printf("\n\n\aDivision by zero error!\n");
    else
      printf("= %ld\n", (long)number1 % (long)number2);
    break;
  default:
    printf("\n\n\aIllegal operation!\n");
    break;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movb   $0x0,-0x19(%rbp)
lea    0xee2(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xeec(%rip),%rdi
lea    -0x10(%rbp),%rsi
lea    -0x19(%rbp),%rdx
lea    -0x18(%rbp),%rcx
call   1040 <scanf@plt>
movsbl -0x19(%rbp),%eax
add    $0xffffffdb,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0xa,%eax
ja     1284 <main+0x164>
mov    -0x28(%rbp),%rax
lea    0xe76(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movsd  -0x10(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
lea    0xeab(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    1292 <main+0x172>
movsd  -0x10(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
lea    0xe8e(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    1292 <main+0x172>
movsd  -0x10(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
lea    0xe71(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    1292 <main+0x172>
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1215 <main+0xf5>
jp     1215 <main+0xf5>
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    122d <main+0x10d>
movsd  -0x10(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
lea    0xe29(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    1292 <main+0x172>
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    125d <main+0x13d>
jp     125d <main+0x13d>
lea    0xe05(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    127f <main+0x15f>
cvttsd2si -0x10(%rbp),%rax
cvttsd2si -0x18(%rbp),%rcx
cqto
idiv   %rcx
mov    %rdx,%rsi
lea    0xdfa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1292 <main+0x172>
lea    0xdee(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
movq   $0x0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
movb   $0x0,0x7(%rsp)
lea    0xef3(%rip),%rdi
call   1030 <puts@plt>
lea    0xece(%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     11c0 <main+0x90>
lea    0xe7a(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movsd  0x8(%rsp),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11a1 <main+0x71>
jnp    1205 <main+0xd5>
cvttsd2si 0x10(%rsp),%rax
cvttsd2si %xmm0,%rcx
mov    %rax,%rdx
or     %rcx,%rdx
shr    $0x20,%rdx
je     1232 <main+0x102>
cqto
idiv   %rcx
jmp    1236 <main+0x106>
lea    0xeb0(%rip),%rdi
jmp    120c <main+0xdc>
movsd  0x10(%rsp),%xmm0
mulsd  0x8(%rsp),%xmm0
jmp    121d <main+0xed>
movsd  0x10(%rsp),%xmm0
addsd  0x8(%rsp),%xmm0
jmp    121d <main+0xed>
movsd  0x10(%rsp),%xmm0
subsd  0x8(%rsp),%xmm0
jmp    121d <main+0xed>
movsd  0x8(%rsp),%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jne    1213 <main+0xe3>
jp     1213 <main+0xe3>
lea    0xe50(%rip),%rdi
call   1030 <puts@plt>
jmp    122b <main+0xfb>
movsd  0x10(%rsp),%xmm0
divsd  %xmm1,%xmm0
lea    0xe13(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret
xor    %edx,%edx
div    %ecx
lea    0xe01(%rip),%rdi
mov    %rdx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    122b <main+0xfb>

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

LLVM IR (-O2):
@.str.1 = [11 x i8] c"%lf %c %lf\00"
@.str.2 = [7 x i8] c"= %lf\0A\00"
@.str.4 = [7 x i8] c"= %ld\0A\00"
@str = [23 x i8] c"\0AEnter the calculation\00"
@str.7 = [27 x i8] c"\0A\0A\07Division by zero error!\00"
@str.8 = [22 x i8] c"\0A\0A\07Illegal operation!\00"
define i32 @main() {
%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 ([23 x i8], [23 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 = sext i8 %8 to i32
switch i32 %9, label %45 [
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 ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), double %13)
br label %47
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 ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), double %18)
br label %47
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 ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), double %23)
br label %47
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 ([27 x i8], [27 x i8]* @str.7, i64 0, i64 0))
br label %47
30: ; preds = %25
%31 = load double, double* %1
%32 = fdiv double %31, %26
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), double %32)
br label %47
34: ; preds = %0
%35 = load double, double* %2
%36 = fcmp oeq double %35, 0.000000e+00
br i1 %36, label %37, label %39
37: ; preds = %34
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.7, i64 0, i64 0))
br label %47
39: ; preds = %34
%40 = load double, double* %1
%41 = fptosi double %40 to i64
%42 = fptosi double %35 to i64
%43 = srem i64 %41, %42
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i64 %43)
br label %47
45: ; preds = %0
%46 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.8, i64 0, i64 0))
br label %47
47: ; preds = %37, %39, %28, %30, %45, %20, %15, %10
ret i32 0
}