// File: /workspace/github_c_makefile_star2_O0/waywardgeek[P]sonic/sonic.c
// Function: allocateStreamBuffers
static int allocateStreamBuffers(sonicStream stream, int sampleRate,
                                 int numChannels) {
  int minPeriod = sampleRate / SONIC_MAX_PITCH;
  int maxPeriod = sampleRate / SONIC_MIN_PITCH;
  int maxRequired = 2 * maxPeriod;
  int skip = computeSkip(stream, sampleRate);

  /* Allocate 25% more than needed so we hopefully won't grow. */
  stream->inputBufferSize = maxRequired + (maxRequired >> 2);

  stream->inputBuffer =
      (short*)sonicCalloc(stream->inputBufferSize, sizeof(short) * numChannels);
  if (stream->inputBuffer == NULL) {
    sonicDestroyStream(stream);
    return 0;
  }
  /* Allocate 25% more than needed so we hopefully won't grow. */
  stream->outputBufferSize = maxRequired + (maxRequired >> 2);
  stream->outputBuffer = (short*)sonicCalloc(stream->outputBufferSize,
                                             sizeof(short) * numChannels);
  if (stream->outputBuffer == NULL) {
    sonicDestroyStream(stream);
    return 0;
  }
  /* Allocate 25% more than needed so we hopefully won't grow. */
  stream->pitchBufferSize = maxRequired + (maxRequired >> 2);
  stream->pitchBuffer =
      (short*)sonicCalloc(stream->pitchBufferSize, sizeof(short) * numChannels);
  if (stream->pitchBuffer == NULL) {
    sonicDestroyStream(stream);
    return 0;
  }
  int downSampleBufferSize = (maxRequired + skip - 1) / skip;
  stream->downSampleBuffer =
      (short*)sonicCalloc(downSampleBufferSize, sizeof(short));
  if (stream->downSampleBuffer == NULL) {
    sonicDestroyStream(stream);
    return 0;
  }
  stream->sampleRate = sampleRate;
  stream->samplePeriod = 1.0 / sampleRate;
  stream->numChannels = numChannels;
  stream->oldRatePosition = 0;
  stream->newRatePosition = 0;
  stream->minPeriod = minPeriod;
  stream->maxPeriod = maxPeriod;
  stream->maxRequired = maxRequired;
  stream->prevPeriod = 0;
  return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movl -0x14(%rbp), %eax
movl $0x190, %ecx            # imm = 0x190
cltd
idivl %ecx
movl %eax, -0x1c(%rbp)
movl -0x14(%rbp), %eax
movl $0x41, %ecx
cltd
idivl %ecx
movl %eax, -0x20(%rbp)
movl -0x20(%rbp), %eax
shll %eax
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x2640
movl %eax, -0x28(%rbp)
movl -0x24(%rbp), %ecx
movl -0x24(%rbp), %eax
sarl $0x2, %eax
addl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x54(%rax)
movq -0x10(%rbp), %rax
movl 0x54(%rax), %edi
movslq -0x18(%rbp), %rax
shlq %rax
movl %eax, %esi
callq 0x17b0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x1875
movq -0x10(%rbp), %rdi
callq 0x1100
movl $0x0, -0x4(%rbp)
jmp 0x19d9
movl -0x24(%rbp), %ecx
movl -0x24(%rbp), %eax
sarl $0x2, %eax
addl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x5c(%rax)
movq -0x10(%rbp), %rax
movl 0x5c(%rax), %edi
movslq -0x18(%rbp), %rax
shlq %rax
movl %eax, %esi
callq 0x17b0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x18c7
movq -0x10(%rbp), %rdi
callq 0x1100
movl $0x0, -0x4(%rbp)
jmp 0x19d9
movl -0x24(%rbp), %ecx
movl -0x24(%rbp), %eax
sarl $0x2, %eax
addl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x58(%rax)
movq -0x10(%rbp), %rax
movl 0x58(%rax), %edi
movslq -0x18(%rbp), %rax
shlq %rax
movl %eax, %esi
callq 0x17b0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jne 0x1919
movq -0x10(%rbp), %rdi
callq 0x1100
movl $0x0, -0x4(%rbp)
jmp 0x19d9
movl -0x24(%rbp), %eax
addl -0x28(%rbp), %eax
subl $0x1, %eax
cltd
idivl -0x28(%rbp)
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %edi
movl $0x2, %esi
callq 0x17b0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jne 0x195e
movq -0x10(%rbp), %rdi
callq 0x1100
movl $0x0, -0x4(%rbp)
jmp 0x19d9
movl -0x14(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x7c(%rax)
cvtsi2sdl -0x14(%rbp), %xmm1
movsd 0x36b3(%rip), %xmm0     # 0x5028
divsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movq -0x10(%rbp), %rax
movss %xmm0, 0x38(%rax)
movl -0x18(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x50(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x44(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x48(%rax)
movl -0x1c(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x6c(%rax)
movl -0x20(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x70(%rax)
movl -0x24(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x74(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x80(%rax)
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)