// File: /workspace/github_cpp_makefile_star2_O1/karel-brinda[P]ococo/ext/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
pushq %rax
movq %rdi, %r14
callq 0x48bf3
testl %eax, %eax
je 0x13411
movq %r14, %rdi
callq 0x4230
addq %r14, %rax
decq %rax
movq %rax, %rbx
cmpq %r14, %rax
jb 0x133ed
leaq -0x1(%rbx), %rax
cmpb $0x2f, (%rbx)
jne 0x133dc
incq %rbx
leaq 0x3fc03(%rip), %rsi     # 0x52ffa
movq %rbx, %rdi
callq 0x4600
testq %rax, %rax
je 0x13439
movq %rax, %rdi
callq 0x4530
jmp 0x13547
leaq 0x3fbe2(%rip), %rsi     # 0x52ffa
movq %r14, %rdi
callq 0x4600
testq %rax, %rax
je 0x13545
movq %rax, %rdi
callq 0x4530
movq %r14, %rbx
jmp 0x13547
leaq 0x404d9(%rip), %rsi     # 0x53919
movq %r14, %rdi
callq 0x4883b
testq %rax, %rax
je 0x13545
movq %rax, %r15
leaq 0x3fae9(%rip), %rsi     # 0x52f44
movq %rbx, %rdi
callq 0x4600
movl 0x510e7(%rip), %ecx     # 0x64550
movq %rax, (%rsp)
testq %rax, %rax
je 0x13539
cmpl $0x3, %ecx
jge 0x13559
movl $0x100000, %edi         # imm = 0x100000
movl $0x1, %esi
callq 0x4360
movq %rax, %r13
movq 0x8(%r15), %rsi
movq 0x10(%r15), %r12
subq %rsi, %r12
movl $0x100000, %eax         # imm = 0x100000
cmpq %rax, %r12
movl $0x100000, %ebp         # imm = 0x100000
cmovbq %r12, %rbp
movq %r13, %rdi
movq %rbp, %rdx
callq 0x4420
addq %rbp, 0x8(%r15)
movl $0x100000, %edx         # imm = 0x100000
cmpq $0xfffff, %r12          # imm = 0xFFFFF
ja 0x134db
movq %r15, %rdi
movq %r13, %rsi
movq %rbp, %rcx
callq 0x48187
movq %rax, %rdx
testl %edx, %edx
jle 0x134f8
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movl $0x1, %esi
movq %r13, %rdi
movq (%rsp), %rcx
callq 0x4a30
jmp 0x13491
movq %r13, %rdi
callq 0x4610
movq (%rsp), %rdi
callq 0x4530
movq %r15, %rdi
callq 0x484b2
testl %eax, %eax
je 0x13547
movq 0x50aac(%rip), %rax     # 0x63fc8
movq (%rax), %rdi
leaq 0x3fb53(%rip), %rsi     # 0x53079
leaq 0x3fb0b(%rip), %rdx     # 0x53038
movq %r14, %rcx
xorl %eax, %eax
callq 0x4770
jmp 0x13547
testl %ecx, %ecx
jg 0x13580
movq %r15, %rdi
callq 0x4850c
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x50a68(%rip), %rax     # 0x63fc8
movq (%rax), %rdi
leaq 0x3fadd(%rip), %rsi     # 0x53047
leaq 0x3fac7(%rip), %rdx     # 0x53038
movq %r14, %rcx
xorl %eax, %eax
callq 0x4770
jmp 0x1347f
movq 0x50a41(%rip), %rax     # 0x63fc8
movq (%rax), %rdi
leaq 0x3fa6c(%rip), %rsi     # 0x52ffd
leaq 0x3faa0(%rip), %rdx     # 0x53038
movq %rbx, %rcx
xorl %eax, %eax
callq 0x4770
jmp 0x1353d