#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_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
double pow(double, double);
int /*<<< orphan*/ stderr;
double cal(double d1, double d2, char op) {
  switch (op) {
  case '+':
    return d1 + d2;
    break;
  case '-':
    return d1 - d2;
    break;
  case '*':
    return d1 * d2;
    break;
  case '/':
    return d1 / d2;
    break;
  case '^':
    return pow(d1, d2);
    break;
  default:
    fprintf(stderr, "Operator error!\n");
    exit(EXIT_FAILURE);
    break;
  }
}


x86 assembly (clang, -O0):
<cal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
mov    %al,-0x19(%rbp)
movsbl -0x19(%rbp),%eax
mov    %eax,-0x20(%rbp)
sub    $0x2a,%eax
je     11c9 <cal+0x99>
jmp    115d <cal+0x2d>
mov    -0x20(%rbp),%eax
sub    $0x2b,%eax
je     11a1 <cal+0x71>
jmp    116e <cal+0x3e>
mov    -0x20(%rbp),%eax
sub    $0x2d,%eax
je     11b5 <cal+0x85>
jmp    117f <cal+0x4f>
mov    -0x20(%rbp),%eax
sub    $0x2f,%eax
je     11dd <cal+0xad>
jmp    1190 <cal+0x60>
mov    -0x20(%rbp),%eax
sub    $0x5e,%eax
je     11f1 <cal+0xc1>
jmp    120a <cal+0xda>
movsd  -0x10(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    122d <cal+0xfd>
movsd  -0x10(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    122d <cal+0xfd>
movsd  -0x10(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    122d <cal+0xfd>
movsd  -0x10(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    122d <cal+0xfd>
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
call   1040 <pow@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    122d <cal+0xfd>
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
lea    0xde6(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2db2(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cal>:
push   %rax
lea    -0x2a(%rdi),%eax
cmp    $0x5,%eax
ja     114f <cal+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 <cal+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
mov    0x2e6d(%rip),%rax
mov    (%rax),%edi
lea    0xe9c(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

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

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