#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);
int /*<<< orphan*/ push(int);
void calculate(int operator) {
  int operand2 = pop();
  int operand1 = pop();
  switch (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: \"%c\"\n", operator);
    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)
mov    -0x4(%rbp),%eax
add    $0xffffffd6,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x5,%eax
ja     11dc <calculate+0x9c>
mov    -0x18(%rbp),%rax
lea    0xe7b(%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    11f2 <calculate+0xb2>
mov    -0xc(%rbp),%edi
sub    -0x8(%rbp),%edi
call   1050 <push@plt>
jmp    11f2 <calculate+0xb2>
mov    -0xc(%rbp),%edi
imul   -0x8(%rbp),%edi
call   1050 <push@plt>
jmp    11f2 <calculate+0xb2>
cmpl   $0x0,-0x8(%rbp)
je     11d7 <calculate+0x97>
mov    -0xc(%rbp),%eax
cltd
idivl  -0x8(%rbp)
mov    %eax,%edi
call   1050 <push@plt>
jmp    11f2 <calculate+0xb2>
mov    -0x4(%rbp),%esi
lea    0xe32(%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,%ebx
xor    %eax,%eax
call   1040 <pop@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1040 <pop@plt>
lea    -0x2a(%rbx),%ecx
cmp    $0x5,%ecx
ja     1176 <calculate+0x36>
lea    0xe9c(%rip),%rdx
movslq (%rdx,%rcx,4),%rcx
add    %rdx,%rcx
jmp    *%rcx
imul   %ebp,%eax
jmp    119c <calculate+0x5c>
add    %ebp,%eax
jmp    119c <calculate+0x5c>
lea    0xe9b(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1060 <make_empty@plt>
sub    %ebp,%eax
jmp    119c <calculate+0x5c>
test   %ebp,%ebp
je     11a9 <calculate+0x69>
cltd
idiv   %ebp
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 = [20 x i8] c"Bad operator: \22%c\22\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
switch i32 %7, label %32 [
i32 43, label %8
i32 45, label %13
i32 42, label %18
i32 47, label %23
]
8: ; preds = %1
%9 = load i32, i32* %4
%10 = load i32, i32* %3
%11 = add nsw i32 %9, %10
%12 = call i32 @push(i32 %11)
br label %36
13: ; preds = %1
%14 = load i32, i32* %4
%15 = load i32, i32* %3
%16 = sub nsw i32 %14, %15
%17 = call i32 @push(i32 %16)
br label %36
18: ; preds = %1
%19 = load i32, i32* %4
%20 = load i32, i32* %3
%21 = mul nsw i32 %19, %20
%22 = call i32 @push(i32 %21)
br label %36
23: ; preds = %1
%24 = load i32, i32* %3
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %31
26: ; preds = %23
%27 = load i32, i32* %4
%28 = load i32, i32* %3
%29 = sdiv i32 %27, %28
%30 = call i32 @push(i32 %29)
br label %31
31: ; preds = %26, %23
br label %36
32: ; preds = %1
%33 = load i32, i32* %2
%34 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %33)
%35 = call i32 (...) @make_empty()
br label %36
36: ; preds = %32, %31, %18, %13, %8
ret void
}

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