// File: /workspace/github_c_makefile_star2_O1/samtools[P]htslib/cram/open_trace_file.c
// Function: open_path_mfile
mFILE *open_path_mfile(const char *file, char *path, char *relative_to,
                       int *local) {
    char *newsearch;
    char *ele;
    mFILE *fp;

    if (local)
        *local = 1;

    /* Use path first */
    if (!path)
        path = getenv("RAWDATA");
    if (NULL == (newsearch = tokenise_search_path(path)))
        return NULL;

    /*
     * Step through the search path testing out each component.
     * We now look through each path element treating some prefixes as
     * special, otherwise we treat the element as a directory.
     */
    for (ele = newsearch; *ele; ele += strlen(ele)+1) {
        char *ele2;

        /*
         * '|' prefixing a path component indicates that we do not
         * wish to perform the compression extension searching in that
         * location.
         *
         * NB: this has been removed from the htslib implementation.
         */
        if (*ele == '|') {
            ele2 = ele+1;
        } else {
            ele2 = ele;
        }

        if (0 == strncmp(ele2, "URL=", 4)) {
            if ((fp = find_file_url(file, ele2+4))) {
                if (local)
                    *local = strncmp(ele2+4, "file:", 5) == 0 ? 1 : 0;
                free(newsearch);
                return fp;
            }
        } else if (hisremote(ele2)) {
            if ((fp = find_file_url(file, ele2))) {
                free(newsearch);
                if (local)
                    *local = 0;
                return fp;
            }
        } else if ((fp = find_file_dir(file, ele2))) {
            free(newsearch);
            return fp;
        }
    }

    free(newsearch);

    /* Look in the same location as the incoming 'relative_to' filename */
    if (relative_to) {
        char *cp;
        char relative_path[PATH_MAX+1];
        strcpy(relative_path, relative_to);
        if ((cp = strrchr(relative_path, '/')))
            *cp = 0;
        if ((fp = find_file_dir(file, relative_path)))
            return fp;
    }

    return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1028, %rsp           # imm = 0x1028
movq %rcx, %r15
movq %rdx, %r14
movq %rdi, 0x10(%rsp)
testq %rcx, %rcx
je 0x5a40e
movl $0x1, (%r15)
testq %rsi, %rsi
jne 0x5a422
leaq 0x443d7(%rip), %rdi     # 0x9e7f1
callq 0x4600
movq %rax, %rsi
movq %rsi, %rdi
callq 0x59d7c
testq %rax, %rax
je 0x5a594
movq %rax, %r13
movq %r14, 0x18(%rsp)
leaq 0x443b7(%rip), %rbx     # 0x9e7f9
movq %rax, %r14
movzbl (%r14), %eax
cmpl $0x7c, %eax
je 0x5a45a
movq %r14, %r12
testl %eax, %eax
jne 0x5a45e
jmp 0x5a540
leaq 0x1(%r14), %r12
movl $0x4, %edx
movq %r12, %rdi
movq %rbx, %rsi
callq 0x4210
testl %eax, %eax
je 0x5a4ad
movq %r12, %rdi
callq 0x103cd
testl %eax, %eax
je 0x5a4fa
movq 0x10(%rsp), %rdi
movq %r12, %rsi
callq 0x5a025
testq %rax, %rax
je 0x5a520
movq %rax, %r12
movq %r13, %rdi
callq 0x45c0
testq %r15, %r15
je 0x5a517
movl $0x0, (%r15)
jmp 0x5a517
addq $0x4, %r12
movq 0x10(%rsp), %rdi
movq %r12, %rsi
callq 0x5a025
testq %rax, %rax
je 0x5a520
movq %rax, %rbp
testq %r15, %r15
je 0x5a4e9
movl $0x5, %edx
movq %r12, %rdi
leaq 0x43fe7(%rip), %rsi     # 0x9e4c1
callq 0x4210
xorl %ecx, %ecx
testl %eax, %eax
sete %cl
movl %ecx, (%r15)
movq %r13, %rdi
callq 0x45c0
xorl %eax, %eax
movq %rbp, 0x8(%rsp)
jmp 0x5a522
movq 0x10(%rsp), %rdi
movq %r12, %rsi
callq 0x5a5a8
testq %rax, %rax
je 0x5a520
movq %rax, %r12
movq %r13, %rdi
callq 0x45c0
xorl %eax, %eax
movq %r12, 0x8(%rsp)
jmp 0x5a522
movb $0x1, %al
testb %al, %al
je 0x5a539
movq %r14, %rdi
callq 0x41d0
addq %rax, %r14
incq %r14
jmp 0x5a445
movq 0x8(%rsp), %rax
jmp 0x5a596
movq %r13, %rdi
callq 0x45c0
movq 0x18(%rsp), %rsi
testq %rsi, %rsi
je 0x5a594
leaq 0x20(%rsp), %r14
movq %r14, %rdi
callq 0x4460
movq %r14, %rdi
movl $0x2f, %esi
callq 0x4530
testq %rax, %rax
je 0x5a574
movb $0x0, (%rax)
leaq 0x20(%rsp), %rsi
movq 0x10(%rsp), %rdi
callq 0x5a5a8
testq %rax, %rax
movq 0x8(%rsp), %rcx
cmovneq %rax, %rcx
movq %rcx, %rax
jne 0x5a596
xorl %eax, %eax
addq $0x1028, %rsp           # imm = 0x1028
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq