#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 */
double pow(double, double);
int /*<<< orphan*/ sprintf(char *, char *, ...);
int /*<<< orphan*/ strcpy(char *, char *);
double BinaryOperation(double left, double right, char op, char *strError) {
  strcpy(strError, "");
  switch (op) {
  case '-':
    return left - right;
  case '+':
    return left + right;
  case '*':
    return left * right;
  case '/':
    if (right == 0) {
      sprintf(strError, "Error: division by zero!\n");
      return 0.0;
    } else
      return left / right;
  case '^':
    return pow(left, right);
  default:
    if (op == '(')
      sprintf(strError, "Error: unbalanced brackets.\n");
    else
      sprintf(strError, "Error: unknown operator: %c\n", op);
    return 0.0;
  }
}


x86 assembly (clang, -O0):
<BinaryOperation>:
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)
mov    -0x28(%rbp),%rdi
lea    0xec2(%rip),%rsi
call   1030 <strcpy@plt>
movsbl -0x19(%rbp),%eax
mov    %eax,-0x2c(%rbp)
sub    $0x2a,%eax
je     11dd <BinaryOperation+0xad>
jmp    1171 <BinaryOperation+0x41>
mov    -0x2c(%rbp),%eax
sub    $0x2b,%eax
je     11c9 <BinaryOperation+0x99>
jmp    1182 <BinaryOperation+0x52>
mov    -0x2c(%rbp),%eax
sub    $0x2d,%eax
je     11b5 <BinaryOperation+0x85>
jmp    1193 <BinaryOperation+0x63>
mov    -0x2c(%rbp),%eax
sub    $0x2f,%eax
je     11f1 <BinaryOperation+0xc1>
jmp    11a4 <BinaryOperation+0x74>
mov    -0x2c(%rbp),%eax
sub    $0x5e,%eax
je     123c <BinaryOperation+0x10c>
jmp    1255 <BinaryOperation+0x125>
movsd  -0x10(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1297 <BinaryOperation+0x167>
movsd  -0x10(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1297 <BinaryOperation+0x167>
movsd  -0x10(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1297 <BinaryOperation+0x167>
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1228 <BinaryOperation+0xf8>
jp     1228 <BinaryOperation+0xf8>
mov    -0x28(%rbp),%rdi
lea    0xdec(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1297 <BinaryOperation+0x167>
movsd  -0x10(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1297 <BinaryOperation+0x167>
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
call   1040 <pow@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    1297 <BinaryOperation+0x167>
movsbl -0x19(%rbp),%eax
cmp    $0x28,%eax
jne    1279 <BinaryOperation+0x149>
mov    -0x28(%rbp),%rdi
lea    0xdad(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
jmp    128f <BinaryOperation+0x15f>
mov    -0x28(%rbp),%rdi
movsbl -0x19(%rbp),%edx
lea    0xdaf(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BinaryOperation>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
movsd  %xmm1,0x10(%rsp)
movsd  %xmm0,0x8(%rsp)
lea    0xee2(%rip),%rsi
mov    %r14,%rdi
call   1030 <strcpy@plt>
lea    -0x2a(%rbx),%eax
cmp    $0x5,%eax
ja     1180 <BinaryOperation+0x50>
lea    0xe9a(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movsd  0x8(%rsp),%xmm0
mulsd  0x10(%rsp),%xmm0
jmp    1229 <BinaryOperation+0xf9>
cmp    $0x5e,%ebx
jne    119d <BinaryOperation+0x6d>
movsd  0x8(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
add    $0x18,%rsp
pop    %rbx
pop    %r14
jmp    1040 <pow@plt>
cmp    $0x28,%bl
jne    1206 <BinaryOperation+0xd6>
movups 0xe96(%rip),%xmm0
movups %xmm0,0xd(%r14)
movupd 0xe7c(%rip),%xmm0
movupd %xmm0,(%r14)
jmp    1219 <BinaryOperation+0xe9>
movsd  0x8(%rsp),%xmm0
addsd  0x10(%rsp),%xmm0
jmp    1229 <BinaryOperation+0xf9>
movsd  0x8(%rsp),%xmm0
subsd  0x10(%rsp),%xmm0
jmp    1229 <BinaryOperation+0xf9>
xorpd  %xmm0,%xmm0
movsd  0x10(%rsp),%xmm1
ucomisd %xmm0,%xmm1
jne    121f <BinaryOperation+0xef>
jp     121f <BinaryOperation+0xef>
movups 0xe30(%rip),%xmm1
movups %xmm1,0xa(%r14)
movupd 0xe19(%rip),%xmm1
movupd %xmm1,(%r14)
jmp    1229 <BinaryOperation+0xf9>
lea    0xe42(%rip),%rsi
mov    %r14,%rdi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <sprintf@plt>
xorpd  %xmm0,%xmm0
jmp    1229 <BinaryOperation+0xf9>
movsd  0x8(%rsp),%xmm0
divsd  %xmm1,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [26 x i8] c"Error: division by zero!\0A\00"
@.str.2 = [29 x i8] c"Error: unbalanced brackets.\0A\00"
@.str.3 = [29 x i8] c"Error: unknown operator: %c\0A\00"
define double @BinaryOperation(double %0, double %1, i8 signext %2, i8* %3) {
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca i8
%9 = alloca i8*
store double %0, double* %6
store double %1, double* %7
store i8 %2, i8* %8
store i8* %3, i8** %9
%10 = load i8*, i8** %9
%11 = call i32 @strcpy(i8* %10, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%12 = load i8, i8* %8
%13 = sext i8 %12 to i32
switch i32 %13, label %40 [
i32 45, label %14
i32 43, label %18
i32 42, label %22
i32 47, label %26
i32 94, label %36
]
14: ; preds = %4
%15 = load double, double* %6
%16 = load double, double* %7
%17 = fsub double %15, %16
store double %17, double* %5
br label %53
18: ; preds = %4
%19 = load double, double* %6
%20 = load double, double* %7
%21 = fadd double %19, %20
store double %21, double* %5
br label %53
22: ; preds = %4
%23 = load double, double* %6
%24 = load double, double* %7
%25 = fmul double %23, %24
store double %25, double* %5
br label %53
26: ; preds = %4
%27 = load double, double* %7
%28 = fcmp oeq double %27, 0.000000e+00
br i1 %28, label %29, label %32
29: ; preds = %26
%30 = load i8*, i8** %9
%31 = call i32 (i8*, i8*, ...) @sprintf(i8* %30, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
store double 0.000000e+00, double* %5
br label %53
32: ; preds = %26
%33 = load double, double* %6
%34 = load double, double* %7
%35 = fdiv double %33, %34
store double %35, double* %5
br label %53
36: ; preds = %4
%37 = load double, double* %6
%38 = load double, double* %7
%39 = call double @pow(double %37, double %38)
store double %39, double* %5
br label %53
40: ; preds = %4
%41 = load i8, i8* %8
%42 = sext i8 %41 to i32
%43 = icmp eq i32 %42, 40
br i1 %43, label %44, label %47
44: ; preds = %40
%45 = load i8*, i8** %9
%46 = call i32 (i8*, i8*, ...) @sprintf(i8* %45, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
br label %52
47: ; preds = %40
%48 = load i8*, i8** %9
%49 = load i8, i8* %8
%50 = sext i8 %49 to i32
%51 = call i32 (i8*, i8*, ...) @sprintf(i8* %48, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i32 %50)
br label %52
52: ; preds = %47, %44
store double 0.000000e+00, double* %5
br label %53
53: ; preds = %52, %36, %32, %29, %22, %18, %14
%54 = load double, double* %5
ret double %54
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [26 x i8] c"Error: division by zero!\0A\00"
@.str.2 = [29 x i8] c"Error: unbalanced brackets.\0A\00"
@.str.3 = [29 x i8] c"Error: unknown operator: %c\0A\00"
define double @BinaryOperation(double %0, double %1, i8 signext %2, i8* %3) {
%5 = tail call i32 @strcpy(i8* %3, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%6 = sext i8 %2 to i32
switch i32 %6, label %20 [
i32 45, label %7
i32 43, label %9
i32 42, label %11
i32 47, label %13
i32 94, label %18
]
7: ; preds = %4
%8 = fsub double %0, %1
br label %25
9: ; preds = %4
%10 = fadd double %0, %1
br label %25
11: ; preds = %4
%12 = fmul double %0, %1
br label %25
13: ; preds = %4
%14 = fcmp oeq double %1, 0.000000e+00
br i1 %14, label %15, label %16
15: ; preds = %13
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(26) %3, i8* align 1 dereferenceable(26) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i64 26, i1 false)
br label %25
16: ; preds = %13
%17 = fdiv double %0, %1
br label %25
18: ; preds = %4
%19 = tail call double @pow(double %0, double %1)
br label %25
20: ; preds = %4
%21 = icmp eq i8 %2, 40
br i1 %21, label %22, label %23
22: ; preds = %20
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(29) %3, i8* align 1 dereferenceable(29) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i64 29, i1 false)
br label %25
23: ; preds = %20
%24 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %3, i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i32 %6)
br label %25
25: ; preds = %22, %23, %18, %16, %15, %11, %9, %7
%26 = phi double [ %19, %18 ], [ 0.000000e+00, %15 ], [ %17, %16 ], [ %12, %11 ], [ %10, %9 ], [ %8, %7 ], [ 0.000000e+00, %23 ], [ 0.000000e+00, %22 ]
ret double %26
}