#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*/ isOperator(char);
double pow(double, double);
int applyOperator(double left, double right, char operator, double * res) {
  if (!isOperator(operator)) {
    return -1;
  }
  switch (operator) {
  case '+':
    *res = left + right;
    break;
  case '-':
    *res = left - right;
    break;
  case '/':
    *res = left / right;
    break;
  case '*':
    *res = left * right;
    break;
  case '^':
    *res = pow(left, right);
    break;
  }
  return 0;
}


x86 assembly (clang, -O0):
<applyOperator>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dil,%al
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
mov    %al,-0x19(%rbp)
mov    %rsi,-0x28(%rbp)
movsbl -0x19(%rbp),%edi
call   1030 <isOperator@plt>
cmp    $0x0,%eax
jne    115a <applyOperator+0x3a>
movl   $0xffffffff,-0x4(%rbp)
jmp    122d <applyOperator+0x10d>
movsbl -0x19(%rbp),%eax
mov    %eax,-0x2c(%rbp)
sub    $0x2a,%eax
je     11f8 <applyOperator+0xd8>
jmp    116f <applyOperator+0x4f>
mov    -0x2c(%rbp),%eax
sub    $0x2b,%eax
je     11b3 <applyOperator+0x93>
jmp    1180 <applyOperator+0x60>
mov    -0x2c(%rbp),%eax
sub    $0x2d,%eax
je     11ca <applyOperator+0xaa>
jmp    1191 <applyOperator+0x71>
mov    -0x2c(%rbp),%eax
sub    $0x2f,%eax
je     11e1 <applyOperator+0xc1>
jmp    11a2 <applyOperator+0x82>
mov    -0x2c(%rbp),%eax
sub    $0x5e,%eax
je     120f <applyOperator+0xef>
jmp    1226 <applyOperator+0x106>
movsd  -0x10(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    1226 <applyOperator+0x106>
movsd  -0x10(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    1226 <applyOperator+0x106>
movsd  -0x10(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    1226 <applyOperator+0x106>
movsd  -0x10(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    1226 <applyOperator+0x106>
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
call   1040 <pow@plt>
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<applyOperator>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
movsd  %xmm1,0x8(%rsp)
movsd  %xmm0,0x10(%rsp)
call   1030 <isOperator@plt>
test   %eax,%eax
je     116c <applyOperator+0x4c>
movsbl %bpl,%eax
xor    %ebp,%ebp
lea    -0x2a(%rax),%ecx
cmp    $0x5,%ecx
ja     1173 <applyOperator+0x53>
lea    0xeab(%rip),%rax
movslq (%rax,%rcx,4),%rcx
add    %rax,%rcx
jmp    *%rcx
movsd  0x10(%rsp),%xmm0
mulsd  0x8(%rsp),%xmm0
jmp    11b3 <applyOperator+0x93>
mov    $0xffffffff,%ebp
jmp    11b7 <applyOperator+0x97>
cmp    $0x5e,%eax
jne    11b7 <applyOperator+0x97>
movsd  0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
call   1040 <pow@plt>
jmp    11b3 <applyOperator+0x93>
movsd  0x10(%rsp),%xmm0
addsd  0x8(%rsp),%xmm0
jmp    11b3 <applyOperator+0x93>
movsd  0x10(%rsp),%xmm0
subsd  0x8(%rsp),%xmm0
jmp    11b3 <applyOperator+0x93>
movsd  0x10(%rsp),%xmm0
divsd  0x8(%rsp),%xmm0
movsd  %xmm0,(%rbx)
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @applyOperator(double %0, double %1, i8 signext %2, double* %3) {
%5 = alloca i32
%6 = alloca double
%7 = alloca double
%8 = alloca i8
%9 = alloca double*
store double %0, double* %6
store double %1, double* %7
store i8 %2, i8* %8
store double* %3, double** %9
%10 = load i8, i8* %8
%11 = call i32 @isOperator(i8 signext %10)
%12 = icmp ne i32 %11, 0
br i1 %12, label %14, label %13
13: ; preds = %4
store i32 -1, i32* %5
br label %43
14: ; preds = %4
%15 = load i8, i8* %8
%16 = sext i8 %15 to i32
switch i32 %16, label %42 [
i32 43, label %17
i32 45, label %22
i32 47, label %27
i32 42, label %32
i32 94, label %37
]
17: ; preds = %14
%18 = load double, double* %6
%19 = load double, double* %7
%20 = fadd double %18, %19
%21 = load double*, double** %9
store double %20, double* %21
br label %42
22: ; preds = %14
%23 = load double, double* %6
%24 = load double, double* %7
%25 = fsub double %23, %24
%26 = load double*, double** %9
store double %25, double* %26
br label %42
27: ; preds = %14
%28 = load double, double* %6
%29 = load double, double* %7
%30 = fdiv double %28, %29
%31 = load double*, double** %9
store double %30, double* %31
br label %42
32: ; preds = %14
%33 = load double, double* %6
%34 = load double, double* %7
%35 = fmul double %33, %34
%36 = load double*, double** %9
store double %35, double* %36
br label %42
37: ; preds = %14
%38 = load double, double* %6
%39 = load double, double* %7
%40 = call double @pow(double %38, double %39)
%41 = load double*, double** %9
store double %40, double* %41
br label %42
42: ; preds = %14, %37, %32, %27, %22, %17
store i32 0, i32* %5
br label %43
43: ; preds = %42, %13
%44 = load i32, i32* %5
ret i32 %44
}

LLVM IR (-O2):
define i32 @applyOperator(double %0, double %1, i8 signext %2, double* nocapture writeonly %3) {
%5 = tail call i32 @isOperator(i8 signext %2)
%6 = icmp eq i32 %5, 0
br i1 %6, label %21, label %7
7: ; preds = %4
%8 = sext i8 %2 to i32
switch i32 %8, label %21 [
i32 43, label %9
i32 45, label %11
i32 47, label %13
i32 42, label %15
i32 94, label %17
]
9: ; preds = %7
%10 = fadd double %0, %1
br label %19
11: ; preds = %7
%12 = fsub double %0, %1
br label %19
13: ; preds = %7
%14 = fdiv double %0, %1
br label %19
15: ; preds = %7
%16 = fmul double %0, %1
br label %19
17: ; preds = %7
%18 = tail call double @pow(double %0, double %1)
br label %19
19: ; preds = %17, %15, %13, %11, %9
%20 = phi double [ %10, %9 ], [ %12, %11 ], [ %14, %13 ], [ %16, %15 ], [ %18, %17 ]
store double %20, double* %3
br label %21
21: ; preds = %19, %7, %4
%22 = phi i32 [ -1, %4 ], [ 0, %7 ], [ 0, %19 ]
ret i32 %22
}