#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*/ exit(int);
double pow(double, double);
int /*<<< orphan*/ printf(char *);
double operation(char operator, double pre, double post) {
  switch (operator) {
  case '^':
    return pow(pre, post);
  case '/':
    return pre / post;
  case '*':
    return pre * post;
  case '+':
    return pre + post;
  case '-':
    return pre - post;
  }
  printf("Unknown operator\n");
  exit(1);
}


x86 assembly (clang, -O0):
<operation>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dil,%al
mov    %al,-0x9(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  %xmm1,-0x20(%rbp)
movsbl -0x9(%rbp),%eax
mov    %eax,-0x24(%rbp)
sub    $0x2a,%eax
je     11ce <operation+0x9e>
jmp    115d <operation+0x2d>
mov    -0x24(%rbp),%eax
sub    $0x2b,%eax
je     11e2 <operation+0xb2>
jmp    116e <operation+0x3e>
mov    -0x24(%rbp),%eax
sub    $0x2d,%eax
je     11f6 <operation+0xc6>
jmp    117f <operation+0x4f>
mov    -0x24(%rbp),%eax
sub    $0x2f,%eax
je     11ba <operation+0x8a>
jmp    1190 <operation+0x60>
mov    -0x24(%rbp),%eax
sub    $0x5e,%eax
jne    120a <operation+0xda>
jmp    11a1 <operation+0x71>
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
call   1040 <pow@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    1220 <operation+0xf0>
movsd  -0x18(%rbp),%xmm0
divsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1220 <operation+0xf0>
movsd  -0x18(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1220 <operation+0xf0>
movsd  -0x18(%rbp),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1220 <operation+0xf0>
movsd  -0x18(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1220 <operation+0xf0>
lea    0xdef(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<operation>:
push   %rax
lea    -0x2a(%rdi),%eax
cmp    $0x5,%eax
ja     114f <operation+0x1f>
lea    0xec0(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mulsd  %xmm1,%xmm0
pop    %rax
ret
cmp    $0x5e,%edi
jne    116c <operation+0x3c>
pop    %rax
jmp    1040 <pow@plt>
addsd  %xmm1,%xmm0
pop    %rax
ret
subsd  %xmm1,%xmm0
pop    %rax
ret
divsd  %xmm1,%xmm0
pop    %rax
ret
lea    0xea5(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"Unknown operator\0A\00"
define double @operation(i8 signext %0, double %1, double %2) {
%4 = alloca double
%5 = alloca i8
%6 = alloca double
%7 = alloca double
store i8 %0, i8* %5
store double %1, double* %6
store double %2, double* %7
%8 = load i8, i8* %5
%9 = sext i8 %8 to i32
switch i32 %9, label %30 [
i32 94, label %10
i32 47, label %14
i32 42, label %18
i32 43, label %22
i32 45, label %26
]
10: ; preds = %3
%11 = load double, double* %6
%12 = load double, double* %7
%13 = call double @pow(double %11, double %12)
store double %13, double* %4
br label %33
14: ; preds = %3
%15 = load double, double* %6
%16 = load double, double* %7
%17 = fdiv double %15, %16
store double %17, double* %4
br label %33
18: ; preds = %3
%19 = load double, double* %6
%20 = load double, double* %7
%21 = fmul double %19, %20
store double %21, double* %4
br label %33
22: ; preds = %3
%23 = load double, double* %6
%24 = load double, double* %7
%25 = fadd double %23, %24
store double %25, double* %4
br label %33
26: ; preds = %3
%27 = load double, double* %6
%28 = load double, double* %7
%29 = fsub double %27, %28
store double %29, double* %4
br label %33
30: ; preds = %3
%31 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %26, %22, %18, %14, %10
%34 = load double, double* %4
ret double %34
}

LLVM IR (-O2):
@str = [17 x i8] c"Unknown operator\00"
define double @operation(i8 signext %0, double %1, double %2) {
%4 = sext i8 %0 to i32
switch i32 %4, label %15 [
i32 94, label %5
i32 47, label %7
i32 42, label %9
i32 43, label %11
i32 45, label %13
]
5: ; preds = %3
%6 = tail call double @pow(double %1, double %2)
br label %18
7: ; preds = %3
%8 = fdiv double %1, %2
br label %18
9: ; preds = %3
%10 = fmul double %1, %2
br label %18
11: ; preds = %3
%12 = fadd double %1, %2
br label %18
13: ; preds = %3
%14 = fsub double %1, %2
br label %18
15: ; preds = %3
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %13, %11, %9, %7, %5
%19 = phi double [ %14, %13 ], [ %12, %11 ], [ %10, %9 ], [ %8, %7 ], [ %6, %5 ]
ret double %19
}