#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 *, ...);
void main(void) {
  double a, b;
  char operator;
  printf("Which operation you want to perform (+,-,*,/,%%)?\n");
  scanf("%c", &operator);
  printf("Enter two operands:\n");
  scanf("%lf%lf", &a, &b);
  switch (operator) {
  case '+':
    printf("addition of %0.2lf & %0.2lf is: %0.4lf\n", a, b, a + b);
    break;
  case '-':
    printf("subtraction of %0.2lf & %0.2lf is: %0.4lf\n", a, b, a - b);
    break;
  case '*':
    printf("multiplication of %0.2lf & %0.2lf is: %0.4lf\n", a, b, a * b);
    break;
  case '/':
    printf("division of %0.2lf & %0.2lf is: %0.4lf\n", a, b, a / b);
    break;
  case '%':
    printf("mod remainder of %0.2lf & %0.2lf is: %d\n", a, b, (int)a % (int)b);
    break;
  default:
    printf("Please enter valid operator\n");
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xefd(%rip),%rdi
xor    %eax,%eax
mov    %al,-0x21(%rbp)
call   1030 <printf@plt>
mov    -0x21(%rbp),%al
lea    0xf1c(%rip),%rdi
lea    -0x11(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x21(%rbp),%al
lea    0xf0c(%rip),%rdi
call   1030 <printf@plt>
mov    -0x21(%rbp),%al
lea    0xf12(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0x10(%rbp),%rdx
call   1040 <scanf@plt>
movsbl -0x11(%rbp),%eax
add    $0xffffffdb,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0xa,%eax
ja     1264 <main+0x144>
mov    -0x20(%rbp),%rax
lea    0xe6d(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movsd  -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  -0x8(%rbp),%xmm2
addsd  -0x10(%rbp),%xmm2
lea    0xec7(%rip),%rdi
mov    $0x3,%al
call   1030 <printf@plt>
jmp    1272 <main+0x152>
movsd  -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  -0x8(%rbp),%xmm2
subsd  -0x10(%rbp),%xmm2
lea    0xec8(%rip),%rdi
mov    $0x3,%al
call   1030 <printf@plt>
jmp    1272 <main+0x152>
movsd  -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  -0x8(%rbp),%xmm2
mulsd  -0x10(%rbp),%xmm2
lea    0xecc(%rip),%rdi
mov    $0x3,%al
call   1030 <printf@plt>
jmp    1272 <main+0x152>
movsd  -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  -0x8(%rbp),%xmm2
divsd  -0x10(%rbp),%xmm2
lea    0xed3(%rip),%rdi
mov    $0x3,%al
call   1030 <printf@plt>
jmp    1272 <main+0x152>
movsd  -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
cvttsd2si -0x8(%rbp),%eax
cvttsd2si -0x10(%rbp),%ecx
cltd
idiv   %ecx
mov    %edx,%esi
lea    0xecf(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
jmp    1272 <main+0x152>
lea    0xee5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
lea    0xef1(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xf16(%rip),%rdi
lea    0x7(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
lea    0xfdf(%rip),%rdi
call   1030 <puts@plt>
lea    0xefa(%rip),%rdi
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
xor    %eax,%eax
call   1050 <scanf@plt>
movsbl 0x7(%rsp),%eax
add    $0xffffffdb,%eax
cmp    $0xa,%eax
ja     11c2 <main+0x92>
lea    0xe73(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movsd  0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
cvttsd2si %xmm0,%eax
cvttsd2si %xmm1,%ecx
cltd
idiv   %ecx
lea    0xf5e(%rip),%rdi
mov    %edx,%esi
mov    $0x2,%al
call   1040 <printf@plt>
add    $0x18,%rsp
ret
lea    0xf86(%rip),%rdi
call   1030 <puts@plt>
add    $0x18,%rsp
ret
movsd  0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
movapd %xmm0,%xmm2
mulsd  %xmm1,%xmm2
lea    0xece(%rip),%rdi
jmp    1245 <main+0x115>
movsd  0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
movapd %xmm0,%xmm2
addsd  %xmm1,%xmm2
lea    0xe5e(%rip),%rdi
jmp    1245 <main+0x115>
movsd  0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
movapd %xmm0,%xmm2
subsd  %xmm1,%xmm2
lea    0xe69(%rip),%rdi
jmp    1245 <main+0x115>
movsd  0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
movapd %xmm0,%xmm2
divsd  %xmm1,%xmm2
lea    0xea5(%rip),%rdi
mov    $0x3,%al
call   1040 <printf@plt>
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [51 x i8] c"Which operation you want to perform (+,-,*,/,%%)?\0A\00"
@.str.1 = [3 x i8] c"%c\00"
@.str.2 = [21 x i8] c"Enter two operands:\0A\00"
@.str.3 = [7 x i8] c"%lf%lf\00"
@.str.4 = [40 x i8] c"addition of %0.2lf & %0.2lf is: %0.4lf\0A\00"
@.str.5 = [43 x i8] c"subtraction of %0.2lf & %0.2lf is: %0.4lf\0A\00"
@.str.6 = [46 x i8] c"multiplication of %0.2lf & %0.2lf is: %0.4lf\0A\00"
@.str.7 = [40 x i8] c"division of %0.2lf & %0.2lf is: %0.4lf\0A\00"
@.str.8 = [41 x i8] c"mod remainder of %0.2lf & %0.2lf is: %d\0A\00"
@.str.9 = [29 x i8] c"Please enter valid operator\0A\00"
define void @main() {
%1 = alloca double
%2 = alloca double
%3 = alloca i8
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
%5 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%7 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), double* %1, double* %2)
%8 = load i8, i8* %3
%9 = sext i8 %8 to i32
switch i32 %9, label %47 [
i32 43, label %10
i32 45, label %17
i32 42, label %24
i32 47, label %31
i32 37, label %38
]
10: ; preds = %0
%11 = load double, double* %1
%12 = load double, double* %2
%13 = load double, double* %1
%14 = load double, double* %2
%15 = fadd double %13, %14
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), double %11, double %12, double %15)
br label %49
17: ; preds = %0
%18 = load double, double* %1
%19 = load double, double* %2
%20 = load double, double* %1
%21 = load double, double* %2
%22 = fsub double %20, %21
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0), double %18, double %19, double %22)
br label %49
24: ; preds = %0
%25 = load double, double* %1
%26 = load double, double* %2
%27 = load double, double* %1
%28 = load double, double* %2
%29 = fmul double %27, %28
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.6, i64 0, i64 0), double %25, double %26, double %29)
br label %49
31: ; preds = %0
%32 = load double, double* %1
%33 = load double, double* %2
%34 = load double, double* %1
%35 = load double, double* %2
%36 = fdiv double %34, %35
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.7, i64 0, i64 0), double %32, double %33, double %36)
br label %49
38: ; preds = %0
%39 = load double, double* %1
%40 = load double, double* %2
%41 = load double, double* %1
%42 = fptosi double %41 to i32
%43 = load double, double* %2
%44 = fptosi double %43 to i32
%45 = srem i32 %42, %44
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.8, i64 0, i64 0), double %39, double %40, i32 %45)
br label %49
47: ; preds = %0
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.9, i64 0, i64 0))
br label %49
49: ; preds = %47, %38, %31, %24, %17, %10
ret void
}

LLVM IR (-O2):
@.str = [51 x i8] c"Which operation you want to perform (+,-,*,/,%%)?\0A\00"
@.str.1 = [3 x i8] c"%c\00"
@.str.3 = [7 x i8] c"%lf%lf\00"
@.str.4 = [40 x i8] c"addition of %0.2lf & %0.2lf is: %0.4lf\0A\00"
@.str.5 = [43 x i8] c"subtraction of %0.2lf & %0.2lf is: %0.4lf\0A\00"
@.str.6 = [46 x i8] c"multiplication of %0.2lf & %0.2lf is: %0.4lf\0A\00"
@.str.7 = [40 x i8] c"division of %0.2lf & %0.2lf is: %0.4lf\0A\00"
@.str.8 = [41 x i8] c"mod remainder of %0.2lf & %0.2lf is: %d\0A\00"
@str = [20 x i8] c"Enter two operands:\00"
@str.10 = [28 x i8] c"Please enter valid 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 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
%7 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%9 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), double* %1, double* %2)
%10 = load i8, i8* %3
%11 = sext i8 %10 to i32
switch i32 %11, label %39 [
i32 43, label %12
i32 45, label %17
i32 42, label %22
i32 47, label %27
i32 37, label %32
]
12: ; preds = %0
%13 = load double, double* %1
%14 = load double, double* %2
%15 = fadd double %13, %14
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), double %13, double %14, double %15)
br label %41
17: ; preds = %0
%18 = load double, double* %1
%19 = load double, double* %2
%20 = fsub double %18, %19
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0), double %18, double %19, double %20)
br label %41
22: ; preds = %0
%23 = load double, double* %1
%24 = load double, double* %2
%25 = fmul double %23, %24
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.6, i64 0, i64 0), double %23, double %24, double %25)
br label %41
27: ; preds = %0
%28 = load double, double* %1
%29 = load double, double* %2
%30 = fdiv double %28, %29
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.7, i64 0, i64 0), double %28, double %29, double %30)
br label %41
32: ; preds = %0
%33 = load double, double* %1
%34 = load double, double* %2
%35 = fptosi double %33 to i32
%36 = fptosi double %34 to i32
%37 = srem i32 %35, %36
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.8, i64 0, i64 0), double %33, double %34, i32 %37)
br label %41
39: ; preds = %0
%40 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.10, i64 0, i64 0))
br label %41
41: ; preds = %39, %32, %27, %22, %17, %12
ret void
}