#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 */

/* Variables and functions */
int quantize5(int);
void compute_pitch_contour(int nnotes, int *midipitch, int qntflag) {
  int lastpitch, newpitch;
  int i;
  lastpitch = -1;
  for (i = 0; i < nnotes; i++) {
    if (midipitch[i] == -1000 || midipitch[i] == 0)
      continue;
    if (lastpitch < 0) {
      lastpitch = midipitch[i];
      midipitch[i] = -1;
      continue;
    } else {
      newpitch = midipitch[i];
      midipitch[i] = midipitch[i] - lastpitch;
      lastpitch = newpitch;
      if (qntflag > 0)
        midipitch[i] = quantize5(midipitch[i]);
      midipitch[i] += 256;
    }
  }
}


x86 assembly (clang, -O0):
<compute_pitch_contour>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0xffffffff,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    120f <compute_pitch_contour+0xff>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
cmpl   $0xfffffc18,(%rax,%rcx,4)
je     1163 <compute_pitch_contour+0x53>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jne    1168 <compute_pitch_contour+0x58>
jmp    1201 <compute_pitch_contour+0xf1>
cmpl   $0x0,-0x18(%rbp)
jge    1194 <compute_pitch_contour+0x84>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
movl   $0xffffffff,(%rax,%rcx,4)
jmp    1201 <compute_pitch_contour+0xf1>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
sub    -0x18(%rbp),%edx
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    11e8 <compute_pitch_contour+0xd8>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
call   1030 <quantize5@plt>
mov    %eax,%edx
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
add    $0x100,%edx
mov    %edx,(%rax,%rcx,4)
jmp    1201 <compute_pitch_contour+0xf1>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1130 <compute_pitch_contour+0x20>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compute_pitch_contour>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %edi,%edi
jle    1177 <compute_pitch_contour+0x67>
mov    %edx,%r14d
mov    %rsi,%r12
mov    %edi,%r15d
mov    $0xffffffff,%ecx
xor    %ebp,%ebp
jmp    113d <compute_pitch_contour+0x2d>
xchg   %ax,%ax
mov    %ecx,%ebx
add    $0x1,%rbp
mov    %ebx,%ecx
cmp    %rbp,%r15
je     1177 <compute_pitch_contour+0x67>
mov    (%r12,%rbp,4),%ebx
cmp    $0xfffffc18,%ebx
je     1130 <compute_pitch_contour+0x20>
test   %ebx,%ebx
je     1130 <compute_pitch_contour+0x20>
test   %ecx,%ecx
js     116c <compute_pitch_contour+0x5c>
mov    %ebx,%eax
sub    %ecx,%eax
mov    %eax,(%r12,%rbp,4)
test   %r14d,%r14d
jle    1165 <compute_pitch_contour+0x55>
mov    %eax,%edi
call   1030 <quantize5@plt>
add    $0x100,%eax
jmp    1171 <compute_pitch_contour+0x61>
mov    $0xffffffff,%eax
mov    %eax,(%r12,%rbp,4)
jmp    1132 <compute_pitch_contour+0x22>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @compute_pitch_contour(i32 %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
store i32 %2, i32* %6
store i32 -1, i32* %7
store i32 0, i32* %9
br label %10
10: ; preds = %81, %3
%11 = load i32, i32* %9
%12 = load i32, i32* %4
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %84
14: ; preds = %10
%15 = load i32*, i32** %5
%16 = load i32, i32* %9
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i32, i32* %15, i64 %17
%19 = load i32, i32* %18
%20 = icmp eq i32 %19, -1000
br i1 %20, label %28, label %21
21: ; preds = %14
%22 = load i32*, i32** %5
%23 = load i32, i32* %9
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %22, i64 %24
%26 = load i32, i32* %25
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %21, %14
br label %81
29: ; preds = %21
%30 = load i32, i32* %7
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %42
32: ; preds = %29
%33 = load i32*, i32** %5
%34 = load i32, i32* %9
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32, i32* %33, i64 %35
%37 = load i32, i32* %36
store i32 %37, i32* %7
%38 = load i32*, i32** %5
%39 = load i32, i32* %9
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i32, i32* %38, i64 %40
store i32 -1, i32* %41
br label %81
42: ; preds = %29
%43 = load i32*, i32** %5
%44 = load i32, i32* %9
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i32, i32* %43, i64 %45
%47 = load i32, i32* %46
store i32 %47, i32* %8
%48 = load i32*, i32** %5
%49 = load i32, i32* %9
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i32, i32* %48, i64 %50
%52 = load i32, i32* %51
%53 = load i32, i32* %7
%54 = sub nsw i32 %52, %53
%55 = load i32*, i32** %5
%56 = load i32, i32* %9
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i32, i32* %55, i64 %57
store i32 %54, i32* %58
%59 = load i32, i32* %8
store i32 %59, i32* %7
%60 = load i32, i32* %6
%61 = icmp sgt i32 %60, 0
br i1 %61, label %62, label %73
62: ; preds = %42
%63 = load i32*, i32** %5
%64 = load i32, i32* %9
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i32, i32* %63, i64 %65
%67 = load i32, i32* %66
%68 = call i32 @quantize5(i32 %67)
%69 = load i32*, i32** %5
%70 = load i32, i32* %9
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds i32, i32* %69, i64 %71
store i32 %68, i32* %72
br label %73
73: ; preds = %62, %42
%74 = load i32*, i32** %5
%75 = load i32, i32* %9
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds i32, i32* %74, i64 %76
%78 = load i32, i32* %77
%79 = add nsw i32 %78, 256
store i32 %79, i32* %77
br label %80
80: ; preds = %73
br label %81
81: ; preds = %80, %32, %28
%82 = load i32, i32* %9
%83 = add nsw i32 %82, 1
store i32 %83, i32* %9
br label %10
84: ; preds = %10
ret void
}

LLVM IR (-O2):
define void @compute_pitch_contour(i32 %0, i32* nocapture %1, i32 %2) {
%4 = icmp sgt i32 %0, 0
br i1 %4, label %5, label %28
5: ; preds = %3
%6 = icmp sgt i32 %2, 0
%7 = zext i32 %0 to i64
br label %8
8: ; preds = %5, %24
%9 = phi i64 [ 0, %5 ], [ %26, %24 ]
%10 = phi i32 [ -1, %5 ], [ %25, %24 ]
%11 = getelementptr inbounds i32, i32* %1, i64 %9
%12 = load i32, i32* %11
switch i32 %12, label %13 [
i32 -1000, label %24
i32 0, label %24
]
13: ; preds = %8
%14 = icmp slt i32 %10, 0
br i1 %14, label %22, label %15
15: ; preds = %13
%16 = sub nsw i32 %12, %10
store i32 %16, i32* %11
br i1 %6, label %17, label %19
17: ; preds = %15
%18 = tail call i32 @quantize5(i32 %16)
br label %19
19: ; preds = %17, %15
%20 = phi i32 [ %18, %17 ], [ %16, %15 ]
%21 = add nsw i32 %20, 256
br label %22
22: ; preds = %13, %19
%23 = phi i32 [ %21, %19 ], [ -1, %13 ]
store i32 %23, i32* %11
br label %24
24: ; preds = %22, %8, %8
%25 = phi i32 [ %10, %8 ], [ %10, %8 ], [ %12, %22 ]
%26 = add nuw nsw i64 %9, 1
%27 = icmp eq i64 %26, %7
br i1 %27, label %28, label %8
28: ; preds = %24, %3
ret void
}