#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 */
int atoi(char *);
int /*<<< orphan*/ isalpha(char);
int /*<<< orphan*/ strncpy(char *, char const *, int);
char toupper(char);
int muGetNoteFromName(const char *pName) {
  int note_map[] = {9, 11, 0, 2, 4, 5, 7};
  char *p, cpy[16];
  int note = 0;
  strncpy(cpy, pName, 15);
  cpy[15] = '\0';
  p = cpy;
  while (!isalpha(*p) && *p)
    p++;
  if (*p) {
    note = toupper(*p) - 'A';
    if (note >= 0 && note <= 7) {
      note = note_map[note];
      p++;
      if (*p == 'b')
        note--, p++;
      else if (*p == '#')
        note++, p++;
      note += atoi(p) * 12 + 0;
    }
  }
  return note;
}


x86 assembly (clang, -O0):
<muGetNoteFromName>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    0xead(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xeaa(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xea7(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xea5(%rip),%eax
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x54(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0xf,%edx
call   1030 <strncpy@plt>
movb   $0x0,-0x41(%rbp)
lea    -0x50(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
movsbl (%rax),%edi
call   1050 <isalpha@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x55(%rbp)
jne    11c7 <muGetNoteFromName+0x87>
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x55(%rbp)
mov    -0x55(%rbp),%al
test   $0x1,%al
jne    11d7 <muGetNoteFromName+0x97>
jmp    11e8 <muGetNoteFromName+0xa8>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    119b <muGetNoteFromName+0x5b>
mov    -0x38(%rbp),%rax
cmpb   $0x0,(%rax)
je     12a3 <muGetNoteFromName+0x163>
mov    -0x38(%rbp),%rax
movsbl (%rax),%edi
call   1040 <toupper@plt>
movsbl %al,%eax
sub    $0x41,%eax
mov    %eax,-0x54(%rbp)
cmpl   $0x0,-0x54(%rbp)
jl     129e <muGetNoteFromName+0x15e>
cmpl   $0x7,-0x54(%rbp)
jg     129e <muGetNoteFromName+0x15e>
movslq -0x54(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%eax
mov    %eax,-0x54(%rbp)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x62,%eax
jne    125f <muGetNoteFromName+0x11f>
mov    -0x54(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x54(%rbp)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    1289 <muGetNoteFromName+0x149>
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
jne    1284 <muGetNoteFromName+0x144>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    1289 <muGetNoteFromName+0x149>
mov    -0x38(%rbp),%rdi
call   1060 <atoi@plt>
imul   $0xc,%eax,%eax
add    $0x0,%eax
add    -0x54(%rbp),%eax
mov    %eax,-0x54(%rbp)
jmp    12a3 <muGetNoteFromName+0x163>
mov    -0x54(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<muGetNoteFromName>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0xf,%edx
call   1030 <strncpy@plt>
movb   $0x0,0xf(%rsp)
movsbl (%rsp),%edi
call   1050 <isalpha@plt>
test   %eax,%eax
jne    1186 <muGetNoteFromName+0x46>
mov    %rsp,%rbx
nop
cmpb   $0x0,(%rbx)
je     11c0 <muGetNoteFromName+0x80>
movsbl 0x1(%rbx),%edi
add    $0x1,%rbx
call   1050 <isalpha@plt>
test   %eax,%eax
je     1170 <muGetNoteFromName+0x30>
mov    (%rbx),%al
test   %al,%al
je     11c0 <muGetNoteFromName+0x80>
movsbl %al,%edi
call   1040 <toupper@plt>
movsbl %al,%ecx
lea    -0x41(%rcx),%eax
add    $0xbf,%cl
cmp    $0x7,%cl
ja     11e1 <muGetNoteFromName+0xa1>
cltq
lea    0xe55(%rip),%rcx
mov    (%rcx,%rax,4),%r14d
mov    0x1(%rbx),%al
cmp    $0x23,%al
je     11c4 <muGetNoteFromName+0x84>
cmp    $0x62,%al
jne    11ce <muGetNoteFromName+0x8e>
add    $0xffffffff,%r14d
jmp    11c8 <muGetNoteFromName+0x88>
xor    %eax,%eax
jmp    11e1 <muGetNoteFromName+0xa1>
add    $0x1,%r14d
add    $0x2,%rbx
jmp    11d2 <muGetNoteFromName+0x92>
add    $0x1,%rbx
mov    %rbx,%rdi
call   1060 <atoi@plt>
lea    (%rax,%rax,2),%eax
lea    (%r14,%rax,4),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.muGetNoteFromName.note_map = [7 x i32] [i32 9, i32 11, i32 0, i32 2, i32 4, i32 5, i32 7]
define i32 @muGetNoteFromName(i8* %0) {
%2 = alloca i8*
%3 = alloca [7 x i32]
%4 = alloca i8*
%5 = alloca [16 x i8]
%6 = alloca i32
store i8* %0, i8** %2
%7 = bitcast [7 x i32]* %3 to i8*
store i32 0, i32* %6
%8 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%9 = load i8*, i8** %2
%10 = call i32 @strncpy(i8* %8, i8* %9, i32 15)
%11 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 15
store i8 0, i8* %11
%12 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
store i8* %12, i8** %4
br label %13
13: ; preds = %25, %1
%14 = load i8*, i8** %4
%15 = load i8, i8* %14
%16 = call i32 @isalpha(i8 signext %15)
%17 = icmp ne i32 %16, 0
br i1 %17, label %23, label %18
18: ; preds = %13
%19 = load i8*, i8** %4
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 0
br label %23
23: ; preds = %18, %13
%24 = phi i1 [ false, %13 ], [ %22, %18 ]
br i1 %24, label %25, label %28
25: ; preds = %23
%26 = load i8*, i8** %4
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %4
br label %13
28: ; preds = %23
%29 = load i8*, i8** %4
%30 = load i8, i8* %29
%31 = icmp ne i8 %30, 0
br i1 %31, label %32, label %78
32: ; preds = %28
%33 = load i8*, i8** %4
%34 = load i8, i8* %33
%35 = call signext i8 @toupper(i8 signext %34)
%36 = sext i8 %35 to i32
%37 = sub nsw i32 %36, 65
store i32 %37, i32* %6
%38 = load i32, i32* %6
%39 = icmp sge i32 %38, 0
br i1 %39, label %40, label %77
40: ; preds = %32
%41 = load i32, i32* %6
%42 = icmp sle i32 %41, 7
br i1 %42, label %43, label %77
43: ; preds = %40
%44 = load i32, i32* %6
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [7 x i32], [7 x i32]* %3, i64 0, i64 %45
%47 = load i32, i32* %46
store i32 %47, i32* %6
%48 = load i8*, i8** %4
%49 = getelementptr inbounds i8, i8* %48, i32 1
store i8* %49, i8** %4
%50 = load i8*, i8** %4
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
%53 = icmp eq i32 %52, 98
br i1 %53, label %54, label %59
54: ; preds = %43
%55 = load i32, i32* %6
%56 = add nsw i32 %55, -1
store i32 %56, i32* %6
%57 = load i8*, i8** %4
%58 = getelementptr inbounds i8, i8* %57, i32 1
store i8* %58, i8** %4
br label %70
59: ; preds = %43
%60 = load i8*, i8** %4
%61 = load i8, i8* %60
%62 = sext i8 %61 to i32
%63 = icmp eq i32 %62, 35
br i1 %63, label %64, label %69
64: ; preds = %59
%65 = load i32, i32* %6
%66 = add nsw i32 %65, 1
store i32 %66, i32* %6
%67 = load i8*, i8** %4
%68 = getelementptr inbounds i8, i8* %67, i32 1
store i8* %68, i8** %4
br label %69
69: ; preds = %64, %59
br label %70
70: ; preds = %69, %54
%71 = load i8*, i8** %4
%72 = call i32 @atoi(i8* %71)
%73 = mul nsw i32 %72, 12
%74 = add nsw i32 %73, 0
%75 = load i32, i32* %6
%76 = add nsw i32 %75, %74
store i32 %76, i32* %6
br label %77
77: ; preds = %70, %40, %32
br label %78
78: ; preds = %77, %28
%79 = load i32, i32* %6
ret i32 %79
}

LLVM IR (-O2):
@__const.muGetNoteFromName.note_map = [7 x i32] [i32 9, i32 11, i32 0, i32 2, i32 4, i32 5, i32 7]
define i32 @muGetNoteFromName(i8* %0) {
%2 = alloca [16 x i8]
%3 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%4 = call i32 @strncpy(i8* %3, i8* %0, i32 15)
%5 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 15
store i8 0, i8* %5
%6 = load i8, i8* %3
%7 = call i32 @isalpha(i8 signext %6)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %18
9: ; preds = %1, %13
%10 = phi i8* [ %14, %13 ], [ %3, %1 ]
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 0
br i1 %12, label %46, label %13
13: ; preds = %9
%14 = getelementptr inbounds i8, i8* %10, i64 1
%15 = load i8, i8* %14
%16 = call i32 @isalpha(i8 signext %15)
%17 = icmp eq i32 %16, 0
br i1 %17, label %9, label %18
18: ; preds = %13, %1
%19 = phi i8* [ %3, %1 ], [ %14, %13 ]
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 0
br i1 %21, label %46, label %22
22: ; preds = %18
%23 = call signext i8 @toupper(i8 signext %20)
%24 = sext i8 %23 to i32
%25 = add nsw i32 %24, -65
%26 = add i8 %23, -65
%27 = icmp ult i8 %26, 8
br i1 %27, label %28, label %46
28: ; preds = %22
%29 = sext i32 %25 to i64
%30 = getelementptr inbounds [7 x i32], [7 x i32]* @__const.muGetNoteFromName.note_map, i64 0, i64 %29
%31 = load i32, i32* %30
%32 = getelementptr inbounds i8, i8* %19, i64 1
%33 = load i8, i8* %32
switch i8 %33, label %40 [
i8 98, label %34
i8 35, label %37
]
34: ; preds = %28
%35 = add nsw i32 %31, -1
%36 = getelementptr inbounds i8, i8* %19, i64 2
br label %40
37: ; preds = %28
%38 = add nsw i32 %31, 1
%39 = getelementptr inbounds i8, i8* %19, i64 2
br label %40
40: ; preds = %28, %37, %34
%41 = phi i8* [ %36, %34 ], [ %39, %37 ], [ %32, %28 ]
%42 = phi i32 [ %35, %34 ], [ %38, %37 ], [ %31, %28 ]
%43 = call i32 @atoi(i8* %41)
%44 = mul nsw i32 %43, 12
%45 = add nsw i32 %44, %42
br label %46
46: ; preds = %9, %22, %40, %18
%47 = phi i32 [ %45, %40 ], [ %25, %22 ], [ 0, %18 ], [ 0, %9 ]
ret i32 %47
}