// File: /workspace/github_cpp_makefile_star2_O3/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 %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rsi, %r15
movq %rdi, %rbx
movq 0x18(%rdi), %rax
xorl %ecx, %ecx
subq %rsi, %rax
cmovaeq %rax, %rcx
movq 0x10(%rdi), %rax
movq %rcx, 0x18(%rdi)
leaq 0x28(%rdi), %r14
movabsq $-0x5555555555555555, %r12 # imm = 0xAAAAAAAAAAAAAAAB
testq %rax, %rax
je 0x4e1e2
movq 0x38(%rbx), %rdi
callq 0x27270
jmp 0x4e1e6
movq 0x8(%rbx), %rax
movq (%rbx), %rdx
subq %rdx, %rax
movq %r15, %r13
subq %rax, %r13
jb 0x4e261
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
cmpq $0x1, %rcx
je 0x4e286
movq %r14, %rdi
callq 0x278a0
movq 0x10(%rbx), %rax
decq %rax
movq %rax, 0x10(%rbx)
movq $0x0, (%rbx)
movq %r13, %r15
jmp 0x4e1d2
addq %r15, %rdx
movq %rdx, (%rbx)
movq 0x8(%rbx), %rax
movq 0x10(%rbx), %rcx
xorq %rax, %rdx
orq %rcx, %rdx
jne 0x4e3a1
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
jmp 0x4e39d
movq %r14, %rdi
xorl %esi, %esi
callq 0x262b0
movq 0x38(%rbx), %rdi
movq 0x50(%rbx), %r8
movq %rdi, %rsi
subq 0x40(%rbx), %rsi
movq %rsi, %rcx
sarq $0x3, %rcx
imulq %r12, %rcx
cmpq $-0x17, %rsi
jl 0x4e2d5
cmpq $0x15, %rcx
jb 0x4e306
movabsq $-0x79e79e79e79e79e7, %rdx # imm = 0x8618618618618619
movq %rcx, %rax
mulq %rdx
subq %rdx, %rcx
shrq %rcx
addq %rdx, %rcx
shrq $0x4, %rcx
jmp 0x4e2f8
notq %rcx
movabsq $-0x79e79e79e79e79e7, %rdx # imm = 0x8618618618618619
movq %rcx, %rax
mulq %rdx
subq %rdx, %rcx
shrq %rcx
addq %rdx, %rcx
shrq $0x4, %rcx
notq %rcx
imulq $-0x1f8, %rcx, %rdi     # imm = 0xFE08
addq (%r8,%rcx,8), %rdi
addq %rsi, %rdi
callq 0x27270
movq 0x20(%rbx), %rsi
cmpq %rsi, %rax
je 0x4e38f
movq 0x38(%rbx), %rdi
movq 0x50(%rbx), %r9
movq %rdi, %r8
subq 0x40(%rbx), %r8
movq %r8, %rcx
sarq $0x3, %rcx
imulq %r12, %rcx
cmpq $-0x17, %r8
jl 0x4e359
cmpq $0x15, %rcx
jb 0x4e38a
movabsq $-0x79e79e79e79e79e7, %rdx # imm = 0x8618618618618619
movq %rcx, %rax
mulq %rdx
subq %rdx, %rcx
shrq %rcx
addq %rdx, %rcx
shrq $0x4, %rcx
jmp 0x4e37c
notq %rcx
movabsq $-0x79e79e79e79e79e7, %rdx # imm = 0x8618618618618619
movq %rcx, %rax
mulq %rdx
subq %rdx, %rcx
shrq %rcx
addq %rdx, %rcx
shrq $0x4, %rcx
notq %rcx
imulq $-0x1f8, %rcx, %rdi     # imm = 0xFE08
addq (%r9,%rcx,8), %rdi
addq %r8, %rdi
callq 0x26d90
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
movq $0x0, 0x10(%rbx)
xorl %eax, %eax
xorl %ecx, %ecx
orq %rcx, %rax
je 0x4e3b0
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movq %rbx, %rdi
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x27be0
nop