int Precedence(char op) {
  if (op == '(')
    return -1;
  else if (op == '+' || op == '-')
    return 0;
  else if (op == '*' || op == '/' || op == '%')
    return 1;
  else if (op == '^')
    return 2;
}


x86 assembly (clang, -O0):
<Precedence>:
push   %rbp
mov    %rsp,%rbp
mov    %dil,%al
mov    %al,-0x5(%rbp)
movsbl -0x5(%rbp),%eax
cmp    $0x28,%eax
jne    1123 <Precedence+0x23>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a4 <Precedence+0xa4>
movsbl -0x5(%rbp),%eax
cmp    $0x2b,%eax
je     113d <Precedence+0x3d>
movsbl -0x5(%rbp),%eax
cmp    $0x2d,%eax
jne    1149 <Precedence+0x49>
movl   $0x0,-0x4(%rbp)
jmp    11a4 <Precedence+0xa4>
movsbl -0x5(%rbp),%eax
cmp    $0x2a,%eax
je     1170 <Precedence+0x70>
movsbl -0x5(%rbp),%eax
cmp    $0x2f,%eax
je     1170 <Precedence+0x70>
movsbl -0x5(%rbp),%eax
cmp    $0x25,%eax
jne    117c <Precedence+0x7c>
movl   $0x1,-0x4(%rbp)
jmp    11a4 <Precedence+0xa4>
movsbl -0x5(%rbp),%eax
cmp    $0x5e,%eax
jne    1195 <Precedence+0x95>
movl   $0x2,-0x4(%rbp)
jmp    11a4 <Precedence+0xa4>
jmp    119a <Precedence+0x9a>
jmp    119f <Precedence+0x9f>
jmp    11a4 <Precedence+0xa4>
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<Precedence>:
cmp    $0x2c,%dil
jg     1114 <Precedence+0x14>
cmp    $0x28,%dil
je     112f <Precedence+0x2f>
cmp    $0x2b,%dil
je     1126 <Precedence+0x26>
jmp    1129 <Precedence+0x29>
cmp    $0x2d,%dil
je     1126 <Precedence+0x26>
cmp    $0x5e,%dil
jne    1129 <Precedence+0x29>
mov    $0x2,%eax
ret
xor    %eax,%eax
ret
mov    $0x1,%eax
ret
mov    $0xffffffff,%eax
ret

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

LLVM IR (-O2):
define i32 @Precedence(i8 signext %0) {
switch i8 %0, label %4 [
i8 40, label %5
i8 45, label %3
i8 43, label %3
i8 94, label %2
]
2: ; preds = %1
br label %5
3: ; preds = %1, %1
br label %5
4: ; preds = %1
br label %5
5: ; preds = %1, %4, %3, %2
%6 = phi i32 [ 2, %2 ], [ -1, %1 ], [ 0, %3 ], [ 1, %4 ]
ret i32 %6
}