#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 audioPlayFetchByte();
int /*<<< orphan*/ audioPlayTryFeed(int);
int audioPlayFetch(char *dst, int ask) {
  int n = 0;
  int c;
  audioPlayTryFeed(ask);
  while (n < ask) {
    c = audioPlayFetchByte();
    if (c < 0)
      return n;
    dst[n++] = c;
  }
  return n;
}


x86 assembly (clang, -O0):
<audioPlayFetch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <audioPlayTryFeed@plt>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1188 <audioPlayFetch+0x68>
mov    $0x0,%al
call   1030 <audioPlayFetchByte@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1169 <audioPlayFetch+0x49>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    118e <audioPlayFetch+0x6e>
mov    -0x1c(%rbp),%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x18(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    113e <audioPlayFetch+0x1e>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<audioPlayFetch>:
push   %r15
push   %r14
push   %rbx
mov    %esi,%ebx
mov    %rdi,%r14
mov    %esi,%edi
call   1040 <audioPlayTryFeed@plt>
test   %ebx,%ebx
jle    115d <audioPlayFetch+0x3d>
mov    %ebx,%r15d
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <audioPlayFetchByte@plt>
test   %eax,%eax
js     115f <audioPlayFetch+0x3f>
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1140 <audioPlayFetch+0x20>
mov    %r15d,%ebx
jmp    115f <audioPlayFetch+0x3f>
xor    %ebx,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i32 @audioPlayFetch(i8* nocapture writeonly %0, i32 %1) {
%3 = tail call i32 @audioPlayTryFeed(i32 %1)
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %18
5: ; preds = %2
%6 = zext i32 %1 to i64
br label %7
7: ; preds = %5, %11
%8 = phi i64 [ 0, %5 ], [ %13, %11 ]
%9 = tail call i32 (...) @audioPlayFetchByte()
%10 = icmp slt i32 %9, 0
br i1 %10, label %16, label %11
11: ; preds = %7
%12 = trunc i32 %9 to i8
%13 = add nuw nsw i64 %8, 1
%14 = getelementptr inbounds i8, i8* %0, i64 %8
store i8 %12, i8* %14
%15 = icmp eq i64 %13, %6
br i1 %15, label %18, label %7
16: ; preds = %7
%17 = trunc i64 %8 to i32
br label %18
18: ; preds = %11, %16, %2
%19 = phi i32 [ 0, %2 ], [ %17, %16 ], [ %1, %11 ]
ret i32 %19
}