// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/cram/cram_io.c
// Function: cram_ref_load
ref_entry *cram_ref_load(refs_t *r, int id, int is_md5) {
    ref_entry *e = r->ref_id[id];
    hts_pos_t start = 1, end = e->length;
    char *seq;

    if (e->seq) {
        return e;
    }

    assert(e->count == 0);

    if (r->last) {
#ifdef REF_DEBUG
        int idx = 0;
        for (idx = 0; idx < r->nref; idx++)
            if (r->last == r->ref_id[idx])
                break;
        RP("%d cram_ref_load DECR %d\n", gettid(), idx);
#endif
        assert(r->last->count > 0);
        if (--r->last->count <= 0) {
            RP("%d FREE REF %d (%p)\n", gettid(), id, r->ref_id[id]->seq);
            if (r->last->seq)
                ref_entry_free_seq(r->last);
        }
    }

    if (!r->fn)
        return NULL;

    /* Open file if it's not already the current open reference */
    if (strcmp(r->fn, e->fn) || r->fp == NULL) {
        if (r->fp)
            if (bgzf_close(r->fp) != 0)
                return NULL;
        r->fn = e->fn;
        if (!(r->fp = bgzf_open_ref(r->fn, "r", is_md5)))
            return NULL;
    }

    RP("%d Loading ref %d (%d..%d)\n", gettid(), id, start, end);

    if (!(seq = load_ref_portion(r->fp, e, start, end))) {
        return NULL;
    }

    RP("%d Loaded ref %d (%d..%d) = %p\n", gettid(), id, start, end, seq);

    RP("%d INC REF %d, %"PRId64"\n", gettid(), id, (e->count+1));
    e->seq = seq;
    e->mf = NULL;
    e->count++;

    /*
     * Also keep track of last used ref so incr/decr loops on the same
     * sequence don't cause load/free loops.
     */
    RP("%d cram_ref_load INCR %d => %"PRId64"\n", gettid(), id, e->count+1);
    r->last = e;
    e->count++;

    return e;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x20(%rbp)
movq $0x1, -0x28(%rbp)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rax
cmpq $0x0, 0x38(%rax)
je 0x72382
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x72546
movq -0x20(%rbp), %rax
cmpq $0x0, 0x30(%rax)
jne 0x7238f
jmp 0x723ae
leaq 0x83484(%rip), %rdi     # 0xf581a
leaq 0x83275(%rip), %rsi     # 0xf5612
movl $0xd00, %edx            # imm = 0xD00
leaq 0x8347f(%rip), %rcx     # 0xf5828
callq 0x42e0
movq -0x10(%rbp), %rax
cmpq $0x0, 0x60(%rax)
je 0x72423
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rax
cmpq $0x0, 0x30(%rax)
jle 0x723ca
jmp 0x723e9
leaq 0x83484(%rip), %rdi     # 0xf5855
leaq 0x8323a(%rip), %rsi     # 0xf5612
movl $0xd0a, %edx            # imm = 0xD0A
leaq 0x83444(%rip), %rcx     # 0xf5828
callq 0x42e0
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rcx
movq 0x30(%rcx), %rax
addq $-0x1, %rax
movq %rax, 0x30(%rcx)
cmpq $0x0, %rax
jg 0x72421
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rax
cmpq $0x0, 0x38(%rax)
je 0x7241f
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rdi
callq 0x71900
jmp 0x72421
jmp 0x72423
movq -0x10(%rbp), %rax
cmpq $0x0, 0x20(%rax)
jne 0x7243b
movq $0x0, -0x8(%rbp)
jmp 0x72546
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0x4690
cmpl $0x0, %eax
jne 0x72460
movq -0x10(%rbp), %rax
cmpq $0x0, 0x28(%rax)
jne 0x724cd
movq -0x10(%rbp), %rax
cmpq $0x0, 0x28(%rax)
je 0x7248c
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x103d0
cmpl $0x0, %eax
je 0x7248a
movq $0x0, -0x8(%rbp)
jmp 0x72546
jmp 0x7248c
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
movl -0x18(%rbp), %edx
leaq 0x80643(%rip), %rsi     # 0xf2af1
callq 0x72550
movq -0x10(%rbp), %rcx
movq %rax, 0x28(%rcx)
cmpq $0x0, %rax
jne 0x724cb
movq $0x0, -0x8(%rbp)
jmp 0x72546
jmp 0x724cd
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x30(%rbp), %rcx
callq 0x72690
movq %rax, -0x38(%rbp)
cmpq $0x0, %rax
jne 0x724fa
movq $0x0, -0x8(%rbp)
jmp 0x72546
movq -0x38(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x20(%rbp), %rax
movq $0x0, 0x40(%rax)
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x30(%rax)
movq -0x20(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x60(%rax)
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x30(%rax)
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq