// File: /workspace/github_c_makefile_star2_O2/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 0x60afe(%rip), %rsi     # 0x77ed1
callq 0x40e0
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x1741e
movq %rax, %r15
movq %r14, %rdi
callq 0x4930
testq %rax, %rax
je 0x17446
movq %rax, %r12
movq %r15, %rax
subq %r14, %rax
movb $0x0, (%r12,%rax)
addq $0x7, %r15
movq %r12, %rdi
movq %r15, %rsi
movl %ebp, %edx
movl %ebx, %ecx
callq 0x1755d
movq %rax, %rbx
movq %r12, %rdi
jmp 0x174c9
leaq 0x8(%rsp), %rdx
movq %r14, %rdi
movl %ebp, %esi
callq 0x16f81
testl %eax, %eax
je 0x1746d
movq 0x8(%rsp), %r15
testq %r15, %r15
je 0x174f6
testb $0x1, %bl
je 0x17497
jmp 0x174b4
callq 0x4050
movl (%rax), %edi
callq 0x4150
leaq 0x61676(%rip), %rsi     # 0x78acf
leaq 0x62fc9(%rip), %rdx     # 0x7a429
xorl %ebx, %ebx
pushq $0x1
popq %rdi
movq %rax, %rcx
jmp 0x17511
movq %r14, %rdi
callq 0xe4f2
testl %eax, %eax
je 0x17431
leaq 0x6112b(%rip), %rsi     # 0x785ab
testb $0x1, %bl
jne 0x174a1
movq %r14, %rdi
xorl %edx, %edx
callq 0x172ee
movq %rax, %r15
testq %rax, %rax
je 0x174d0
movq %r15, %rdi
callq 0x17c67
jmp 0x174c3
pushq $0x1
popq %rdx
movq %r14, %rdi
callq 0x172ee
movq %rax, %r15
testq %rax, %rax
je 0x174e3
movq %r14, %rdi
movq %r15, %rsi
movl %ebp, %edx
movl %ebx, %ecx
callq 0x1755d
movq %rax, %rbx
movq %r15, %rdi
callq 0x45c0
jmp 0x17518
cmpl $0x2, %ebp
je 0x1752c
cmpl $0x1, %ebp
jne 0x174f6
leaq 0x610c5(%rip), %rsi     # 0x785a6
jmp 0x17533
cmpl $0x2, %ebp
je 0x1753a
cmpl $0x1, %ebp
jne 0x174f6
leaq 0x610b2(%rip), %rsi     # 0x785a6
jmp 0x17541
testb $0x2, %bl
jne 0x17528
leaq 0x615cd(%rip), %rsi     # 0x78acf
leaq 0x615d8(%rip), %rdx     # 0x78ae1
xorl %ebx, %ebx
pushq $0x1
popq %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x110c6
movq %rbx, %rax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
xorl %ebx, %ebx
jmp 0x17518
leaq 0x6107d(%rip), %rsi     # 0x785b0
movq %r14, %rdi
xorl %edx, %edx
jmp 0x17547
leaq 0x6106f(%rip), %rsi     # 0x785b0
pushq $0x1
popq %rdx
movq %r14, %rdi
callq 0x172ee
movq %rax, %r15
jmp 0x17436