int _major_scale(int num) {
  switch (num) {
  case 0:
    return 0;
  case 1:
    return 2;
  case 2:
    return 4;
  case 3:
    return 5;
  case 4:
    return 7;
  case 5:
    return 9;
  case 6:
    return 11;
  default:
    if (num < 0) {
      return _major_scale(num + 7) - 12;
    } else {
      return _major_scale(num - 7) + 12;
    }
  }
}


x86 assembly (clang, -O0):
<_major_scale>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %rax,-0x10(%rbp)
sub    $0x6,%rax
ja     1194 <_major_scale+0x84>
mov    -0x10(%rbp),%rax
lea    0xec9(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x0,-0x4(%rbp)
jmp    11c5 <_major_scale+0xb5>
movl   $0x2,-0x4(%rbp)
jmp    11c5 <_major_scale+0xb5>
movl   $0x4,-0x4(%rbp)
jmp    11c5 <_major_scale+0xb5>
movl   $0x5,-0x4(%rbp)
jmp    11c5 <_major_scale+0xb5>
movl   $0x7,-0x4(%rbp)
jmp    11c5 <_major_scale+0xb5>
movl   $0x9,-0x4(%rbp)
jmp    11c5 <_major_scale+0xb5>
movl   $0xb,-0x4(%rbp)
jmp    11c5 <_major_scale+0xb5>
cmpl   $0x0,-0x8(%rbp)
jge    11b4 <_major_scale+0xa4>
mov    -0x8(%rbp),%edi
add    $0x7,%edi
call   1030 <_major_scale@plt>
sub    $0xc,%eax
mov    %eax,-0x4(%rbp)
jmp    11c5 <_major_scale+0xb5>
mov    -0x8(%rbp),%edi
sub    $0x7,%edi
call   1030 <_major_scale@plt>
add    $0xc,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_major_scale>:
push   %rbx
movslq %edi,%rax
lea    0xee5(%rip),%rcx
lea    (%rcx,%rax,4),%rax
xor    %ebx,%ebx
cmp    $0x7,%edi
jb     1143 <_major_scale+0x33>
cs nopw 0x0(%rax,%rax,1)
test   %edi,%edi
jns    1147 <_major_scale+0x37>
add    $0x7,%edi
add    $0xfffffff4,%ebx
add    $0x1c,%rax
cmp    $0x7,%edi
jae    1130 <_major_scale+0x20>
add    (%rax),%ebx
jmp    1154 <_major_scale+0x44>
add    $0xfffffff9,%edi
call   1030 <_major_scale@plt>
add    %eax,%ebx
add    $0xc,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @_major_scale(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
switch i32 %4, label %12 [
i32 0, label %5
i32 1, label %6
i32 2, label %7
i32 3, label %8
i32 4, label %9
i32 5, label %10
i32 6, label %11
]
5: ; preds = %1
store i32 0, i32* %2
br label %25
6: ; preds = %1
store i32 2, i32* %2
br label %25
7: ; preds = %1
store i32 4, i32* %2
br label %25
8: ; preds = %1
store i32 5, i32* %2
br label %25
9: ; preds = %1
store i32 7, i32* %2
br label %25
10: ; preds = %1
store i32 9, i32* %2
br label %25
11: ; preds = %1
store i32 11, i32* %2
br label %25
12: ; preds = %1
%13 = load i32, i32* %3
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %12
%16 = load i32, i32* %3
%17 = add nsw i32 %16, 7
%18 = call i32 @_major_scale(i32 %17)
%19 = sub nsw i32 %18, 12
store i32 %19, i32* %2
br label %25
20: ; preds = %12
%21 = load i32, i32* %3
%22 = sub nsw i32 %21, 7
%23 = call i32 @_major_scale(i32 %22)
%24 = add nsw i32 %23, 12
store i32 %24, i32* %2
br label %25
25: ; preds = %20, %15, %11, %10, %9, %8, %7, %6, %5
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
@switch.table._major_scale = [7 x i32] [i32 0, i32 2, i32 4, i32 5, i32 7, i32 9, i32 11]
define i32 @_major_scale(i32 %0) {
br label %2
2: ; preds = %8, %1
%3 = phi i32 [ 0, %1 ], [ %10, %8 ]
%4 = phi i32 [ %0, %1 ], [ %9, %8 ]
%5 = icmp ult i32 %4, 7
br i1 %5, label %18, label %6
6: ; preds = %2
%7 = icmp slt i32 %4, 0
br i1 %7, label %8, label %13
8: ; preds = %6
%9 = add nsw i32 %4, 7
%10 = add nsw i32 %3, -12
br label %2
11: ; preds = %18, %13
%12 = phi i32 [ %17, %13 ], [ %22, %18 ]
ret i32 %12
13: ; preds = %6
%14 = add nsw i32 %4, -7
%15 = tail call i32 @_major_scale(i32 %14)
%16 = add i32 %3, 12
%17 = add i32 %16, %15
br label %11
18: ; preds = %2
%19 = sext i32 %4 to i64
%20 = getelementptr inbounds [7 x i32], [7 x i32]* @switch.table._major_scale, i64 0, i64 %19
%21 = load i32, i32* %20
%22 = add nsw i32 %21, %3
br label %11
}