#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 */
typedef int const intmax_t;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ pow(int const, int const);
int /*<<< orphan*/ stderr;
intmax_t do_operation(const intmax_t lvalue, const intmax_t rvalue,
                      const int op) {
  switch (op) {
  case '/':
    if (rvalue == 0) {
      fprintf(stderr, "error: divide by zero\n");
      return 0;
    }
    return (lvalue / rvalue);
  case '+':
    return (lvalue + rvalue);
  case '-':
    return (lvalue - rvalue);
  case '*':
    return (lvalue * rvalue);
  case '%':
    return (lvalue % rvalue);
  case '^':
    return (intmax_t)pow(lvalue, rvalue);
  default:
    fprintf(stderr, "error: bad operation\n");
    return 0;
  }
  return 0;
}


x86 assembly (clang, -O0):
<do_operation>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    $0xffffffdb,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x39,%eax
ja     11e1 <do_operation+0xc1>
mov    -0x18(%rbp),%rax
lea    0xeaf(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
cmpl   $0x0,-0xc(%rbp)
jne    1185 <do_operation+0x65>
mov    0x2e75(%rip),%rax
mov    (%rax),%edi
lea    0xf74(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11fd <do_operation+0xdd>
mov    -0x8(%rbp),%eax
cltd
idivl  -0xc(%rbp)
mov    %eax,-0x4(%rbp)
jmp    11fd <do_operation+0xdd>
mov    -0x8(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11fd <do_operation+0xdd>
mov    -0x8(%rbp),%eax
sub    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11fd <do_operation+0xdd>
mov    -0x8(%rbp),%eax
imul   -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11fd <do_operation+0xdd>
mov    -0x8(%rbp),%eax
cltd
idivl  -0xc(%rbp)
mov    %edx,-0x4(%rbp)
jmp    11fd <do_operation+0xdd>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1040 <pow@plt>
mov    %eax,-0x4(%rbp)
jmp    11fd <do_operation+0xdd>
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
lea    0xf0e(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_operation>:
push   %rax
add    $0xffffffdb,%edx
cmp    $0x39,%edx
ja     1142 <do_operation+0x22>
lea    0xed0(%rip),%rax
movslq (%rax,%rdx,4),%rcx
add    %rax,%rcx
jmp    *%rcx
mov    %edi,%eax
cltd
idiv   %esi
mov    %edx,%esi
jmp    118d <do_operation+0x6d>
mov    0x2e97(%rip),%rax
mov    (%rax),%edi
lea    0xfad(%rip),%rsi
jmp    1186 <do_operation+0x66>
imul   %edi,%esi
jmp    118d <do_operation+0x6d>
add    %edi,%esi
jmp    118d <do_operation+0x6d>
sub    %esi,%edi
mov    %edi,%esi
jmp    118d <do_operation+0x6d>
test   %esi,%esi
je     1176 <do_operation+0x56>
mov    %edi,%eax
cltd
idiv   %esi
mov    %eax,%esi
jmp    118d <do_operation+0x6d>
pop    %rax
jmp    1040 <pow@plt>
mov    0x2e63(%rip),%rax
mov    (%rax),%edi
lea    0xf62(%rip),%rsi
call   1030 <fprintf@plt>
xor    %esi,%esi
mov    %esi,%eax
pop    %rcx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [23 x i8] c"error: divide by zero\0A\00"
@.str.1 = [22 x i8] c"error: bad operation\0A\00"
define i32 @do_operation(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%8 = load i32, i32* %7
switch i32 %8, label %39 [
i32 47, label %9
i32 43, label %19
i32 45, label %23
i32 42, label %27
i32 37, label %31
i32 94, label %35
]
9: ; preds = %3
%10 = load i32, i32* %6
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %4
br label %42
15: ; preds = %9
%16 = load i32, i32* %5
%17 = load i32, i32* %6
%18 = sdiv i32 %16, %17
store i32 %18, i32* %4
br label %42
19: ; preds = %3
%20 = load i32, i32* %5
%21 = load i32, i32* %6
%22 = add nsw i32 %20, %21
store i32 %22, i32* %4
br label %42
23: ; preds = %3
%24 = load i32, i32* %5
%25 = load i32, i32* %6
%26 = sub nsw i32 %24, %25
store i32 %26, i32* %4
br label %42
27: ; preds = %3
%28 = load i32, i32* %5
%29 = load i32, i32* %6
%30 = mul nsw i32 %28, %29
store i32 %30, i32* %4
br label %42
31: ; preds = %3
%32 = load i32, i32* %5
%33 = load i32, i32* %6
%34 = srem i32 %32, %33
store i32 %34, i32* %4
br label %42
35: ; preds = %3
%36 = load i32, i32* %5
%37 = load i32, i32* %6
%38 = call i32 @pow(i32 %36, i32 %37)
store i32 %38, i32* %4
br label %42
39: ; preds = %3
%40 = load i32, i32* @stderr
%41 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %4
br label %42
42: ; preds = %39, %35, %31, %27, %23, %19, %15, %12
%43 = load i32, i32* %4
ret i32 %43
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [23 x i8] c"error: divide by zero\0A\00"
@.str.1 = [22 x i8] c"error: bad operation\0A\00"
define i32 @do_operation(i32 %0, i32 %1, i32 %2) {
switch i32 %2, label %21 [
i32 47, label %4
i32 43, label %11
i32 45, label %13
i32 42, label %15
i32 37, label %17
i32 94, label %19
]
4: ; preds = %3
%5 = icmp eq i32 %1, 0
br i1 %5, label %6, label %9
6: ; preds = %4
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %24
9: ; preds = %4
%10 = sdiv i32 %0, %1
br label %24
11: ; preds = %3
%12 = add nsw i32 %1, %0
br label %24
13: ; preds = %3
%14 = sub nsw i32 %0, %1
br label %24
15: ; preds = %3
%16 = mul nsw i32 %1, %0
br label %24
17: ; preds = %3
%18 = srem i32 %0, %1
br label %24
19: ; preds = %3
%20 = tail call i32 @pow(i32 %0, i32 %1)
br label %24
21: ; preds = %3
%22 = load i32, i32* @stderr
%23 = tail call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %24
24: ; preds = %21, %19, %17, %15, %13, %11, %9, %6
%25 = phi i32 [ 0, %21 ], [ %20, %19 ], [ %18, %17 ], [ %16, %15 ], [ %14, %13 ], [ %12, %11 ], [ 0, %6 ], [ %10, %9 ]
ret i32 %25
}