// File: /workspace/github_c_makefile_star2_O3/zhou-lab[P]tbmate/htslib/hts.c
// Function: test_and_fetch
static char *test_and_fetch(const char *fn)
{
    FILE *fp;
    if (hisremote(fn)) {
        const int buf_size = 1 * 1024 * 1024;
        hFILE *fp_remote;
        uint8_t *buf;
        int l;
        const char *p;
        for (p = fn + strlen(fn) - 1; p >= fn; --p)
            if (*p == '/') break;
        ++p; // p now points to the local file name
        // Attempt to open local file first
        if ((fp = fopen((char*)p, "rb")) != 0)
        {
            fclose(fp);
            return (char*)p;
        }
        // Attempt to open remote file. Stay quiet on failure, it is OK to fail when trying first .csi then .tbi index.
        if ((fp_remote = hopen(fn, "r")) == 0) return 0;
        if ((fp = fopen(p, "w")) == 0) {
            if (hts_verbose >= 1) fprintf(stderr, "[E::%s] fail to create file '%s' in the working directory\n", __func__, p);
            hclose_abruptly(fp_remote);
            return 0;
        }
        if (hts_verbose >= 3) fprintf(stderr, "[M::%s] downloading file '%s' to local directory\n", __func__, fn);
        buf = (uint8_t*)calloc(buf_size, 1);
        while ((l = hread(fp_remote, buf, buf_size)) > 0) fwrite(buf, 1, l, fp);
        free(buf);
        fclose(fp);
        if (hclose(fp_remote) != 0) fprintf(stderr, "[E::%s] fail to close remote file '%s'\n", __func__, fn);
        return (char*)p;
    } else {
        if ((fp = fopen(fn, "rb")) == 0) return 0;
        fclose(fp);
        return (char*)fn;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %r14
callq 0x2c305
testl %eax, %eax
je 0x11838
movq %r14, %rdi
callq 0x3380
addq %r14, %rax
decq %rax
movq %rax, %rbx
cmpq %r14, %rax
jb 0x11814
leaq -0x1(%rbx), %rax
cmpb $0x2f, (%rbx)
jne 0x11803
incq %rbx
leaq 0x3bfe4(%rip), %rsi     # 0x4d802
movq %rbx, %rdi
callq 0x3250
testq %rax, %rax
je 0x11860
movq %rax, %rdi
callq 0x36c0
jmp 0x11982
leaq 0x3bfc3(%rip), %rsi     # 0x4d802
movq %r14, %rdi
callq 0x3250
testq %rax, %rax
je 0x11980
movq %rax, %rdi
callq 0x36c0
movq %r14, %rbx
jmp 0x11982
leaq 0x3f9be(%rip), %rsi     # 0x51225
movq %r14, %rdi
callq 0x2bf5d
testq %rax, %rax
je 0x11980
movq %rax, %r15
leaq 0x3b836(%rip), %rsi     # 0x4d0b8
movq %rbx, %rdi
callq 0x3250
movl 0x4dbf8(%rip), %ecx     # 0x5f488
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x11974
cmpl $0x3, %ecx
jge 0x11994
movq %r14, 0x10(%rsp)
movl $0x100000, %edi         # imm = 0x100000
movl $0x1, %esi
callq 0x36a0
movq %rax, %r13
movq 0x8(%r15), %r12
movq 0x10(%r15), %r14
subq %r12, %r14
movl $0x100000, %eax         # imm = 0x100000
cmpq %rax, %r14
movl $0x100000, %ebp         # imm = 0x100000
cmovbq %r14, %rbp
movq %r13, %rdi
movq %r12, %rsi
movq %rbp, %rdx
callq 0x3850
addq %rbp, %r12
movq %r12, 0x8(%r15)
movl $0x100000, %eax         # imm = 0x100000
cmpq $0xfffff, %r14          # imm = 0xFFFFF
ja 0x11914
movl $0x100000, %edx         # imm = 0x100000
movq %r15, %rdi
movq %r13, %rsi
movq %rbp, %rcx
callq 0x2b8df
testl %eax, %eax
jle 0x11930
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl $0x1, %esi
movq %r13, %rdi
movq %rax, %rdx
movq 0x8(%rsp), %rcx
callq 0x3770
jmp 0x118be
movq %r13, %rdi
callq 0x3370
movq 0x8(%rsp), %rdi
callq 0x36c0
movq %r15, %rdi
callq 0x2bbcf
testl %eax, %eax
je 0x11982
movq 0x4d693(%rip), %rax     # 0x5efe8
movq (%rax), %rdi
leaq 0x3ce95(%rip), %rsi     # 0x4e7f4
leaq 0x3ce4d(%rip), %rdx     # 0x4e7b3
movq 0x10(%rsp), %rcx
xorl %eax, %eax
callq 0x37e0
jmp 0x11982
testl %ecx, %ecx
jg 0x119bb
movq %r15, %rdi
callq 0x2bc29
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x4d64d(%rip), %rax     # 0x5efe8
movq (%rax), %rdi
leaq 0x3ce1d(%rip), %rsi     # 0x4e7c2
leaq 0x3ce07(%rip), %rdx     # 0x4e7b3
movq %r14, %rcx
xorl %eax, %eax
callq 0x37e0
jmp 0x118a7
movq 0x4d626(%rip), %rax     # 0x5efe8
movq (%rax), %rdi
leaq 0x3cdac(%rip), %rsi     # 0x4e778
leaq 0x3cde0(%rip), %rdx     # 0x4e7b3
movq %rbx, %rcx
xorl %eax, %eax
callq 0x37e0
jmp 0x11978