#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 AUDIO_FIFO_GET(unsigned char *, int);
int /*<<< orphan*/ free(unsigned char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ vs_write_data(unsigned char *, int);
int audio_play(int len) {
  unsigned char *data;
  int i = 0;
  if (len <= 0)
    return 0;
  data = (unsigned char *)malloc(len * sizeof(*data));
  len = AUDIO_FIFO_GET(data, len);
  for (i = 32; i <= len; i += 32)
    vs_write_data(data + (i - 32), 32);
  if ((len + 32 - i) > 0)
    vs_write_data(data + i - 32, len + 32 - i);
  free(data);
  return 1;
}


x86 assembly (clang, -O0):
<audio_play>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x0,-0x8(%rbp)
jg     1168 <audio_play+0x28>
movl   $0x0,-0x4(%rbp)
jmp    1203 <audio_play+0xc3>
movslq -0x8(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1050 <AUDIO_FIFO_GET@plt>
mov    %eax,-0x8(%rbp)
movl   $0x20,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     11c4 <audio_play+0x84>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%eax
sub    $0x20,%eax
cltq
add    %rax,%rdi
mov    $0x20,%esi
call   1040 <vs_write_data@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%eax
mov    %eax,-0x14(%rbp)
jmp    1191 <audio_play+0x51>
mov    -0x8(%rbp),%eax
add    $0x20,%eax
sub    -0x14(%rbp),%eax
cmp    $0x0,%eax
jle    11f3 <audio_play+0xb3>
mov    -0x10(%rbp),%rdi
movslq -0x14(%rbp),%rax
add    %rax,%rdi
add    $0xffffffffffffffe0,%rdi
mov    -0x8(%rbp),%esi
add    $0x20,%esi
sub    -0x14(%rbp),%esi
call   1040 <vs_write_data@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<audio_play>:
test   %edi,%edi
jle    11ce <audio_play+0x8e>
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edi,%ebx
call   1060 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %ebx,%esi
call   1050 <AUDIO_FIFO_GET@plt>
mov    %eax,%r15d
mov    $0x20,%ebp
cmp    $0x20,%eax
jl     119a <audio_play+0x5a>
mov    %r15d,%r12d
mov    $0x20,%ebp
mov    %r14,%rbx
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    $0x20,%esi
call   1040 <vs_write_data@plt>
add    $0x20,%rbp
add    $0x20,%rbx
cmp    %r12,%rbp
jle    1180 <audio_play+0x40>
sub    %ebp,%r15d
add    $0x20,%r15d
test   %r15d,%r15d
jle    11b8 <audio_play+0x78>
mov    %ebp,%eax
lea    (%r14,%rax,1),%rdi
add    $0xffffffffffffffe0,%rdi
mov    %r15d,%esi
call   1040 <vs_write_data@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
ret

LLVM IR (-O0):
define i32 @audio_play(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
store i32 %0, i32* %3
store i32 0, i32* %5
%6 = load i32, i32* %3
%7 = icmp sle i32 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %1
store i32 0, i32* %2
br label %53
9: ; preds = %1
%10 = load i32, i32* %3
%11 = sext i32 %10 to i64
%12 = mul i64 %11, 1
%13 = trunc i64 %12 to i32
%14 = call i64 @malloc(i32 %13)
%15 = inttoptr i64 %14 to i8*
store i8* %15, i8** %4
%16 = load i8*, i8** %4
%17 = load i32, i32* %3
%18 = call i32 @AUDIO_FIFO_GET(i8* %16, i32 %17)
store i32 %18, i32* %3
store i32 32, i32* %5
br label %19
19: ; preds = %30, %9
%20 = load i32, i32* %5
%21 = load i32, i32* %3
%22 = icmp sle i32 %20, %21
br i1 %22, label %23, label %33
23: ; preds = %19
%24 = load i8*, i8** %4
%25 = load i32, i32* %5
%26 = sub nsw i32 %25, 32
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %24, i64 %27
%29 = call i32 @vs_write_data(i8* %28, i32 32)
br label %30
30: ; preds = %23
%31 = load i32, i32* %5
%32 = add nsw i32 %31, 32
store i32 %32, i32* %5
br label %19
33: ; preds = %19
%34 = load i32, i32* %3
%35 = add nsw i32 %34, 32
%36 = load i32, i32* %5
%37 = sub nsw i32 %35, %36
%38 = icmp sgt i32 %37, 0
br i1 %38, label %39, label %50
39: ; preds = %33
%40 = load i8*, i8** %4
%41 = load i32, i32* %5
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %40, i64 %42
%44 = getelementptr inbounds i8, i8* %43, i64 -32
%45 = load i32, i32* %3
%46 = add nsw i32 %45, 32
%47 = load i32, i32* %5
%48 = sub nsw i32 %46, %47
%49 = call i32 @vs_write_data(i8* %44, i32 %48)
br label %50
50: ; preds = %39, %33
%51 = load i8*, i8** %4
%52 = call i32 @free(i8* %51)
store i32 1, i32* %2
br label %53
53: ; preds = %50, %8
%54 = load i32, i32* %2
ret i32 %54
}

LLVM IR (-O2):
define i32 @audio_play(i32 %0) {
%2 = icmp slt i32 %0, 1
br i1 %2, label %31, label %3
3: ; preds = %1
%4 = tail call i64 @malloc(i32 %0)
%5 = inttoptr i64 %4 to i8*
%6 = tail call i32 @AUDIO_FIFO_GET(i8* %5, i32 %0)
%7 = icmp slt i32 %6, 32
br i1 %7, label %19, label %8
8: ; preds = %3
%9 = zext i32 %6 to i64
br label %10
10: ; preds = %8, %10
%11 = phi i64 [ 32, %8 ], [ %15, %10 ]
%12 = add nsw i64 %11, -32
%13 = getelementptr inbounds i8, i8* %5, i64 %12
%14 = tail call i32 @vs_write_data(i8* %13, i32 32)
%15 = add nuw i64 %11, 32
%16 = icmp sgt i64 %15, %9
br i1 %16, label %17, label %10
17: ; preds = %10
%18 = trunc i64 %15 to i32
br label %19
19: ; preds = %17, %3
%20 = phi i32 [ 32, %3 ], [ %18, %17 ]
%21 = add nsw i32 %6, 32
%22 = sub i32 %21, %20
%23 = icmp sgt i32 %22, 0
br i1 %23, label %24, label %29
24: ; preds = %19
%25 = zext i32 %20 to i64
%26 = getelementptr inbounds i8, i8* %5, i64 %25
%27 = getelementptr inbounds i8, i8* %26, i64 -32
%28 = tail call i32 @vs_write_data(i8* %27, i32 %22)
br label %29
29: ; preds = %24, %19
%30 = tail call i32 @free(i8* %5)
br label %31
31: ; preds = %1, %29
%32 = phi i32 [ 1, %29 ], [ 0, %1 ]
ret i32 %32
}