#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 *);
scalar_t__ isdigit(char);
char *scan_note(char *arg, int *note, int *length) {
  int notes[12] = {'C', 'X', 'D', 'X', 'E', 'F', 'X', 'G', 'X', 'A', 'X', 'B'};
  char *p;
  int i;
  *length = 16;
  p = arg;
  for (i = 0; i < 12; i++) {
    if (*p == notes[i]) {
      *note = i;
      break;
    }
  }
  p++;
  if (*p == '#' || *p == '+') {
    (*note)++;
    p++;
  } else if (*p == '-') {
    (*note)--;
    p++;
  }
  if (isdigit(*p)) {
    *length = atoi(p);
    while (isdigit(*p)) {
      p++;
    }
  }
  return p;
}


x86 assembly (clang, -O0):
<scan_note>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x50(%rbp),%rdi
lea    0xeb1(%rip),%rsi
mov    $0x30,%edx
call   1040 <memcpy@plt>
mov    -0x18(%rbp),%rax
movl   $0x10,(%rax)
mov    -0x8(%rbp),%rax
mov    %rax,-0x58(%rbp)
movl   $0x0,-0x5c(%rbp)
cmpl   $0xc,-0x5c(%rbp)
jge    11b2 <scan_note+0x82>
mov    -0x58(%rbp),%rax
movsbl (%rax),%eax
movslq -0x5c(%rbp),%rcx
cmp    -0x50(%rbp,%rcx,4),%eax
jne    119f <scan_note+0x6f>
mov    -0x5c(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
jmp    11b2 <scan_note+0x82>
jmp    11a4 <scan_note+0x74>
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    1172 <scan_note+0x42>
mov    -0x58(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
je     11de <scan_note+0xae>
mov    -0x58(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2b,%eax
jne    11fa <scan_note+0xca>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x58(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x58(%rbp)
jmp    1226 <scan_note+0xf6>
mov    -0x58(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    1221 <scan_note+0xf1>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0xffffffff,%ecx
mov    %ecx,(%rax)
mov    -0x58(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x58(%rbp)
jmp    1226 <scan_note+0xf6>
mov    -0x58(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     1279 <scan_note+0x149>
mov    -0x58(%rbp),%rdi
call   1050 <atoi@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x58(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     1274 <scan_note+0x144>
mov    -0x58(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x58(%rbp)
jmp    124d <scan_note+0x11d>
jmp    1279 <scan_note+0x149>
mov    -0x58(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scan_note>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rdi,%rbx
movl   $0x10,(%rdx)
mov    (%rdi),%cl
add    $0xbf,%cl
cmp    $0x17,%cl
ja     1180 <scan_note+0x60>
xor    %eax,%eax
movzbl %cl,%ecx
lea    0xeba(%rip),%rdx
movslq (%rdx,%rcx,4),%rcx
add    %rdx,%rcx
jmp    *%rcx
mov    $0x9,%eax
jmp    117e <scan_note+0x5e>
mov    $0xb,%eax
jmp    117e <scan_note+0x5e>
mov    $0x2,%eax
jmp    117e <scan_note+0x5e>
mov    $0x4,%eax
jmp    117e <scan_note+0x5e>
mov    $0x5,%eax
jmp    117e <scan_note+0x5e>
mov    $0x7,%eax
jmp    117e <scan_note+0x5e>
mov    $0x1,%eax
mov    %eax,(%rsi)
mov    0x1(%rbx),%cl
mov    $0x1,%eax
cmp    $0x23,%cl
je     119c <scan_note+0x7c>
cmp    $0x2b,%cl
je     119c <scan_note+0x7c>
cmp    $0x2d,%cl
jne    11a4 <scan_note+0x84>
mov    $0xffffffff,%eax
add    %eax,(%rsi)
add    $0x2,%rbx
jmp    11a8 <scan_note+0x88>
add    $0x1,%rbx
movsbl (%rbx),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     11e2 <scan_note+0xc2>
mov    %rbx,%rdi
call   1040 <atoi@plt>
mov    %eax,(%r14)
add    $0xffffffffffffffff,%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbl 0x1(%rbx),%edi
add    $0x1,%rbx
call   1030 <isdigit@plt>
test   %rax,%rax
jne    11d0 <scan_note+0xb0>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define i8* @scan_note(i8* %0, i32* nocapture %1, i32* nocapture writeonly %2) {
store i32 16, i32* %2
%4 = load i8, i8* %0
switch i8 %4, label %14 [
i8 67, label %12
i8 88, label %5
i8 68, label %6
i8 69, label %7
i8 70, label %8
i8 71, label %9
i8 65, label %10
i8 66, label %11
]
5: ; preds = %3
br label %12
6: ; preds = %3
br label %12
7: ; preds = %3
br label %12
8: ; preds = %3
br label %12
9: ; preds = %3
br label %12
10: ; preds = %3
br label %12
11: ; preds = %3
br label %12
12: ; preds = %3, %11, %10, %9, %8, %7, %6, %5
%13 = phi i32 [ 0, %3 ], [ 1, %5 ], [ 2, %6 ], [ 4, %7 ], [ 5, %8 ], [ 7, %9 ], [ 9, %10 ], [ 11, %11 ]
store i32 %13, i32* %1
br label %14
14: ; preds = %3, %12
%15 = getelementptr inbounds i8, i8* %0, i64 1
%16 = load i8, i8* %15
switch i8 %16, label %23 [
i8 35, label %18
i8 43, label %18
i8 45, label %17
]
17: ; preds = %14
br label %18
18: ; preds = %14, %14, %17
%19 = phi i32 [ -1, %17 ], [ 1, %14 ], [ 1, %14 ]
%20 = load i32, i32* %1
%21 = add nsw i32 %20, %19
store i32 %21, i32* %1
%22 = getelementptr inbounds i8, i8* %0, i64 2
br label %23
23: ; preds = %18, %14
%24 = phi i8* [ %15, %14 ], [ %22, %18 ]
%25 = load i8, i8* %24
%26 = tail call i64 @isdigit(i8 signext %25)
%27 = icmp eq i64 %26, 0
br i1 %27, label %36, label %28
28: ; preds = %23
%29 = tail call i32 @atoi(i8* %24)
store i32 %29, i32* %2
br label %30
30: ; preds = %30, %28
%31 = phi i8* [ %24, %28 ], [ %35, %30 ]
%32 = load i8, i8* %31
%33 = tail call i64 @isdigit(i8 signext %32)
%34 = icmp eq i64 %33, 0
%35 = getelementptr inbounds i8, i8* %31, i64 1
br i1 %34, label %36, label %30
36: ; preds = %30, %23
%37 = phi i8* [ %24, %23 ], [ %31, %30 ]
ret i8* %37
}