#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ perror(char *);
int read(int, short *, int);
int /*<<< orphan*/ stderr;
int pull(int fd, signed short *pcm, int samples) {
  int r, bytes;
  bytes = samples * 2 * sizeof(short);
  r = read(fd, pcm, bytes);
  if (r == -1) {
    perror("read");
    return -1;
  }
  if (r < bytes)
    fprintf(stderr, "Device input underrun.\n");
  return r / 2 / sizeof(short);
}


x86 assembly (clang, -O0):
<pull>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
shl    $0x1,%eax
cltq
shl    $0x1,%rax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <read@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    1185 <pull+0x55>
lea    0xe8c(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ba <pull+0x8a>
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11a6 <pull+0x76>
mov    0x2e48(%rip),%rax
mov    (%rax),%edi
lea    0xe64(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cltq
shr    $0x1,%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pull>:
push   %rbp
push   %rbx
push   %rax
mov    %edx,%ebp
shl    $0x2,%ebp
mov    %ebp,%edx
call   1030 <read@plt>
cmp    $0xffffffff,%eax
je     1170 <pull+0x40>
mov    %eax,%ebx
cmp    %ebp,%eax
jge    115f <pull+0x2f>
mov    0x2e8f(%rip),%rax
mov    (%rax),%edi
lea    0xeab(%rip),%rsi
call   1040 <fprintf@plt>
mov    %ebx,%eax
shr    $0x1f,%eax
add    %ebx,%eax
sar    $0x2,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe89(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%eax
jmp    1169 <pull+0x39>

LLVM IR (-O0):
@.str = [5 x i8] c"read\00"
@stderr = global i32 0
@.str.1 = [24 x i8] c"Device input underrun.\0A\00"
define i32 @pull(i32 %0, i16* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i16*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %5
store i16* %1, i16** %6
store i32 %2, i32* %7
%10 = load i32, i32* %7
%11 = mul nsw i32 %10, 2
%12 = sext i32 %11 to i64
%13 = mul i64 %12, 2
%14 = trunc i64 %13 to i32
store i32 %14, i32* %9
%15 = load i32, i32* %5
%16 = load i16*, i16** %6
%17 = load i32, i32* %9
%18 = call i32 @read(i32 %15, i16* %16, i32 %17)
store i32 %18, i32* %8
%19 = load i32, i32* %8
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %23
21: ; preds = %3
%22 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %36
23: ; preds = %3
%24 = load i32, i32* %8
%25 = load i32, i32* %9
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %30
27: ; preds = %23
%28 = load i32, i32* @stderr
%29 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %30
30: ; preds = %27, %23
%31 = load i32, i32* %8
%32 = sdiv i32 %31, 2
%33 = sext i32 %32 to i64
%34 = udiv i64 %33, 2
%35 = trunc i64 %34 to i32
store i32 %35, i32* %4
br label %36
36: ; preds = %30, %21
%37 = load i32, i32* %4
ret i32 %37
}

LLVM IR (-O2):
@.str = [5 x i8] c"read\00"
@stderr = global i32 0
@.str.1 = [24 x i8] c"Device input underrun.\0A\00"
define i32 @pull(i32 %0, i16* nocapture %1, i32 %2) {
%4 = shl i32 %2, 2
%5 = tail call i32 @read(i32 %0, i16* %1, i32 %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %17
9: ; preds = %3
%10 = icmp slt i32 %5, %4
br i1 %10, label %11, label %14
11: ; preds = %9
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %11, %9
%15 = sdiv i32 %5, 2
%16 = ashr i32 %15, 1
br label %17
17: ; preds = %14, %7
%18 = phi i32 [ -1, %7 ], [ %16, %14 ]
ret i32 %18
}