#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*/ stderr;
int /*<<< orphan*/ stdout;
int8_t midi_cc_generator(uint32_t *bufsize, uint8_t **buf, uint8_t cc,
                         uint16_t ticks_per_beat, uint32_t count,
                         uint32_t times[], uint8_t values[]) {
  *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) + (count * 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);
  for (int i = 0; i < count; i++) {
    uint32_t timediff = times[i] - last_time;
    last_time = times[i];
    uint32_t timediff4 = (timediff >> 28) & 0x7F;
    uint32_t timediff3 = (timediff >> 21) & 0x7F;
    uint32_t timediff2 = (timediff >> 14) & 0x7F;
    uint32_t timediff1 = (timediff >> 7) & 0x7F;
    uint32_t timediff0 = (timediff >> 0) & 0x7F;
    if (timediff4 > 0)
      (*buf)[curBufferPosition++] = 128 + timediff4;
    if (timediff3 > 0)
      (*buf)[curBufferPosition++] = 128 + timediff3;
    if (timediff2 > 0)
      (*buf)[curBufferPosition++] = 128 + timediff2;
    if (timediff1 > 0)
      (*buf)[curBufferPosition++] = 128 + timediff1;
    (*buf)[curBufferPosition++] = timediff0;
    if (0 == i)
      (*buf)[curBufferPosition++] = 176;
    (*buf)[curBufferPosition++] = cc;
    (*buf)[curBufferPosition++] = values[i];
  }
  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; %d bytes were "
          "actually used.\n",
          (int)alloc_size, (int)count, (int)curBufferPosition);
  return 0;
}


x86 assembly (clang, -O0):
<midi_cc_generator>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
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    0xe88(%rip),%rsi
mov    $0x58,%edx
call   1040 <memcpy@plt>
mov    0xed7(%rip),%rax
mov    %rax,-0xa0(%rbp)
mov    0xed1(%rip),%rax
mov    %rax,-0x98(%rbp)
movl   $0x40000,-0xa4(%rbp)
mov    -0x24(%rbp),%eax
shl    $0x3,%eax
cltq
add    $0x68,%rax
mov    %eax,-0xa8(%rbp)
cmpl   $0x40000,-0xa8(%rbp)
jle    11f8 <midi_cc_generator+0xc8>
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
mov    -0xa8(%rbp),%edx
lea    0xe90(%rip),%rsi
mov    $0x40000,%ecx
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15ba <midi_cc_generator+0x48a>
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    1245 <midi_cc_generator+0x115>
mov    0x2dbd(%rip),%rax
mov    (%rax),%edi
mov    -0xa8(%rbp),%edx
lea    0xe80(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15ba <midi_cc_generator+0x48a>
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)
mov    -0xb8(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    14d6 <midi_cc_generator+0x3a6>
mov    -0x30(%rbp),%rax
movslq -0xb8(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
sub    -0xac(%rbp),%eax
mov    %eax,-0xbc(%rbp)
mov    -0x30(%rbp),%rax
movslq -0xb8(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0xac(%rbp)
mov    -0xbc(%rbp),%eax
sar    $0x1c,%eax
and    $0x7f,%eax
mov    %eax,-0xc0(%rbp)
mov    -0xbc(%rbp),%eax
sar    $0x15,%eax
and    $0x7f,%eax
mov    %eax,-0xc4(%rbp)
mov    -0xbc(%rbp),%eax
sar    $0xe,%eax
and    $0x7f,%eax
mov    %eax,-0xc8(%rbp)
mov    -0xbc(%rbp),%eax
sar    $0x7,%eax
and    $0x7f,%eax
mov    %eax,-0xcc(%rbp)
mov    -0xbc(%rbp),%eax
sar    $0x0,%eax
and    $0x7f,%eax
mov    %eax,-0xd0(%rbp)
cmpl   $0x0,-0xc0(%rbp)
jle    137c <midi_cc_generator+0x24c>
mov    -0xc0(%rbp),%edx
add    $0x80,%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)
cmpl   $0x0,-0xc4(%rbp)
jle    13b3 <midi_cc_generator+0x283>
mov    -0xc4(%rbp),%edx
add    $0x80,%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)
cmpl   $0x0,-0xc8(%rbp)
jle    13ea <midi_cc_generator+0x2ba>
mov    -0xc8(%rbp),%edx
add    $0x80,%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)
cmpl   $0x0,-0xcc(%rbp)
jle    1421 <midi_cc_generator+0x2f1>
mov    -0xcc(%rbp),%edx
add    $0x80,%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    -0xd0(%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)
xor    %eax,%eax
cmp    -0xb8(%rbp),%eax
jne    1475 <midi_cc_generator+0x345>
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   $0xb0,(%rax,%rcx,4)
mov    -0x1c(%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    0x10(%rbp),%rax
movslq -0xb8(%rbp),%rcx
mov    (%rax,%rcx,4),%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    -0xb8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xb8(%rbp)
jmp    12ae <midi_cc_generator+0x17e>
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,-0xd4(%rbp)
mov    -0xd4(%rbp),%ecx
sar    $0x18,%ecx
and    $0xff,%ecx
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %ecx,0x48(%rax)
mov    -0xd4(%rbp),%ecx
sar    $0x10,%ecx
and    $0xff,%ecx
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %ecx,0x4c(%rax)
mov    -0xd4(%rbp),%ecx
sar    $0x8,%ecx
and    $0xff,%ecx
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %ecx,0x50(%rax)
mov    -0xd4(%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    0x2a45(%rip),%rax
mov    (%rax),%edi
mov    -0xa8(%rbp),%edx
mov    -0x24(%rbp),%ecx
mov    -0xb4(%rbp),%r8d
lea    0xb24(%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_cc_generator>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
mov    %r8d,%r13d
movl   $0x0,(%rdi)
movq   $0x0,(%rsi)
mov    0xef8(%rip),%rax
mov    %rax,0x90(%rsp)
movaps 0xed9(%rip),%xmm0
movaps %xmm0,0x80(%rsp)
movaps 0xeba(%rip),%xmm0
movaps %xmm0,0x70(%rsp)
movaps 0xe9e(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
movaps 0xe82(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xe66(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xeba(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
lea    0x68(,%r13,8),%ebx
cmp    $0x40001,%ebx
jl     11e3 <midi_cc_generator+0xb3>
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
lea    0xea5(%rip),%rsi
mov    %ebx,%edx
mov    $0x40000,%ecx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0xffffffff,%ebx
jmp    1397 <midi_cc_generator+0x267>
mov    %edx,%r12d
mov    %rsi,%rbp
mov    %rdi,%r15
mov    %r9,0x28(%rsp)
mov    %ecx,%r14d
mov    %ebx,%edi
call   1050 <malloc@plt>
mov    %rax,0x0(%rbp)
test   %rax,%rax
je     127e <midi_cc_generator+0x14e>
mov    %ebx,0x14(%rsp)
mov    %r15,0x20(%rsp)
lea    0x40(%rsp),%rsi
mov    $0x16,%r15d
mov    %rax,%rdi
mov    $0x16,%edx
call   1040 <memcpy@plt>
mov    %r14d,%edx
movzbl %dh,%ecx
mov    %rbp,0x18(%rsp)
mov    0x0(%rbp),%rax
mov    %ecx,0x30(%rax)
movzbl %dl,%ecx
mov    %ecx,0x34(%rax)
mov    %r13,0x8(%rsp)
test   %r13d,%r13d
mov    0x28(%rsp),%r11
jle    1329 <midi_cc_generator+0x1f9>
mov    (%r11),%r10d
mov    %r10d,%ecx
sar    $0x1c,%ecx
mov    %r10d,%edi
shr    $0x15,%edi
and    $0x7f,%edi
mov    %r10d,%edx
shr    $0xe,%edx
and    $0x7f,%ecx
je     12a1 <midi_cc_generator+0x171>
or     $0x80,%ecx
mov    %ecx,0x58(%rax)
mov    $0x17,%r15d
jmp    12a7 <midi_cc_generator+0x177>
mov    0x2d5b(%rip),%rax
mov    (%rax),%edi
lea    0xe24(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0xffffffff,%ebx
jmp    1397 <midi_cc_generator+0x267>
mov    $0x16,%r15d
mov    %r10d,%ecx
shr    $0x7,%ecx
and    $0x7f,%edx
test   %edi,%edi
je     12c4 <midi_cc_generator+0x194>
or     $0x80,%edi
mov    %r15d,%esi
add    $0x1,%r15d
mov    %edi,(%rax,%rsi,4)
mov    0x8(%rsp),%rdi
and    $0x7f,%ecx
test   %edx,%edx
je     12e0 <midi_cc_generator+0x1b0>
or     $0x80,%edx
mov    %r15d,%esi
add    $0x1,%r15d
mov    %edx,(%rax,%rsi,4)
mov    0xd0(%rsp),%r8
mov    %r10d,%edx
and    $0x7f,%edx
test   %ecx,%ecx
je     1302 <midi_cc_generator+0x1d2>
or     $0x80,%ecx
mov    %r15d,%esi
add    $0x1,%r15d
mov    %ecx,(%rax,%rsi,4)
mov    %r15d,%ecx
mov    %edx,(%rax,%rcx,4)
movl   $0xb0,0x4(%rax,%rcx,4)
mov    %r12d,0x8(%rax,%rcx,4)
mov    (%r8),%edx
add    $0x4,%r15d
mov    %edx,0xc(%rax,%rcx,4)
cmp    $0x1,%edi
jne    13ab <midi_cc_generator+0x27b>
movslq %r15d,%rbx
lea    (%rax,%rbx,4),%rdi
lea    0x30(%rsp),%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
lea    0x4(%rbx),%r8d
add    $0xffffffee,%ebx
mov    %ebx,%eax
shr    $0x18,%eax
mov    0x18(%rsp),%rcx
mov    (%rcx),%rcx
mov    %eax,0x48(%rcx)
mov    %ebx,%eax
shr    $0x10,%eax
movzbl %al,%eax
mov    %eax,0x4c(%rcx)
movzbl %bh,%eax
mov    %eax,0x50(%rcx)
movzbl %bl,%eax
mov    %eax,0x54(%rcx)
mov    0x20(%rsp),%rax
mov    %r8d,(%rax)
mov    0x2c5c(%rip),%rax
mov    (%rax),%edi
lea    0xd4b(%rip),%rsi
xor    %ebx,%ebx
mov    0x14(%rsp),%edx
mov    0x8(%rsp),%rcx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    %ebx,%eax
add    $0x98,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %edi,%r9d
mov    $0x1,%edi
jmp    13e4 <midi_cc_generator+0x2b4>
cs nopw 0x0(%rax,%rax,1)
nop
movslq %r15d,%rcx
mov    %ebp,(%rax,%rcx,4)
mov    %r12d,0x4(%rax,%rcx,4)
mov    (%r8,%rdi,4),%edx
lea    0x3(%rcx),%r15d
mov    %edx,0x8(%rax,%rcx,4)
add    $0x1,%rdi
cmp    %rdi,%r9
je     1329 <midi_cc_generator+0x1f9>
mov    %r10d,%ecx
mov    (%r11,%rdi,4),%r10d
mov    %r10d,%ebp
sub    %ecx,%ebp
mov    %ebp,%esi
sar    $0x1c,%esi
mov    %ebp,%edx
shr    $0x15,%edx
and    $0x7f,%edx
mov    %ebp,%ecx
shr    $0xe,%ecx
and    $0x7f,%esi
je     1417 <midi_cc_generator+0x2e7>
or     $0x80,%esi
movslq %r15d,%rbx
add    $0x1,%r15d
mov    %esi,(%rax,%rbx,4)
mov    %ebp,%ebx
shr    $0x7,%ebx
and    $0x7f,%ecx
test   %edx,%edx
je     1433 <midi_cc_generator+0x303>
or     $0x80,%edx
movslq %r15d,%rsi
add    $0x1,%r15d
mov    %edx,(%rax,%rsi,4)
and    $0x7f,%ebx
test   %ecx,%ecx
je     144a <midi_cc_generator+0x31a>
or     $0x80,%ecx
movslq %r15d,%rdx
add    $0x1,%r15d
mov    %ecx,(%rax,%rdx,4)
and    $0x7f,%ebp
test   %ebx,%ebx
je     13c0 <midi_cc_generator+0x290>
or     $0x80,%ebx
movslq %r15d,%rcx
add    $0x1,%r15d
mov    %ebx,(%rax,%rcx,4)
jmp    13c0 <midi_cc_generator+0x290>

LLVM IR (-O0):
@__const.midi_cc_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_cc_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 = [77 x i8] c"Allocated %d bytes for %d points of MIDI data; %d bytes were actually used.\0A\00"
define i32 @midi_cc_generator(i32* %0, i32** %1, i32 %2, i32 %3, i32 %4, i32* %5, i32* %6) {
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32**
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32*
%15 = alloca i32*
%16 = alloca [22 x i32]
%17 = alloca [4 x i32]
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
%23 = alloca i32
%24 = alloca i32
%25 = alloca i32
%26 = alloca i32
%27 = alloca i32
%28 = alloca i32
%29 = alloca i32
%30 = alloca i32
store i32* %0, i32** %9
store i32** %1, i32*** %10
store i32 %2, i32* %11
store i32 %3, i32* %12
store i32 %4, i32* %13
store i32* %5, i32** %14
store i32* %6, i32** %15
%31 = load i32*, i32** %9
store i32 0, i32* %31
%32 = load i32**, i32*** %10
store i32* null, i32** %32
%33 = bitcast [22 x i32]* %16 to i8*
%34 = bitcast [4 x i32]* %17 to i8*
store i32 262144, i32* %18
%35 = load i32, i32* %13
%36 = mul nsw i32 %35, 8
%37 = sext i32 %36 to i64
%38 = add i64 104, %37
%39 = trunc i64 %38 to i32
store i32 %39, i32* %19
%40 = load i32, i32* %19
%41 = icmp sgt i32 %40, 262144
br i1 %41, label %42, label %46
42: ; preds = %7
%43 = load i32, i32* @stderr
%44 = load i32, i32* %19
%45 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str, i64 0, i64 0), i32 %44, i32 262144)
store i32 -1, i32* %8
br label %236
46: ; preds = %7
%47 = load i32, i32* %19
%48 = call i32* @malloc(i32 %47)
%49 = load i32**, i32*** %10
store i32* %48, i32** %49
%50 = load i32**, i32*** %10
%51 = load i32*, i32** %50
%52 = icmp eq i32* null, %51
br i1 %52, label %53, label %57
53: ; preds = %46
%54 = load i32, i32* @stderr
%55 = load i32, i32* %19
%56 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %55)
store i32 -1, i32* %8
br label %236
57: ; preds = %46
%58 = load i32**, i32*** %10
%59 = load i32*, i32** %58
%60 = getelementptr inbounds [22 x i32], [22 x i32]* %16, i64 0, i64 0
%61 = call i32 @memcpy(i32* %59, i32* %60, i32 22)
%62 = load i32, i32* %12
%63 = ashr i32 %62, 8
%64 = and i32 %63, 255
%65 = load i32**, i32*** %10
%66 = load i32*, i32** %65
%67 = getelementptr inbounds i32, i32* %66, i64 12
store i32 %64, i32* %67
%68 = load i32, i32* %12
%69 = and i32 %68, 255
%70 = load i32**, i32*** %10
%71 = load i32*, i32** %70
%72 = getelementptr inbounds i32, i32* %71, i64 13
store i32 %69, i32* %72
store i32 0, i32* %20
store i32 22, i32* %21
store i32 22, i32* %22
store i32 0, i32* %23
br label %73
73: ; preds = %188, %57
%74 = load i32, i32* %23
%75 = load i32, i32* %13
%76 = icmp slt i32 %74, %75
br i1 %76, label %77, label %191
77: ; preds = %73
%78 = load i32*, i32** %14
%79 = load i32, i32* %23
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds i32, i32* %78, i64 %80
%82 = load i32, i32* %81
%83 = load i32, i32* %20
%84 = sub nsw i32 %82, %83
store i32 %84, i32* %24
%85 = load i32*, i32** %14
%86 = load i32, i32* %23
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds i32, i32* %85, i64 %87
%89 = load i32, i32* %88
store i32 %89, i32* %20
%90 = load i32, i32* %24
%91 = ashr i32 %90, 28
%92 = and i32 %91, 127
store i32 %92, i32* %25
%93 = load i32, i32* %24
%94 = ashr i32 %93, 21
%95 = and i32 %94, 127
store i32 %95, i32* %26
%96 = load i32, i32* %24
%97 = ashr i32 %96, 14
%98 = and i32 %97, 127
store i32 %98, i32* %27
%99 = load i32, i32* %24
%100 = ashr i32 %99, 7
%101 = and i32 %100, 127
store i32 %101, i32* %28
%102 = load i32, i32* %24
%103 = ashr i32 %102, 0
%104 = and i32 %103, 127
store i32 %104, i32* %29
%105 = load i32, i32* %25
%106 = icmp sgt i32 %105, 0
br i1 %106, label %107, label %116
107: ; preds = %77
%108 = load i32, i32* %25
%109 = add nsw i32 128, %108
%110 = load i32**, i32*** %10
%111 = load i32*, i32** %110
%112 = load i32, i32* %22
%113 = add nsw i32 %112, 1
store i32 %113, i32* %22
%114 = sext i32 %112 to i64
%115 = getelementptr inbounds i32, i32* %111, i64 %114
store i32 %109, i32* %115
br label %116
116: ; preds = %107, %77
%117 = load i32, i32* %26
%118 = icmp sgt i32 %117, 0
br i1 %118, label %119, label %128
119: ; preds = %116
%120 = load i32, i32* %26
%121 = add nsw i32 128, %120
%122 = load i32**, i32*** %10
%123 = load i32*, i32** %122
%124 = load i32, i32* %22
%125 = add nsw i32 %124, 1
store i32 %125, i32* %22
%126 = sext i32 %124 to i64
%127 = getelementptr inbounds i32, i32* %123, i64 %126
store i32 %121, i32* %127
br label %128
128: ; preds = %119, %116
%129 = load i32, i32* %27
%130 = icmp sgt i32 %129, 0
br i1 %130, label %131, label %140
131: ; preds = %128
%132 = load i32, i32* %27
%133 = add nsw i32 128, %132
%134 = load i32**, i32*** %10
%135 = load i32*, i32** %134
%136 = load i32, i32* %22
%137 = add nsw i32 %136, 1
store i32 %137, i32* %22
%138 = sext i32 %136 to i64
%139 = getelementptr inbounds i32, i32* %135, i64 %138
store i32 %133, i32* %139
br label %140
140: ; preds = %131, %128
%141 = load i32, i32* %28
%142 = icmp sgt i32 %141, 0
br i1 %142, label %143, label %152
143: ; preds = %140
%144 = load i32, i32* %28
%145 = add nsw i32 128, %144
%146 = load i32**, i32*** %10
%147 = load i32*, i32** %146
%148 = load i32, i32* %22
%149 = add nsw i32 %148, 1
store i32 %149, i32* %22
%150 = sext i32 %148 to i64
%151 = getelementptr inbounds i32, i32* %147, i64 %150
store i32 %145, i32* %151
br label %152
152: ; preds = %143, %140
%153 = load i32, i32* %29
%154 = load i32**, i32*** %10
%155 = load i32*, i32** %154
%156 = load i32, i32* %22
%157 = add nsw i32 %156, 1
store i32 %157, i32* %22
%158 = sext i32 %156 to i64
%159 = getelementptr inbounds i32, i32* %155, i64 %158
store i32 %153, i32* %159
%160 = load i32, i32* %23
%161 = icmp eq i32 0, %160
br i1 %161, label %162, label %169
162: ; preds = %152
%163 = load i32**, i32*** %10
%164 = load i32*, i32** %163
%165 = load i32, i32* %22
%166 = add nsw i32 %165, 1
store i32 %166, i32* %22
%167 = sext i32 %165 to i64
%168 = getelementptr inbounds i32, i32* %164, i64 %167
store i32 176, i32* %168
br label %169
169: ; preds = %162, %152
%170 = load i32, i32* %11
%171 = load i32**, i32*** %10
%172 = load i32*, i32** %171
%173 = load i32, i32* %22
%174 = add nsw i32 %173, 1
store i32 %174, i32* %22
%175 = sext i32 %173 to i64
%176 = getelementptr inbounds i32, i32* %172, i64 %175
store i32 %170, i32* %176
%177 = load i32*, i32** %15
%178 = load i32, i32* %23
%179 = sext i32 %178 to i64
%180 = getelementptr inbounds i32, i32* %177, i64 %179
%181 = load i32, i32* %180
%182 = load i32**, i32*** %10
%183 = load i32*, i32** %182
%184 = load i32, i32* %22
%185 = add nsw i32 %184, 1
store i32 %185, i32* %22
%186 = sext i32 %184 to i64
%187 = getelementptr inbounds i32, i32* %183, i64 %186
store i32 %181, i32* %187
br label %188
188: ; preds = %169
%189 = load i32, i32* %23
%190 = add nsw i32 %189, 1
store i32 %190, i32* %23
br label %73
191: ; preds = %73
%192 = load i32**, i32*** %10
%193 = load i32*, i32** %192
%194 = load i32, i32* %22
%195 = sext i32 %194 to i64
%196 = getelementptr inbounds i32, i32* %193, i64 %195
%197 = getelementptr inbounds [4 x i32], [4 x i32]* %17, i64 0, i64 0
%198 = call i32 @memcpy(i32* %196, i32* %197, i32 4)
%199 = load i32, i32* %22
%200 = sext i32 %199 to i64
%201 = add i64 %200, 4
%202 = trunc i64 %201 to i32
store i32 %202, i32* %22
%203 = load i32, i32* %22
%204 = load i32, i32* %21
%205 = sub nsw i32 %203, %204
store i32 %205, i32* %30
%206 = load i32, i32* %30
%207 = ashr i32 %206, 24
%208 = and i32 %207, 255
%209 = load i32**, i32*** %10
%210 = load i32*, i32** %209
%211 = getelementptr inbounds i32, i32* %210, i64 18
store i32 %208, i32* %211
%212 = load i32, i32* %30
%213 = ashr i32 %212, 16
%214 = and i32 %213, 255
%215 = load i32**, i32*** %10
%216 = load i32*, i32** %215
%217 = getelementptr inbounds i32, i32* %216, i64 19
store i32 %214, i32* %217
%218 = load i32, i32* %30
%219 = ashr i32 %218, 8
%220 = and i32 %219, 255
%221 = load i32**, i32*** %10
%222 = load i32*, i32** %221
%223 = getelementptr inbounds i32, i32* %222, i64 20
store i32 %220, i32* %223
%224 = load i32, i32* %30
%225 = and i32 %224, 255
%226 = load i32**, i32*** %10
%227 = load i32*, i32** %226
%228 = getelementptr inbounds i32, i32* %227, i64 21
store i32 %225, i32* %228
%229 = load i32, i32* %22
%230 = load i32*, i32** %9
store i32 %229, i32* %230
%231 = load i32, i32* @stdout
%232 = load i32, i32* %19
%233 = load i32, i32* %13
%234 = load i32, i32* %22
%235 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %231, i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str.2, i64 0, i64 0), i32 %232, i32 %233, i32 %234)
store i32 0, i32* %8
br label %236
236: ; preds = %191, %53, %42
%237 = load i32, i32* %8
ret i32 %237
}

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