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

/* Variables and functions */
double *malloc(int);
int /*<<< orphan*/ nextSample(int /*<<< orphan*/ *, int, int);
double *readSample(FILE *file, int chunkSize, int sampleSize, int numChan) {
  double *result;
  double *dst;
  int i, size;
  size = chunkSize / (numChan * sampleSize);
  result = malloc(size * sizeof(double));
  dst = result;
  for (i = 0; i < size; i++)
    *dst++ = nextSample(file, sampleSize, numChan);
  return result;
}


x86 assembly (clang, -O0):
<readSample>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    -0xc(%rbp),%eax
mov    -0x14(%rbp),%ecx
imul   -0x10(%rbp),%ecx
cltd
idiv   %ecx
mov    %eax,-0x30(%rbp)
movslq -0x30(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x30(%rbp),%eax
jge    11a7 <readSample+0x87>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1030 <nextSample@plt>
cvtsi2sd %eax,%xmm0
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x28(%rbp)
movsd  %xmm0,(%rax)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1167 <readSample+0x47>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readSample>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r15d
mov    %edx,%r13d
mov    %esi,%eax
mov    %rdi,%r14
imul   %edx,%ecx
cltd
idiv   %ecx
mov    %eax,%ebx
lea    0x0(,%rbx,8),%edi
call   1040 <malloc@plt>
mov    %rax,%r12
test   %ebx,%ebx
jle    1183 <readSample+0x63>
mov    %ebx,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
mov    %r13d,%esi
mov    %r15d,%edx
call   1030 <nextSample@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,(%r12,%rbx,8)
add    $0x1,%rbx
cmp    %ebx,%ebp
jne    1160 <readSample+0x40>
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double* @readSample(i32* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca double*
%10 = alloca double*
%11 = alloca i32
%12 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%13 = load i32, i32* %6
%14 = load i32, i32* %8
%15 = load i32, i32* %7
%16 = mul nsw i32 %14, %15
%17 = sdiv i32 %13, %16
store i32 %17, i32* %12
%18 = load i32, i32* %12
%19 = sext i32 %18 to i64
%20 = mul i64 %19, 8
%21 = trunc i64 %20 to i32
%22 = call double* @malloc(i32 %21)
store double* %22, double** %9
%23 = load double*, double** %9
store double* %23, double** %10
store i32 0, i32* %11
br label %24
24: ; preds = %36, %4
%25 = load i32, i32* %11
%26 = load i32, i32* %12
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %39
28: ; preds = %24
%29 = load i32*, i32** %5
%30 = load i32, i32* %7
%31 = load i32, i32* %8
%32 = call i32 @nextSample(i32* %29, i32 %30, i32 %31)
%33 = sitofp i32 %32 to double
%34 = load double*, double** %10
%35 = getelementptr inbounds double, double* %34, i32 1
store double* %35, double** %10
store double %33, double* %34
br label %36
36: ; preds = %28
%37 = load i32, i32* %11
%38 = add nsw i32 %37, 1
store i32 %38, i32* %11
br label %24
39: ; preds = %24
%40 = load double*, double** %9
ret double* %40
}

LLVM IR (-O2):
define noalias double* @readSample(i32* %0, i32 %1, i32 %2, i32 %3) {
%5 = mul nsw i32 %3, %2
%6 = sdiv i32 %1, %5
%7 = shl i32 %6, 3
%8 = tail call double* @malloc(i32 %7)
%9 = icmp sgt i32 %6, 0
br i1 %9, label %10, label %18
10: ; preds = %4, %10
%11 = phi double* [ %15, %10 ], [ %8, %4 ]
%12 = phi i32 [ %16, %10 ], [ 0, %4 ]
%13 = tail call i32 @nextSample(i32* %0, i32 %2, i32 %3)
%14 = sitofp i32 %13 to double
%15 = getelementptr inbounds double, double* %11, i64 1
store double %14, double* %11
%16 = add nuw nsw i32 %12, 1
%17 = icmp eq i32 %16, %6
br i1 %17, label %18, label %10
18: ; preds = %10, %4
ret double* %8
}