// File: /workspace/github_c_makefile_star2_O1/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
movq %rdi, %rbx
movslq %esi, %r14
imulq $0x7e07e07f, %r14, %r13 # imm = 0x7E07E07F
movq %r13, %rax
shrq $0x3f, %rax
sarq $0x25, %r13
addl %eax, %r13d
leal (,%r13,2), %ecx
movl $0x1, %ebp
cmpl $0xfa1, %r14d           # imm = 0xFA1
jl 0x157f
cmpl $0x0, 0x4c(%rbx)
jne 0x157f
movl %esi, %eax
imulq $0x10624dd3, %rax, %rbp # imm = 0x10624DD3
shrq $0x28, %rbp
movl %esi, 0x4(%rsp)
movl %r13d, %eax
sarl %eax
movq %rcx, 0x10(%rsp)
addl %ecx, %eax
movl %eax, 0x54(%rbx)
movq %rdx, 0x8(%rsp)
leal (%rdx,%rdx), %ecx
movslq %eax, %r15
movslq %ecx, %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x10a0
movq %rax, (%rbx)
testq %rax, %rax
je 0x1676
movl %r15d, 0x5c(%rbx)
movq %r15, %rdi
movq %r12, %rsi
callq 0x10a0
movq %rax, 0x8(%rbx)
testq %rax, %rax
je 0x1676
movl %r15d, 0x58(%rbx)
movq %r15, %rdi
movq %r12, %rsi
callq 0x10a0
movq %rax, 0x10(%rbx)
testq %rax, %rax
je 0x1676
movq 0x10(%rsp), %r15
leal (%r15,%rbp), %eax
decl %eax
cltd
idivl %ebp
movslq %eax, %rdi
movl $0x2, %esi
callq 0x10a0
movq %rax, 0x18(%rbx)
testq %rax, %rax
je 0x1676
imulq $0x51eb851f, %r14, %rax # imm = 0x51EB851F
movq %rax, %rcx
shrq $0x3f, %rcx
sarq $0x27, %rax
addl %ecx, %eax
movl 0x4(%rsp), %ecx
movl %ecx, 0x7c(%rbx)
cvtsi2sd %ecx, %xmm0
movsd 0x29f6(%rip), %xmm1     # 0x4030
divsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsd2ss %xmm1, %xmm0
movss %xmm0, 0x38(%rbx)
movq 0x8(%rsp), %rcx
movl %ecx, 0x50(%rbx)
movq $0x0, 0x44(%rbx)
movl %eax, 0x6c(%rbx)
movl %r13d, 0x70(%rbx)
movl %r15d, 0x74(%rbx)
movl $0x0, 0x80(%rbx)
movl $0x1, %eax
jmp 0x1688
movq %rbx, %rdi
callq 0x1467
movq %rbx, %rdi
callq 0x1030
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq