#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 *, ...);
void operation(double num1, double num2, char operand) {
  double result;
  switch (operand) {
  case '+':
    result = num1 + num2;
    printf("The result is: %.2lf\n", result);
    break;
  case '-':
    result = num1 - num2;
    printf("The result is: %.2lf\n", result);
    break;
  case '*':
    result = num1 * num2;
    printf("The result is: %.2lf\n", result);
    break;
  case '/':
    if (num2 == 0) {
      printf("Division by zero not allowed");
      break;
    }
    result = num1 / num2;
    printf("The result is: %.2lf\n", result);
    break;
  default:
    printf("Invalid input\n");
  }
}


x86 assembly (clang, -O0):
<operation>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dil,%al
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    %al,-0x11(%rbp)
movsbl -0x11(%rbp),%eax
add    $0xffffffd6,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x5,%eax
ja     1219 <operation+0x109>
mov    -0x28(%rbp),%rax
lea    0xeb7(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movsd  -0x8(%rbp),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
lea    0xeab(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    1227 <operation+0x117>
movsd  -0x8(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
lea    0xe84(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    1227 <operation+0x117>
movsd  -0x8(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
lea    0xe5d(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    1227 <operation+0x117>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11f2 <operation+0xe2>
jp     11f2 <operation+0xe2>
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1227 <operation+0x117>
movsd  -0x8(%rbp),%xmm0
divsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
lea    0xe0b(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    1227 <operation+0x117>
lea    0xe2b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<operation>:
add    $0xffffffd6,%edi
cmp    $0x5,%edi
ja     1144 <operation+0x24>
lea    0xed1(%rip),%rax
movslq (%rax,%rdi,4),%rcx
add    %rax,%rcx
jmp    *%rcx
mulsd  %xmm1,%xmm0
jmp    1174 <operation+0x54>
addsd  %xmm1,%xmm0
jmp    1174 <operation+0x54>
lea    0xf00(%rip),%rdi
jmp    1030 <puts@plt>
subsd  %xmm1,%xmm0
jmp    1174 <operation+0x54>
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm1
jne    1170 <operation+0x50>
jp     1170 <operation+0x50>
lea    0xec5(%rip),%rdi
xor    %eax,%eax
jmp    1040 <printf@plt>
divsd  %xmm1,%xmm0
lea    0xe9d(%rip),%rdi
mov    $0x1,%al
jmp    1040 <printf@plt>

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

LLVM IR (-O2):
@.str = [22 x i8] c"The result is: %.2lf\0A\00"
@.str.1 = [29 x i8] c"Division by zero not allowed\00"
@str = [14 x i8] c"Invalid input\00"
define void @operation(double %0, double %1, i8 signext %2) {
%4 = sext i8 %2 to i32
switch i32 %4, label %21 [
i32 43, label %5
i32 45, label %8
i32 42, label %11
i32 47, label %14
]
5: ; preds = %3
%6 = fadd double %0, %1
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), double %6)
br label %23
8: ; preds = %3
%9 = fsub double %0, %1
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), double %9)
br label %23
11: ; preds = %3
%12 = fmul double %0, %1
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), double %12)
br label %23
14: ; preds = %3
%15 = fcmp oeq double %1, 0.000000e+00
br i1 %15, label %16, label %18
16: ; preds = %14
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
br label %23
18: ; preds = %14
%19 = fdiv double %0, %1
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), double %19)
br label %23
21: ; preds = %3
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
br label %23
23: ; preds = %21, %18, %16, %11, %8, %5
ret void
}