#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 fmod(double, double);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, ...);
int main(int argc, const char *argv[]) {
  printf("Calculator v. 0.0.1\n\n");
  printf("Select Operation: \n"
         "+ : Addition\n"
         "- : Subtraction\n"
         "* : Multiplication\n"
         "/ : Division\n"
         "%% : remainder after division (modulo division)\n"
         "Option: ");
  char operation;
  scanf("%c", &operation);
  printf("Enter First Number: ");
  double firstNumber = 0;
  scanf("%lf", &firstNumber);
  printf("Enter Second Number: ");
  double secondNumber = 0;
  scanf("%lf", &secondNumber);
  double result = 0;
  switch (operation) {
  case '+':
    result = firstNumber + secondNumber;
    printf("Result: %lf\n", result);
    break;
  case '-':
    result = firstNumber - secondNumber;
    printf("Result: %lf\n", result);
    break;
  case '*':
    result = firstNumber * secondNumber;
    printf("Result: %lf\n", result);
    break;
  case '/':
    if (secondNumber == 0) {
      printf("Division by 0 is IMPOSSIBLE!!!\n");
      break;
    }
    result = firstNumber / secondNumber;
    printf("Result: %lf\n", result);
    break;
  case '%':
    result = fmod(firstNumber, secondNumber);
    printf("Result: %lf\n", result);
    break;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xedf(%rip),%rdi
xor    %eax,%eax
mov    %al,-0x39(%rbp)
call   1030 <printf@plt>
mov    -0x39(%rbp),%al
lea    0xee1(%rip),%rdi
call   1030 <printf@plt>
mov    -0x39(%rbp),%al
lea    0xf5b(%rip),%rdi
lea    -0x11(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x39(%rbp),%al
lea    0xf4b(%rip),%rdi
call   1030 <printf@plt>
mov    -0x39(%rbp),%al
movq   $0x0,-0x20(%rbp)
lea    0xf49(%rip),%rdi
mov    %rdi,-0x48(%rbp)
lea    -0x20(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x39(%rbp),%al
lea    0xf36(%rip),%rdi
call   1030 <printf@plt>
mov    -0x48(%rbp),%rdi
mov    -0x39(%rbp),%al
movq   $0x0,-0x28(%rbp)
lea    -0x28(%rbp),%rsi
call   1050 <scanf@plt>
movq   $0x0,-0x30(%rbp)
movsbl -0x11(%rbp),%eax
add    $0xffffffdb,%eax
mov    %eax,%ecx
mov    %rcx,-0x38(%rbp)
sub    $0xa,%eax
ja     12ee <main+0x1be>
mov    -0x38(%rbp),%rax
lea    0xe09(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movsd  -0x20(%rbp),%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
lea    0xee2(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    12ee <main+0x1be>
movsd  -0x20(%rbp),%xmm0
subsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
lea    0xebb(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    12ee <main+0x1be>
movsd  -0x20(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
lea    0xe94(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    12ee <main+0x1be>
movsd  -0x28(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    12a0 <main+0x170>
jp     12a0 <main+0x170>
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12ee <main+0x1be>
movsd  -0x20(%rbp),%xmm0
divsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
lea    0xe42(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    12ee <main+0x1be>
movsd  -0x20(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
call   1040 <fmod@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
lea    0xe16(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
lea    0xfa8(%rip),%rdi
call   1030 <puts@plt>
lea    0xed4(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xf4f(%rip),%rdi
lea    0xf(%rsp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
lea    0xf3f(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movq   $0x0,0x18(%rsp)
lea    0xf3d(%rip),%rbx
lea    0x18(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <scanf@plt>
lea    0xf2b(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movq   $0x0,0x10(%rsp)
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <scanf@plt>
movsbl 0xf(%rsp),%eax
add    $0xffffffdb,%eax
cmp    $0xa,%eax
ja     125b <main+0x11b>
lea    0xe23(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movsd  0x18(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
call   1050 <fmod@plt>
jmp    124d <main+0x10d>
movsd  0x18(%rsp),%xmm0
mulsd  0x10(%rsp),%xmm0
jmp    124d <main+0x10d>
movsd  0x18(%rsp),%xmm0
addsd  0x10(%rsp),%xmm0
jmp    124d <main+0x10d>
movsd  0x18(%rsp),%xmm0
subsd  0x10(%rsp),%xmm0
jmp    124d <main+0x10d>
movsd  0x10(%rsp),%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jne    1243 <main+0x103>
jp     1243 <main+0x103>
lea    0xecd(%rip),%rdi
call   1030 <puts@plt>
jmp    125b <main+0x11b>
movsd  0x18(%rsp),%xmm0
divsd  %xmm1,%xmm0
lea    0xe93(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [22 x i8] c"Calculator v. 0.0.1\0A\0A\00"
@.str.1 = [137 x i8] c"Select Operation: \0A+ : Addition\0A- : Subtraction\0A* : Multiplication\0A/ : Division\0A%% : remainder after division (modulo division)\0AOption: \00"
@.str.2 = [3 x i8] c"%c\00"
@.str.3 = [21 x i8] c"Enter First Number: \00"
@.str.4 = [4 x i8] c"%lf\00"
@.str.5 = [22 x i8] c"Enter Second Number: \00"
@.str.6 = [13 x i8] c"Result: %lf\0A\00"
@.str.7 = [32 x i8] c"Division by 0 is IMPOSSIBLE!!!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8
%7 = alloca double
%8 = alloca double
%9 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %6)
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
store double 0.000000e+00, double* %7
%14 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), double* %7)
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
store double 0.000000e+00, double* %8
%16 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), double* %8)
store double 0.000000e+00, double* %9
%17 = load i8, i8* %6
%18 = sext i8 %17 to i32
switch i32 %18, label %54 [
i32 43, label %19
i32 45, label %25
i32 42, label %31
i32 47, label %37
i32 37, label %48
]
19: ; preds = %2
%20 = load double, double* %7
%21 = load double, double* %8
%22 = fadd double %20, %21
store double %22, double* %9
%23 = load double, double* %9
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), double %23)
br label %54
25: ; preds = %2
%26 = load double, double* %7
%27 = load double, double* %8
%28 = fsub double %26, %27
store double %28, double* %9
%29 = load double, double* %9
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), double %29)
br label %54
31: ; preds = %2
%32 = load double, double* %7
%33 = load double, double* %8
%34 = fmul double %32, %33
store double %34, double* %9
%35 = load double, double* %9
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), double %35)
br label %54
37: ; preds = %2
%38 = load double, double* %8
%39 = fcmp oeq double %38, 0.000000e+00
br i1 %39, label %40, label %42
40: ; preds = %37
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i64 0, i64 0))
br label %54
42: ; preds = %37
%43 = load double, double* %7
%44 = load double, double* %8
%45 = fdiv double %43, %44
store double %45, double* %9
%46 = load double, double* %9
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), double %46)
br label %54
48: ; preds = %2
%49 = load double, double* %7
%50 = load double, double* %8
%51 = call double @fmod(double %49, double %50)
store double %51, double* %9
%52 = load double, double* %9
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), double %52)
br label %54
54: ; preds = %2, %48, %42, %40, %31, %25, %19
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [137 x i8] c"Select Operation: \0A+ : Addition\0A- : Subtraction\0A* : Multiplication\0A/ : Division\0A%% : remainder after division (modulo division)\0AOption: \00"
@.str.2 = [3 x i8] c"%c\00"
@.str.3 = [21 x i8] c"Enter First Number: \00"
@.str.4 = [4 x i8] c"%lf\00"
@.str.5 = [22 x i8] c"Enter Second Number: \00"
@.str.6 = [13 x i8] c"Result: %lf\0A\00"
@str = [21 x i8] c"Calculator v. 0.0.1\0A\00"
@str.8 = [31 x i8] c"Division by 0 is IMPOSSIBLE!!!\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i8
%4 = alloca double
%5 = alloca double
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([137 x i8], [137 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %3)
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%10 = bitcast double* %4 to i8*
store double 0.000000e+00, double* %4
%11 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), double* %4)
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
%13 = bitcast double* %5 to i8*
store double 0.000000e+00, double* %5
%14 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), double* %5)
%15 = load i8, i8* %3
%16 = sext i8 %15 to i32
switch i32 %16, label %46 [
i32 43, label %17
i32 45, label %22
i32 42, label %27
i32 47, label %32
i32 37, label %41
]
17: ; preds = %2
%18 = load double, double* %4
%19 = load double, double* %5
%20 = fadd double %18, %19
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), double %20)
br label %46
22: ; preds = %2
%23 = load double, double* %4
%24 = load double, double* %5
%25 = fsub double %23, %24
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), double %25)
br label %46
27: ; preds = %2
%28 = load double, double* %4
%29 = load double, double* %5
%30 = fmul double %28, %29
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), double %30)
br label %46
32: ; preds = %2
%33 = load double, double* %5
%34 = fcmp oeq double %33, 0.000000e+00
br i1 %34, label %35, label %37
35: ; preds = %32
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.8, i64 0, i64 0))
br label %46
37: ; preds = %32
%38 = load double, double* %4
%39 = fdiv double %38, %33
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), double %39)
br label %46
41: ; preds = %2
%42 = load double, double* %4
%43 = load double, double* %5
%44 = call double @fmod(double %42, double %43)
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), double %44)
br label %46
46: ; preds = %2, %41, %37, %35, %27, %22, %17
ret i32 0
}