#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 int16_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_pitchbend_generator(uint32_t *bufsize, uint8_t **buf, uint8_t cc,
                                uint16_t ticks_per_beat, uint32_t count,
                                uint32_t times[], int16_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++] = 224;
    (*buf)[curBufferPosition++] = (values[i] + 8192) % 128;
    (*buf)[curBufferPosition++] = (values[i] + 8192) / 128;
  }
  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_pitchbend_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_pitchbend_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    15e1 <midi_pitchbend_generator+0x4b1>
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_pitchbend_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    15e1 <midi_pitchbend_generator+0x4b1>
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    14fd <midi_pitchbend_generator+0x3cd>
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_pitchbend_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_pitchbend_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_pitchbend_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_pitchbend_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_pitchbend_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   $0xe0,(%rax,%rcx,4)
mov    0x10(%rbp),%rax
movslq -0xb8(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
add    $0x2000,%eax
mov    $0x80,%ecx
cltd
idiv   %ecx
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),%eax
add    $0x2000,%eax
mov    $0x80,%ecx
cltd
idiv   %ecx
mov    %eax,%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_pitchbend_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    0x2a1e(%rip),%rax
mov    (%rax),%edi
mov    -0xa8(%rbp),%edx
mov    -0x24(%rbp),%ecx
mov    -0xb4(%rbp),%r8d
lea    0xafd(%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_pitchbend_generator>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    %r8d,%r12d
movl   $0x0,(%rdi)
movq   $0x0,(%rsi)
mov    0xefb(%rip),%rax
mov    %rax,0x70(%rsp)
movaps 0xedf(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
movaps 0xec3(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xea7(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xe8b(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xe6f(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xec3(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
lea    0x68(,%r12,8),%r13d
cmp    $0x40001,%r13d
jl     11d7 <midi_pitchbend_generator+0xa7>
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
lea    0xead(%rip),%rsi
mov    %r13d,%edx
mov    $0x40000,%ecx
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    13cf <midi_pitchbend_generator+0x29f>
mov    %r9,%r14
mov    %rsi,%rbp
mov    %rdi,%rbx
mov    %ecx,%r15d
mov    %r13d,%edi
call   1050 <malloc@plt>
mov    %rax,0x0(%rbp)
test   %rax,%rax
je     13b5 <midi_pitchbend_generator+0x285>
mov    %rbx,0x8(%rsp)
lea    0x20(%rsp),%rsi
mov    %rbp,%rbx
mov    $0x16,%ebp
mov    %rax,%rdi
mov    $0x16,%edx
call   1040 <memcpy@plt>
mov    %r15d,%ecx
movzbl %ch,%eax
mov    %rbx,(%rsp)
mov    (%rbx),%r11
mov    %eax,0x30(%r11)
movzbl %cl,%eax
mov    %eax,0x34(%r11)
test   %r12d,%r12d
jle    1349 <midi_pitchbend_generator+0x219>
mov    0xb0(%rsp),%r8
mov    %r12d,%r9d
mov    $0x16,%ebp
xor    %esi,%esi
xor    %r10d,%r10d
jmp    12a4 <midi_pitchbend_generator+0x174>
nop
mov    (%r8,%rsi,4),%eax
lea    0x2000(%rax),%edx
lea    0x207f(%rax),%edi
test   %edx,%edx
cmovns %edx,%edi
and    $0xffffff80,%edi
neg    %edi
add    %edi,%eax
add    $0x2000,%eax
movslq %ecx,%rcx
mov    %eax,(%r11,%rcx,4)
mov    (%r8,%rsi,4),%eax
lea    0x2000(%rax),%edx
add    $0x207f,%eax
test   %edx,%edx
cmovns %edx,%eax
sar    $0x7,%eax
lea    0x2(%rcx),%ebp
mov    %eax,0x4(%r11,%rcx,4)
add    $0x1,%rsi
cmp    %rsi,%r9
je     1349 <midi_pitchbend_generator+0x219>
mov    %r10d,%ecx
mov    (%r14,%rsi,4),%r10d
mov    %r10d,%eax
sub    %ecx,%eax
mov    %eax,%edx
sar    $0x1c,%edx
mov    %eax,%ecx
shr    $0x15,%ecx
and    $0x7f,%ecx
mov    %eax,%edi
shr    $0xe,%edi
and    $0x7f,%edx
je     12d7 <midi_pitchbend_generator+0x1a7>
or     $0x80,%edx
movslq %ebp,%rbx
add    $0x1,%ebp
mov    %edx,(%r11,%rbx,4)
mov    %eax,%ebx
shr    $0x7,%ebx
and    $0x7f,%edi
test   %ecx,%ecx
je     12f3 <midi_pitchbend_generator+0x1c3>
or     $0x80,%ecx
movslq %ebp,%rdx
add    $0x1,%ebp
mov    %ecx,(%r11,%rdx,4)
and    $0x7f,%ebx
test   %edi,%edi
je     130a <midi_pitchbend_generator+0x1da>
or     $0x80,%edi
movslq %ebp,%rcx
add    $0x1,%ebp
mov    %edi,(%r11,%rcx,4)
and    $0x7f,%eax
test   %ebx,%ebx
je     1321 <midi_pitchbend_generator+0x1f1>
or     $0x80,%ebx
movslq %ebp,%rcx
add    $0x1,%ebp
mov    %ebx,(%r11,%rcx,4)
lea    0x1(%rbp),%ecx
movslq %ebp,%rdx
mov    %eax,(%r11,%rdx,4)
test   %rsi,%rsi
jne    1250 <midi_pitchbend_generator+0x120>
add    $0x2,%ebp
movslq %ecx,%rax
movl   $0xe0,(%r11,%rax,4)
mov    %ebp,%ecx
jmp    1250 <midi_pitchbend_generator+0x120>
movslq %ebp,%rbx
lea    (%r11,%rbx,4),%rdi
lea    0x10(%rsp),%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
lea    0x4(%rbx),%r8d
add    $0xffffffee,%ebx
mov    %ebx,%eax
shr    $0x18,%eax
mov    (%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    0x8(%rsp),%rax
mov    %r8d,(%rax)
mov    0x2c3d(%rip),%rax
mov    (%rax),%edi
lea    0xd2c(%rip),%rsi
xor    %ebx,%ebx
mov    %r13d,%edx
mov    %r12d,%ecx
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    13d4 <midi_pitchbend_generator+0x2a4>
mov    0x2c24(%rip),%rax
mov    (%rax),%edi
lea    0xced(%rip),%rsi
mov    %r13d,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.midi_pitchbend_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_pitchbend_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_pitchbend_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 %244
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 %244
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 = %196, %57
%74 = load i32, i32* %23
%75 = load i32, i32* %13
%76 = icmp slt i32 %74, %75
br i1 %76, label %77, label %199
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 224, i32* %168
br label %169
169: ; preds = %162, %152
%170 = load i32*, i32** %15
%171 = load i32, i32* %23
%172 = sext i32 %171 to i64
%173 = getelementptr inbounds i32, i32* %170, i64 %172
%174 = load i32, i32* %173
%175 = add nsw i32 %174, 8192
%176 = srem i32 %175, 128
%177 = load i32**, i32*** %10
%178 = load i32*, i32** %177
%179 = load i32, i32* %22
%180 = add nsw i32 %179, 1
store i32 %180, i32* %22
%181 = sext i32 %179 to i64
%182 = getelementptr inbounds i32, i32* %178, i64 %181
store i32 %176, i32* %182
%183 = load i32*, i32** %15
%184 = load i32, i32* %23
%185 = sext i32 %184 to i64
%186 = getelementptr inbounds i32, i32* %183, i64 %185
%187 = load i32, i32* %186
%188 = add nsw i32 %187, 8192
%189 = sdiv i32 %188, 128
%190 = load i32**, i32*** %10
%191 = load i32*, i32** %190
%192 = load i32, i32* %22
%193 = add nsw i32 %192, 1
store i32 %193, i32* %22
%194 = sext i32 %192 to i64
%195 = getelementptr inbounds i32, i32* %191, i64 %194
store i32 %189, i32* %195
br label %196
196: ; preds = %169
%197 = load i32, i32* %23
%198 = add nsw i32 %197, 1
store i32 %198, i32* %23
br label %73
199: ; preds = %73
%200 = load i32**, i32*** %10
%201 = load i32*, i32** %200
%202 = load i32, i32* %22
%203 = sext i32 %202 to i64
%204 = getelementptr inbounds i32, i32* %201, i64 %203
%205 = getelementptr inbounds [4 x i32], [4 x i32]* %17, i64 0, i64 0
%206 = call i32 @memcpy(i32* %204, i32* %205, i32 4)
%207 = load i32, i32* %22
%208 = sext i32 %207 to i64
%209 = add i64 %208, 4
%210 = trunc i64 %209 to i32
store i32 %210, i32* %22
%211 = load i32, i32* %22
%212 = load i32, i32* %21
%213 = sub nsw i32 %211, %212
store i32 %213, i32* %30
%214 = load i32, i32* %30
%215 = ashr i32 %214, 24
%216 = and i32 %215, 255
%217 = load i32**, i32*** %10
%218 = load i32*, i32** %217
%219 = getelementptr inbounds i32, i32* %218, i64 18
store i32 %216, i32* %219
%220 = load i32, i32* %30
%221 = ashr i32 %220, 16
%222 = and i32 %221, 255
%223 = load i32**, i32*** %10
%224 = load i32*, i32** %223
%225 = getelementptr inbounds i32, i32* %224, i64 19
store i32 %222, i32* %225
%226 = load i32, i32* %30
%227 = ashr i32 %226, 8
%228 = and i32 %227, 255
%229 = load i32**, i32*** %10
%230 = load i32*, i32** %229
%231 = getelementptr inbounds i32, i32* %230, i64 20
store i32 %228, i32* %231
%232 = load i32, i32* %30
%233 = and i32 %232, 255
%234 = load i32**, i32*** %10
%235 = load i32*, i32** %234
%236 = getelementptr inbounds i32, i32* %235, i64 21
store i32 %233, i32* %236
%237 = load i32, i32* %22
%238 = load i32*, i32** %9
store i32 %237, i32* %238
%239 = load i32, i32* @stdout
%240 = load i32, i32* %19
%241 = load i32, i32* %13
%242 = load i32, i32* %22
%243 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %239, i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str.2, i64 0, i64 0), i32 %240, i32 %241, i32 %242)
store i32 0, i32* %8
br label %244
244: ; preds = %199, %53, %42
%245 = load i32, i32* %8
ret i32 %245
}

LLVM IR (-O2):
@__const.midi_pitchbend_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_pitchbend_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_pitchbend_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 %130
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 %130
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 %36
34: ; preds = %24
%35 = zext i32 %4 to i64
br label %57
36: ; preds = %113, %24
%37 = phi i32 [ 22, %24 ], [ %125, %113 ]
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i32, i32* %29, i64 %38
%40 = getelementptr inbounds [4 x i32], [4 x i32]* %9, i64 0, i64 0
%41 = call i32 @memcpy(i32* %39, i32* %40, i32 4)
%42 = add i32 %37, 4
%43 = add i32 %37, -18
%44 = lshr i32 %43, 24
%45 = load i32*, i32** %1
%46 = getelementptr inbounds i32, i32* %45, i64 18
store i32 %44, i32* %46
%47 = lshr i32 %43, 16
%48 = and i32 %47, 255
%49 = getelementptr inbounds i32, i32* %45, i64 19
store i32 %48, i32* %49
%50 = lshr i32 %43, 8
%51 = and i32 %50, 255
%52 = getelementptr inbounds i32, i32* %45, i64 20
store i32 %51, i32* %52
%53 = and i32 %43, 255
%54 = getelementptr inbounds i32, i32* %45, i64 21
store i32 %53, i32* %54
store i32 %42, i32* %0
%55 = load i32, i32* @stdout
%56 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str.2, i64 0, i64 0), i32 %13, i32 %4, i32 %42)
br label %130
57: ; preds = %34, %113
%58 = phi i64 [ 0, %34 ], [ %128, %113 ]
%59 = phi i32 [ 0, %34 ], [ %62, %113 ]
%60 = phi i32 [ 22, %34 ], [ %125, %113 ]
%61 = getelementptr inbounds i32, i32* %5, i64 %58
%62 = load i32, i32* %61
%63 = sub nsw i32 %62, %59
%64 = ashr i32 %63, 28
%65 = and i32 %64, 127
%66 = lshr i32 %63, 21
%67 = and i32 %66, 127
%68 = lshr i32 %63, 14
%69 = and i32 %68, 127
%70 = lshr i32 %63, 7
%71 = and i32 %70, 127
%72 = and i32 %63, 127
%73 = icmp eq i32 %65, 0
br i1 %73, label %79, label %74
74: ; preds = %57
%75 = or i32 %65, 128
%76 = add nsw i32 %60, 1
%77 = sext i32 %60 to i64
%78 = getelementptr inbounds i32, i32* %29, i64 %77
store i32 %75, i32* %78
br label %79
79: ; preds = %74, %57
%80 = phi i32 [ %76, %74 ], [ %60, %57 ]
%81 = icmp eq i32 %67, 0
br i1 %81, label %87, label %82
82: ; preds = %79
%83 = or i32 %67, 128
%84 = add nsw i32 %80, 1
%85 = sext i32 %80 to i64
%86 = getelementptr inbounds i32, i32* %29, i64 %85
store i32 %83, i32* %86
br label %87
87: ; preds = %82, %79
%88 = phi i32 [ %84, %82 ], [ %80, %79 ]
%89 = icmp eq i32 %69, 0
br i1 %89, label %95, label %90
90: ; preds = %87
%91 = or i32 %69, 128
%92 = add nsw i32 %88, 1
%93 = sext i32 %88 to i64
%94 = getelementptr inbounds i32, i32* %29, i64 %93
store i32 %91, i32* %94
br label %95
95: ; preds = %90, %87
%96 = phi i32 [ %92, %90 ], [ %88, %87 ]
%97 = icmp eq i32 %71, 0
br i1 %97, label %103, label %98
98: ; preds = %95
%99 = or i32 %71, 128
%100 = add nsw i32 %96, 1
%101 = sext i32 %96 to i64
%102 = getelementptr inbounds i32, i32* %29, i64 %101
store i32 %99, i32* %102
br label %103
103: ; preds = %98, %95
%104 = phi i32 [ %100, %98 ], [ %96, %95 ]
%105 = add nsw i32 %104, 1
%106 = sext i32 %104 to i64
%107 = getelementptr inbounds i32, i32* %29, i64 %106
store i32 %72, i32* %107
%108 = icmp eq i64 %58, 0
br i1 %108, label %109, label %113
109: ; preds = %103
%110 = add nsw i32 %104, 2
%111 = sext i32 %105 to i64
%112 = getelementptr inbounds i32, i32* %29, i64 %111
store i32 224, i32* %112
br label %113
113: ; preds = %109, %103
%114 = phi i32 [ %110, %109 ], [ %105, %103 ]
%115 = getelementptr inbounds i32, i32* %6, i64 %58
%116 = load i32, i32* %115
%117 = add nsw i32 %116, 8192
%118 = srem i32 %117, 128
%119 = add nsw i32 %114, 1
%120 = sext i32 %114 to i64
%121 = getelementptr inbounds i32, i32* %29, i64 %120
store i32 %118, i32* %121
%122 = load i32, i32* %115
%123 = add nsw i32 %122, 8192
%124 = sdiv i32 %123, 128
%125 = add nsw i32 %114, 2
%126 = sext i32 %119 to i64
%127 = getelementptr inbounds i32, i32* %29, i64 %126
store i32 %124, i32* %127
%128 = add nuw nsw i64 %58, 1
%129 = icmp eq i64 %128, %35
br i1 %129, label %36, label %57
130: ; preds = %36, %21, %15
%131 = phi i32 [ -1, %15 ], [ -1, %21 ], [ 0, %36 ]
ret i32 %131
}