// File: /workspace/github_c_makefile_star2_O3/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 0x7ac26(%rip), %rsi     # 0x95ee0
callq 0x40e0
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x1b305
movq %rax, %r15
movq %r14, %rdi
callq 0x4930
testq %rax, %rax
je 0x1b32d
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 0x1b449
movq %rax, %rbx
movq %r12, %rdi
jmp 0x1b3b1
leaq 0x8(%rsp), %rdx
movq %r14, %rdi
movl %ebp, %esi
callq 0x1ae7b
testl %eax, %eax
je 0x1b356
movq 0x8(%rsp), %r15
testq %r15, %r15
je 0x1b3de
testb $0x1, %bl
je 0x1b380
jmp 0x1b39c
callq 0x4050
movl (%rax), %edi
callq 0x4150
leaq 0x7b79e(%rip), %rsi     # 0x96ade
leaq 0x7d187(%rip), %rdx     # 0x984ce
xorl %ebx, %ebx
movl $0x1, %edi
movq %rax, %rcx
jmp 0x1b3fb
movq %r14, %rdi
callq 0x101ec
testl %eax, %eax
je 0x1b318
leaq 0x7b251(%rip), %rsi     # 0x965ba
movq %r14, %rdi
testb $0x1, %bl
jne 0x1b38a
xorl %edx, %edx
callq 0x1b1d1
movq %rax, %r15
testq %rax, %rax
je 0x1b3b8
movq %r15, %rdi
callq 0x1bbcc
jmp 0x1b3ab
movl $0x1, %edx
callq 0x1b1d1
movq %rax, %r15
testq %rax, %rax
je 0x1b3cb
movq %r14, %rdi
movq %r15, %rsi
movl %ebp, %edx
movl %ebx, %ecx
callq 0x1b449
movq %rax, %rbx
movq %r15, %rdi
callq 0x45c0
jmp 0x1b402
cmpl $0x2, %ebp
je 0x1b416
cmpl $0x1, %ebp
jne 0x1b3de
leaq 0x7b1ec(%rip), %rsi     # 0x965b5
jmp 0x1b41d
cmpl $0x2, %ebp
je 0x1b424
cmpl $0x1, %ebp
jne 0x1b3de
leaq 0x7b1d9(%rip), %rsi     # 0x965b5
jmp 0x1b42b
testb $0x2, %bl
jne 0x1b412
leaq 0x7b6f4(%rip), %rsi     # 0x96ade
leaq 0x7b6ff(%rip), %rdx     # 0x96af0
xorl %ebx, %ebx
movl $0x1, %edi
movq %r14, %rcx
xorl %eax, %eax
callq 0x13de5
movq %rbx, %rax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
xorl %ebx, %ebx
jmp 0x1b402
leaq 0x7b1a2(%rip), %rsi     # 0x965bf
movq %r14, %rdi
xorl %edx, %edx
jmp 0x1b433
leaq 0x7b194(%rip), %rsi     # 0x965bf
movq %r14, %rdi
movl $0x1, %edx
callq 0x1b1d1
movq %rax, %r15
jmp 0x1b31d