// File: /workspace/github_cpp_makefile_star2_O1/zeeev[P]DASVC/bamtools/src/api/internal/io/RollingBuffer_p.cpp
// Function: BamTools::Internal::RollingBuffer::Free(unsigned long)
void RollingBuffer::Free(size_t n) {

    // update buffer size
    if ( n > m_totalBufferSize )
        m_totalBufferSize = 0;
    else
        m_totalBufferSize -= n;

    // loop until target case hit
    for ( ; ; ) {

        const size_t blockSize = BlockSize();

        // if there's room in current array
        if ( n < blockSize ) {

            // shift 'head' over @n bytes
            m_head += n;

            // check for emptied, single byte array
            if ( m_head == m_tail && m_tailBufferIndex == 0 ) {
                m_head = 0;
                m_tail = 0;
            }

            break;
        }

        // otherwise we need to check next byte array
        // first update amount to remove
        n -= blockSize;

        // special case - there was only 1 array
        if ( m_data.size() == 1 ) {
            if ( m_data.at(0).Size() != m_bufferGrowth )
                m_data[0].Resize(m_bufferGrowth);
            m_head = 0;
            m_tail = 0;
            m_tailBufferIndex = 0;
            break;
        }

        // otherwise, remove first array and move to next iteration
        m_data.pop_front();
        --m_tailBufferIndex;
        m_head = 0;
    }

    // if buffer is now empty, reset state & clear up memory
    if ( IsEmpty() )
        Clear();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r15
movq %rdi, %rbx
movq 0x18(%rdi), %rax
xorl %ecx, %ecx
subq %rsi, %rax
cmovaeq %rax, %rcx
movq %rcx, 0x18(%rdi)
leaq 0x28(%rdi), %r14
movabsq $-0x5555555555555555, %r12 # imm = 0xAAAAAAAAAAAAAAAB
movabsq $-0x79e79e79e79e79e7, %r13 # imm = 0x8618618618618619
cmpq $0x0, 0x10(%rbx)
je 0x4e23e
movq 0x38(%rbx), %rdi
callq 0x27270
jmp 0x4e242
movq 0x8(%rbx), %rax
subq (%rbx), %rax
movq %r15, %rbp
subq %rax, %rbp
jae 0x4e275
movq (%rbx), %rcx
addq %r15, %rcx
movq %rcx, (%rbx)
xorl %eax, %eax
cmpq 0x8(%rbx), %rcx
jne 0x4e26d
cmpq $0x0, 0x10(%rbx)
jne 0x4e26d
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
xorl %eax, %eax
movq %r15, %rbp
jmp 0x4e3c6
movq 0x70(%rbx), %rax
movq %rax, %rcx
subq 0x50(%rbx), %rcx
sarq $0x3, %rcx
cmpq $0x1, %rax
adcq $-0x1, %rcx
leaq (%rcx,%rcx,4), %rax
leaq (%rcx,%rax,4), %rax
movq 0x48(%rbx), %rcx
movq 0x58(%rbx), %rdx
subq 0x60(%rbx), %rdx
sarq $0x3, %rdx
imulq %r12, %rdx
subq 0x38(%rbx), %rcx
sarq $0x3, %rcx
imulq %r12, %rcx
addq %rdx, %rcx
addq %rax, %rcx
movq %r14, %rdi
cmpq $0x1, %rcx
jne 0x4e300
xorl %esi, %esi
callq 0x262b0
movq 0x38(%rbx), %rdi
movq %rdi, %rsi
subq 0x40(%rbx), %rsi
movq %rsi, %rcx
sarq $0x3, %rcx
imulq %r12, %rcx
cmpq $0x15, %rcx
jb 0x4e342
testq %rsi, %rsi
jle 0x4e317
movq %rcx, %rax
mulq %r13
subq %rdx, %rcx
shrq %rcx
addq %rdx, %rcx
shrq $0x4, %rcx
jmp 0x4e330
callq 0x278a0
decq 0x10(%rbx)
movq $0x0, (%rbx)
movb $0x1, %al
jmp 0x4e3c6
notq %rcx
movq %rcx, %rax
mulq %r13
subq %rdx, %rcx
shrq %rcx
addq %rdx, %rcx
shrq $0x4, %rcx
notq %rcx
movq 0x50(%rbx), %rax
imulq $-0x1f8, %rcx, %rdi     # imm = 0xFE08
addq (%rax,%rcx,8), %rdi
addq %rsi, %rdi
callq 0x27270
movq 0x20(%rbx), %rsi
cmpq %rsi, %rax
je 0x4e3b6
movq 0x38(%rbx), %rdi
movq %rdi, %r8
subq 0x40(%rbx), %r8
movq %r8, %rcx
sarq $0x3, %rcx
imulq %r12, %rcx
cmpq $0x15, %rcx
jb 0x4e3b1
testq %r8, %r8
jle 0x4e386
movq %rcx, %rax
mulq %r13
subq %rdx, %rcx
shrq %rcx
addq %rdx, %rcx
shrq $0x4, %rcx
jmp 0x4e39f
notq %rcx
movq %rcx, %rax
mulq %r13
subq %rdx, %rcx
shrq %rcx
addq %rdx, %rcx
shrq $0x4, %rcx
notq %rcx
movq 0x50(%rbx), %rax
imulq $-0x1f8, %rcx, %rdi     # imm = 0xFE08
addq (%rax,%rcx,8), %rdi
addq %r8, %rdi
callq 0x26d90
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
movq $0x0, 0x10(%rbx)
xorl %eax, %eax
movq %rbp, %r15
testb %al, %al
jne 0x4e22c
movq 0x8(%rbx), %rax
orq 0x10(%rbx), %rax
jne 0x4e3f1
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x27bf0
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq