// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %edx, %r8d
movl %esi, %r15d
movq %rdi, %rbx
movl $0x190, %ecx            # imm = 0x190
movl %esi, %eax
cltd
idivl %ecx
movl %eax, 0x4(%rsp)
pushq $0x41
popq %rcx
movl %esi, %eax
cltd
idivl %ecx
movl %eax, %r12d
leal (%r12,%r12), %r13d
pushq $0x1
popq %rax
cmpl $0xfa1, %esi            # imm = 0xFA1
jl 0x144d
cmpl $0x0, 0x4c(%rbx)
jne 0x144d
movl $0xfa0, %ecx            # imm = 0xFA0
movl %r15d, %eax
xorl %edx, %edx
divl %ecx
movq %rax, 0x10(%rsp)
movl %r12d, %ebp
sarl %ebp
addl %r13d, %ebp
movl %ebp, 0x54(%rbx)
movq %r8, 0x8(%rsp)
leal (%r8,%r8), %r14d
movl %ebp, %edi
movl %r14d, %esi
callq 0x13f1
movq %rax, (%rbx)
testq %rax, %rax
je 0x150f
movl %ebp, 0x5c(%rbx)
movl %ebp, %edi
movl %r14d, %esi
callq 0x13f1
movq %rax, 0x8(%rbx)
testq %rax, %rax
je 0x150f
movl %ebp, 0x58(%rbx)
movl %ebp, %edi
movl %r14d, %esi
callq 0x13f1
movq %rax, 0x10(%rbx)
testq %rax, %rax
je 0x150f
movq 0x10(%rsp), %rcx
leal (%rcx,%r13), %eax
decl %eax
cltd
idivl %ecx
pushq $0x2
popq %rsi
movl %eax, %edi
callq 0x13f1
movq %rax, 0x18(%rbx)
testq %rax, %rax
je 0x150f
movl %r15d, 0x7c(%rbx)
cvtsi2sd %r15d, %xmm0
movsd 0x1b86(%rip), %xmm1     # 0x3060
divsd %xmm0, %xmm1
cvtsd2ss %xmm1, %xmm0
movss %xmm0, 0x38(%rbx)
movq 0x8(%rsp), %rax
movl %eax, 0x50(%rbx)
andq $0x0, 0x44(%rbx)
movl 0x4(%rsp), %eax
movl %eax, 0x6c(%rbx)
movl %r12d, 0x70(%rbx)
movl %r13d, 0x74(%rbx)
andl $0x0, 0x80(%rbx)
pushq $0x1
popq %rax
jmp 0x1519
movq %rbx, %rdi
callq 0x10d0
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq