#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 */
typedef int int8_t;

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ isalpha(char);
int /*<<< orphan*/ strncpy(char *, char const *, int);
int toupper(char);
int8_t muGetNoteFromName(const char *pName) {
  int8_t note_map[] = {9, 11, 0, 2, 4, 5, 7};
  int8_t note = 0;
  char *p, cpy[16];
  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,-0x34(%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,-0x40(%rbp)
mov    -0x40(%rbp),%rax
movsbl (%rax),%edi
call   1050 <isalpha@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x51(%rbp)
jne    11c7 <muGetNoteFromName+0x87>
mov    -0x40(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x51(%rbp)
mov    -0x51(%rbp),%al
test   $0x1,%al
jne    11d7 <muGetNoteFromName+0x97>
jmp    11e8 <muGetNoteFromName+0xa8>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    119b <muGetNoteFromName+0x5b>
mov    -0x40(%rbp),%rax
cmpb   $0x0,(%rax)
je     12a0 <muGetNoteFromName+0x160>
mov    -0x40(%rbp),%rax
movsbl (%rax),%edi
call   1040 <toupper@plt>
sub    $0x41,%eax
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jl     129b <muGetNoteFromName+0x15b>
cmpl   $0x7,-0x34(%rbp)
jg     129b <muGetNoteFromName+0x15b>
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%eax
mov    %eax,-0x34(%rbp)
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x62,%eax
jne    125c <muGetNoteFromName+0x11c>
mov    -0x34(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x34(%rbp)
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    1286 <muGetNoteFromName+0x146>
mov    -0x40(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
jne    1281 <muGetNoteFromName+0x141>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    1286 <muGetNoteFromName+0x146>
mov    -0x40(%rbp),%rdi
call   1060 <atoi@plt>
imul   $0xc,%eax,%eax
add    $0x0,%eax
add    -0x34(%rbp),%eax
mov    %eax,-0x34(%rbp)
jmp    12a0 <muGetNoteFromName+0x160>
mov    -0x34(%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     11ba <muGetNoteFromName+0x7a>
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     11ba <muGetNoteFromName+0x7a>
movsbl %al,%edi
call   1040 <toupper@plt>
add    $0xffffffbf,%eax
cmp    $0x7,%eax
ja     11db <muGetNoteFromName+0x9b>
mov    %eax,%eax
lea    0xe5b(%rip),%rcx
mov    (%rcx,%rax,4),%r14d
mov    0x1(%rbx),%al
cmp    $0x23,%al
je     11be <muGetNoteFromName+0x7e>
cmp    $0x62,%al
jne    11c8 <muGetNoteFromName+0x88>
add    $0xffffffff,%r14d
jmp    11c2 <muGetNoteFromName+0x82>
xor    %eax,%eax
jmp    11db <muGetNoteFromName+0x9b>
add    $0x1,%r14d
add    $0x2,%rbx
jmp    11cc <muGetNoteFromName+0x8c>
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 i32
%5 = alloca i8*
%6 = alloca [16 x i8]
store i8* %0, i8** %2
%7 = bitcast [7 x i32]* %3 to i8*
store i32 0, i32* %4
%8 = getelementptr inbounds [16 x i8], [16 x i8]* %6, 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]* %6, i64 0, i64 15
store i8 0, i8* %11
%12 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
store i8* %12, i8** %5
br label %13
13: ; preds = %25, %1
%14 = load i8*, i8** %5
%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** %5
%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** %5
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %5
br label %13
28: ; preds = %23
%29 = load i8*, i8** %5
%30 = load i8, i8* %29
%31 = icmp ne i8 %30, 0
br i1 %31, label %32, label %77
32: ; preds = %28
%33 = load i8*, i8** %5
%34 = load i8, i8* %33
%35 = call i32 @toupper(i8 signext %34)
%36 = sub nsw i32 %35, 65
store i32 %36, i32* %4
%37 = load i32, i32* %4
%38 = icmp sge i32 %37, 0
br i1 %38, label %39, label %76
39: ; preds = %32
%40 = load i32, i32* %4
%41 = icmp sle i32 %40, 7
br i1 %41, label %42, label %76
42: ; preds = %39
%43 = load i32, i32* %4
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [7 x i32], [7 x i32]* %3, i64 0, i64 %44
%46 = load i32, i32* %45
store i32 %46, i32* %4
%47 = load i8*, i8** %5
%48 = getelementptr inbounds i8, i8* %47, i32 1
store i8* %48, i8** %5
%49 = load i8*, i8** %5
%50 = load i8, i8* %49
%51 = sext i8 %50 to i32
%52 = icmp eq i32 %51, 98
br i1 %52, label %53, label %58
53: ; preds = %42
%54 = load i32, i32* %4
%55 = add nsw i32 %54, -1
store i32 %55, i32* %4
%56 = load i8*, i8** %5
%57 = getelementptr inbounds i8, i8* %56, i32 1
store i8* %57, i8** %5
br label %69
58: ; preds = %42
%59 = load i8*, i8** %5
%60 = load i8, i8* %59
%61 = sext i8 %60 to i32
%62 = icmp eq i32 %61, 35
br i1 %62, label %63, label %68
63: ; preds = %58
%64 = load i32, i32* %4
%65 = add nsw i32 %64, 1
store i32 %65, i32* %4
%66 = load i8*, i8** %5
%67 = getelementptr inbounds i8, i8* %66, i32 1
store i8* %67, i8** %5
br label %68
68: ; preds = %63, %58
br label %69
69: ; preds = %68, %53
%70 = load i8*, i8** %5
%71 = call i32 @atoi(i8* %70)
%72 = mul nsw i32 %71, 12
%73 = add nsw i32 %72, 0
%74 = load i32, i32* %4
%75 = add nsw i32 %74, %73
store i32 %75, i32* %4
br label %76
76: ; preds = %69, %39, %32
br label %77
77: ; preds = %76, %28
%78 = load i32, i32* %4
ret i32 %78
}

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 %44, 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 %44, label %22
22: ; preds = %18
%23 = call i32 @toupper(i8 signext %20)
%24 = add i32 %23, -65
%25 = icmp ult i32 %24, 8
br i1 %25, label %26, label %44
26: ; preds = %22
%27 = zext i32 %24 to i64
%28 = getelementptr inbounds [7 x i32], [7 x i32]* @__const.muGetNoteFromName.note_map, i64 0, i64 %27
%29 = load i32, i32* %28
%30 = getelementptr inbounds i8, i8* %19, i64 1
%31 = load i8, i8* %30
switch i8 %31, label %38 [
i8 98, label %32
i8 35, label %35
]
32: ; preds = %26
%33 = add nsw i32 %29, -1
%34 = getelementptr inbounds i8, i8* %19, i64 2
br label %38
35: ; preds = %26
%36 = add nsw i32 %29, 1
%37 = getelementptr inbounds i8, i8* %19, i64 2
br label %38
38: ; preds = %26, %35, %32
%39 = phi i32 [ %33, %32 ], [ %36, %35 ], [ %29, %26 ]
%40 = phi i8* [ %34, %32 ], [ %37, %35 ], [ %30, %26 ]
%41 = call i32 @atoi(i8* %40)
%42 = mul nsw i32 %41, 12
%43 = add nsw i32 %42, %39
br label %44
44: ; preds = %9, %22, %38, %18
%45 = phi i32 [ %43, %38 ], [ %24, %22 ], [ 0, %18 ], [ 0, %9 ]
ret i32 %45
}