#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 */
char tolower(char const);
int parse_root(const char *note, char **endptr) {
  int n = -1;
  char *c = (char *)note;
  switch (tolower(note[0])) {
  case 'c':
    n = 0;
    break;
  case 'd':
    n = 2;
    break;
  case 'e':
    n = 4;
    break;
  case 'f':
    n = 5;
    break;
  case 'g':
    n = 7;
    break;
  case 'a':
    n = 9;
    break;
  case 'b':
  case 'h':
    n = 11;
    break;
  default:
    *endptr = NULL;
    return n;
    break;
  }
  for (++c;; ++c) {
    if (*c == '#')
      ++n;
    else if (tolower(*c) == 'b')
      --n;
    else
      break;
  }
  *endptr = c;
  return n;
}


x86 assembly (clang, -O0):
<parse_root>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <tolower@plt>
movsbl %al,%eax
add    $0xffffff9f,%eax
mov    %eax,%ecx
mov    %rcx,-0x30(%rbp)
sub    $0x7,%eax
ja     11b8 <parse_root+0xa8>
mov    -0x30(%rbp),%rax
lea    0xea5(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x0,-0x1c(%rbp)
jmp    11ce <parse_root+0xbe>
movl   $0x2,-0x1c(%rbp)
jmp    11ce <parse_root+0xbe>
movl   $0x4,-0x1c(%rbp)
jmp    11ce <parse_root+0xbe>
movl   $0x5,-0x1c(%rbp)
jmp    11ce <parse_root+0xbe>
movl   $0x7,-0x1c(%rbp)
jmp    11ce <parse_root+0xbe>
movl   $0x9,-0x1c(%rbp)
jmp    11ce <parse_root+0xbe>
movl   $0xb,-0x1c(%rbp)
jmp    11ce <parse_root+0xbe>
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    124f <parse_root+0x13f>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
jne    11f8 <parse_root+0xe8>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1228 <parse_root+0x118>
mov    -0x28(%rbp),%rax
movsbl (%rax),%edi
call   1030 <tolower@plt>
movsbl %al,%eax
cmp    $0x62,%eax
jne    121e <parse_root+0x10e>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    1223 <parse_root+0x113>
jmp    123e <parse_root+0x12e>
jmp    1228 <parse_root+0x118>
jmp    122d <parse_root+0x11d>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    11da <parse_root+0xca>
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_root>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
movsbl (%rdi),%edi
call   1030 <tolower@plt>
movsbl %al,%eax
add    $0xffffff9f,%eax
cmp    $0x7,%eax
ja     1165 <parse_root+0x55>
cltq
lea    0xeca(%rip),%rcx
mov    (%rcx,%rax,4),%ebp
jmp    1142 <parse_root+0x32>
nopl   0x0(%rax,%rax,1)
add    %ecx,%ebp
add    $0x1,%rbx
movzbl (%rbx),%eax
mov    $0x1,%ecx
cmp    $0x23,%al
je     1140 <parse_root+0x30>
movsbl %al,%edi
call   1030 <tolower@plt>
mov    $0xffffffff,%ecx
cmp    $0x62,%al
je     1140 <parse_root+0x30>
jmp    116c <parse_root+0x5c>
mov    $0xffffffff,%ebp
xor    %ebx,%ebx
mov    %rbx,(%r14)
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @parse_root(i8* %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %4
store i8** %1, i8*** %5
store i32 -1, i32* %6
%8 = load i8*, i8** %4
store i8* %8, i8** %7
%9 = load i8*, i8** %4
%10 = getelementptr inbounds i8, i8* %9, i64 0
%11 = load i8, i8* %10
%12 = call signext i8 @tolower(i8 signext %11)
%13 = sext i8 %12 to i32
switch i32 %13, label %21 [
i32 99, label %14
i32 100, label %15
i32 101, label %16
i32 102, label %17
i32 103, label %18
i32 97, label %19
i32 98, label %20
i32 104, label %20
]
14: ; preds = %2
store i32 0, i32* %6
br label %24
15: ; preds = %2
store i32 2, i32* %6
br label %24
16: ; preds = %2
store i32 4, i32* %6
br label %24
17: ; preds = %2
store i32 5, i32* %6
br label %24
18: ; preds = %2
store i32 7, i32* %6
br label %24
19: ; preds = %2
store i32 9, i32* %6
br label %24
20: ; preds = %2, %2
store i32 11, i32* %6
br label %24
21: ; preds = %2
%22 = load i8**, i8*** %5
store i8* null, i8** %22
%23 = load i32, i32* %6
store i32 %23, i32* %3
br label %54
24: ; preds = %20, %19, %18, %17, %16, %15, %14
%25 = load i8*, i8** %7
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %7
br label %27
27: ; preds = %47, %24
%28 = load i8*, i8** %7
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 35
br i1 %31, label %32, label %35
32: ; preds = %27
%33 = load i32, i32* %6
%34 = add nsw i32 %33, 1
store i32 %34, i32* %6
br label %46
35: ; preds = %27
%36 = load i8*, i8** %7
%37 = load i8, i8* %36
%38 = call signext i8 @tolower(i8 signext %37)
%39 = sext i8 %38 to i32
%40 = icmp eq i32 %39, 98
br i1 %40, label %41, label %44
41: ; preds = %35
%42 = load i32, i32* %6
%43 = add nsw i32 %42, -1
store i32 %43, i32* %6
br label %45
44: ; preds = %35
br label %50
45: ; preds = %41
br label %46
46: ; preds = %45, %32
br label %47
47: ; preds = %46
%48 = load i8*, i8** %7
%49 = getelementptr inbounds i8, i8* %48, i32 1
store i8* %49, i8** %7
br label %27
50: ; preds = %44
%51 = load i8*, i8** %7
%52 = load i8**, i8*** %5
store i8* %51, i8** %52
%53 = load i32, i32* %6
store i32 %53, i32* %3
br label %54
54: ; preds = %50, %21
%55 = load i32, i32* %3
ret i32 %55
}

LLVM IR (-O2):
@switch.table.parse_root = [8 x i32] [i32 9, i32 11, i32 0, i32 2, i32 4, i32 5, i32 7, i32 11]
define i32 @parse_root(i8* %0, i8** nocapture writeonly %1) {
%3 = load i8, i8* %0
%4 = tail call signext i8 @tolower(i8 signext %3)
%5 = sext i8 %4 to i32
%6 = add nsw i32 %5, -97
%7 = icmp ult i32 %6, 8
br i1 %7, label %8, label %24
8: ; preds = %2
%9 = sext i32 %6 to i64
%10 = getelementptr inbounds [8 x i32], [8 x i32]* @switch.table.parse_root, i64 0, i64 %9
%11 = load i32, i32* %10
br label %12
12: ; preds = %21, %8
%13 = phi i32 [ %11, %8 ], [ %23, %21 ]
%14 = phi i8* [ %0, %8 ], [ %15, %21 ]
%15 = getelementptr inbounds i8, i8* %14, i64 1
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 35
br i1 %17, label %21, label %18
18: ; preds = %12
%19 = tail call signext i8 @tolower(i8 signext %16)
%20 = icmp eq i8 %19, 98
br i1 %20, label %21, label %24
21: ; preds = %18, %12
%22 = phi i32 [ 1, %12 ], [ -1, %18 ]
%23 = add nsw i32 %13, %22
br label %12
24: ; preds = %18, %2
%25 = phi i8* [ null, %2 ], [ %15, %18 ]
%26 = phi i32 [ -1, %2 ], [ %13, %18 ]
store i8* %25, i8** %1
ret i32 %26
}