// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/hts.c
// Function: hts_idx_check_local
int hts_idx_check_local(const char *fn, int fmt, char **fnidx) {
    int i, l_fn, l_ext;
    const char *fn_tmp = NULL;
    char *fnidx_tmp;
    const char *csi_ext = ".csi";
    const char *bai_ext = ".bai";
    const char *tbi_ext = ".tbi";
    const char *crai_ext = ".crai";
    const char *fai_ext = ".fai";
    const char *gzi_ext = ".gzi";

    if (!fn)
        return 0;

    if (hisremote(fn)) {
        for (i = strlen(fn) - 1; i >= 0; --i)
            if (fn[i] == '/') {
                fn_tmp = (char *)&fn[i+1];
                break;
            }
    } else {
        // Borrowed from hopen_fd_fileuri()
        if (strncmp(fn, "file://localhost/", 17) == 0) fn_tmp = fn + 16;
        else if (strncmp(fn, "file:///", 8) == 0) fn_tmp = fn + 7;
        else fn_tmp = fn;
#if defined(_WIN32) || defined(__MSYS__)
        // For cases like C:/foo
        if (fn_tmp[0] == '/' && fn_tmp[1] && fn_tmp[2] == ':' && fn_tmp[3] == '/')
            fn_tmp++;
#endif
    }

    if (!fn_tmp) return 0;
    hts_log_info("Using alignment file '%s'", fn_tmp);
    l_fn = strlen(fn_tmp); l_ext = 5;
    fnidx_tmp = (char*)calloc(l_fn + l_ext + 1, 1);
    if (!fnidx_tmp) return 0;

    struct stat sbuf;

    // Try alignment.bam.csi first
    strcpy(fnidx_tmp, fn_tmp); strcpy(fnidx_tmp + l_fn, csi_ext);
    if(stat(fnidx_tmp, &sbuf) == 0) {
        *fnidx = fnidx_tmp;
        return 1;
    } else { // Then try alignment.csi
        for (i = l_fn - 1; i > 0; --i)
            if (fnidx_tmp[i] == '.') {
                strcpy(fnidx_tmp + i, csi_ext);
                if(stat(fnidx_tmp, &sbuf) == 0) {
                    *fnidx = fnidx_tmp;
                    return 1;
                }
                break;
            }
    }
    if (fmt == HTS_FMT_BAI) {
        // Next, try alignment.bam.bai
        strcpy(fnidx_tmp, fn_tmp); strcpy(fnidx_tmp + l_fn, bai_ext);
        if(stat(fnidx_tmp, &sbuf) == 0) {
            *fnidx = fnidx_tmp;
            return 1;
        } else { // And finally, try alignment.bai
            for (i = l_fn - 1; i > 0; --i)
                if (fnidx_tmp[i] == '.') {
                    strcpy(fnidx_tmp + i, bai_ext);
                    if(stat(fnidx_tmp, &sbuf) == 0) {
                        *fnidx = fnidx_tmp;
                        return 1;
                    }
                    break;
                }
        }
    } else if (fmt == HTS_FMT_TBI) { // Or .tbi
        strcpy(fnidx_tmp, fn_tmp); strcpy(fnidx_tmp + l_fn, tbi_ext);
        if(stat(fnidx_tmp, &sbuf) == 0) {
            *fnidx = fnidx_tmp;
            return 1;
        } else {
            for (i = l_fn - 1; i > 0; --i)
                if (fnidx_tmp[i] == '.') {
                    strcpy(fnidx_tmp + i, tbi_ext);
                    if(stat(fnidx_tmp, &sbuf) == 0) {
                        *fnidx = fnidx_tmp;
                        return 1;
                    }
                    break;
                }
        }
    } else if (fmt == HTS_FMT_CRAI) { // Or .crai
        strcpy(fnidx_tmp, fn_tmp); strcpy(fnidx_tmp + l_fn, crai_ext);
        if(stat(fnidx_tmp, &sbuf) == 0) {
            *fnidx = fnidx_tmp;
            return 1;
        } else {
            for (i = l_fn - 1; i > 0; --i)
                if (fnidx_tmp[i] == '.') {
                    strcpy(fnidx_tmp + i, crai_ext);
                    if(stat(fnidx_tmp, &sbuf) == 0) {
                        *fnidx = fnidx_tmp;
                        return 1;
                    }
                    break;
                }
        }
    } else if (fmt == HTS_FMT_FAI) { // Or .fai
        // Check .gzi if we have a .gz file
        strcpy(fnidx_tmp, fn_tmp);
        int gzi_ok = 1;
        if ((l_fn > 3 && strcmp(fn_tmp+l_fn-3, ".gz") == 0) ||
            (l_fn > 5 && strcmp(fn_tmp+l_fn-5, ".bgzf") == 0)) {
            strcpy(fnidx_tmp + l_fn, gzi_ext);
            gzi_ok = stat(fnidx_tmp, &sbuf)==0;
        }

        // Now check for .fai.  Occurs second as we're returning this
        // in *fnidx irrespective of whether we did gzi check.
        strcpy(fnidx_tmp + l_fn, fai_ext);
        *fnidx = fnidx_tmp;
        if (stat(fnidx_tmp, &sbuf) == 0)
            return gzi_ok;
        else
            return 0;
    }

    free(fnidx_tmp);
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movq $0x0, -0x38(%rbp)
leaq 0xcb45d(%rip), %rax     # 0xf07f2
movq %rax, -0x48(%rbp)
leaq 0xcb44d(%rip), %rax     # 0xf07ed
movq %rax, -0x50(%rbp)
leaq 0xcb44c(%rip), %rax     # 0xf07f7
movq %rax, -0x58(%rbp)
leaq 0xcb7cf(%rip), %rax     # 0xf0b85
movq %rax, -0x60(%rbp)
leaq 0xd09cf(%rip), %rax     # 0xf5d90
movq %rax, -0x68(%rbp)
leaq 0xd2578(%rip), %rax     # 0xf7944
movq %rax, -0x70(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x253e3
movl $0x0, -0x4(%rbp)
jmp 0x2592f
movq -0x10(%rbp), %rdi
callq 0x15cf0
cmpl $0x0, %eax
je 0x2543d
movq -0x10(%rbp), %rdi
callq 0x41b0
subq $0x1, %rax
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jl 0x2543b
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2f, %eax
jne 0x2542e
movq -0x10(%rbp), %rax
movl -0x24(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
jmp 0x2543b
jmp 0x25430
movl -0x24(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x25401
jmp 0x25499
movq -0x10(%rbp), %rdi
leaq 0xca3fb(%rip), %rsi     # 0xef843
movl $0x11, %edx
callq 0x4200
cmpl $0x0, %eax
jne 0x25465
movq -0x10(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x38(%rbp)
jmp 0x25497
movq -0x10(%rbp), %rdi
leaq 0xca3e5(%rip), %rsi     # 0xef855
movl $0x8, %edx
callq 0x4200
cmpl $0x0, %eax
jne 0x2548d
movq -0x10(%rbp), %rax
addq $0x7, %rax
movq %rax, -0x38(%rbp)
jmp 0x25495
movq -0x10(%rbp), %rax
movq %rax, -0x38(%rbp)
jmp 0x25497
jmp 0x25499
cmpq $0x0, -0x38(%rbp)
jne 0x254ac
movl $0x0, -0x4(%rbp)
jmp 0x2592f
movq -0x38(%rbp), %rcx
movl $0x4, %edi
leaq 0xcb6cf(%rip), %rsi     # 0xf0b8b
leaq 0xcb6dc(%rip), %rdx     # 0xf0b9f
movb $0x0, %al
callq 0x1b030
movq -0x38(%rbp), %rdi
callq 0x41b0
movl %eax, -0x28(%rbp)
movl $0x5, -0x2c(%rbp)
movl -0x28(%rbp), %eax
addl -0x2c(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rdi
movl $0x1, %esi
callq 0x42f0
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x2550a
movl $0x0, -0x4(%rbp)
jmp 0x2592f
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x4450
movq -0x40(%rbp), %rdi
movslq -0x28(%rbp), %rax
addq %rax, %rdi
movq -0x48(%rbp), %rsi
callq 0x4450
movq -0x40(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0x4410
cmpl $0x0, %eax
jne 0x25557
movq -0x40(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movl $0x1, -0x4(%rbp)
jmp 0x2592f
movl -0x28(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jle 0x255c6
movq -0x40(%rbp), %rax
movslq -0x24(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2e, %eax
jne 0x255b9
movq -0x40(%rbp), %rdi
movslq -0x24(%rbp), %rax
addq %rax, %rdi
movq -0x48(%rbp), %rsi
callq 0x4450
movq -0x40(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0x4410
cmpl $0x0, %eax
jne 0x255b7
movq -0x40(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movl $0x1, -0x4(%rbp)
jmp 0x2592f
jmp 0x255c6
jmp 0x255bb
movl -0x24(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x25560
jmp 0x255c8
cmpl $0x1, -0x14(%rbp)
jne 0x25695
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x4450
movq -0x40(%rbp), %rdi
movslq -0x28(%rbp), %rax
addq %rax, %rdi
movq -0x50(%rbp), %rsi
callq 0x4450
movq -0x40(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0x4410
cmpl $0x0, %eax
jne 0x2561f
movq -0x40(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movl $0x1, -0x4(%rbp)
jmp 0x2592f
movl -0x28(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jle 0x2568e
movq -0x40(%rbp), %rax
movslq -0x24(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2e, %eax
jne 0x25681
movq -0x40(%rbp), %rdi
movslq -0x24(%rbp), %rax
addq %rax, %rdi
movq -0x50(%rbp), %rsi
callq 0x4450
movq -0x40(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0x4410
cmpl $0x0, %eax
jne 0x2567f
movq -0x40(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movl $0x1, -0x4(%rbp)
jmp 0x2592f
jmp 0x2568e
jmp 0x25683
movl -0x24(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x25628
jmp 0x25690
jmp 0x2591f
cmpl $0x2, -0x14(%rbp)
jne 0x25762
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x4450
movq -0x40(%rbp), %rdi
movslq -0x28(%rbp), %rax
addq %rax, %rdi
movq -0x58(%rbp), %rsi
callq 0x4450
movq -0x40(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0x4410
cmpl $0x0, %eax
jne 0x256ec
movq -0x40(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movl $0x1, -0x4(%rbp)
jmp 0x2592f
movl -0x28(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jle 0x2575b
movq -0x40(%rbp), %rax
movslq -0x24(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2e, %eax
jne 0x2574e
movq -0x40(%rbp), %rdi
movslq -0x24(%rbp), %rax
addq %rax, %rdi
movq -0x58(%rbp), %rsi
callq 0x4450
movq -0x40(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0x4410
cmpl $0x0, %eax
jne 0x2574c
movq -0x40(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movl $0x1, -0x4(%rbp)
jmp 0x2592f
jmp 0x2575b
jmp 0x25750
movl -0x24(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x256f5
jmp 0x2575d
jmp 0x2591d
cmpl $0x3, -0x14(%rbp)
jne 0x2582f
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x4450
movq -0x40(%rbp), %rdi
movslq -0x28(%rbp), %rax
addq %rax, %rdi
movq -0x60(%rbp), %rsi
callq 0x4450
movq -0x40(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0x4410
cmpl $0x0, %eax
jne 0x257b9
movq -0x40(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movl $0x1, -0x4(%rbp)
jmp 0x2592f
movl -0x28(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jle 0x25828
movq -0x40(%rbp), %rax
movslq -0x24(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2e, %eax
jne 0x2581b
movq -0x40(%rbp), %rdi
movslq -0x24(%rbp), %rax
addq %rax, %rdi
movq -0x60(%rbp), %rsi
callq 0x4450
movq -0x40(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0x4410
cmpl $0x0, %eax
jne 0x25819
movq -0x40(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movl $0x1, -0x4(%rbp)
jmp 0x2592f
jmp 0x25828
jmp 0x2581d
movl -0x24(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x257c2
jmp 0x2582a
jmp 0x2591b
cmpl $0x4, -0x14(%rbp)
jne 0x25919
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x4450
movl $0x1, -0x104(%rbp)
cmpl $0x3, -0x28(%rbp)
jle 0x25876
movq -0x38(%rbp), %rdi
movslq -0x28(%rbp), %rax
addq %rax, %rdi
addq $-0x3, %rdi
leaq 0xcac41(%rip), %rsi     # 0xf04ad
callq 0x4690
cmpl $0x0, %eax
je 0x2589c
cmpl $0x5, -0x28(%rbp)
jle 0x258d1
movq -0x38(%rbp), %rdi
movslq -0x28(%rbp), %rax
addq %rax, %rdi
addq $-0x5, %rdi
leaq 0xcb327(%rip), %rsi     # 0xf0bb9
callq 0x4690
cmpl $0x0, %eax
jne 0x258d1
movq -0x40(%rbp), %rdi
movslq -0x28(%rbp), %rax
addq %rax, %rdi
movq -0x70(%rbp), %rsi
callq 0x4450
movq -0x40(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0x4410
cmpl $0x0, %eax
sete %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x104(%rbp)
movq -0x40(%rbp), %rdi
movslq -0x28(%rbp), %rax
addq %rax, %rdi
movq -0x68(%rbp), %rsi
callq 0x4450
movq -0x40(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movq -0x40(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0x4410
cmpl $0x0, %eax
jne 0x25910
movl -0x104(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x2592f
movl $0x0, -0x4(%rbp)
jmp 0x2592f
jmp 0x2591b
jmp 0x2591d
jmp 0x2591f
movq -0x40(%rbp), %rdi
callq 0x45a0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
nopl (%rax,%rax)