#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*/ make_empty();
int pop();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ push(int);
void calculate(int operator) {
  int operand2 = pop();
  int operand1 = pop();
  switch ((char)operator) {
  case '+':
    push(operand1 + operand2);
    break;
  case '-':
    push(operand1 - operand2);
    break;
  case '*':
    push(operand1 * operand2);
    break;
  case '/':
    if (operand2 != 0) {
      push(operand1 / operand2);
    }
    break;
  default:
    printf("Bad operator!\n");
    make_empty();
  }
}


x86 assembly (clang, -O0):
<calculate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
xor    %eax,%eax
mov    %al,-0x19(%rbp)
call   1040 <pop@plt>
mov    %eax,%ecx
mov    -0x19(%rbp),%al
mov    %ecx,-0x8(%rbp)
call   1040 <pop@plt>
mov    %eax,-0xc(%rbp)
movsbl -0x4(%rbp),%eax
add    $0xffffffd6,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x5,%eax
ja     11dd <calculate+0x9d>
mov    -0x18(%rbp),%rax
lea    0xe7a(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0xc(%rbp),%edi
add    -0x8(%rbp),%edi
call   1050 <push@plt>
jmp    11f0 <calculate+0xb0>
mov    -0xc(%rbp),%edi
sub    -0x8(%rbp),%edi
call   1050 <push@plt>
jmp    11f0 <calculate+0xb0>
mov    -0xc(%rbp),%edi
imul   -0x8(%rbp),%edi
call   1050 <push@plt>
jmp    11f0 <calculate+0xb0>
cmpl   $0x0,-0x8(%rbp)
je     11d8 <calculate+0x98>
mov    -0xc(%rbp),%eax
cltd
idivl  -0x8(%rbp)
mov    %eax,%edi
call   1050 <push@plt>
jmp    11f0 <calculate+0xb0>
lea    0xe34(%rip),%rdi
call   1030 <printf@plt>
mov    $0x0,%al
call   1060 <make_empty@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calculate>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
xor    %eax,%eax
call   1040 <pop@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1040 <pop@plt>
movsbl %bpl,%ecx
add    $0xffffffd6,%ecx
cmp    $0x5,%ecx
ja     117a <calculate+0x3a>
lea    0xe98(%rip),%rdx
movslq (%rdx,%rcx,4),%rcx
add    %rdx,%rcx
jmp    *%rcx
imul   %ebx,%eax
jmp    119e <calculate+0x5e>
add    %ebx,%eax
jmp    119e <calculate+0x5e>
lea    0xe97(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1060 <make_empty@plt>
sub    %ebx,%eax
jmp    119e <calculate+0x5e>
test   %ebx,%ebx
je     11ab <calculate+0x6b>
cltd
idiv   %ebx
mov    %eax,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <push@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"Bad operator!\0A\00"
define void @calculate(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
%5 = call i32 (...) @pop()
store i32 %5, i32* %3
%6 = call i32 (...) @pop()
store i32 %6, i32* %4
%7 = load i32, i32* %2
%8 = trunc i32 %7 to i8
%9 = sext i8 %8 to i32
switch i32 %9, label %34 [
i32 43, label %10
i32 45, label %15
i32 42, label %20
i32 47, label %25
]
10: ; preds = %1
%11 = load i32, i32* %4
%12 = load i32, i32* %3
%13 = add nsw i32 %11, %12
%14 = call i32 @push(i32 %13)
br label %37
15: ; preds = %1
%16 = load i32, i32* %4
%17 = load i32, i32* %3
%18 = sub nsw i32 %16, %17
%19 = call i32 @push(i32 %18)
br label %37
20: ; preds = %1
%21 = load i32, i32* %4
%22 = load i32, i32* %3
%23 = mul nsw i32 %21, %22
%24 = call i32 @push(i32 %23)
br label %37
25: ; preds = %1
%26 = load i32, i32* %3
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %33
28: ; preds = %25
%29 = load i32, i32* %4
%30 = load i32, i32* %3
%31 = sdiv i32 %29, %30
%32 = call i32 @push(i32 %31)
br label %33
33: ; preds = %28, %25
br label %37
34: ; preds = %1
%35 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%36 = call i32 (...) @make_empty()
br label %37
37: ; preds = %34, %33, %20, %15, %10
ret void
}

LLVM IR (-O2):
@str = [14 x i8] c"Bad operator!\00"
define void @calculate(i32 %0) {
%2 = tail call i32 (...) @pop()
%3 = tail call i32 (...) @pop()
%4 = shl i32 %0, 24
%5 = ashr exact i32 %4, 24
switch i32 %5, label %20 [
i32 43, label %6
i32 45, label %9
i32 42, label %12
i32 47, label %15
]
6: ; preds = %1
%7 = add nsw i32 %3, %2
%8 = tail call i32 @push(i32 %7)
br label %23
9: ; preds = %1
%10 = sub nsw i32 %3, %2
%11 = tail call i32 @push(i32 %10)
br label %23
12: ; preds = %1
%13 = mul nsw i32 %3, %2
%14 = tail call i32 @push(i32 %13)
br label %23
15: ; preds = %1
%16 = icmp eq i32 %2, 0
br i1 %16, label %23, label %17
17: ; preds = %15
%18 = sdiv i32 %3, %2
%19 = tail call i32 @push(i32 %18)
br label %23
20: ; preds = %1
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
%22 = tail call i32 (...) @make_empty()
br label %23
23: ; preds = %15, %17, %20, %12, %9, %6
ret void
}