#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*/ puts(char *);
int calculate(int lvalue, int rvalue, char operator) {
  int total = 0;
  switch (operator) {
  case '*':
    total = lvalue * rvalue;
    return total;
  case '/':
    total = lvalue / rvalue;
    return total;
  case '+':
    total = lvalue + rvalue;
    return total;
  case '-':
    total = lvalue - rvalue;
    return total;
  default:
    puts("something unexpected happened while calculating.");
    return 0;
  }
}


x86 assembly (clang, -O0):
<calculate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dl,%al
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %al,-0xd(%rbp)
movl   $0x0,-0x14(%rbp)
movsbl -0xd(%rbp),%eax
add    $0xffffffd6,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x5,%eax
ja     11a6 <calculate+0x96>
mov    -0x20(%rbp),%rax
lea    0xeb5(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x8(%rbp),%eax
imul   -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11b9 <calculate+0xa9>
mov    -0x8(%rbp),%eax
cltd
idivl  -0xc(%rbp)
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11b9 <calculate+0xa9>
mov    -0x8(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11b9 <calculate+0xa9>
mov    -0x8(%rbp),%eax
sub    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11b9 <calculate+0xa9>
lea    0xe6b(%rip),%rdi
call   1030 <puts@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calculate>:
push   %rax
add    $0xffffffd6,%edx
cmp    $0x5,%edx
ja     1132 <calculate+0x22>
lea    0xee0(%rip),%rax
movslq (%rax,%rdx,4),%rcx
add    %rax,%rcx
jmp    *%rcx
imul   %edi,%esi
jmp    114f <calculate+0x3f>
add    %edi,%esi
jmp    114f <calculate+0x3f>
lea    0xedf(%rip),%rdi
call   1030 <puts@plt>
xor    %esi,%esi
jmp    114f <calculate+0x3f>
sub    %esi,%edi
mov    %edi,%esi
jmp    114f <calculate+0x3f>
mov    %edi,%eax
cltd
idiv   %esi
mov    %eax,%esi
mov    %esi,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [49 x i8] c"something unexpected happened while calculating.\00"
define i32 @calculate(i32 %0, i32 %1, i8 signext %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8
%8 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8 %2, i8* %7
store i32 0, i32* %8
%9 = load i8, i8* %7
%10 = sext i8 %9 to i32
switch i32 %10, label %31 [
i32 42, label %11
i32 47, label %16
i32 43, label %21
i32 45, label %26
]
11: ; preds = %3
%12 = load i32, i32* %5
%13 = load i32, i32* %6
%14 = mul nsw i32 %12, %13
store i32 %14, i32* %8
%15 = load i32, i32* %8
store i32 %15, i32* %4
br label %33
16: ; preds = %3
%17 = load i32, i32* %5
%18 = load i32, i32* %6
%19 = sdiv i32 %17, %18
store i32 %19, i32* %8
%20 = load i32, i32* %8
store i32 %20, i32* %4
br label %33
21: ; preds = %3
%22 = load i32, i32* %5
%23 = load i32, i32* %6
%24 = add nsw i32 %22, %23
store i32 %24, i32* %8
%25 = load i32, i32* %8
store i32 %25, i32* %4
br label %33
26: ; preds = %3
%27 = load i32, i32* %5
%28 = load i32, i32* %6
%29 = sub nsw i32 %27, %28
store i32 %29, i32* %8
%30 = load i32, i32* %8
store i32 %30, i32* %4
br label %33
31: ; preds = %3
%32 = call i32 @puts(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %4
br label %33
33: ; preds = %31, %26, %21, %16, %11
%34 = load i32, i32* %4
ret i32 %34
}

LLVM IR (-O2):
@.str = [49 x i8] c"something unexpected happened while calculating.\00"
define i32 @calculate(i32 %0, i32 %1, i8 signext %2) {
%4 = sext i8 %2 to i32
switch i32 %4, label %13 [
i32 42, label %5
i32 47, label %7
i32 43, label %9
i32 45, label %11
]
5: ; preds = %3
%6 = mul nsw i32 %1, %0
br label %15
7: ; preds = %3
%8 = sdiv i32 %0, %1
br label %15
9: ; preds = %3
%10 = add nsw i32 %1, %0
br label %15
11: ; preds = %3
%12 = sub nsw i32 %0, %1
br label %15
13: ; preds = %3
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %13, %11, %9, %7, %5
%16 = phi i32 [ 0, %13 ], [ %12, %11 ], [ %10, %9 ], [ %8, %7 ], [ %6, %5 ]
ret i32 %16
}