#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 uint8_t;
typedef int uint32_t;
typedef int uint16_t;
typedef int int8_t;
typedef int /*<<< orphan*/ header;
typedef int /*<<< orphan*/ footer;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, ...);
int *malloc(int);
int /*<<< orphan*/ memcpy(int *, int *, int);
int /*<<< orphan*/ midi_note_off(int, int, int, int **, int *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int8_t midi_note_velocity_generator(uint32_t *bufsize, uint8_t **buf,
                                    uint8_t cc, uint16_t ticks_per_beat,
                                    uint32_t count0, uint32_t times0[],
                                    uint8_t values0[], uint32_t count1,
                                    uint32_t times1[], uint8_t values1[]) {
  *bufsize = 0;
  *buf = NULL;
  uint8_t header[] = {77, 84, 104, 100, 0,  0,   0,   6, 0, 0, 0,
                      1,  0,  120, 77,  84, 114, 107, 0, 0, 0, 0};
  uint8_t footer[] = {0, 255, 47, 0};
  const int max_alloc_size = (1024 * 256);
  int alloc_size =
      sizeof(header) + sizeof(footer) + (2 * (count0 + count1) * 8);
  if (alloc_size > max_alloc_size) {
    fprintf(
        stderr,
        "Maximum potential buffer size of %d bytes exceeds %d byte limit.\n",
        (int)alloc_size, (int)max_alloc_size);
    return -1;
  }
  (*buf) = malloc(alloc_size);
  if (NULL == (*buf)) {
    fprintf(stderr, "Unable to allocate %d bytes.\n", (int)alloc_size);
    return -1;
  }
  memcpy((*buf), header, sizeof(header) / sizeof(uint8_t));
  (*buf)[12] = (ticks_per_beat >> 8) & 0xFF;
  (*buf)[13] = ticks_per_beat & 0xFF;
  uint32_t last_time = 0;
  int startbufposition = sizeof(header) / sizeof(uint8_t);
  int curBufferPosition = sizeof(header) / sizeof(uint8_t);
  int i0 = 0;
  int i1 = 0;
  int mergedevents = 0;
  uint8_t curValue0 = 0;
  uint8_t curValue1 = 0;
  while ((i0 < count0) || (i1 < count1)) {
    char handling0;
    char handling1;
    uint32_t timediff;
    handling0 = 0;
    if ((i0 < count0) && (i1 < count1)) {
      if (times0[i0] == times1[i1]) {
        mergedevents++;
        handling0 = handling1 = 1;
      } else {
        handling0 = (times0[i0] < times1[i1]);
        handling1 = !handling0;
      }
    } else {
      handling0 = (i0 < count0);
      handling1 = !handling0;
    }
    uint32_t this_time;
    if (handling0)
      this_time = times0[i0];
    if (handling1)
      this_time = times1[i1];
    timediff = this_time - last_time;
    last_time = this_time;
    if (i0 > 0 || i1 > 0) {
      midi_note_off(curValue0, curValue1, timediff, buf, &curBufferPosition);
    }
    if (handling0) {
      curValue0 = values0[i0];
      i0++;
    }
    if (handling1) {
      curValue1 = values1[i1];
      if (0 == curValue1)
        curValue1 = 1;
      i1++;
    }
    (*buf)[curBufferPosition++] = 0;
    (*buf)[curBufferPosition++] = 144;
    (*buf)[curBufferPosition++] = curValue0;
    (*buf)[curBufferPosition++] = curValue1;
  }
  if (last_time > 0) {
    uint32_t end_time = (1 + (last_time / ticks_per_beat)) * ticks_per_beat;
    fprintf(stdout, "Setting end_time to %d based off of last_time %d.\n",
            (int)end_time, (int)last_time);
    midi_note_off(curValue0, curValue1, end_time - last_time, buf,
                  &curBufferPosition);
  }
  memcpy((*buf) + curBufferPosition, footer,
         (sizeof(footer) / sizeof(uint8_t)));
  curBufferPosition += (sizeof(footer) / sizeof(uint8_t));
  uint32_t num_bytes = curBufferPosition - startbufposition;
  (*buf)[18] = (num_bytes >> 24) & 0xFF;
  (*buf)[19] = (num_bytes >> 16) & 0xFF;
  (*buf)[20] = (num_bytes >> 8) & 0xFF;
  (*buf)[21] = num_bytes & 0xFF;
  *bufsize = curBufferPosition;
  fprintf(stdout,
          "Allocated %d bytes for %d points of MIDI data of which %d were "
          "merged; %d bytes were actually used.\n",
          (int)alloc_size, (int)(count0 + count1), (int)(mergedevents),
          (int)curBufferPosition);
  return 0;
}


x86 assembly (clang, -O0):
<midi_note_velocity_generator>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
mov    0x28(%rbp),%rax
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%rax
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
lea    -0x90(%rbp),%rdi
lea    0xe6d(%rip),%rsi
mov    $0x58,%edx
call   1040 <memcpy@plt>
mov    0xebc(%rip),%rax
mov    %rax,-0xa0(%rbp)
mov    0xeb6(%rip),%rax
mov    %rax,-0x98(%rbp)
movl   $0x40000,-0xa4(%rbp)
mov    -0x24(%rbp),%eax
add    0x18(%rbp),%eax
shl    $0x1,%eax
shl    $0x3,%eax
cltq
add    $0x68,%rax
mov    %eax,-0xa8(%rbp)
cmpl   $0x40000,-0xa8(%rbp)
jle    1219 <midi_note_velocity_generator+0xd9>
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
mov    -0xa8(%rbp),%edx
lea    0xe6f(%rip),%rsi
mov    $0x40000,%ecx
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1712 <midi_note_velocity_generator+0x5d2>
mov    -0xa8(%rbp),%edi
call   1050 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rcx
xor    %eax,%eax
cmp    (%rcx),%rax
jne    1266 <midi_note_velocity_generator+0x126>
mov    0x2d9c(%rip),%rax
mov    (%rax),%edi
mov    -0xa8(%rbp),%edx
lea    0xe5f(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1712 <midi_note_velocity_generator+0x5d2>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
lea    -0x90(%rbp),%rsi
mov    $0x16,%edx
call   1040 <memcpy@plt>
mov    -0x20(%rbp),%ecx
sar    $0x8,%ecx
and    $0xff,%ecx
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %ecx,0x30(%rax)
mov    -0x20(%rbp),%ecx
and    $0xff,%ecx
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %ecx,0x34(%rax)
movl   $0x0,-0xac(%rbp)
movl   $0x16,-0xb0(%rbp)
movl   $0x16,-0xb4(%rbp)
movl   $0x0,-0xb8(%rbp)
movl   $0x0,-0xbc(%rbp)
movl   $0x0,-0xc0(%rbp)
movl   $0x0,-0xc4(%rbp)
movl   $0x0,-0xc8(%rbp)
mov    -0xb8(%rbp),%ecx
mov    $0x1,%al
cmp    -0x24(%rbp),%ecx
mov    %al,-0xdd(%rbp)
jl     1320 <midi_note_velocity_generator+0x1e0>
mov    -0xbc(%rbp),%eax
cmp    0x18(%rbp),%eax
setl   %al
mov    %al,-0xdd(%rbp)
mov    -0xdd(%rbp),%al
test   $0x1,%al
jne    1333 <midi_note_velocity_generator+0x1f3>
jmp    15b5 <midi_note_velocity_generator+0x475>
movb   $0x0,-0xc9(%rbp)
mov    -0xb8(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    13e2 <midi_note_velocity_generator+0x2a2>
mov    -0xbc(%rbp),%eax
cmp    0x18(%rbp),%eax
jge    13e2 <midi_note_velocity_generator+0x2a2>
mov    -0x30(%rbp),%rax
movslq -0xb8(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    0x20(%rbp),%rcx
movslq -0xbc(%rbp),%rdx
cmp    (%rcx,%rdx,4),%eax
jne    139c <midi_note_velocity_generator+0x25c>
mov    -0xc0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc0(%rbp)
movb   $0x1,-0xca(%rbp)
movb   $0x1,-0xc9(%rbp)
jmp    13dd <midi_note_velocity_generator+0x29d>
mov    -0x30(%rbp),%rax
movslq -0xb8(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    0x20(%rbp),%rcx
movslq -0xbc(%rbp),%rdx
cmp    (%rcx,%rdx,4),%eax
setl   %al
and    $0x1,%al
movzbl %al,%eax
mov    %al,-0xc9(%rbp)
cmpb   $0x0,-0xc9(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %al,-0xca(%rbp)
jmp    1410 <midi_note_velocity_generator+0x2d0>
mov    -0xb8(%rbp),%eax
cmp    -0x24(%rbp),%eax
setl   %al
and    $0x1,%al
movzbl %al,%eax
mov    %al,-0xc9(%rbp)
cmpb   $0x0,-0xc9(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %al,-0xca(%rbp)
cmpb   $0x0,-0xc9(%rbp)
je     1431 <midi_note_velocity_generator+0x2f1>
mov    -0x30(%rbp),%rax
movslq -0xb8(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0xd4(%rbp)
cmpb   $0x0,-0xca(%rbp)
je     1452 <midi_note_velocity_generator+0x312>
mov    0x20(%rbp),%rax
movslq -0xbc(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0xd4(%rbp)
mov    -0xd4(%rbp),%eax
sub    -0xac(%rbp),%eax
mov    %eax,-0xd0(%rbp)
mov    -0xd4(%rbp),%eax
mov    %eax,-0xac(%rbp)
cmpl   $0x0,-0xb8(%rbp)
jg     148a <midi_note_velocity_generator+0x34a>
cmpl   $0x0,-0xbc(%rbp)
jle    14ac <midi_note_velocity_generator+0x36c>
mov    -0xc4(%rbp),%edi
mov    -0xc8(%rbp),%esi
mov    -0xd0(%rbp),%edx
mov    -0x18(%rbp),%rcx
lea    -0xb4(%rbp),%r8
call   1060 <midi_note_off@plt>
cmpb   $0x0,-0xc9(%rbp)
je     14dc <midi_note_velocity_generator+0x39c>
mov    0x10(%rbp),%rax
movslq -0xb8(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0xc4(%rbp)
mov    -0xb8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xb8(%rbp)
cmpb   $0x0,-0xca(%rbp)
je     1524 <midi_note_velocity_generator+0x3e4>
mov    0x28(%rbp),%rax
movslq -0xbc(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0xc8(%rbp)
xor    %eax,%eax
cmp    -0xc8(%rbp),%eax
jne    1515 <midi_note_velocity_generator+0x3d5>
movl   $0x1,-0xc8(%rbp)
mov    -0xbc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xbc(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    -0xb4(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0xb4(%rbp)
movslq %ecx,%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    -0xb4(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0xb4(%rbp)
movslq %ecx,%rcx
movl   $0x90,(%rax,%rcx,4)
mov    -0xc4(%rbp),%edx
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    -0xb4(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0xb4(%rbp)
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0xc8(%rbp),%edx
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    -0xb4(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0xb4(%rbp)
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
jmp    12f7 <midi_note_velocity_generator+0x1b7>
cmpl   $0x0,-0xac(%rbp)
jle    1624 <midi_note_velocity_generator+0x4e4>
mov    -0xac(%rbp),%eax
cltd
idivl  -0x20(%rbp)
add    $0x1,%eax
imul   -0x20(%rbp),%eax
mov    %eax,-0xd8(%rbp)
mov    0x29f8(%rip),%rax
mov    (%rax),%edi
mov    -0xd8(%rbp),%edx
mov    -0xac(%rbp),%ecx
lea    0xadb(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0xc4(%rbp),%edi
mov    -0xc8(%rbp),%esi
mov    -0xd8(%rbp),%edx
sub    -0xac(%rbp),%edx
mov    -0x18(%rbp),%rcx
lea    -0xb4(%rbp),%r8
call   1060 <midi_note_off@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
movslq -0xb4(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
lea    -0xa0(%rbp),%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
movslq -0xb4(%rbp),%rax
add    $0x4,%rax
mov    %eax,-0xb4(%rbp)
mov    -0xb4(%rbp),%eax
sub    -0xb0(%rbp),%eax
mov    %eax,-0xdc(%rbp)
mov    -0xdc(%rbp),%ecx
sar    $0x18,%ecx
and    $0xff,%ecx
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %ecx,0x48(%rax)
mov    -0xdc(%rbp),%ecx
sar    $0x10,%ecx
and    $0xff,%ecx
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %ecx,0x4c(%rax)
mov    -0xdc(%rbp),%ecx
sar    $0x8,%ecx
and    $0xff,%ecx
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %ecx,0x50(%rax)
mov    -0xdc(%rbp),%ecx
and    $0xff,%ecx
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %ecx,0x54(%rax)
mov    -0xb4(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    0x28f7(%rip),%rax
mov    (%rax),%edi
mov    -0xa8(%rbp),%edx
mov    -0x24(%rbp),%ecx
add    0x18(%rbp),%ecx
mov    -0xc0(%rbp),%r8d
mov    -0xb4(%rbp),%r9d
lea    0x9ff(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<midi_note_velocity_generator>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa8,%rsp
mov    %r9,0x20(%rsp)
mov    %ecx,%ebx
mov    0xe8(%rsp),%ecx
movl   $0x0,(%rdi)
movq   $0x0,(%rsi)
mov    0xedd(%rip),%rax
mov    %rax,0xa0(%rsp)
movaps 0xebe(%rip),%xmm0
movaps %xmm0,0x90(%rsp)
movaps 0xe9f(%rip),%xmm0
movaps %xmm0,0x80(%rsp)
movaps 0xe80(%rip),%xmm0
movaps %xmm0,0x70(%rsp)
movaps 0xe64(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
movaps 0xe48(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xe9c(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
lea    (%rcx,%r8,1),%r15d
mov    %r15d,%ebp
shl    $0x4,%ebp
add    $0x68,%ebp
cmp    $0x40001,%ebp
jl     1206 <midi_note_velocity_generator+0xc6>
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
lea    0xe82(%rip),%rsi
mov    %ebp,%edx
mov    $0x40000,%ecx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0xffffffff,%ebx
jmp    1574 <midi_note_velocity_generator+0x434>
mov    %rdi,%r14
mov    %r8,0x38(%rsp)
mov    %ebp,%edi
mov    %rsi,0x10(%rsp)
call   1050 <malloc@plt>
mov    0x10(%rsp),%rcx
mov    %rax,(%rcx)
test   %rax,%rax
je     1474 <midi_note_velocity_generator+0x334>
lea    0x50(%rsp),%rsi
mov    %rax,%rdi
mov    $0x16,%edx
call   1040 <memcpy@plt>
mov    0x10(%rsp),%rcx
movzbl %bh,%eax
mov    (%rcx),%rsi
mov    %eax,0x30(%rsi)
mov    %ebx,0x28(%rsp)
movzbl %bl,%eax
mov    %eax,0x34(%rsi)
movl   $0x16,0x4(%rsp)
mov    0xe8(%rsp),%r9d
test   %r9d,%r9d
setg   %dl
mov    0x38(%rsp),%r8
test   %r8d,%r8d
setg   %bl
jg     1284 <midi_note_velocity_generator+0x144>
xor    %r12d,%r12d
test   %r9d,%r9d
jle    1505 <midi_note_velocity_generator+0x3c5>
mov    %r15d,0x18(%rsp)
mov    %r14,0x30(%rsp)
mov    %ebp,0x1c(%rsp)
mov    0xf0(%rsp),%r14
xor    %r12d,%r12d
xor    %r10d,%r10d
xor    %r11d,%r11d
movl   $0x0,0xc(%rsp)
xor    %r15d,%r15d
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
test   $0x1,%bl
je     12f0 <midi_note_velocity_generator+0x1b0>
test   $0x1,%dl
je     12f0 <midi_note_velocity_generator+0x1b0>
movslq %r13d,%rdx
mov    0x20(%rsp),%rsi
mov    (%rsi,%rdx,4),%esi
movslq %r15d,%rbp
mov    (%r14,%rbp,4),%edi
cmp    %edi,%esi
jne    1310 <midi_note_velocity_generator+0x1d0>
addl   $0x1,0xc(%rsp)
mov    $0x1,%bl
jmp    1335 <midi_note_velocity_generator+0x1f5>
nopl   0x0(%rax)
test   $0x1,%bl
je     1330 <midi_note_velocity_generator+0x1f0>
movslq %r13d,%rdx
mov    0x20(%rsp),%rsi
lea    (%rsi,%rdx,4),%rdx
mov    $0x1,%al
xor    %ebx,%ebx
jmp    133d <midi_note_velocity_generator+0x1fd>
nopw   0x0(%rax,%rax,1)
xor    %ebx,%ebx
cmp    %edi,%esi
jge    1335 <midi_note_velocity_generator+0x1f5>
mov    0x20(%rsp),%rsi
lea    (%rsi,%rdx,4),%rdx
mov    $0x1,%al
jmp    133d <midi_note_velocity_generator+0x1fd>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movslq %r15d,%rbp
xor    %ebx,%ebx
lea    (%r14,%rbp,4),%rdx
mov    %ebx,%eax
mov    $0x1,%bl
mov    (%rdx),%edi
test   %r13d,%r13d
jg     13f0 <midi_note_velocity_generator+0x2b0>
test   %r15d,%r15d
jg     13f0 <midi_note_velocity_generator+0x2b0>
test   %al,%al
jne    1454 <midi_note_velocity_generator+0x314>
test   %bl,%bl
je     137c <midi_note_velocity_generator+0x23c>
movslq %r15d,%rax
mov    0xf8(%rsp),%rdx
mov    (%rdx,%rax,4),%r10d
test   %r10d,%r10d
mov    $0x1,%eax
cmove  %eax,%r10d
add    $0x1,%r15d
mov    (%rcx),%rsi
movslq 0x4(%rsp),%rax
lea    0x1(%rax),%edx
mov    %edx,0x4(%rsp)
movl   $0x0,(%rsi,%rax,4)
movslq 0x4(%rsp),%rax
lea    0x1(%rax),%edx
mov    %edx,0x4(%rsp)
movl   $0x90,(%rsi,%rax,4)
movslq 0x4(%rsp),%rax
lea    0x1(%rax),%edx
mov    %edx,0x4(%rsp)
mov    %r11d,(%rsi,%rax,4)
movslq 0x4(%rsp),%rax
lea    0x1(%rax),%edx
mov    %edx,0x4(%rsp)
mov    %r10d,(%rsi,%rax,4)
cmp    %r9d,%r15d
setl   %dl
mov    %edi,%r12d
cmp    %r8d,%r13d
setl   %bl
jl     12c0 <midi_note_velocity_generator+0x180>
mov    %edi,%r12d
cmp    %r9d,%r15d
jl     12c0 <midi_note_velocity_generator+0x180>
jmp    1497 <midi_note_velocity_generator+0x357>
nopl   0x0(%rax,%rax,1)
mov    %edi,%edx
sub    %r12d,%edx
mov    %edi,0x2c(%rsp)
mov    %r11d,%edi
mov    %al,0xb(%rsp)
mov    %r10d,%esi
lea    0x4(%rsp),%r8
mov    %r10d,%ebp
mov    %ebx,%r12d
mov    %r15d,%ebx
mov    %r13d,%r15d
mov    %r14,%r13
mov    %r11d,%r14d
call   1060 <midi_note_off@plt>
movzbl 0xb(%rsp),%eax
mov    0x2c(%rsp),%edi
mov    %r14d,%r11d
mov    %r13,%r14
mov    %r15d,%r13d
mov    %ebx,%r15d
mov    %r12d,%ebx
mov    %ebp,%r10d
mov    0xe8(%rsp),%r9d
mov    0x38(%rsp),%r8
mov    0x10(%rsp),%rcx
test   %al,%al
je     1359 <midi_note_velocity_generator+0x219>
movslq %r13d,%rax
mov    0xe0(%rsp),%rdx
mov    (%rdx,%rax,4),%r11d
add    $0x1,%r13d
test   %bl,%bl
jne    135d <midi_note_velocity_generator+0x21d>
jmp    137c <midi_note_velocity_generator+0x23c>
mov    0x2b65(%rip),%rax
mov    (%rax),%edi
lea    0xc2e(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0xffffffff,%ebx
jmp    1574 <midi_note_velocity_generator+0x434>
test   %edi,%edi
jle    14f2 <midi_note_velocity_generator+0x3b2>
mov    %edi,%eax
cltd
mov    0x28(%rsp),%ecx
idiv   %ecx
lea    0x1(%rax),%r14d
imul   %ecx,%r14d
mov    0x2b25(%rip),%rax
mov    %edi,%ebx
mov    (%rax),%edi
lea    0xc12(%rip),%rsi
mov    %r14d,%edx
mov    %ebx,%ecx
xor    %eax,%eax
mov    %r10d,%r15d
mov    %r11d,%ebp
call   1030 <fprintf@plt>
sub    %ebx,%r14d
lea    0x4(%rsp),%r8
mov    %ebp,%edi
mov    %r15d,%esi
mov    %r14d,%edx
mov    0x10(%rsp),%rcx
call   1060 <midi_note_off@plt>
mov    0x10(%rsp),%rcx
mov    (%rcx),%rsi
mov    0x1c(%rsp),%ebp
mov    0x30(%rsp),%r14
mov    0x18(%rsp),%r15d
mov    0xc(%rsp),%r12d
movslq 0x4(%rsp),%rax
lea    (%rsi,%rax,4),%rdi
lea    0x40(%rsp),%rsi
mov    $0x4,%edx
mov    %rcx,%rbx
call   1040 <memcpy@plt>
mov    0x4(%rsp),%eax
lea    0x4(%rax),%r9d
mov    %r9d,0x4(%rsp)
add    $0xffffffee,%eax
mov    %eax,%ecx
movzbl %ah,%edx
movzbl %al,%esi
shr    $0x18,%eax
mov    (%rbx),%rdi
mov    %eax,0x48(%rdi)
shr    $0x10,%ecx
movzbl %cl,%eax
mov    %eax,0x4c(%rdi)
mov    %edx,0x50(%rdi)
mov    %esi,0x54(%rdi)
mov    %r9d,(%r14)
mov    0x2a7e(%rip),%rax
mov    (%rax),%edi
lea    0xba0(%rip),%rsi
xor    %ebx,%ebx
mov    %ebp,%edx
mov    %r15d,%ecx
mov    %r12d,%r8d
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    %ebx,%eax
add    $0xa8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.midi_note_velocity_generator.header = [22 x i32] [i32 77, i32 84, i32 104, i32 100, i32 0, i32 0, i32 0, i32 6, i32 0, i32 0, i32 0, i32 1, i32 0, i32 120, i32 77, i32 84, i32 114, i32 107, i32 0, i32 0, i32 0, i32 0]
@__const.midi_note_velocity_generator.footer = [4 x i32] [i32 0, i32 255, i32 47, i32 0]
@stderr = global i32 0
@.str = [66 x i8] c"Maximum potential buffer size of %d bytes exceeds %d byte limit.\0A\00"
@.str.1 = [30 x i8] c"Unable to allocate %d bytes.\0A\00"
@stdout = global i32 0
@.str.2 = [51 x i8] c"Setting end_time to %d based off of last_time %d.\0A\00"
@.str.3 = [101 x i8] c"Allocated %d bytes for %d points of MIDI data of which %d were merged; %d bytes were actually used.\0A\00"
define i32 @midi_note_velocity_generator(i32* %0, i32** %1, i32 %2, i32 %3, i32 %4, i32* %5, i32* %6, i32 %7, i32* %8, i32* %9) {
%11 = alloca i32
%12 = alloca i32*
%13 = alloca i32**
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32*
%18 = alloca i32*
%19 = alloca i32
%20 = alloca i32*
%21 = alloca i32*
%22 = alloca [22 x i32]
%23 = alloca [4 x i32]
%24 = alloca i32
%25 = alloca i32
%26 = alloca i32
%27 = alloca i32
%28 = alloca i32
%29 = alloca i32
%30 = alloca i32
%31 = alloca i32
%32 = alloca i32
%33 = alloca i32
%34 = alloca i8
%35 = alloca i8
%36 = alloca i32
%37 = alloca i32
%38 = alloca i32
%39 = alloca i32
store i32* %0, i32** %12
store i32** %1, i32*** %13
store i32 %2, i32* %14
store i32 %3, i32* %15
store i32 %4, i32* %16
store i32* %5, i32** %17
store i32* %6, i32** %18
store i32 %7, i32* %19
store i32* %8, i32** %20
store i32* %9, i32** %21
%40 = load i32*, i32** %12
store i32 0, i32* %40
%41 = load i32**, i32*** %13
store i32* null, i32** %41
%42 = bitcast [22 x i32]* %22 to i8*
%43 = bitcast [4 x i32]* %23 to i8*
store i32 262144, i32* %24
%44 = load i32, i32* %16
%45 = load i32, i32* %19
%46 = add nsw i32 %44, %45
%47 = mul nsw i32 2, %46
%48 = mul nsw i32 %47, 8
%49 = sext i32 %48 to i64
%50 = add i64 104, %49
%51 = trunc i64 %50 to i32
store i32 %51, i32* %25
%52 = load i32, i32* %25
%53 = icmp sgt i32 %52, 262144
br i1 %53, label %54, label %58
54: ; preds = %10
%55 = load i32, i32* @stderr
%56 = load i32, i32* %25
%57 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str, i64 0, i64 0), i32 %56, i32 262144)
store i32 -1, i32* %11
br label %305
58: ; preds = %10
%59 = load i32, i32* %25
%60 = call i32* @malloc(i32 %59)
%61 = load i32**, i32*** %13
store i32* %60, i32** %61
%62 = load i32**, i32*** %13
%63 = load i32*, i32** %62
%64 = icmp eq i32* null, %63
br i1 %64, label %65, label %69
65: ; preds = %58
%66 = load i32, i32* @stderr
%67 = load i32, i32* %25
%68 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %66, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %67)
store i32 -1, i32* %11
br label %305
69: ; preds = %58
%70 = load i32**, i32*** %13
%71 = load i32*, i32** %70
%72 = getelementptr inbounds [22 x i32], [22 x i32]* %22, i64 0, i64 0
%73 = call i32 @memcpy(i32* %71, i32* %72, i32 22)
%74 = load i32, i32* %15
%75 = ashr i32 %74, 8
%76 = and i32 %75, 255
%77 = load i32**, i32*** %13
%78 = load i32*, i32** %77
%79 = getelementptr inbounds i32, i32* %78, i64 12
store i32 %76, i32* %79
%80 = load i32, i32* %15
%81 = and i32 %80, 255
%82 = load i32**, i32*** %13
%83 = load i32*, i32** %82
%84 = getelementptr inbounds i32, i32* %83, i64 13
store i32 %81, i32* %84
store i32 0, i32* %26
store i32 22, i32* %27
store i32 22, i32* %28
store i32 0, i32* %29
store i32 0, i32* %30
store i32 0, i32* %31
store i32 0, i32* %32
store i32 0, i32* %33
br label %85
85: ; preds = %209, %69
%86 = load i32, i32* %29
%87 = load i32, i32* %16
%88 = icmp slt i32 %86, %87
br i1 %88, label %93, label %89
89: ; preds = %85
%90 = load i32, i32* %30
%91 = load i32, i32* %19
%92 = icmp slt i32 %90, %91
br label %93
93: ; preds = %89, %85
%94 = phi i1 [ true, %85 ], [ %92, %89 ]
br i1 %94, label %95, label %236
95: ; preds = %93
store i8 0, i8* %34
%96 = load i32, i32* %29
%97 = load i32, i32* %16
%98 = icmp slt i32 %96, %97
br i1 %98, label %99, label %138
99: ; preds = %95
%100 = load i32, i32* %30
%101 = load i32, i32* %19
%102 = icmp slt i32 %100, %101
br i1 %102, label %103, label %138
103: ; preds = %99
%104 = load i32*, i32** %17
%105 = load i32, i32* %29
%106 = sext i32 %105 to i64
%107 = getelementptr inbounds i32, i32* %104, i64 %106
%108 = load i32, i32* %107
%109 = load i32*, i32** %20
%110 = load i32, i32* %30
%111 = sext i32 %110 to i64
%112 = getelementptr inbounds i32, i32* %109, i64 %111
%113 = load i32, i32* %112
%114 = icmp eq i32 %108, %113
br i1 %114, label %115, label %118
115: ; preds = %103
%116 = load i32, i32* %31
%117 = add nsw i32 %116, 1
store i32 %117, i32* %31
store i8 1, i8* %35
store i8 1, i8* %34
br label %137
118: ; preds = %103
%119 = load i32*, i32** %17
%120 = load i32, i32* %29
%121 = sext i32 %120 to i64
%122 = getelementptr inbounds i32, i32* %119, i64 %121
%123 = load i32, i32* %122
%124 = load i32*, i32** %20
%125 = load i32, i32* %30
%126 = sext i32 %125 to i64
%127 = getelementptr inbounds i32, i32* %124, i64 %126
%128 = load i32, i32* %127
%129 = icmp slt i32 %123, %128
%130 = zext i1 %129 to i32
%131 = trunc i32 %130 to i8
store i8 %131, i8* %34
%132 = load i8, i8* %34
%133 = icmp ne i8 %132, 0
%134 = xor i1 %133, true
%135 = zext i1 %134 to i32
%136 = trunc i32 %135 to i8
store i8 %136, i8* %35
br label %137
137: ; preds = %118, %115
br label %149
138: ; preds = %99, %95
%139 = load i32, i32* %29
%140 = load i32, i32* %16
%141 = icmp slt i32 %139, %140
%142 = zext i1 %141 to i32
%143 = trunc i32 %142 to i8
store i8 %143, i8* %34
%144 = load i8, i8* %34
%145 = icmp ne i8 %144, 0
%146 = xor i1 %145, true
%147 = zext i1 %146 to i32
%148 = trunc i32 %147 to i8
store i8 %148, i8* %35
br label %149
149: ; preds = %138, %137
%150 = load i8, i8* %34
%151 = icmp ne i8 %150, 0
br i1 %151, label %152, label %158
152: ; preds = %149
%153 = load i32*, i32** %17
%154 = load i32, i32* %29
%155 = sext i32 %154 to i64
%156 = getelementptr inbounds i32, i32* %153, i64 %155
%157 = load i32, i32* %156
store i32 %157, i32* %37
br label %158
158: ; preds = %152, %149
%159 = load i8, i8* %35
%160 = icmp ne i8 %159, 0
br i1 %160, label %161, label %167
161: ; preds = %158
%162 = load i32*, i32** %20
%163 = load i32, i32* %30
%164 = sext i32 %163 to i64
%165 = getelementptr inbounds i32, i32* %162, i64 %164
%166 = load i32, i32* %165
store i32 %166, i32* %37
br label %167
167: ; preds = %161, %158
%168 = load i32, i32* %37
%169 = load i32, i32* %26
%170 = sub nsw i32 %168, %169
store i32 %170, i32* %36
%171 = load i32, i32* %37
store i32 %171, i32* %26
%172 = load i32, i32* %29
%173 = icmp sgt i32 %172, 0
br i1 %173, label %177, label %174
174: ; preds = %167
%175 = load i32, i32* %30
%176 = icmp sgt i32 %175, 0
br i1 %176, label %177, label %183
177: ; preds = %174, %167
%178 = load i32, i32* %32
%179 = load i32, i32* %33
%180 = load i32, i32* %36
%181 = load i32**, i32*** %13
%182 = call i32 @midi_note_off(i32 %178, i32 %179, i32 %180, i32** %181, i32* %28)
br label %183
183: ; preds = %177, %174
%184 = load i8, i8* %34
%185 = icmp ne i8 %184, 0
br i1 %185, label %186, label %194
186: ; preds = %183
%187 = load i32*, i32** %18
%188 = load i32, i32* %29
%189 = sext i32 %188 to i64
%190 = getelementptr inbounds i32, i32* %187, i64 %189
%191 = load i32, i32* %190
store i32 %191, i32* %32
%192 = load i32, i32* %29
%193 = add nsw i32 %192, 1
store i32 %193, i32* %29
br label %194
194: ; preds = %186, %183
%195 = load i8, i8* %35
%196 = icmp ne i8 %195, 0
br i1 %196, label %197, label %209
197: ; preds = %194
%198 = load i32*, i32** %21
%199 = load i32, i32* %30
%200 = sext i32 %199 to i64
%201 = getelementptr inbounds i32, i32* %198, i64 %200
%202 = load i32, i32* %201
store i32 %202, i32* %33
%203 = load i32, i32* %33
%204 = icmp eq i32 0, %203
br i1 %204, label %205, label %206
205: ; preds = %197
store i32 1, i32* %33
br label %206
206: ; preds = %205, %197
%207 = load i32, i32* %30
%208 = add nsw i32 %207, 1
store i32 %208, i32* %30
br label %209
209: ; preds = %206, %194
%210 = load i32**, i32*** %13
%211 = load i32*, i32** %210
%212 = load i32, i32* %28
%213 = add nsw i32 %212, 1
store i32 %213, i32* %28
%214 = sext i32 %212 to i64
%215 = getelementptr inbounds i32, i32* %211, i64 %214
store i32 0, i32* %215
%216 = load i32**, i32*** %13
%217 = load i32*, i32** %216
%218 = load i32, i32* %28
%219 = add nsw i32 %218, 1
store i32 %219, i32* %28
%220 = sext i32 %218 to i64
%221 = getelementptr inbounds i32, i32* %217, i64 %220
store i32 144, i32* %221
%222 = load i32, i32* %32
%223 = load i32**, i32*** %13
%224 = load i32*, i32** %223
%225 = load i32, i32* %28
%226 = add nsw i32 %225, 1
store i32 %226, i32* %28
%227 = sext i32 %225 to i64
%228 = getelementptr inbounds i32, i32* %224, i64 %227
store i32 %222, i32* %228
%229 = load i32, i32* %33
%230 = load i32**, i32*** %13
%231 = load i32*, i32** %230
%232 = load i32, i32* %28
%233 = add nsw i32 %232, 1
store i32 %233, i32* %28
%234 = sext i32 %232 to i64
%235 = getelementptr inbounds i32, i32* %231, i64 %234
store i32 %229, i32* %235
br label %85
236: ; preds = %93
%237 = load i32, i32* %26
%238 = icmp sgt i32 %237, 0
br i1 %238, label %239, label %257
239: ; preds = %236
%240 = load i32, i32* %26
%241 = load i32, i32* %15
%242 = sdiv i32 %240, %241
%243 = add nsw i32 1, %242
%244 = load i32, i32* %15
%245 = mul nsw i32 %243, %244
store i32 %245, i32* %38
%246 = load i32, i32* @stdout
%247 = load i32, i32* %38
%248 = load i32, i32* %26
%249 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %246, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0), i32 %247, i32 %248)
%250 = load i32, i32* %32
%251 = load i32, i32* %33
%252 = load i32, i32* %38
%253 = load i32, i32* %26
%254 = sub nsw i32 %252, %253
%255 = load i32**, i32*** %13
%256 = call i32 @midi_note_off(i32 %250, i32 %251, i32 %254, i32** %255, i32* %28)
br label %257
257: ; preds = %239, %236
%258 = load i32**, i32*** %13
%259 = load i32*, i32** %258
%260 = load i32, i32* %28
%261 = sext i32 %260 to i64
%262 = getelementptr inbounds i32, i32* %259, i64 %261
%263 = getelementptr inbounds [4 x i32], [4 x i32]* %23, i64 0, i64 0
%264 = call i32 @memcpy(i32* %262, i32* %263, i32 4)
%265 = load i32, i32* %28
%266 = sext i32 %265 to i64
%267 = add i64 %266, 4
%268 = trunc i64 %267 to i32
store i32 %268, i32* %28
%269 = load i32, i32* %28
%270 = load i32, i32* %27
%271 = sub nsw i32 %269, %270
store i32 %271, i32* %39
%272 = load i32, i32* %39
%273 = ashr i32 %272, 24
%274 = and i32 %273, 255
%275 = load i32**, i32*** %13
%276 = load i32*, i32** %275
%277 = getelementptr inbounds i32, i32* %276, i64 18
store i32 %274, i32* %277
%278 = load i32, i32* %39
%279 = ashr i32 %278, 16
%280 = and i32 %279, 255
%281 = load i32**, i32*** %13
%282 = load i32*, i32** %281
%283 = getelementptr inbounds i32, i32* %282, i64 19
store i32 %280, i32* %283
%284 = load i32, i32* %39
%285 = ashr i32 %284, 8
%286 = and i32 %285, 255
%287 = load i32**, i32*** %13
%288 = load i32*, i32** %287
%289 = getelementptr inbounds i32, i32* %288, i64 20
store i32 %286, i32* %289
%290 = load i32, i32* %39
%291 = and i32 %290, 255
%292 = load i32**, i32*** %13
%293 = load i32*, i32** %292
%294 = getelementptr inbounds i32, i32* %293, i64 21
store i32 %291, i32* %294
%295 = load i32, i32* %28
%296 = load i32*, i32** %12
store i32 %295, i32* %296
%297 = load i32, i32* @stdout
%298 = load i32, i32* %25
%299 = load i32, i32* %16
%300 = load i32, i32* %19
%301 = add nsw i32 %299, %300
%302 = load i32, i32* %31
%303 = load i32, i32* %28
%304 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %297, i8* getelementptr inbounds ([101 x i8], [101 x i8]* @.str.3, i64 0, i64 0), i32 %298, i32 %301, i32 %302, i32 %303)
store i32 0, i32* %11
br label %305
305: ; preds = %257, %65, %54
%306 = load i32, i32* %11
ret i32 %306
}

LLVM IR (-O2):
@__const.midi_note_velocity_generator.header = [22 x i32] [i32 77, i32 84, i32 104, i32 100, i32 0, i32 0, i32 0, i32 6, i32 0, i32 0, i32 0, i32 1, i32 0, i32 120, i32 77, i32 84, i32 114, i32 107, i32 0, i32 0, i32 0, i32 0]
@__const.midi_note_velocity_generator.footer = [4 x i32] [i32 0, i32 255, i32 47, i32 0]
@stderr = global i32 0
@.str = [66 x i8] c"Maximum potential buffer size of %d bytes exceeds %d byte limit.\0A\00"
@.str.1 = [30 x i8] c"Unable to allocate %d bytes.\0A\00"
@stdout = global i32 0
@.str.2 = [51 x i8] c"Setting end_time to %d based off of last_time %d.\0A\00"
@.str.3 = [101 x i8] c"Allocated %d bytes for %d points of MIDI data of which %d were merged; %d bytes were actually used.\0A\00"
define i32 @midi_note_velocity_generator(i32* nocapture writeonly %0, i32** %1, i32 %2, i32 %3, i32 %4, i32* nocapture %5, i32* nocapture %6, i32 %7, i32* nocapture %8, i32* nocapture %9) {
%11 = alloca [22 x i32]
%12 = alloca [4 x i32]
%13 = alloca i32
store i32 0, i32* %0
store i32* null, i32** %1
%14 = bitcast [22 x i32]* %11 to i8*
%15 = bitcast [4 x i32]* %12 to i8*
%16 = add nsw i32 %7, %4
%17 = shl nsw i32 %16, 4
%18 = add i32 %17, 104
%19 = icmp sgt i32 %18, 262144
br i1 %19, label %20, label %23
20: ; preds = %10
%21 = load i32, i32* @stderr
%22 = tail call i32 (i32, i8*, i32, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str, i64 0, i64 0), i32 %18, i32 262144)
br label %161
23: ; preds = %10
%24 = tail call i32* @malloc(i32 %18)
store i32* %24, i32** %1
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = load i32, i32* @stderr
%28 = tail call i32 (i32, i8*, i32, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %18)
br label %161
29: ; preds = %23
%30 = getelementptr inbounds [22 x i32], [22 x i32]* %11, i64 0, i64 0
%31 = call i32 @memcpy(i32* %24, i32* %30, i32 22)
%32 = lshr i32 %3, 8
%33 = and i32 %32, 255
%34 = load i32*, i32** %1
%35 = getelementptr inbounds i32, i32* %34, i64 12
store i32 %33, i32* %35
%36 = and i32 %3, 255
%37 = getelementptr inbounds i32, i32* %34, i64 13
store i32 %36, i32* %37
%38 = bitcast i32* %13 to i8*
store i32 22, i32* %13
%39 = icmp sgt i32 %4, 0
%40 = icmp sgt i32 %7, 0
%41 = or i1 %39, %40
br i1 %41, label %42, label %137
42: ; preds = %29, %103
%43 = phi i1 [ %124, %103 ], [ %40, %29 ]
%44 = phi i1 [ %123, %103 ], [ %39, %29 ]
%45 = phi i32 [ %80, %103 ], [ 0, %29 ]
%46 = phi i32 [ %105, %103 ], [ 0, %29 ]
%47 = phi i32 [ %95, %103 ], [ 0, %29 ]
%48 = phi i32 [ %76, %103 ], [ 0, %29 ]
%49 = phi i32 [ %104, %103 ], [ 0, %29 ]
%50 = phi i32 [ %94, %103 ], [ 0, %29 ]
%51 = select i1 %44, i1 %43, i1 false
br i1 %51, label %52, label %64
52: ; preds = %42
%53 = sext i32 %50 to i64
%54 = getelementptr inbounds i32, i32* %5, i64 %53
%55 = load i32, i32* %54
%56 = sext i32 %49 to i64
%57 = getelementptr inbounds i32, i32* %8, i64 %56
%58 = load i32, i32* %57
%59 = icmp eq i32 %55, %58
br i1 %59, label %60, label %62
60: ; preds = %52
%61 = add nsw i32 %48, 1
br label %70
62: ; preds = %52
%63 = icmp slt i32 %55, %58
br i1 %63, label %75, label %70
64: ; preds = %42
br i1 %44, label %67, label %65
65: ; preds = %64
%66 = sext i32 %49 to i64
br label %70
67: ; preds = %64
%68 = sext i32 %50 to i64
%69 = getelementptr inbounds i32, i32* %5, i64 %68
br label %75
70: ; preds = %65, %60, %62
%71 = phi i64 [ %66, %65 ], [ %56, %60 ], [ %56, %62 ]
%72 = phi i32 [ %48, %65 ], [ %61, %60 ], [ %48, %62 ]
%73 = phi i1 [ false, %65 ], [ true, %60 ], [ false, %62 ]
%74 = getelementptr inbounds i32, i32* %8, i64 %71
br label %75
75: ; preds = %62, %67, %70
%76 = phi i32 [ %72, %70 ], [ %48, %67 ], [ %48, %62 ]
%77 = phi i1 [ %73, %70 ], [ true, %67 ], [ true, %62 ]
%78 = phi i1 [ true, %70 ], [ false, %67 ], [ false, %62 ]
%79 = phi i32* [ %74, %70 ], [ %69, %67 ], [ %54, %62 ]
%80 = load i32, i32* %79
%81 = icmp sgt i32 %50, 0
%82 = icmp sgt i32 %49, 0
%83 = select i1 %81, i1 true, i1 %82
br i1 %83, label %84, label %87
84: ; preds = %75
%85 = sub nsw i32 %80, %45
%86 = call i32 @midi_note_off(i32 %47, i32 %46, i32 %85, i32** %1, i32* %13)
br label %87
87: ; preds = %75, %84
br i1 %77, label %88, label %93
88: ; preds = %87
%89 = sext i32 %50 to i64
%90 = getelementptr inbounds i32, i32* %6, i64 %89
%91 = load i32, i32* %90
%92 = add nsw i32 %50, 1
br label %93
93: ; preds = %88, %87
%94 = phi i32 [ %92, %88 ], [ %50, %87 ]
%95 = phi i32 [ %91, %88 ], [ %47, %87 ]
br i1 %78, label %96, label %103
96: ; preds = %93
%97 = sext i32 %49 to i64
%98 = getelementptr inbounds i32, i32* %9, i64 %97
%99 = load i32, i32* %98
%100 = icmp eq i32 %99, 0
%101 = select i1 %100, i32 1, i32 %99
%102 = add nsw i32 %49, 1
br label %103
103: ; preds = %96, %93
%104 = phi i32 [ %102, %96 ], [ %49, %93 ]
%105 = phi i32 [ %101, %96 ], [ %46, %93 ]
%106 = load i32*, i32** %1
%107 = load i32, i32* %13
%108 = add nsw i32 %107, 1
store i32 %108, i32* %13
%109 = sext i32 %107 to i64
%110 = getelementptr inbounds i32, i32* %106, i64 %109
store i32 0, i32* %110
%111 = load i32, i32* %13
%112 = add nsw i32 %111, 1
store i32 %112, i32* %13
%113 = sext i32 %111 to i64
%114 = getelementptr inbounds i32, i32* %106, i64 %113
store i32 144, i32* %114
%115 = load i32, i32* %13
%116 = add nsw i32 %115, 1
store i32 %116, i32* %13
%117 = sext i32 %115 to i64
%118 = getelementptr inbounds i32, i32* %106, i64 %117
store i32 %95, i32* %118
%119 = load i32, i32* %13
%120 = add nsw i32 %119, 1
store i32 %120, i32* %13
%121 = sext i32 %119 to i64
%122 = getelementptr inbounds i32, i32* %106, i64 %121
store i32 %105, i32* %122
%123 = icmp slt i32 %94, %4
%124 = icmp slt i32 %104, %7
%125 = select i1 %123, i1 true, i1 %124
br i1 %125, label %42, label %126
126: ; preds = %103
%127 = icmp sgt i32 %80, 0
br i1 %127, label %128, label %137
128: ; preds = %126
%129 = sdiv i32 %80, %3
%130 = add nsw i32 %129, 1
%131 = mul nsw i32 %130, %3
%132 = load i32, i32* @stdout
%133 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %132, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0), i32 %131, i32 %80)
%134 = sub nsw i32 %131, %80
%135 = call i32 @midi_note_off(i32 %95, i32 %105, i32 %134, i32** %1, i32* %13)
%136 = load i32*, i32** %1
br label %137
137: ; preds = %29, %128, %126
%138 = phi i32 [ %76, %128 ], [ %76, %126 ], [ 0, %29 ]
%139 = phi i32* [ %136, %128 ], [ %106, %126 ], [ %34, %29 ]
%140 = load i32, i32* %13
%141 = sext i32 %140 to i64
%142 = getelementptr inbounds i32, i32* %139, i64 %141
%143 = getelementptr inbounds [4 x i32], [4 x i32]* %12, i64 0, i64 0
%144 = call i32 @memcpy(i32* %142, i32* %143, i32 4)
%145 = load i32, i32* %13
%146 = add i32 %145, 4
store i32 %146, i32* %13
%147 = add i32 %145, -18
%148 = lshr i32 %147, 24
%149 = load i32*, i32** %1
%150 = getelementptr inbounds i32, i32* %149, i64 18
store i32 %148, i32* %150
%151 = lshr i32 %147, 16
%152 = and i32 %151, 255
%153 = getelementptr inbounds i32, i32* %149, i64 19
store i32 %152, i32* %153
%154 = lshr i32 %147, 8
%155 = and i32 %154, 255
%156 = getelementptr inbounds i32, i32* %149, i64 20
store i32 %155, i32* %156
%157 = and i32 %147, 255
%158 = getelementptr inbounds i32, i32* %149, i64 21
store i32 %157, i32* %158
store i32 %146, i32* %0
%159 = load i32, i32* @stdout
%160 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %159, i8* getelementptr inbounds ([101 x i8], [101 x i8]* @.str.3, i64 0, i64 0), i32 %18, i32 %16, i32 %138, i32 %146)
br label %161
161: ; preds = %137, %26, %20
%162 = phi i32 [ -1, %20 ], [ -1, %26 ], [ 0, %137 ]
ret i32 %162
}