#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_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
long eval_simple_op(char op, long a, long b) {
  switch (op) {
  case 'p':
    return (a < 0) ? -1 * a : a;
  case 'n':
    return (a > 0) ? -1 * a : a;
  case '+':
    return a + b;
  case '-':
    return a - b;
  case '*':
    return a * b;
  case '<':
    return a << b;
  case '>':
    return a >> b;
  }
  if (!b) {
    fprintf(stderr, ("eval_simple_op: Division by 0.\n"));
    exit(EXIT_FAILURE);
  }
  if (op == '/')
    return a / b;
  return a % b;
}


x86 assembly (clang, -O0):
<eval_simple_op>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %dil,%al
mov    %al,-0x9(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movsbl -0x9(%rbp),%eax
mov    %eax,-0x24(%rbp)
sub    $0x2a,%eax
je     122f <eval_simple_op+0x10f>
jmp    114b <eval_simple_op+0x2b>
mov    -0x24(%rbp),%eax
sub    $0x2b,%eax
je     120d <eval_simple_op+0xed>
jmp    115c <eval_simple_op+0x3c>
mov    -0x24(%rbp),%eax
sub    $0x2d,%eax
je     121e <eval_simple_op+0xfe>
jmp    116d <eval_simple_op+0x4d>
mov    -0x24(%rbp),%eax
sub    $0x3c,%eax
je     1241 <eval_simple_op+0x121>
jmp    117e <eval_simple_op+0x5e>
mov    -0x24(%rbp),%eax
sub    $0x3e,%eax
je     1255 <eval_simple_op+0x135>
jmp    118f <eval_simple_op+0x6f>
mov    -0x24(%rbp),%eax
sub    $0x6e,%eax
je     11df <eval_simple_op+0xbf>
jmp    11a0 <eval_simple_op+0x80>
mov    -0x24(%rbp),%eax
sub    $0x70,%eax
jne    1269 <eval_simple_op+0x149>
jmp    11b1 <eval_simple_op+0x91>
cmpq   $0x0,-0x18(%rbp)
jge    11ca <eval_simple_op+0xaa>
imul   $0xffffffffffffffff,-0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    11d2 <eval_simple_op+0xb2>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12c5 <eval_simple_op+0x1a5>
cmpq   $0x0,-0x18(%rbp)
jle    11f8 <eval_simple_op+0xd8>
imul   $0xffffffffffffffff,-0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    1200 <eval_simple_op+0xe0>
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12c5 <eval_simple_op+0x1a5>
mov    -0x18(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12c5 <eval_simple_op+0x1a5>
mov    -0x18(%rbp),%rax
sub    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12c5 <eval_simple_op+0x1a5>
mov    -0x18(%rbp),%rax
imul   -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12c5 <eval_simple_op+0x1a5>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
shl    %cl,%rax
mov    %rax,-0x8(%rbp)
jmp    12c5 <eval_simple_op+0x1a5>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
sar    %cl,%rax
mov    %rax,-0x8(%rbp)
jmp    12c5 <eval_simple_op+0x1a5>
cmpq   $0x0,-0x20(%rbp)
jne    1297 <eval_simple_op+0x177>
mov    0x2d65(%rip),%rax
mov    (%rax),%edi
lea    0xd7c(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2d48(%rip),%rax
mov    (%rax),%edi
call   1040 <exit@plt>
movsbl -0x9(%rbp),%eax
cmp    $0x2f,%eax
jne    12b7 <eval_simple_op+0x197>
mov    -0x18(%rbp),%rax
cqto
idivq  -0x20(%rbp)
mov    %rax,-0x8(%rbp)
jmp    12c5 <eval_simple_op+0x1a5>
mov    -0x18(%rbp),%rax
cqto
idivq  -0x20(%rbp)
mov    %rdx,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<eval_simple_op>:
push   %rax
mov    %rdx,%rcx
lea    -0x2a(%rdi),%eax
cmp    $0x14,%eax
ja     1145 <eval_simple_op+0x25>
lea    0xecd(%rip),%rdx
movslq (%rdx,%rax,4),%rax
add    %rdx,%rax
jmp    *%rax
imul   %rsi,%rcx
jmp    11cd <eval_simple_op+0xad>
cmp    $0x6e,%edi
je     119c <eval_simple_op+0x7c>
cmp    $0x70,%edi
jne    115b <eval_simple_op+0x3b>
mov    %rsi,%rax
neg    %rax
cmovs  %rsi,%rax
pop    %rcx
ret
test   %rcx,%rcx
je     11d2 <eval_simple_op+0xb2>
mov    %rsi,%rax
or     %rcx,%rax
cmp    $0x2f,%dil
jne    11a8 <eval_simple_op+0x88>
shr    $0x20,%rax
je     11bb <eval_simple_op+0x9b>
mov    %rsi,%rax
cqto
idiv   %rcx
mov    %rax,%rcx
jmp    11cd <eval_simple_op+0xad>
add    %rsi,%rcx
jmp    11cd <eval_simple_op+0xad>
sub    %rcx,%rsi
mov    %rsi,%rcx
jmp    11cd <eval_simple_op+0xad>
shl    %cl,%rsi
mov    %rsi,%rcx
jmp    11cd <eval_simple_op+0xad>
sar    %cl,%rsi
mov    %rsi,%rcx
jmp    11cd <eval_simple_op+0xad>
mov    %rsi,%rcx
neg    %rcx
cmovns %rsi,%rcx
jmp    11cd <eval_simple_op+0xad>
shr    $0x20,%rax
je     11c5 <eval_simple_op+0xa5>
mov    %rsi,%rax
cqto
idiv   %rcx
mov    %rdx,%rcx
jmp    11cd <eval_simple_op+0xad>
mov    %esi,%eax
xor    %edx,%edx
div    %ecx
mov    %eax,%ecx
jmp    11cd <eval_simple_op+0xad>
mov    %esi,%eax
xor    %edx,%edx
div    %ecx
mov    %edx,%ecx
mov    %rcx,%rax
pop    %rcx
ret
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
lea    0xe72(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2dea(%rip),%rax
mov    (%rax),%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [32 x i8] c"eval_simple_op: Division by 0.\0A\00"
@EXIT_FAILURE = global i32 0
define i64 @eval_simple_op(i8 signext %0, i64 %1, i64 %2) {
%4 = alloca i64
%5 = alloca i8
%6 = alloca i64
%7 = alloca i64
store i8 %0, i8* %5
store i64 %1, i64* %6
store i64 %2, i64* %7
%8 = load i8, i8* %5
%9 = sext i8 %8 to i32
switch i32 %9, label %50 [
i32 112, label %10
i32 110, label %20
i32 43, label %30
i32 45, label %34
i32 42, label %38
i32 60, label %42
i32 62, label %46
]
10: ; preds = %3
%11 = load i64, i64* %6
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = load i64, i64* %6
%15 = mul nsw i64 -1, %14
br label %18
16: ; preds = %10
%17 = load i64, i64* %6
br label %18
18: ; preds = %16, %13
%19 = phi i64 [ %15, %13 ], [ %17, %16 ]
store i64 %19, i64* %4
br label %70
20: ; preds = %3
%21 = load i64, i64* %6
%22 = icmp sgt i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = load i64, i64* %6
%25 = mul nsw i64 -1, %24
br label %28
26: ; preds = %20
%27 = load i64, i64* %6
br label %28
28: ; preds = %26, %23
%29 = phi i64 [ %25, %23 ], [ %27, %26 ]
store i64 %29, i64* %4
br label %70
30: ; preds = %3
%31 = load i64, i64* %6
%32 = load i64, i64* %7
%33 = add nsw i64 %31, %32
store i64 %33, i64* %4
br label %70
34: ; preds = %3
%35 = load i64, i64* %6
%36 = load i64, i64* %7
%37 = sub nsw i64 %35, %36
store i64 %37, i64* %4
br label %70
38: ; preds = %3
%39 = load i64, i64* %6
%40 = load i64, i64* %7
%41 = mul nsw i64 %39, %40
store i64 %41, i64* %4
br label %70
42: ; preds = %3
%43 = load i64, i64* %6
%44 = load i64, i64* %7
%45 = shl i64 %43, %44
store i64 %45, i64* %4
br label %70
46: ; preds = %3
%47 = load i64, i64* %6
%48 = load i64, i64* %7
%49 = ashr i64 %47, %48
store i64 %49, i64* %4
br label %70
50: ; preds = %3
%51 = load i64, i64* %7
%52 = icmp ne i64 %51, 0
br i1 %52, label %58, label %53
53: ; preds = %50
%54 = load i32, i32* @stderr
%55 = call i32 @fprintf(i32 %54, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%56 = load i32, i32* @EXIT_FAILURE
%57 = call i32 @exit(i32 %56)
unreachable
58: ; preds = %50
%59 = load i8, i8* %5
%60 = sext i8 %59 to i32
%61 = icmp eq i32 %60, 47
br i1 %61, label %62, label %66
62: ; preds = %58
%63 = load i64, i64* %6
%64 = load i64, i64* %7
%65 = sdiv i64 %63, %64
store i64 %65, i64* %4
br label %70
66: ; preds = %58
%67 = load i64, i64* %6
%68 = load i64, i64* %7
%69 = srem i64 %67, %68
store i64 %69, i64* %4
br label %70
70: ; preds = %66, %62, %46, %42, %38, %34, %30, %28, %18
%71 = load i64, i64* %4
ret i64 %71
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [32 x i8] c"eval_simple_op: Division by 0.\0A\00"
@EXIT_FAILURE = global i32 0
define i64 @eval_simple_op(i8 signext %0, i64 %1, i64 %2) {
%4 = sext i8 %0 to i32
switch i32 %4, label %20 [
i32 112, label %5
i32 110, label %7
i32 43, label %10
i32 45, label %12
i32 42, label %14
i32 60, label %16
i32 62, label %18
]
5: ; preds = %3
%6 = tail call i64 @llvm.abs.i64(i64 %1, i1 true)
br label %33
7: ; preds = %3
%8 = tail call i64 @llvm.abs.i64(i64 %1, i1 false)
%9 = sub i64 0, %8
br label %33
10: ; preds = %3
%11 = add nsw i64 %2, %1
br label %33
12: ; preds = %3
%13 = sub nsw i64 %1, %2
br label %33
14: ; preds = %3
%15 = mul nsw i64 %2, %1
br label %33
16: ; preds = %3
%17 = shl i64 %1, %2
br label %33
18: ; preds = %3
%19 = ashr i64 %1, %2
br label %33
20: ; preds = %3
%21 = icmp eq i64 %2, 0
br i1 %21, label %22, label %27
22: ; preds = %20
%23 = load i32, i32* @stderr
%24 = tail call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%25 = load i32, i32* @EXIT_FAILURE
%26 = tail call i32 @exit(i32 %25)
unreachable
27: ; preds = %20
%28 = icmp eq i8 %0, 47
br i1 %28, label %29, label %31
29: ; preds = %27
%30 = sdiv i64 %1, %2
br label %33
31: ; preds = %27
%32 = srem i64 %1, %2
br label %33
33: ; preds = %31, %29, %18, %16, %14, %12, %10, %7, %5
%34 = phi i64 [ %30, %29 ], [ %32, %31 ], [ %19, %18 ], [ %17, %16 ], [ %15, %14 ], [ %13, %12 ], [ %11, %10 ], [ %9, %7 ], [ %6, %5 ]
ret i64 %34
}