#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ int16_t;

/* Variables and functions */
int /*<<< orphan*/ music5000_get_sample(int /*<<< orphan*/ *,
                                        int /*<<< orphan*/ *);
int /*<<< orphan*/ music5000_update_6MHz();
void music5000_fillbuf(int16_t *buffer, int len) {
  int i;
  int sample;
  for (sample = 0; sample < len; sample++) {
    for (i = 0; i < 128; i++) {
      music5000_update_6MHz();
    }
    music5000_get_sample(buffer, buffer + 1);
    buffer += 2;
  }
}


x86 assembly (clang, -O0):
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1196 <music5000_fillbuf+0x76>
movl   $0x0,-0x10(%rbp)
cmpl   $0x80,-0x10(%rbp)
jge    116b <music5000_fillbuf+0x4b>
mov    $0x0,%al
call   1040 <music5000_update_6MHz@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1149 <music5000_fillbuf+0x29>
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rsi
add    $0x4,%rsi
call   1030 <music5000_get_sample@plt>
mov    -0x8(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x8(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1136 <music5000_fillbuf+0x16>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %esi,%esi
jle    1175 <music5000_fillbuf+0x55>
mov    %esi,%r14d
mov    %rdi,%rbx
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    $0x80,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1040 <music5000_update_6MHz@plt>
add    $0xffffffff,%ebp
jne    1150 <music5000_fillbuf+0x30>
lea    0x4(%rbx),%rsi
mov    %rbx,%rdi
call   1030 <music5000_get_sample@plt>
add    $0x8,%rbx
add    $0x1,%r15d
cmp    %r14d,%r15d
jne    1140 <music5000_fillbuf+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @music5000_fillbuf(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
store i32 0, i32* %6
br label %7
7: ; preds = %27, %2
%8 = load i32, i32* %6
%9 = load i32, i32* %4
%10 = icmp slt i32 %8, %9
br i1 %10, label %11, label %30
11: ; preds = %7
store i32 0, i32* %5
br label %12
12: ; preds = %17, %11
%13 = load i32, i32* %5
%14 = icmp slt i32 %13, 128
br i1 %14, label %15, label %20
15: ; preds = %12
%16 = call i32 (...) @music5000_update_6MHz()
br label %17
17: ; preds = %15
%18 = load i32, i32* %5
%19 = add nsw i32 %18, 1
store i32 %19, i32* %5
br label %12
20: ; preds = %12
%21 = load i32*, i32** %3
%22 = load i32*, i32** %3
%23 = getelementptr inbounds i32, i32* %22, i64 1
%24 = call i32 @music5000_get_sample(i32* %21, i32* %23)
%25 = load i32*, i32** %3
%26 = getelementptr inbounds i32, i32* %25, i64 2
store i32* %26, i32** %3
br label %27
27: ; preds = %20
%28 = load i32, i32* %6
%29 = add nsw i32 %28, 1
store i32 %29, i32* %6
br label %7
30: ; preds = %7
ret void
}

LLVM IR (-O2):
define void @music5000_fillbuf(i32* %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %18
4: ; preds = %2, %12
%5 = phi i32 [ %16, %12 ], [ 0, %2 ]
%6 = phi i32* [ %15, %12 ], [ %0, %2 ]
br label %7
7: ; preds = %4, %7
%8 = phi i32 [ 0, %4 ], [ %10, %7 ]
%9 = tail call i32 (...) @music5000_update_6MHz()
%10 = add nuw nsw i32 %8, 1
%11 = icmp eq i32 %10, 128
br i1 %11, label %12, label %7
12: ; preds = %7
%13 = getelementptr inbounds i32, i32* %6, i64 1
%14 = tail call i32 @music5000_get_sample(i32* %6, i32* %13)
%15 = getelementptr inbounds i32, i32* %6, i64 2
%16 = add nuw nsw i32 %5, 1
%17 = icmp eq i32 %16, %1
br i1 %17, label %18, label %4
18: ; preds = %12, %2
ret void
}