// File: /workspace/github_c_makefile_star2_O1/samtools[P]htslib/hts.c
// Function: idx_find_and_load
static hts_idx_t *idx_find_and_load(const char *fn, int fmt, int flags)
{
    char *fnidx = strstr(fn, HTS_IDX_DELIM);
    hts_idx_t *idx;

    if ( fnidx ) {
        char *fn2 = strdup(fn);
        if (!fn2) {
            hts_log_error("%s", strerror(errno));
            return NULL;
        }
        fn2[fnidx - fn] = '\0';
        fnidx += strlen(HTS_IDX_DELIM);
        idx = hts_idx_load3(fn2, fnidx, fmt, flags);
        free(fn2);
        return idx;
    }

    if (hts_idx_check_local(fn, fmt, &fnidx) == 0 && hisremote(fn)) {
        if (flags & HTS_IDX_SAVE_REMOTE) {
            fnidx = idx_filename(fn, ".csi", HTS_IDX_SAVE_REMOTE);
            if (!fnidx) {
                switch (fmt) {
                case HTS_FMT_BAI: fnidx = idx_filename(fn, ".bai", HTS_IDX_SAVE_REMOTE); break;
                case HTS_FMT_TBI: fnidx = idx_filename(fn, ".tbi", HTS_IDX_SAVE_REMOTE); break;
                default: break;
                }
            }
        } else {
            fnidx = idx_filename(fn, ".csi", 0);
            if (!fnidx) {
                switch (fmt) {
                case HTS_FMT_BAI: fnidx = idx_filename(fn, ".bai", 0); break;
                case HTS_FMT_TBI: fnidx = idx_filename(fn, ".tbi", 0); break;
                default: break;
                }
            }
        }
    }
    if (!fnidx) {
        if (!(flags & HTS_IDX_SILENT_FAIL))
            hts_log_error("Could not retrieve index file for '%s'", fn);
        return 0;
    }

    if (flags & HTS_IDX_SAVE_REMOTE)
        idx = hts_idx_load3(fn, fnidx, fmt, flags);
    else
        idx = idx_read(fnidx);
    free(fnidx);
    return idx;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movl %edx, %ebx
movl %esi, %ebp
movq %rdi, %r14
leaq 0x7d639(%rip), %rsi     # 0x98e40
callq 0x40e0
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x1b857
movq %rax, %r15
movq %r14, %rdi
callq 0x4930
testq %rax, %rax
je 0x1b88e
movq %rax, %r12
movq %r15, %rax
subq %r14, %rax
movb $0x0, (%r12,%rax)
addq $0x7, %r15
movq %r15, 0x8(%rsp)
movq %r12, %rdi
movq %r15, %rsi
movl %ebp, %edx
movl %ebx, %ecx
callq 0x1b9ba
movq %rax, %rbx
movq %r12, %rdi
jmp 0x1b93d
leaq 0x8(%rsp), %rdx
movq %r14, %rdi
movl %ebp, %esi
callq 0x1b3b7
testl %eax, %eax
je 0x1b8b4
movq 0x8(%rsp), %r15
testq %r15, %r15
je 0x1b902
testb $0x1, %bl
jne 0x1b928
movq %r15, %rdi
callq 0x1c17e
jmp 0x1b937
callq 0x4050
movl (%rax), %edi
callq 0x4150
leaq 0x7e19d(%rip), %rsi     # 0x99a3e
leaq 0x7fc1f(%rip), %rdx     # 0x9b4c7
xorl %ebx, %ebx
movl $0x1, %edi
movq %rax, %rcx
jmp 0x1b91f
movq %r14, %rdi
callq 0x103cd
testl %eax, %eax
je 0x1b86a
leaq 0x7dc53(%rip), %rsi     # 0x9951a
movq %r14, %rdi
testb $0x1, %bl
jne 0x1b956
xorl %edx, %edx
callq 0x1b71e
movq %rax, 0x8(%rsp)
testq %rax, %rax
jne 0x1b86a
cmpl $0x2, %ebp
je 0x1b985
cmpl $0x1, %ebp
jne 0x1b86a
leaq 0x7dc18(%rip), %rsi     # 0x99515
jmp 0x1b98c
testb $0x2, %bl
jne 0x1b952
leaq 0x7e130(%rip), %rsi     # 0x99a3e
leaq 0x7e13b(%rip), %rdx     # 0x99a50
xorl %ebx, %ebx
movl $0x1, %edi
movq %r14, %rcx
xorl %eax, %eax
callq 0x14378
jmp 0x1b942
movq %r14, %rdi
movq %r15, %rsi
movl %ebp, %edx
movl %ebx, %ecx
callq 0x1b9ba
movq %rax, %rbx
movq %r15, %rdi
callq 0x45c0
movq %rbx, %rax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
xorl %ebx, %ebx
jmp 0x1b942
movl $0x1, %edx
callq 0x1b71e
movq %rax, 0x8(%rsp)
testq %rax, %rax
jne 0x1b86a
cmpl $0x2, %ebp
je 0x1b993
cmpl $0x1, %ebp
jne 0x1b86a
leaq 0x7db92(%rip), %rsi     # 0x99515
jmp 0x1b99a
leaq 0x7db93(%rip), %rsi     # 0x9951f
movq %r14, %rdi
xorl %edx, %edx
jmp 0x1b9a2
leaq 0x7db85(%rip), %rsi     # 0x9951f
movq %r14, %rdi
movl $0x1, %edx
callq 0x1b71e
movq %rax, 0x8(%rsp)
jmp 0x1b86a