int getprecedence(char c) {
  if (c == '^')
    return 2;
  else if (c == '*' || c == '/')
    return 1;
  else if (c == '-' || c == '+')
    return 0;
  else if (c == '(')
    return 3;
  else if (c == ')')
    return 4;
  else
    return 0;
}


x86 assembly (clang, -O0):
<getprecedence>:
push   %rbp
mov    %rsp,%rbp
mov    %dil,%al
mov    %al,-0x5(%rbp)
movsbl -0x5(%rbp),%eax
cmp    $0x5e,%eax
jne    1123 <getprecedence+0x23>
movl   $0x2,-0x4(%rbp)
jmp    11a8 <getprecedence+0xa8>
movsbl -0x5(%rbp),%eax
cmp    $0x2a,%eax
je     113d <getprecedence+0x3d>
movsbl -0x5(%rbp),%eax
cmp    $0x2f,%eax
jne    1149 <getprecedence+0x49>
movl   $0x1,-0x4(%rbp)
jmp    11a8 <getprecedence+0xa8>
movsbl -0x5(%rbp),%eax
cmp    $0x2d,%eax
je     1163 <getprecedence+0x63>
movsbl -0x5(%rbp),%eax
cmp    $0x2b,%eax
jne    116f <getprecedence+0x6f>
movl   $0x0,-0x4(%rbp)
jmp    11a8 <getprecedence+0xa8>
movsbl -0x5(%rbp),%eax
cmp    $0x28,%eax
jne    1188 <getprecedence+0x88>
movl   $0x3,-0x4(%rbp)
jmp    11a8 <getprecedence+0xa8>
movsbl -0x5(%rbp),%eax
cmp    $0x29,%eax
jne    11a1 <getprecedence+0xa1>
movl   $0x4,-0x4(%rbp)
jmp    11a8 <getprecedence+0xa8>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<getprecedence>:
lea    -0x28(%rdi),%eax
cmp    $0x7,%al
ja     1121 <getprecedence+0x21>
movzbl %al,%eax
lea    0xeef(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    $0x1,%eax
jmp    112c <getprecedence+0x2c>
mov    $0x2,%eax
cmp    $0x5e,%dil
jne    112d <getprecedence+0x2d>
ret
xor    %eax,%eax
ret
mov    $0x3,%eax
ret
mov    $0x4,%eax
ret

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

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