#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*/ printf(char *);
int calculate(int number1, char operator, int number2) {
  int result = 0;
  switch (operator) {
  case '+':
    result = number1 + number2;
    break;
  case '-':
    result = number1 - number2;
    break;
  case '*':
    result = number1 * number2;
    break;
  case '/':
    result = number1 / number2;
    break;
  default:
    printf("Invalid operator");
  }
  return result;
}


x86 assembly (clang, -O0):
<calculate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %edi,-0x4(%rbp)
mov    %al,-0x5(%rbp)
mov    %edx,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movsbl -0x5(%rbp),%eax
add    $0xffffffd6,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x5,%eax
ja     118f <calculate+0x7f>
mov    -0x18(%rbp),%rax
lea    0xeb4(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x4(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    119b <calculate+0x8b>
mov    -0x4(%rbp),%eax
sub    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    119b <calculate+0x8b>
mov    -0x4(%rbp),%eax
imul   -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    119b <calculate+0x8b>
mov    -0x4(%rbp),%eax
cltd
idivl  -0xc(%rbp)
mov    %eax,-0x10(%rbp)
jmp    119b <calculate+0x8b>
lea    0xe82(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calculate>:
push   %rax
add    $0xffffffd6,%esi
cmp    $0x5,%esi
ja     1134 <calculate+0x24>
mov    %edx,%ecx
lea    0xede(%rip),%rax
movslq (%rax,%rsi,4),%rdx
add    %rax,%rdx
jmp    *%rdx
imul   %edi,%ecx
jmp    1151 <calculate+0x41>
add    %edi,%ecx
jmp    1151 <calculate+0x41>
lea    0xedd(%rip),%rdi
call   1030 <printf@plt>
xor    %ecx,%ecx
jmp    1151 <calculate+0x41>
sub    %ecx,%edi
mov    %edi,%ecx
jmp    1151 <calculate+0x41>
mov    %edi,%eax
cltd
idiv   %ecx
mov    %eax,%ecx
mov    %ecx,%eax
pop    %rcx
ret

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

LLVM IR (-O2):
@.str = [17 x i8] c"Invalid operator\00"
define i32 @calculate(i32 %0, i8 signext %1, i32 %2) {
%4 = sext i8 %1 to i32
switch i32 %4, label %13 [
i32 43, label %5
i32 45, label %7
i32 42, label %9
i32 47, label %11
]
5: ; preds = %3
%6 = add nsw i32 %2, %0
br label %15
7: ; preds = %3
%8 = sub nsw i32 %0, %2
br label %15
9: ; preds = %3
%10 = mul nsw i32 %2, %0
br label %15
11: ; preds = %3
%12 = sdiv i32 %0, %2
br label %15
13: ; preds = %3
%14 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 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
}