// File: /workspace/github_c_makefile_star2_O1/samtools[P]htslib/bgzf.c
// Function: cache_block
static void cache_block(BGZF *fp, int size)
{
    int ret;
    khint_t k, k_orig;
    uint8_t *block = NULL;
    cache_t *p;
    //fprintf(stderr, "Cache block at %llx\n", (int)fp->block_address);
    khash_t(cache) *h = fp->cache->h;
    if (BGZF_MAX_BLOCK_SIZE >= fp->cache_size) return;
    if (fp->block_length < 0 || fp->block_length > BGZF_MAX_BLOCK_SIZE) return;
    if ((kh_size(h) + 1) * BGZF_MAX_BLOCK_SIZE > (uint32_t)fp->cache_size) {
        /* Remove uniformly from any position in the hash by a simple
         * round-robin approach.  An alternative strategy would be to
         * remove the least recently accessed block, but the round-robin
         * removal is simpler and is not expected to have a big impact
         * on performance */
        if (fp->cache->last_pos >= kh_end(h)) fp->cache->last_pos = kh_begin(h);
        k_orig = k = fp->cache->last_pos;
        if (++k >= kh_end(h)) k = kh_begin(h);
        while (k != k_orig) {
            if (kh_exist(h, k))
                break;
            if (++k == kh_end(h))
                k = kh_begin(h);
        }
        fp->cache->last_pos = k;

        if (k != k_orig) {
            block = kh_val(h, k).block;
            kh_del(cache, h, k);
        }
    } else {
        block = (uint8_t*)malloc(BGZF_MAX_BLOCK_SIZE);
    }
    if (!block) return;
    k = kh_put(cache, h, fp->block_address, &ret);
    if (ret <= 0) { // kh_put failed, or in there already (shouldn't happen)
        free(block);
        return;
    }
    p = &kh_val(h, k);
    p->size = fp->block_length;
    p->end_offset = fp->block_address + size;
    p->block = block;
    memcpy(p->block, fp->uncompressed_block, p->size);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl 0x4(%rdi), %ecx
cmpl $0x10001, %ecx          # imm = 0x10001
jl 0xbd7b
movq %rdi, %rbx
cmpl $0x10000, 0x8(%rdi)     # imm = 0x10000
ja 0xbd7b
movl %esi, %ebp
movq 0x38(%rbx), %rax
movq (%rax), %r14
movl 0x4(%r14), %edx
shll $0x10, %edx
addl $0x10000, %edx          # imm = 0x10000
cmpl %ecx, %edx
jbe 0xbd4a
movl (%r14), %edx
cmpl %edx, 0x8(%rax)
jb 0xbcfb
movl $0x0, 0x8(%rax)
movl 0x8(%rax), %r8d
leal 0x1(%r8), %esi
xorl %r9d, %r9d
cmpl %edx, %esi
cmovael %r9d, %esi
cmpl %r8d, %esi
je 0xbd42
movq 0x10(%r14), %rdi
leal (%rsi,%rsi), %ecx
andl $0x1e, %ecx
movl $0x3, %r11d
shll %cl, %r11d
movl %esi, %r10d
shrl $0x4, %r10d
testl %r11d, (%rdi,%r10,4)
je 0xbe2d
incl %esi
cmpl %edx, %esi
cmovel %r9d, %esi
cmpl %r8d, %esi
jne 0xbd15
movl %esi, 0x8(%rax)
xorl %r15d, %r15d
jmp 0xbd57
movl $0x10000, %edi          # imm = 0x10000
callq 0x4680
movq %rax, %r15
testq %r15, %r15
je 0xbd7b
movq 0x18(%rbx), %r12
movl 0x8(%r14), %eax
cmpl 0xc(%r14), %eax
jb 0xbd9c
movl (%r14), %esi
movl 0x4(%r14), %eax
addl %eax, %eax
cmpl %eax, %esi
jbe 0xbd8a
decl %esi
jmp 0xbd8c
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
incl %esi
movq %r14, %rdi
callq 0xe941
testl %eax, %eax
js 0xbe65
movl (%r14), %esi
leal -0x1(%rsi), %r9d
movq %r12, %rax
shrq $0x21, %rax
movl %r12d, %ecx
shll $0xb, %ecx
xorl %ecx, %eax
xorl %r12d, %eax
andl %r9d, %eax
movq 0x10(%r14), %rdx
movl %eax, %ecx
shrl $0x4, %ecx
movl (%rdx,%rcx,4), %edi
leal (%rax,%rax), %ecx
shrl %cl, %edi
testb $0x2, %dil
jne 0xbe99
movq %r15, (%rsp)
movl $0x1, %r10d
movl %eax, %r8d
movl %esi, %edi
movl %r8d, %ecx
shrl $0x4, %ecx
movl (%rdx,%rcx,4), %r11d
leal (%r8,%r8), %ecx
andl $0x1e, %ecx
movl %r11d, %r13d
shrl %cl, %r13d
testb $0x2, %r13b
jne 0xbe70
testb $0x1, %r13b
jne 0xbe13
movq 0x18(%r14), %r13
movl %r8d, %r15d
cmpq %r12, (%r13,%r15,8)
je 0xbe70
btl %ecx, %r11d
cmovbl %r8d, %edi
addl %r10d, %r8d
andl %r9d, %r8d
incl %r10d
movl %edi, %ecx
cmpl %eax, %r8d
jne 0xbde2
jmp 0xbe72
movl %esi, 0x8(%rax)
movq 0x20(%r14), %rax
movl %esi, %r8d
leaq (%r8,%r8,2), %r8
movq 0x8(%rax,%r8,8), %r15
cmpl %esi, %edx
je 0xbd57
movl (%rdi,%r10,4), %eax
testl %r11d, %eax
jne 0xbd57
btsl %ecx, %eax
movl %eax, (%rdi,%r10,4)
decl 0x4(%r14)
jmp 0xbd57
movl (%r14), %eax
movb $0x1, %r8b
jmp 0xbf06
movl %esi, %ecx
movl %ecx, %eax
cmpl %esi, %ecx
movq (%rsp), %r15
jne 0xbe99
movl %r8d, %eax
shrl $0x4, %eax
movl (%rdx,%rax,4), %eax
leal (%r8,%r8), %ecx
shrl %cl, %eax
cmpl %esi, %edi
cmovel %r8d, %edi
testb $0x2, %al
cmovel %r8d, %edi
movl %edi, %eax
movl %eax, %esi
shrl $0x4, %esi
movl (%rdx,%rsi,4), %edi
leal (%rax,%rax), %ecx
andl $0x1e, %ecx
movl %edi, %r9d
shrl %cl, %r9d
testb $0x2, %r9b
jne 0xbedf
movb $0x1, %r8b
testb $0x1, %r9b
je 0xbf06
movq 0x18(%r14), %r8
movl %eax, %r9d
movl $0x3, %r10d
shll %cl, %r10d
movq %r12, (%r8,%r9,8)
notl %r10d
andl %r10d, %edi
movl %edi, (%rdx,%rsi,4)
incl 0x4(%r14)
jmp 0xbf03
movq 0x18(%r14), %r8
movl $0x3, %r9d
shll %cl, %r9d
movl %eax, %ecx
movq %r12, (%r8,%rcx,8)
notl %r9d
andl %r9d, %edi
movl %edi, (%rdx,%rsi,4)
incl 0x4(%r14)
incl 0x8(%r14)
xorl %r8d, %r8d
testb %r8b, %r8b
je 0xbf21
movq %r15, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x45c0
movq 0x20(%r14), %rcx
movl %eax, %eax
leaq (%rax,%rax,2), %rax
movslq 0x8(%rbx), %rdx
movl %edx, (%rcx,%rax,8)
movslq %ebp, %rsi
addq 0x18(%rbx), %rsi
movq %rsi, 0x10(%rcx,%rax,8)
movq %r15, 0x8(%rcx,%rax,8)
movq 0x28(%rbx), %rsi
movq %r15, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x43c0