#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 /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ ParseMidiFile(char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ _memcpy(char *, char *, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ lengthContaining(char *, char *);
int lengthNotContaining(char *, char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, char const *, ...);
int main(int argc, char **argv) {
  if (argc < 2) {
    printf("Usage: midi.exe [name of directory]\n");
    return 0;
  }
  const char *dirName = argv[1];
  char midiTxtFileName[256] = {};
  sprintf(midiTxtFileName, "%s/midi.txt", dirName);
  FILE *midiTextFile = fopen(midiTxtFileName, "rb");
  if (midiTextFile == NULL) {
    printf("Could not open '%s', skipping.\n", midiTxtFileName);
    return 0;
  }
  fseek(midiTextFile, 0, SEEK_END);
  int midiTextFileSize = ftell(midiTextFile);
  fseek(midiTextFile, 0, SEEK_SET);
  char *midiTextFileBuffer = (char *)malloc(midiTextFileSize + 1);
  fread(midiTextFileBuffer, 1, midiTextFileSize, midiTextFile);
  midiTextFileBuffer[midiTextFileSize] = '\0';
  fclose(midiTextFile);
  char midiAssetFileName[256] = {};
  sprintf(midiAssetFileName, "%s/midi.h", dirName);
  FILE *midiAssetFile = fopen(midiAssetFileName, "wb");
  fprintf(
      midiAssetFile,
      "typedef struct{int start; unsigned short length; short pitch;} Note;");
  fprintf(midiAssetFile, "typedef struct{Note* notes; int length;} Song;");
  char *fileCursor = midiTextFileBuffer;
  while (fileCursor - midiTextFileBuffer < midiTextFileSize) {
    fileCursor += lengthContaining(fileCursor, "\t\r\n ");
    int midiFileNameLength = lengthNotContaining(fileCursor, "\t\r\n :");
    char *midiFileName = (char *)malloc(midiFileNameLength + 1);
    _memcpy(midiFileName, fileCursor, midiFileNameLength);
    midiFileName[midiFileNameLength] = '\0';
    fileCursor += midiFileNameLength;
    fileCursor += lengthContaining(fileCursor, "\t\r\n ");
    {
      if (!(*fileCursor == ':')) {
        printf("Assertion failed!\n'%s'\n", "*fileCursor == ':'");
      }
    };
    fileCursor++;
    fileCursor += lengthContaining(fileCursor, "\t\r\n ");
    int varNameLength = lengthNotContaining(fileCursor, "\t\r\n ");
    char *midiVarName = (char *)malloc(varNameLength + 1);
    _memcpy(midiVarName, fileCursor, varNameLength);
    midiVarName[varNameLength] = '\0';
    char midiFileNameFull[256] = {};
    sprintf(midiFileNameFull, "%s/%s", dirName, midiFileName);
    ParseMidiFile(midiFileNameFull, midiVarName, midiAssetFile);
    fileCursor += varNameLength;
    fileCursor += lengthContaining(fileCursor, "\t\r\n ");
    free(midiFileName);
    free(midiVarName);
  }
  fclose(midiAssetFile);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x370,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    122d <main+0x3d>
lea    0xde6(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    161b <main+0x42b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1080 <memset@plt>
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xdc7(%rip),%rsi
mov    $0x0,%al
call   1110 <sprintf@plt>
lea    -0x120(%rbp),%rdi
lea    0xdbe(%rip),%rsi
call   1100 <fopen@plt>
mov    %rax,-0x128(%rbp)
cmpq   $0x0,-0x128(%rbp)
jne    12ae <main+0xbe>
lea    -0x120(%rbp),%rsi
lea    0xd99(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    161b <main+0x42b>
mov    -0x128(%rbp),%rdi
mov    0x2d2c(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10f0 <fseek@plt>
mov    -0x128(%rbp),%rdi
call   10b0 <ftell@plt>
mov    %eax,-0x12c(%rbp)
mov    -0x128(%rbp),%rdi
mov    0x2cf3(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10f0 <fseek@plt>
mov    -0x12c(%rbp),%edi
add    $0x1,%edi
call   10e0 <malloc@plt>
mov    %rax,-0x138(%rbp)
mov    -0x138(%rbp),%rdi
mov    -0x12c(%rbp),%edx
mov    -0x128(%rbp),%rcx
mov    $0x1,%esi
call   1050 <fread@plt>
mov    -0x138(%rbp),%rax
movslq -0x12c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x128(%rbp),%rdi
call   1060 <fclose@plt>
lea    -0x240(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1080 <memset@plt>
lea    -0x240(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xcf0(%rip),%rsi
mov    $0x0,%al
call   1110 <sprintf@plt>
lea    -0x240(%rbp),%rdi
lea    0xce5(%rip),%rsi
call   1100 <fopen@plt>
mov    %rax,-0x248(%rbp)
mov    -0x248(%rbp),%rdi
lea    0xcce(%rip),%rsi
call   10a0 <fprintf@plt>
mov    -0x248(%rbp),%rdi
lea    0xd00(%rip),%rsi
call   10a0 <fprintf@plt>
mov    -0x138(%rbp),%rax
mov    %rax,-0x250(%rbp)
mov    -0x250(%rbp),%rax
mov    -0x138(%rbp),%rcx
sub    %rcx,%rax
movslq -0x12c(%rbp),%rcx
cmp    %rcx,%rax
jge    1608 <main+0x418>
mov    -0x250(%rbp),%rdi
lea    0xced(%rip),%rsi
call   10d0 <lengthContaining@plt>
mov    %eax,%ecx
mov    -0x250(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x250(%rbp)
mov    -0x250(%rbp),%rdi
lea    0xcc9(%rip),%rsi
call   10c0 <lengthNotContaining@plt>
mov    %eax,-0x254(%rbp)
mov    -0x254(%rbp),%edi
add    $0x1,%edi
call   10e0 <malloc@plt>
mov    %rax,-0x260(%rbp)
mov    -0x260(%rbp),%rdi
mov    -0x250(%rbp),%rsi
mov    -0x254(%rbp),%edx
call   1040 <_memcpy@plt>
mov    -0x260(%rbp),%rax
movslq -0x254(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x254(%rbp),%ecx
mov    -0x250(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x250(%rbp)
mov    -0x250(%rbp),%rdi
lea    0xc51(%rip),%rsi
call   10d0 <lengthContaining@plt>
mov    %eax,%ecx
mov    -0x250(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x250(%rbp)
mov    -0x250(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
je     14c7 <main+0x2d7>
lea    0xc27(%rip),%rdi
lea    0xc38(%rip),%rsi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x250(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x250(%rbp)
mov    -0x250(%rbp),%rdi
lea    0xbee(%rip),%rsi
call   10d0 <lengthContaining@plt>
mov    %eax,%ecx
mov    -0x250(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x250(%rbp)
mov    -0x250(%rbp),%rdi
lea    0xbc5(%rip),%rsi
call   10c0 <lengthNotContaining@plt>
mov    %eax,-0x264(%rbp)
mov    -0x264(%rbp),%edi
add    $0x1,%edi
call   10e0 <malloc@plt>
mov    %rax,-0x270(%rbp)
mov    -0x270(%rbp),%rdi
mov    -0x250(%rbp),%rsi
mov    -0x264(%rbp),%edx
call   1040 <_memcpy@plt>
mov    -0x270(%rbp),%rax
movslq -0x264(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
lea    -0x370(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1080 <memset@plt>
lea    -0x370(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x260(%rbp),%rcx
lea    0xb84(%rip),%rsi
mov    $0x0,%al
call   1110 <sprintf@plt>
lea    -0x370(%rbp),%rdi
mov    -0x270(%rbp),%rsi
mov    -0x248(%rbp),%rdx
call   1090 <ParseMidiFile@plt>
mov    -0x264(%rbp),%ecx
mov    -0x250(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x250(%rbp)
mov    -0x250(%rbp),%rdi
lea    0xb05(%rip),%rsi
call   10d0 <lengthContaining@plt>
mov    %eax,%ecx
mov    -0x250(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x250(%rbp)
mov    -0x260(%rbp),%rdi
call   1030 <free@plt>
mov    -0x270(%rbp),%rdi
call   1030 <free@plt>
jmp    13b9 <main+0x1c9>
mov    -0x248(%rbp),%rdi
call   1060 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x370,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x328,%rsp
cmp    $0x1,%edi
jg     1217 <main+0x27>
lea    0xedf(%rip),%rdi
call   1050 <puts@plt>
jmp    15f3 <main+0x403>
mov    0x8(%rsi),%r14
xorps  %xmm0,%xmm0
movaps %xmm0,0x110(%rsp)
movaps %xmm0,0x100(%rsp)
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
lea    0xd6d(%rip),%rsi
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   1100 <sprintf@plt>
lea    0xd60(%rip),%rsi
mov    %rbx,%rdi
call   10f0 <fopen@plt>
test   %rax,%rax
je     15e0 <main+0x3f0>
mov    %rax,%rbx
mov    0x2d21(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10e0 <fseek@plt>
mov    %rbx,%rdi
call   10a0 <ftell@plt>
mov    %eax,%r15d
mov    0x2cf3(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10e0 <fseek@plt>
lea    0x1(%r15),%edi
call   10d0 <malloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    $0x1,%esi
mov    %r15d,%edx
mov    %rbx,%rcx
call   1060 <fread@plt>
movslq %r15d,%r15
mov    %rbp,(%rsp)
movb   $0x0,0x0(%rbp,%r15,1)
mov    %rbx,%rdi
call   1070 <fclose@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x310(%rsp)
movaps %xmm0,0x300(%rsp)
movaps %xmm0,0x2f0(%rsp)
movaps %xmm0,0x2e0(%rsp)
movaps %xmm0,0x2d0(%rsp)
movaps %xmm0,0x2c0(%rsp)
movaps %xmm0,0x2b0(%rsp)
movaps %xmm0,0x2a0(%rsp)
movaps %xmm0,0x290(%rsp)
movaps %xmm0,0x280(%rsp)
movaps %xmm0,0x270(%rsp)
movaps %xmm0,0x260(%rsp)
movaps %xmm0,0x250(%rsp)
movaps %xmm0,0x240(%rsp)
movaps %xmm0,0x230(%rsp)
movaps %xmm0,0x220(%rsp)
lea    0xc80(%rip),%rsi
lea    0x220(%rsp),%rbx
mov    %rbx,%rdi
mov    %r14,0x18(%rsp)
mov    %r14,%rdx
xor    %eax,%eax
call   1100 <sprintf@plt>
lea    0xc69(%rip),%rsi
mov    %rbx,%rdi
call   10f0 <fopen@plt>
mov    %rax,%rbx
lea    0xc5a(%rip),%rdi
mov    $0x44,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1110 <fwrite@plt>
lea    0xc86(%rip),%rdi
mov    $0x2e,%esi
mov    $0x1,%edx
mov    %rbx,0x8(%rsp)
mov    %rbx,%rcx
call   1110 <fwrite@plt>
mov    %r15,0x10(%rsp)
test   %r15d,%r15d
jle    15d4 <main+0x3e4>
lea    0xc89(%rip),%r12
mov    (%rsp),%r13
jmp    1559 <main+0x369>
lea    0x1(%rbp),%rdi
mov    %r12,%rsi
call   10c0 <lengthContaining@plt>
cltq
lea    (%rax,%rbp,1),%r14
add    $0x1,%r14
mov    %r14,%rdi
mov    %r12,%rsi
call   10b0 <lengthNotContaining@plt>
mov    %eax,%ebx
lea    0x1(%rbx),%edi
call   10d0 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1040 <_memcpy@plt>
movslq %ebx,%rbx
movb   $0x0,(%r15,%rbx,1)
xorps  %xmm0,%xmm0
movaps %xmm0,0x210(%rsp)
movaps %xmm0,0x200(%rsp)
movaps %xmm0,0x1f0(%rsp)
movaps %xmm0,0x1e0(%rsp)
movaps %xmm0,0x1d0(%rsp)
movaps %xmm0,0x1c0(%rsp)
movaps %xmm0,0x1b0(%rsp)
movaps %xmm0,0x1a0(%rsp)
movaps %xmm0,0x190(%rsp)
movaps %xmm0,0x180(%rsp)
movaps %xmm0,0x170(%rsp)
movaps %xmm0,0x160(%rsp)
movaps %xmm0,0x150(%rsp)
movaps %xmm0,0x140(%rsp)
movaps %xmm0,0x130(%rsp)
movaps %xmm0,0x120(%rsp)
lea    0x120(%rsp),%rbp
mov    %rbp,%rdi
lea    0xbde(%rip),%rsi
mov    0x18(%rsp),%rdx
mov    %r13,%rcx
xor    %eax,%eax
call   1100 <sprintf@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
mov    0x8(%rsp),%rdx
call   1090 <ParseMidiFile@plt>
add    %rbx,%r14
mov    %r14,%rdi
mov    %r12,%rsi
call   10c0 <lengthContaining@plt>
mov    %r13,%rdi
movslq %eax,%r13
add    %r14,%r13
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r13,%rax
sub    (%rsp),%rax
cmp    0x10(%rsp),%rax
jge    15d4 <main+0x3e4>
mov    %r13,%rdi
mov    %r12,%rsi
call   10c0 <lengthContaining@plt>
movslq %eax,%rbx
add    %r13,%rbx
mov    %rbx,%rdi
lea    0xb41(%rip),%rsi
call   10b0 <lengthNotContaining@plt>
mov    %eax,%ebp
lea    0x1(%rbp),%edi
call   10d0 <malloc@plt>
mov    %rax,%r13
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1040 <_memcpy@plt>
movslq %ebp,%rax
movb   $0x0,0x0(%r13,%rax,1)
add    %rax,%rbx
mov    %rbx,%rdi
mov    %r12,%rsi
call   10c0 <lengthContaining@plt>
cltq
lea    (%rbx,%rax,1),%rbp
cmpb   $0x3a,(%rax,%rbx,1)
je     1430 <main+0x240>
lea    0xafa(%rip),%rdi
lea    0xb0b(%rip),%rsi
xor    %eax,%eax
call   1080 <printf@plt>
jmp    1430 <main+0x240>
mov    0x8(%rsp),%rdi
call   1070 <fclose@plt>
jmp    15f3 <main+0x403>
lea    0xa28(%rip),%rdi
lea    0x20(%rsp),%rsi
xor    %eax,%eax
call   1080 <printf@plt>
xor    %eax,%eax
add    $0x328,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [37 x i8] c"Usage: midi.exe [name of directory]\0A\00"
@.str.1 = [12 x i8] c"%s/midi.txt\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [32 x i8] c"Could not open '%s', skipping.\0A\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.4 = [10 x i8] c"%s/midi.h\00"
@.str.5 = [3 x i8] c"wb\00"
@.str.6 = [69 x i8] c"typedef struct{int start; unsigned short length; short pitch;} Note;\00"
@.str.7 = [47 x i8] c"typedef struct{Note* notes; int length;} Song;\00"
@.str.8 = [5 x i8] c"\09\0D\0A \00"
@.str.9 = [6 x i8] c"\09\0D\0A :\00"
@.str.10 = [24 x i8] c"Assertion failed!\0A'%s'\0A\00"
@.str.11 = [19 x i8] c"*fileCursor == ':'\00"
@.str.12 = [6 x i8] c"%s/%s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca [256 x i8]
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca [256 x i8]
%12 = alloca i32*
%13 = alloca i8*
%14 = alloca i32
%15 = alloca i8*
%16 = alloca i32
%17 = alloca i8*
%18 = alloca [256 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%19 = load i32, i32* %4
%20 = icmp slt i32 %19, 2
br i1 %20, label %21, label %23
21: ; preds = %2
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %163
23: ; preds = %2
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
store i8* %26, i8** %6
%27 = bitcast [256 x i8]* %7 to i8*
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%29 = load i8*, i8** %6
%30 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %28, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %29)
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%32 = call i32* @fopen(i8* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %32, i32** %8
%33 = load i32*, i32** %8
%34 = icmp eq i32* %33, null
br i1 %34, label %35, label %38
35: ; preds = %23
%36 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i8* %36)
store i32 0, i32* %3
br label %163
38: ; preds = %23
%39 = load i32*, i32** %8
%40 = load i32, i32* @SEEK_END
%41 = call i32 @fseek(i32* %39, i32 0, i32 %40)
%42 = load i32*, i32** %8
%43 = call i32 @ftell(i32* %42)
store i32 %43, i32* %9
%44 = load i32*, i32** %8
%45 = load i32, i32* @SEEK_SET
%46 = call i32 @fseek(i32* %44, i32 0, i32 %45)
%47 = load i32, i32* %9
%48 = add nsw i32 %47, 1
%49 = call i64 @malloc(i32 %48)
%50 = inttoptr i64 %49 to i8*
store i8* %50, i8** %10
%51 = load i8*, i8** %10
%52 = load i32, i32* %9
%53 = load i32*, i32** %8
%54 = call i32 @fread(i8* %51, i32 1, i32 %52, i32* %53)
%55 = load i8*, i8** %10
%56 = load i32, i32* %9
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8, i8* %55, i64 %57
store i8 0, i8* %58
%59 = load i32*, i32** %8
%60 = call i32 @fclose(i32* %59)
%61 = bitcast [256 x i8]* %11 to i8*
%62 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%63 = load i8*, i8** %6
%64 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %62, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %63)
%65 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%66 = call i32* @fopen(i8* %65, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
store i32* %66, i32** %12
%67 = load i32*, i32** %12
%68 = call i32 @fprintf(i32* %67, i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.6, i64 0, i64 0))
%69 = load i32*, i32** %12
%70 = call i32 @fprintf(i32* %69, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.7, i64 0, i64 0))
%71 = load i8*, i8** %10
store i8* %71, i8** %13
br label %72
72: ; preds = %116, %38
%73 = load i8*, i8** %13
%74 = load i8*, i8** %10
%75 = ptrtoint i8* %73 to i64
%76 = ptrtoint i8* %74 to i64
%77 = sub i64 %75, %76
%78 = load i32, i32* %9
%79 = sext i32 %78 to i64
%80 = icmp slt i64 %77, %79
br i1 %80, label %81, label %160
81: ; preds = %72
%82 = load i8*, i8** %13
%83 = call i32 @lengthContaining(i8* %82, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%84 = load i8*, i8** %13
%85 = sext i32 %83 to i64
%86 = getelementptr inbounds i8, i8* %84, i64 %85
store i8* %86, i8** %13
%87 = load i8*, i8** %13
%88 = call i32 @lengthNotContaining(i8* %87, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0))
store i32 %88, i32* %14
%89 = load i32, i32* %14
%90 = add nsw i32 %89, 1
%91 = call i64 @malloc(i32 %90)
%92 = inttoptr i64 %91 to i8*
store i8* %92, i8** %15
%93 = load i8*, i8** %15
%94 = load i8*, i8** %13
%95 = load i32, i32* %14
%96 = call i32 @_memcpy(i8* %93, i8* %94, i32 %95)
%97 = load i8*, i8** %15
%98 = load i32, i32* %14
%99 = sext i32 %98 to i64
%100 = getelementptr inbounds i8, i8* %97, i64 %99
store i8 0, i8* %100
%101 = load i32, i32* %14
%102 = load i8*, i8** %13
%103 = sext i32 %101 to i64
%104 = getelementptr inbounds i8, i8* %102, i64 %103
store i8* %104, i8** %13
%105 = load i8*, i8** %13
%106 = call i32 @lengthContaining(i8* %105, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%107 = load i8*, i8** %13
%108 = sext i32 %106 to i64
%109 = getelementptr inbounds i8, i8* %107, i64 %108
store i8* %109, i8** %13
%110 = load i8*, i8** %13
%111 = load i8, i8* %110
%112 = sext i8 %111 to i32
%113 = icmp eq i32 %112, 58
br i1 %113, label %116, label %114
114: ; preds = %81
%115 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.11, i64 0, i64 0))
br label %116
116: ; preds = %114, %81
%117 = load i8*, i8** %13
%118 = getelementptr inbounds i8, i8* %117, i32 1
store i8* %118, i8** %13
%119 = load i8*, i8** %13
%120 = call i32 @lengthContaining(i8* %119, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%121 = load i8*, i8** %13
%122 = sext i32 %120 to i64
%123 = getelementptr inbounds i8, i8* %121, i64 %122
store i8* %123, i8** %13
%124 = load i8*, i8** %13
%125 = call i32 @lengthNotContaining(i8* %124, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
store i32 %125, i32* %16
%126 = load i32, i32* %16
%127 = add nsw i32 %126, 1
%128 = call i64 @malloc(i32 %127)
%129 = inttoptr i64 %128 to i8*
store i8* %129, i8** %17
%130 = load i8*, i8** %17
%131 = load i8*, i8** %13
%132 = load i32, i32* %16
%133 = call i32 @_memcpy(i8* %130, i8* %131, i32 %132)
%134 = load i8*, i8** %17
%135 = load i32, i32* %16
%136 = sext i32 %135 to i64
%137 = getelementptr inbounds i8, i8* %134, i64 %136
store i8 0, i8* %137
%138 = bitcast [256 x i8]* %18 to i8*
%139 = getelementptr inbounds [256 x i8], [256 x i8]* %18, i64 0, i64 0
%140 = load i8*, i8** %6
%141 = load i8*, i8** %15
%142 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %139, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.12, i64 0, i64 0), i8* %140, i8* %141)
%143 = getelementptr inbounds [256 x i8], [256 x i8]* %18, i64 0, i64 0
%144 = load i8*, i8** %17
%145 = load i32*, i32** %12
%146 = call i32 @ParseMidiFile(i8* %143, i8* %144, i32* %145)
%147 = load i32, i32* %16
%148 = load i8*, i8** %13
%149 = sext i32 %147 to i64
%150 = getelementptr inbounds i8, i8* %148, i64 %149
store i8* %150, i8** %13
%151 = load i8*, i8** %13
%152 = call i32 @lengthContaining(i8* %151, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%153 = load i8*, i8** %13
%154 = sext i32 %152 to i64
%155 = getelementptr inbounds i8, i8* %153, i64 %154
store i8* %155, i8** %13
%156 = load i8*, i8** %15
%157 = call i32 @free(i8* %156)
%158 = load i8*, i8** %17
%159 = call i32 @free(i8* %158)
br label %72
160: ; preds = %72
%161 = load i32*, i32** %12
%162 = call i32 @fclose(i32* %161)
store i32 0, i32* %3
br label %163
163: ; preds = %160, %35, %21
%164 = load i32, i32* %3
ret i32 %164
}

LLVM IR (-O2):
@.str.1 = [12 x i8] c"%s/midi.txt\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [32 x i8] c"Could not open '%s', skipping.\0A\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.4 = [10 x i8] c"%s/midi.h\00"
@.str.5 = [3 x i8] c"wb\00"
@.str.6 = [69 x i8] c"typedef struct{int start; unsigned short length; short pitch;} Note;\00"
@.str.7 = [47 x i8] c"typedef struct{Note* notes; int length;} Song;\00"
@.str.8 = [5 x i8] c"\09\0D\0A \00"
@.str.9 = [6 x i8] c"\09\0D\0A :\00"
@.str.10 = [24 x i8] c"Assertion failed!\0A'%s'\0A\00"
@.str.11 = [19 x i8] c"*fileCursor == ':'\00"
@.str.12 = [6 x i8] c"%s/%s\00"
@str = [36 x i8] c"Usage: midi.exe [name of directory]\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = alloca [256 x i8]
%5 = alloca [256 x i8]
%6 = icmp slt i32 %0, 2
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
br label %85
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%13 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %12, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%14 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %18
16: ; preds = %9
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i8* %12)
br label %84
18: ; preds = %9
%19 = load i32, i32* @SEEK_END
%20 = tail call i32 @fseek(i32* %14, i32 0, i32 %19)
%21 = tail call i32 @ftell(i32* %14)
%22 = load i32, i32* @SEEK_SET
%23 = tail call i32 @fseek(i32* %14, i32 0, i32 %22)
%24 = add nsw i32 %21, 1
%25 = tail call i64 @malloc(i32 %24)
%26 = inttoptr i64 %25 to i8*
%27 = tail call i32 @fread(i8* %26, i32 1, i32 %21, i32* %14)
%28 = sext i32 %21 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
store i8 0, i8* %29
%30 = tail call i32 @fclose(i32* %14)
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%32 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %31, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %11)
%33 = call i32* @fopen(i8* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%34 = tail call i64 @fwrite(i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.6, i64 0, i64 0), i64 68, i64 1, i32* %33)
%35 = tail call i64 @fwrite(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.7, i64 0, i64 0), i64 46, i64 1, i32* %33)
%36 = icmp sgt i32 %21, 0
br i1 %36, label %37, label %82
37: ; preds = %18
%38 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
br label %39
39: ; preds = %37, %59
%40 = phi i8* [ %26, %37 ], [ %76, %59 ]
%41 = call i32 @lengthContaining(i8* %40, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %40, i64 %42
%44 = call i32 @lengthNotContaining(i8* %43, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0))
%45 = add nsw i32 %44, 1
%46 = call i64 @malloc(i32 %45)
%47 = inttoptr i64 %46 to i8*
%48 = call i32 @_memcpy(i8* %47, i8* %43, i32 %44)
%49 = sext i32 %44 to i64
%50 = getelementptr inbounds i8, i8* %47, i64 %49
store i8 0, i8* %50
%51 = getelementptr inbounds i8, i8* %43, i64 %49
%52 = call i32 @lengthContaining(i8* %51, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %51, i64 %53
%55 = load i8, i8* %54
%56 = icmp eq i8 %55, 58
br i1 %56, label %59, label %57
57: ; preds = %39
%58 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.11, i64 0, i64 0))
br label %59
59: ; preds = %57, %39
%60 = getelementptr inbounds i8, i8* %54, i64 1
%61 = call i32 @lengthContaining(i8* %60, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8, i8* %60, i64 %62
%64 = call i32 @lengthNotContaining(i8* %63, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%65 = add nsw i32 %64, 1
%66 = call i64 @malloc(i32 %65)
%67 = inttoptr i64 %66 to i8*
%68 = call i32 @_memcpy(i8* %67, i8* %63, i32 %64)
%69 = sext i32 %64 to i64
%70 = getelementptr inbounds i8, i8* %67, i64 %69
store i8 0, i8* %70
%71 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %38, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.12, i64 0, i64 0), i8* %11, i8* %47)
%72 = call i32 @ParseMidiFile(i8* %38, i8* %67, i32* %33)
%73 = getelementptr inbounds i8, i8* %63, i64 %69
%74 = call i32 @lengthContaining(i8* %73, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds i8, i8* %73, i64 %75
%77 = call i32 @free(i8* %47)
%78 = call i32 @free(i8* %67)
%79 = ptrtoint i8* %76 to i64
%80 = sub i64 %79, %25
%81 = icmp slt i64 %80, %28
br i1 %81, label %39, label %82
82: ; preds = %59, %18
%83 = call i32 @fclose(i32* %33)
br label %84
84: ; preds = %82, %16
br label %85
85: ; preds = %84, %7
ret i32 0
}