#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 uint16_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
void writesource(const uint16_t table[], int len) {
  printf("#include <stdint.h>\n\n");
  printf("static const uint16_t notestable[] = {\n");
  const char *notes[] = {"C",  "C#", "D",  "D#", "E",  "F",
                         "F#", "G",  "G#", "A",  "A#", "B"};
  printf("/*");
  for (int i = 0; i < 12; i++) {
    printf("%7s", notes[i]);
  }
  printf(" */");
  for (int i = 0; i < len; i++) {
    if ((i % 12) == 0) {
      printf("\n    ");
    }
    printf("%5d", table[i]);
    if (i < (len - 1)) {
      printf(", ");
    }
  }
  printf("\n};\n");
}


x86 assembly (clang, -O0):
<writesource>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    0xec7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xecf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x70(%rbp),%rdi
lea    0x2c67(%rip),%rsi
mov    $0x60,%edx
call   1040 <memcpy@plt>
lea    0xef1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x74(%rbp)
cmpl   $0xc,-0x74(%rbp)
jge    11a7 <writesource+0x87>
movslq -0x74(%rbp),%rax
mov    -0x70(%rbp,%rax,8),%rsi
lea    0xecc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
jmp    1178 <writesource+0x58>
lea    0xeb4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x78(%rbp)
mov    -0x78(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1235 <writesource+0x115>
mov    -0x78(%rbp),%eax
mov    $0xc,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11ea <writesource+0xca>
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
movslq -0x78(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x78(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1222 <writesource+0x102>
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1227 <writesource+0x107>
mov    -0x78(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x78(%rbp)
jmp    11bc <writesource+0x9c>
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writesource>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%r12
lea    0xefd(%rip),%rdi
call   1030 <puts@plt>
lea    0xf06(%rip),%rdi
call   1030 <puts@plt>
lea    0xecd(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xec2(%rip),%r15
lea    0xe9b(%rip),%rsi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe8c(%rip),%rsi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe7e(%rip),%rsi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe6f(%rip),%rsi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe61(%rip),%rsi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe52(%rip),%rsi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe43(%rip),%rsi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe35(%rip),%rsi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe26(%rip),%rsi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe18(%rip),%rsi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe09(%rip),%rsi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xdfb(%rip),%rsi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xdf3(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
test   %r14d,%r14d
jle    12b0 <writesource+0x190>
lea    -0x1(%r14),%ebx
mov    %r14d,%ebp
mov    $0xaaaaaaab,%r14d
lea    0xddd(%rip),%r13
xor    %r15d,%r15d
jmp    1269 <writesource+0x149>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%r15
cmp    %r15,%rbp
je     12b0 <writesource+0x190>
mov    %r15d,%eax
imul   %r14,%rax
shr    $0x23,%rax
shl    $0x2,%eax
lea    (%rax,%rax,2),%eax
cmp    %eax,%r15d
jne    128d <writesource+0x16d>
lea    0xda2(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%r12,%r15,4),%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    %rbx,%r15
jae    1260 <writesource+0x140>
lea    0xd8b(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1260 <writesource+0x140>
lea    0xdba(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [22 x i8] c"#include <stdint.h>\0A\0A\00"
@.str.1 = [40 x i8] c"static const uint16_t notestable[] = {\0A\00"
@.str.2 = [2 x i8] c"C\00"
@.str.3 = [3 x i8] c"C#\00"
@.str.4 = [2 x i8] c"D\00"
@.str.5 = [3 x i8] c"D#\00"
@.str.6 = [2 x i8] c"E\00"
@.str.7 = [2 x i8] c"F\00"
@.str.8 = [3 x i8] c"F#\00"
@.str.9 = [2 x i8] c"G\00"
@.str.10 = [3 x i8] c"G#\00"
@.str.11 = [2 x i8] c"A\00"
@.str.12 = [3 x i8] c"A#\00"
@.str.13 = [2 x i8] c"B\00"
@__const.writesource.notes = [12 x i8*] [i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.11, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.12, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.13, i32 0, i32 0)]
@.str.14 = [3 x i8] c"/*\00"
@.str.15 = [4 x i8] c"%7s\00"
@.str.16 = [4 x i8] c" */\00"
@.str.17 = [6 x i8] c"\0A \00"
@.str.18 = [4 x i8] c"%5d\00"
@.str.19 = [3 x i8] c", \00"
@.str.20 = [5 x i8] c"\0A};\0A\00"
define void @writesource(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca [12 x i8*]
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
%10 = bitcast [12 x i8*]* %5 to i8*
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.14, i64 0, i64 0))
store i32 0, i32* %6
br label %12
12: ; preds = %21, %2
%13 = load i32, i32* %6
%14 = icmp slt i32 %13, 12
br i1 %14, label %15, label %24
15: ; preds = %12
%16 = load i32, i32* %6
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [12 x i8*], [12 x i8*]* %5, i64 0, i64 %17
%19 = load i8*, i8** %18
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.15, i64 0, i64 0), i8* %19)
br label %21
21: ; preds = %15
%22 = load i32, i32* %6
%23 = add nsw i32 %22, 1
store i32 %23, i32* %6
br label %12
24: ; preds = %12
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.16, i64 0, i64 0))
store i32 0, i32* %7
br label %26
26: ; preds = %50, %24
%27 = load i32, i32* %7
%28 = load i32, i32* %4
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %53
30: ; preds = %26
%31 = load i32, i32* %7
%32 = srem i32 %31, 12
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %30
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.17, i64 0, i64 0))
br label %36
36: ; preds = %34, %30
%37 = load i32*, i32** %3
%38 = load i32, i32* %7
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i32, i32* %37, i64 %39
%41 = load i32, i32* %40
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.18, i64 0, i64 0), i32 %41)
%43 = load i32, i32* %7
%44 = load i32, i32* %4
%45 = sub nsw i32 %44, 1
%46 = icmp slt i32 %43, %45
br i1 %46, label %47, label %49
47: ; preds = %36
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.19, i64 0, i64 0))
br label %49
49: ; preds = %47, %36
br label %50
50: ; preds = %49
%51 = load i32, i32* %7
%52 = add nsw i32 %51, 1
store i32 %52, i32* %7
br label %26
53: ; preds = %26
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.20, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str.2 = [2 x i8] c"C\00"
@.str.3 = [3 x i8] c"C#\00"
@.str.4 = [2 x i8] c"D\00"
@.str.5 = [3 x i8] c"D#\00"
@.str.6 = [2 x i8] c"E\00"
@.str.7 = [2 x i8] c"F\00"
@.str.8 = [3 x i8] c"F#\00"
@.str.9 = [2 x i8] c"G\00"
@.str.10 = [3 x i8] c"G#\00"
@.str.11 = [2 x i8] c"A\00"
@.str.12 = [3 x i8] c"A#\00"
@.str.13 = [2 x i8] c"B\00"
@.str.14 = [3 x i8] c"/*\00"
@.str.15 = [4 x i8] c"%7s\00"
@.str.16 = [4 x i8] c" */\00"
@.str.17 = [6 x i8] c"\0A \00"
@.str.18 = [4 x i8] c"%5d\00"
@.str.19 = [3 x i8] c", \00"
@str = [21 x i8] c"#include <stdint.h>\0A\00"
@str.21 = [39 x i8] c"static const uint16_t notestable[] = {\00"
@str.22 = [4 x i8] c"\0A};\00"
define void @writesource(i32* nocapture %0, i32 %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.21, i64 0, i64 0))
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.14, i64 0, i64 0))
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.15, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.15, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.15, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.15, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.15, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.15, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.15, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.15, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.15, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0))
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.15, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.11, i64 0, i64 0))
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.15, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.12, i64 0, i64 0))
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.15, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.13, i64 0, i64 0))
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.16, i64 0, i64 0))
%19 = icmp sgt i32 %1, 0
br i1 %19, label %20, label %24
20: ; preds = %2
%21 = add nsw i32 %1, -1
%22 = zext i32 %21 to i64
%23 = zext i32 %1 to i64
br label %26
24: ; preds = %40, %2
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str.22, i64 0, i64 0))
ret void
26: ; preds = %20, %40
%27 = phi i64 [ 0, %20 ], [ %41, %40 ]
%28 = trunc i64 %27 to i32
%29 = urem i32 %28, 12
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %26
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.17, i64 0, i64 0))
br label %33
33: ; preds = %31, %26
%34 = getelementptr inbounds i32, i32* %0, i64 %27
%35 = load i32, i32* %34
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.18, i64 0, i64 0), i32 %35)
%37 = icmp ult i64 %27, %22
br i1 %37, label %38, label %40
38: ; preds = %33
%39 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.19, i64 0, i64 0))
br label %40
40: ; preds = %33, %38
%41 = add nuw nsw i64 %27, 1
%42 = icmp eq i64 %41, %23
br i1 %42, label %24, label %26
}