#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 *DuplicateString(char *);
char *ResizedAppend(char *, char *, int);
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ exit_wrapper(int);
int /*<<< orphan*/ puts(char *);
char *ConvertNoteNum(unsigned char notenum) {
  signed int octave = 0;
  char *string = NULL;
  char buffer[3] = {0};
  (assert(notenum < 128));
  switch (notenum % 12) {
  case 1:
    buffer[1] = '#';
  case 0:
    buffer[0] = 'C';
    break;
  case 3:
    buffer[1] = '#';
  case 2:
    buffer[0] = 'D';
    break;
  case 4:
    buffer[0] = 'E';
    break;
  case 6:
    buffer[1] = '#';
  case 5:
    buffer[0] = 'F';
    break;
  case 8:
    buffer[1] = '#';
  case 7:
    buffer[0] = 'G';
    break;
  case 10:
    buffer[1] = '#';
  case 9:
    buffer[0] = 'A';
    break;
  case 11:
    buffer[0] = 'B';
    break;
  default:
    (void)puts("Logic error: x%12 cannot equal 12\nAborting\n");
    exit_wrapper(1);
    break;
  }
  string = DuplicateString(buffer);
  octave = notenum / 12 - 1;
  if (octave < 0)
    string = ResizedAppend(string, "-1", 1);
  else {
    (assert(octave <= 9));
    buffer[0] = '0' + octave;
    buffer[1] = 0;
    string = ResizedAppend(string, buffer, 1);
  }
  return string;
}


x86 assembly (clang, -O0):
<ConvertNoteNum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
movl   $0x0,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movb   $0x0,-0x12(%rbp)
movw   $0x0,-0x14(%rbp)
movzbl -0x1(%rbp),%eax
sub    $0x80,%eax
setl   %al
movzbl %al,%edi
call   1060 <assert@plt>
movzbl -0x1(%rbp),%eax
mov    %eax,%ecx
mov    %ecx,%eax
mov    $0xaaaaaaab,%edx
imul   %rdx,%rcx
shr    $0x23,%rcx
mov    %ecx,%edx
shl    $0x2,%edx
mov    %edx,%ecx
lea    (%rcx,%rcx,2),%ecx
sub    %ecx,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0xb,%eax
ja     1222 <ConvertNoteNum+0xd2>
mov    -0x20(%rbp),%rax
lea    0xe3a(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movb   $0x23,-0x13(%rbp)
movb   $0x43,-0x14(%rbp)
jmp    1238 <ConvertNoteNum+0xe8>
movb   $0x23,-0x13(%rbp)
movb   $0x44,-0x14(%rbp)
jmp    1238 <ConvertNoteNum+0xe8>
movb   $0x45,-0x14(%rbp)
jmp    1238 <ConvertNoteNum+0xe8>
movb   $0x23,-0x13(%rbp)
movb   $0x46,-0x14(%rbp)
jmp    1238 <ConvertNoteNum+0xe8>
movb   $0x23,-0x13(%rbp)
movb   $0x47,-0x14(%rbp)
jmp    1238 <ConvertNoteNum+0xe8>
movb   $0x23,-0x13(%rbp)
movb   $0x41,-0x14(%rbp)
jmp    1238 <ConvertNoteNum+0xe8>
movb   $0x42,-0x14(%rbp)
jmp    1238 <ConvertNoteNum+0xe8>
lea    0xe07(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1050 <exit_wrapper@plt>
lea    -0x14(%rbp),%rdi
call   1040 <DuplicateString@plt>
mov    %rax,-0x10(%rbp)
movzbl -0x1(%rbp),%eax
mov    $0xc,%ecx
cltd
idiv   %ecx
sub    $0x1,%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    127f <ConvertNoteNum+0x12f>
mov    -0x10(%rbp),%rdi
lea    0xdf0(%rip),%rsi
mov    $0x1,%edx
call   1070 <ResizedAppend@plt>
mov    %rax,-0x10(%rbp)
jmp    12b3 <ConvertNoteNum+0x163>
cmpl   $0x9,-0x8(%rbp)
setle  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x8(%rbp),%eax
add    $0x30,%eax
mov    %al,-0x14(%rbp)
movb   $0x0,-0x13(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x14(%rbp),%rsi
mov    $0x1,%edx
call   1070 <ResizedAppend@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ConvertNoteNum>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebp
movb   $0x0,0xe(%rsp)
movw   $0x0,0xc(%rsp)
mov    %ebp,%eax
not    %al
shr    $0x7,%al
movzbl %al,%edi
call   1060 <assert@plt>
imul   $0xab,%ebp,%ebx
shr    $0xb,%ebx
lea    0x0(,%rbx,4),%eax
lea    (%rax,%rax,2),%ecx
mov    %ebp,%eax
sub    %cl,%al
cmp    $0xb,%al
ja     11ed <ConvertNoteNum+0x9d>
movzbl %al,%eax
lea    0xe66(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movb   $0x23,0xd(%rsp)
movb   $0x43,0xc(%rsp)
jmp    1203 <ConvertNoteNum+0xb3>
movb   $0x23,0xd(%rsp)
movb   $0x44,0xc(%rsp)
jmp    1203 <ConvertNoteNum+0xb3>
movb   $0x45,0xc(%rsp)
jmp    1203 <ConvertNoteNum+0xb3>
movb   $0x23,0xd(%rsp)
movb   $0x46,0xc(%rsp)
jmp    1203 <ConvertNoteNum+0xb3>
movb   $0x23,0xd(%rsp)
movb   $0x47,0xc(%rsp)
jmp    1203 <ConvertNoteNum+0xb3>
movb   $0x23,0xd(%rsp)
movb   $0x41,0xc(%rsp)
jmp    1203 <ConvertNoteNum+0xb3>
movb   $0x42,0xc(%rsp)
jmp    1203 <ConvertNoteNum+0xb3>
lea    0xe3c(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1050 <exit_wrapper@plt>
lea    0xc(%rsp),%rdi
call   1040 <DuplicateString@plt>
mov    %rax,%r14
cmp    $0xb,%bpl
ja     121f <ConvertNoteNum+0xcf>
lea    0xe3f(%rip),%rsi
jmp    123f <ConvertNoteNum+0xef>
xor    %edi,%edi
cmp    $0x84,%bpl
setb   %dil
call   1060 <assert@plt>
add    $0x2f,%bl
mov    %bl,0xc(%rsp)
movb   $0x0,0xd(%rsp)
lea    0xc(%rsp),%rsi
mov    %r14,%rdi
mov    $0x1,%edx
call   1070 <ResizedAppend@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [44 x i8] c"Logic error: x%12 cannot equal 12\0AAborting\0A\00"
@.str.1 = [3 x i8] c"-1\00"
define i8* @ConvertNoteNum(i8 zeroext %0) {
%2 = alloca i8
%3 = alloca i32
%4 = alloca i8*
%5 = alloca [3 x i8]
store i8 %0, i8* %2
store i32 0, i32* %3
store i8* null, i8** %4
%6 = bitcast [3 x i8]* %5 to i8*
%7 = load i8, i8* %2
%8 = zext i8 %7 to i32
%9 = icmp slt i32 %8, 128
%10 = zext i1 %9 to i32
%11 = call i32 @assert(i32 %10)
%12 = load i8, i8* %2
%13 = zext i8 %12 to i32
%14 = srem i32 %13, 12
switch i32 %14, label %39 [
i32 1, label %15
i32 0, label %17
i32 3, label %19
i32 2, label %21
i32 4, label %23
i32 6, label %25
i32 5, label %27
i32 8, label %29
i32 7, label %31
i32 10, label %33
i32 9, label %35
i32 11, label %37
]
15: ; preds = %1
%16 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 1
store i8 35, i8* %16
br label %17
17: ; preds = %1, %15
%18 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
store i8 67, i8* %18
br label %42
19: ; preds = %1
%20 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 1
store i8 35, i8* %20
br label %21
21: ; preds = %1, %19
%22 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
store i8 68, i8* %22
br label %42
23: ; preds = %1
%24 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
store i8 69, i8* %24
br label %42
25: ; preds = %1
%26 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 1
store i8 35, i8* %26
br label %27
27: ; preds = %1, %25
%28 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
store i8 70, i8* %28
br label %42
29: ; preds = %1
%30 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 1
store i8 35, i8* %30
br label %31
31: ; preds = %1, %29
%32 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
store i8 71, i8* %32
br label %42
33: ; preds = %1
%34 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 1
store i8 35, i8* %34
br label %35
35: ; preds = %1, %33
%36 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
store i8 65, i8* %36
br label %42
37: ; preds = %1
%38 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
store i8 66, i8* %38
br label %42
39: ; preds = %1
%40 = call i32 @puts(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
%41 = call i32 @exit_wrapper(i32 1)
br label %42
42: ; preds = %39, %37, %35, %31, %27, %23, %21, %17
%43 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
%44 = call i8* @DuplicateString(i8* %43)
store i8* %44, i8** %4
%45 = load i8, i8* %2
%46 = zext i8 %45 to i32
%47 = sdiv i32 %46, 12
%48 = sub nsw i32 %47, 1
store i32 %48, i32* %3
%49 = load i32, i32* %3
%50 = icmp slt i32 %49, 0
br i1 %50, label %51, label %54
51: ; preds = %42
%52 = load i8*, i8** %4
%53 = call i8* @ResizedAppend(i8* %52, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 1)
store i8* %53, i8** %4
br label %67
54: ; preds = %42
%55 = load i32, i32* %3
%56 = icmp sle i32 %55, 9
%57 = zext i1 %56 to i32
%58 = call i32 @assert(i32 %57)
%59 = load i32, i32* %3
%60 = add nsw i32 48, %59
%61 = trunc i32 %60 to i8
%62 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
store i8 %61, i8* %62
%63 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 1
store i8 0, i8* %63
%64 = load i8*, i8** %4
%65 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
%66 = call i8* @ResizedAppend(i8* %64, i8* %65, i32 1)
store i8* %66, i8** %4
br label %67
67: ; preds = %54, %51
%68 = load i8*, i8** %4
ret i8* %68
}

LLVM IR (-O2):
@.str = [44 x i8] c"Logic error: x%12 cannot equal 12\0AAborting\0A\00"
@.str.1 = [3 x i8] c"-1\00"
define i8* @ConvertNoteNum(i8 zeroext %0) {
%2 = alloca [3 x i8]
%3 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 0
%4 = xor i8 %0, -1
%5 = lshr i8 %4, 7
%6 = zext i8 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = urem i8 %0, 12
%9 = udiv i8 %0, 12
%10 = zext i8 %8 to i32
switch i32 %10, label %28 [
i32 1, label %11
i32 0, label %13
i32 3, label %14
i32 2, label %16
i32 4, label %17
i32 6, label %18
i32 5, label %20
i32 8, label %21
i32 7, label %23
i32 10, label %24
i32 9, label %26
i32 11, label %27
]
11: ; preds = %1
%12 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 1
store i8 35, i8* %12
br label %13
13: ; preds = %1, %11
store i8 67, i8* %3
br label %31
14: ; preds = %1
%15 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 1
store i8 35, i8* %15
br label %16
16: ; preds = %1, %14
store i8 68, i8* %3
br label %31
17: ; preds = %1
store i8 69, i8* %3
br label %31
18: ; preds = %1
%19 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 1
store i8 35, i8* %19
br label %20
20: ; preds = %1, %18
store i8 70, i8* %3
br label %31
21: ; preds = %1
%22 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 1
store i8 35, i8* %22
br label %23
23: ; preds = %1, %21
store i8 71, i8* %3
br label %31
24: ; preds = %1
%25 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 1
store i8 35, i8* %25
br label %26
26: ; preds = %1, %24
store i8 65, i8* %3
br label %31
27: ; preds = %1
store i8 66, i8* %3
br label %31
28: ; preds = %1
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
%30 = tail call i32 @exit_wrapper(i32 1)
br label %31
31: ; preds = %28, %27, %26, %23, %20, %17, %16, %13
%32 = call i8* @DuplicateString(i8* %3)
%33 = icmp ult i8 %0, 12
br i1 %33, label %34, label %36
34: ; preds = %31
%35 = call i8* @ResizedAppend(i8* %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 1)
br label %43
36: ; preds = %31
%37 = icmp ult i8 %0, -124
%38 = zext i1 %37 to i32
%39 = call i32 @assert(i32 %38)
%40 = add nuw nsw i8 %9, 47
store i8 %40, i8* %3
%41 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 1
store i8 0, i8* %41
%42 = call i8* @ResizedAppend(i8* %32, i8* %3, i32 1)
br label %43
43: ; preds = %36, %34
%44 = phi i8* [ %35, %34 ], [ %42, %36 ]
ret i8* %44
}