// File: /workspace/github_c_makefile_star2_O3/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 $0x1018, %rsp           # imm = 0x1018
movq %rcx, %r15
movq %rdx, %r12
movq %rdi, %r14
testq %rcx, %rcx
je 0x579ce
movl $0x1, (%r15)
testq %rsi, %rsi
jne 0x579e2
leaq 0x4400f(%rip), %rdi     # 0x9b9e9
callq 0x4600
movq %rax, %rsi
movq %rsi, %rdi
callq 0x57338
testq %rax, %rax
je 0x57ad9
movq %rax, %rbx
movq %r12, 0x8(%rsp)
movq %r15, (%rsp)
leaq 0x43feb(%rip), %r13     # 0x9b9f1
movq %rax, %r12
movzbl (%r12), %eax
cmpl $0x7c, %eax
je 0x57a1c
movq %r12, %rbp
testl %eax, %eax
jne 0x57a21
jmp 0x57a90
leaq 0x1(%r12), %rbp
movl $0x4, %edx
movq %rbp, %rdi
movq %r13, %rsi
callq 0x4210
testl %eax, %eax
je 0x57a56
movq %rbp, %rdi
callq 0x101ec
movq %r14, %rdi
movq %rbp, %rsi
testl %eax, %eax
je 0x57a6f
callq 0x575d1
testq %rax, %rax
je 0x57a7d
jmp 0x57ade
addq $0x4, %rbp
movq %r14, %rdi
movq %rbp, %rsi
callq 0x575d1
testq %rax, %rax
je 0x57a7d
jmp 0x57afa
callq 0x57b46
testq %rax, %rax
jne 0x57b26
movq %r12, %rdi
callq 0x41d0
addq %rax, %r12
incq %r12
jmp 0x57a09
movq %rbx, %rdi
callq 0x45c0
movq 0x8(%rsp), %rsi
testq %rsi, %rsi
je 0x57ad9
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
callq 0x4460
movq %rbx, %rdi
movl $0x2f, %esi
callq 0x4530
testq %rax, %rax
je 0x57ac4
movb $0x0, (%rax)
leaq 0x10(%rsp), %rsi
movq %r14, %rdi
callq 0x57b46
movq %rax, %r15
testq %rax, %rax
jne 0x57b31
xorl %r15d, %r15d
jmp 0x57b31
movq %rax, %r15
movq %rbx, %rdi
callq 0x45c0
movq (%rsp), %rax
testq %rax, %rax
je 0x57b31
movl $0x0, (%rax)
jmp 0x57b31
movq %rax, %r15
movq (%rsp), %r14
testq %r14, %r14
je 0x57b29
leaq 0x43bac(%rip), %rsi     # 0x9b6b9
movl $0x5, %edx
movq %rbp, %rdi
callq 0x4210
xorl %ecx, %ecx
testl %eax, %eax
sete %cl
movl %ecx, (%r14)
jmp 0x57b29
movq %rax, %r15
movq %rbx, %rdi
callq 0x45c0
movq %r15, %rax
addq $0x1018, %rsp           # imm = 0x1018
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq