int precedence(char operator1, char operator2) {
  int result = 1;
  switch (operator1) {
  case '^':
    if (operator2 == '^')
      result = 0;
    break;
  case '*':
  case '/':
  case '%':
    switch (operator2) {
    case '^':
      result = -1;
      break;
    case '*':
    case '/':
    case '%':
      result = 0;
      break;
    default:
      break;
    }
    break;
  case '+':
  case '-':
    switch (operator2) {
    case '-':
    case '+':
      result = 0;
      break;
    default:
      result = -1;
      break;
    }
    break;
  }
  return result;
}


x86 assembly (clang, -O0):
<precedence>:
push   %rbp
mov    %rsp,%rbp
mov    %sil,%al
mov    %dil,%cl
mov    %cl,-0x1(%rbp)
mov    %al,-0x2(%rbp)
movl   $0x1,-0x8(%rbp)
movsbl -0x1(%rbp),%eax
mov    %eax,-0xc(%rbp)
sub    $0x25,%eax
je     119a <precedence+0x9a>
jmp    112c <precedence+0x2c>
mov    -0xc(%rbp),%eax
sub    $0x2a,%eax
je     119a <precedence+0x9a>
jmp    113d <precedence+0x3d>
mov    -0xc(%rbp),%eax
sub    $0x2b,%eax
je     1204 <precedence+0x104>
jmp    114e <precedence+0x4e>
mov    -0xc(%rbp),%eax
sub    $0x2d,%eax
je     1204 <precedence+0x104>
jmp    115f <precedence+0x5f>
mov    -0xc(%rbp),%eax
sub    $0x2f,%eax
je     119a <precedence+0x9a>
jmp    1170 <precedence+0x70>
mov    -0xc(%rbp),%eax
sub    $0x5e,%eax
jne    1242 <precedence+0x142>
jmp    1181 <precedence+0x81>
movsbl -0x2(%rbp),%eax
cmp    $0x5e,%eax
jne    1195 <precedence+0x95>
movl   $0x0,-0x8(%rbp)
jmp    1242 <precedence+0x142>
movsbl -0x2(%rbp),%eax
mov    %eax,-0x10(%rbp)
sub    $0x25,%eax
je     11ee <precedence+0xee>
jmp    11af <precedence+0xaf>
mov    -0x10(%rbp),%eax
sub    $0x2a,%eax
je     11ee <precedence+0xee>
jmp    11c0 <precedence+0xc0>
mov    -0x10(%rbp),%eax
sub    $0x2f,%eax
je     11ee <precedence+0xee>
jmp    11d1 <precedence+0xd1>
mov    -0x10(%rbp),%eax
sub    $0x5e,%eax
jne    11fa <precedence+0xfa>
jmp    11e2 <precedence+0xe2>
movl   $0xffffffff,-0x8(%rbp)
jmp    11ff <precedence+0xff>
movl   $0x0,-0x8(%rbp)
jmp    11ff <precedence+0xff>
jmp    11ff <precedence+0xff>
jmp    1242 <precedence+0x142>
movsbl -0x2(%rbp),%eax
mov    %eax,-0x14(%rbp)
sub    $0x2b,%eax
je     122a <precedence+0x12a>
jmp    1219 <precedence+0x119>
mov    -0x14(%rbp),%eax
sub    $0x2d,%eax
jne    1236 <precedence+0x136>
jmp    122a <precedence+0x12a>
movl   $0x0,-0x8(%rbp)
jmp    123d <precedence+0x13d>
movl   $0xffffffff,-0x8(%rbp)
jmp    1242 <precedence+0x142>
mov    -0x8(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<precedence>:
mov    $0x1,%eax
add    $0xffffffdb,%edi
cmp    $0x39,%edi
ja     1130 <precedence+0x30>
mov    $0x421,%ecx
bt     %rdi,%rcx
jb     1131 <precedence+0x31>
mov    $0x140,%ecx
bt     %rdi,%rcx
jae    1146 <precedence+0x46>
add    $0xd5,%sil
and    $0xfd,%sil
neg    %sil
sbb    %eax,%eax
ret
movsbl %sil,%ecx
cmp    $0x2e,%ecx
jg     1156 <precedence+0x56>
cmp    $0x25,%ecx
je     1166 <precedence+0x66>
cmp    $0x2a,%ecx
je     1166 <precedence+0x66>
jmp    1130 <precedence+0x30>
cmp    $0x39,%rdi
jne    1130 <precedence+0x30>
xor    %eax,%eax
cmp    $0x5e,%sil
setne  %al
ret
cmp    $0x2f,%ecx
je     1166 <precedence+0x66>
cmp    $0x5e,%ecx
jne    1130 <precedence+0x30>
mov    $0xffffffff,%eax
ret
xor    %eax,%eax
ret

LLVM IR (-O0):
define i32 @precedence(i8 signext %0, i8 signext %1) {
%3 = alloca i8
%4 = alloca i8
%5 = alloca i32
store i8 %0, i8* %3
store i8 %1, i8* %4
store i32 1, i32* %5
%6 = load i8, i8* %3
%7 = sext i8 %6 to i32
switch i32 %7, label %27 [
i32 94, label %8
i32 42, label %14
i32 47, label %14
i32 37, label %14
i32 43, label %21
i32 45, label %21
]
8: ; preds = %2
%9 = load i8, i8* %4
%10 = sext i8 %9 to i32
%11 = icmp eq i32 %10, 94
br i1 %11, label %12, label %13
12: ; preds = %8
store i32 0, i32* %5
br label %13
13: ; preds = %12, %8
br label %27
14: ; preds = %2, %2, %2
%15 = load i8, i8* %4
%16 = sext i8 %15 to i32
switch i32 %16, label %19 [
i32 94, label %17
i32 42, label %18
i32 47, label %18
i32 37, label %18
]
17: ; preds = %14
store i32 -1, i32* %5
br label %20
18: ; preds = %14, %14, %14
store i32 0, i32* %5
br label %20
19: ; preds = %14
br label %20
20: ; preds = %19, %18, %17
br label %27
21: ; preds = %2, %2
%22 = load i8, i8* %4
%23 = sext i8 %22 to i32
switch i32 %23, label %25 [
i32 45, label %24
i32 43, label %24
]
24: ; preds = %21, %21
store i32 0, i32* %5
br label %26
25: ; preds = %21
store i32 -1, i32* %5
br label %26
26: ; preds = %25, %24
br label %27
27: ; preds = %2, %26, %20, %13
%28 = load i32, i32* %5
ret i32 %28
}

LLVM IR (-O2):
define i32 @precedence(i8 signext %0, i8 signext %1) {
%3 = sext i8 %0 to i32
switch i32 %3, label %16 [
i32 94, label %4
i32 42, label %7
i32 47, label %7
i32 37, label %7
i32 43, label %11
i32 45, label %11
]
4: ; preds = %2
%5 = icmp ne i8 %1, 94
%6 = zext i1 %5 to i32
br label %16
7: ; preds = %2, %2, %2
%8 = sext i8 %1 to i32
switch i32 %8, label %16 [
i32 94, label %9
i32 42, label %10
i32 47, label %10
i32 37, label %10
]
9: ; preds = %7
br label %16
10: ; preds = %7, %7, %7
br label %16
11: ; preds = %2, %2
%12 = icmp ne i8 %1, 45
%13 = icmp ne i8 %1, 43
%14 = and i1 %12, %13
%15 = sext i1 %14 to i32
br label %16
16: ; preds = %4, %11, %9, %10, %7, %2
%17 = phi i32 [ 1, %2 ], [ 1, %7 ], [ 0, %10 ], [ -1, %9 ], [ %6, %4 ], [ %15, %11 ]
ret i32 %17
}