#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*/ exit(int);
int operate(int num1, char optr, int num2) {
  switch (optr) {
  case '+':
    return num1 + num2;
  case '-':
    return num1 - num2;
  case '*':
    return num1 * num2;
  case '/':
    if (num2 == 0) {
      exit(1);
    }
    return num1 / num2;
  default:
    exit(1);
  }
}


x86 assembly (clang, -O0):
<operate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %edi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    %edx,-0x10(%rbp)
movsbl -0x9(%rbp),%eax
add    $0xffffffd6,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x5,%eax
ja     119c <operate+0x8c>
mov    -0x18(%rbp),%rax
lea    0xebb(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x8(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11a6 <operate+0x96>
mov    -0x8(%rbp),%eax
sub    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11a6 <operate+0x96>
mov    -0x8(%rbp),%eax
imul   -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11a6 <operate+0x96>
cmpl   $0x0,-0x10(%rbp)
jne    118d <operate+0x7d>
mov    $0x1,%edi
call   1030 <exit@plt>
mov    -0x8(%rbp),%eax
cltd
idivl  -0x10(%rbp)
mov    %eax,-0x4(%rbp)
jmp    11a6 <operate+0x96>
mov    $0x1,%edi
call   1030 <exit@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<operate>:
push   %rax
add    $0xffffffd6,%esi
cmp    $0x5,%esi
ja     1149 <operate+0x39>
mov    %edx,%ecx
lea    0xede(%rip),%rax
movslq (%rax,%rsi,4),%rdx
add    %rax,%rdx
jmp    *%rdx
imul   %edi,%ecx
jmp    1145 <operate+0x35>
add    %edi,%ecx
jmp    1145 <operate+0x35>
sub    %ecx,%edi
mov    %edi,%ecx
jmp    1145 <operate+0x35>
test   %ecx,%ecx
je     1149 <operate+0x39>
mov    %edi,%eax
cltd
idiv   %ecx
mov    %eax,%ecx
mov    %ecx,%eax
pop    %rcx
ret
mov    $0x1,%edi
call   1030 <exit@plt>

LLVM IR (-O0):
define i32 @operate(i32 %0, i8 signext %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8
%7 = alloca i32
store i32 %0, i32* %5
store i8 %1, i8* %6
store i32 %2, i32* %7
%8 = load i8, i8* %6
%9 = sext i8 %8 to i32
switch i32 %9, label %31 [
i32 43, label %10
i32 45, label %14
i32 42, label %18
i32 47, label %22
]
10: ; preds = %3
%11 = load i32, i32* %5
%12 = load i32, i32* %7
%13 = add nsw i32 %11, %12
store i32 %13, i32* %4
br label %33
14: ; preds = %3
%15 = load i32, i32* %5
%16 = load i32, i32* %7
%17 = sub nsw i32 %15, %16
store i32 %17, i32* %4
br label %33
18: ; preds = %3
%19 = load i32, i32* %5
%20 = load i32, i32* %7
%21 = mul nsw i32 %19, %20
store i32 %21, i32* %4
br label %33
22: ; preds = %3
%23 = load i32, i32* %7
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %22
%28 = load i32, i32* %5
%29 = load i32, i32* %7
%30 = sdiv i32 %28, %29
store i32 %30, i32* %4
br label %33
31: ; preds = %3
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %27, %18, %14, %10
%34 = load i32, i32* %4
ret i32 %34
}

LLVM IR (-O2):
define i32 @operate(i32 %0, i8 signext %1, i32 %2) {
%4 = sext i8 %1 to i32
switch i32 %4, label %17 [
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 %19
7: ; preds = %3
%8 = sub nsw i32 %0, %2
br label %19
9: ; preds = %3
%10 = mul nsw i32 %2, %0
br label %19
11: ; preds = %3
%12 = icmp eq i32 %2, 0
br i1 %12, label %13, label %15
13: ; preds = %11
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %11
%16 = sdiv i32 %0, %2
br label %19
17: ; preds = %3
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %15, %9, %7, %5
%20 = phi i32 [ %16, %15 ], [ %10, %9 ], [ %8, %7 ], [ %6, %5 ]
ret i32 %20
}