// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq $0x0, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq (%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rcx
movl $0x10000, %eax          # imm = 0x10000
cmpl 0x4(%rcx), %eax
jl 0xe469
jmp 0xe618
movq -0x8(%rbp), %rax
cmpl $0x0, 0x8(%rax)
jl 0xe480
movq -0x8(%rbp), %rax
cmpl $0x10000, 0x8(%rax)     # imm = 0x10000
jle 0xe485
jmp 0xe618
movq -0x30(%rbp), %rax
movl 0x4(%rax), %eax
addl $0x1, %eax
shll $0x10, %eax
movq -0x8(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jbe 0xe573
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movl 0x8(%rax), %eax
movq -0x30(%rbp), %rcx
cmpl (%rcx), %eax
jb 0xe4c1
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movl $0x0, 0x8(%rax)
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movl 0x8(%rax), %eax
movl %eax, -0x14(%rbp)
movl %eax, -0x18(%rbp)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
movq -0x30(%rbp), %rcx
cmpl (%rcx), %eax
jb 0xe4ea
movl $0x0, -0x14(%rbp)
jmp 0xe4ec
movl -0x14(%rbp), %eax
cmpl -0x18(%rbp), %eax
je 0xe535
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x14(%rbp), %ecx
shrl $0x4, %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
movl -0x14(%rbp), %ecx
andl $0xf, %ecx
shll %ecx
shrl %cl, %eax
andl $0x3, %eax
cmpl $0x0, %eax
jne 0xe51b
jmp 0xe535
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
movq -0x30(%rbp), %rcx
cmpl (%rcx), %eax
jne 0xe533
movl $0x0, -0x14(%rbp)
jmp 0xe4ec
movl -0x14(%rbp), %ecx
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movl %ecx, 0x8(%rax)
movl -0x14(%rbp), %eax
cmpl -0x18(%rbp), %eax
je 0xe571
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x14(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x30(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x12470
jmp 0xe581
movl $0x10000, %edi          # imm = 0x10000
callq 0x4650
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0xe58d
jmp 0xe618
movq -0x30(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rsi
leaq -0x10(%rbp), %rdx
callq 0x124f0
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x10(%rbp)
jg 0xe5b6
movq -0x20(%rbp), %rdi
callq 0x45a0
jmp 0xe618
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x14(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rax
movl 0x8(%rax), %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rcx
movslq -0xc(%rbp), %rax
addq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x20(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rsi
movq -0x28(%rbp), %rax
movslq (%rax), %rdx
callq 0x43b0
addq $0x30, %rsp
popq %rbp
retq
nop