// File: karel-brinda[P]ococo/ext/htslib/cram/open_trace_file.c
// Function: open_path_mfile
mFILE *open_path_mfile(char *file, char *path, char *relative_to) {
    char *newsearch;
    char *ele;
    mFILE *fp;

    /* 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))) {
		free(newsearch);
		return fp;
	    }
	} else if (!strncmp(ele2, "http:", 5) ||
		   !strncmp(ele2, "ftp:", 4)) {
	    if ((fp = find_file_url(file, ele2))) {
		free(newsearch);
		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
movq %rsp, %rbp
subq $0x1050, %rsp           # imm = 0x1050
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x5799e
leaq 0x25d4c(%rip), %rdi     # 0x7d6e1
callq 0x46e0
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
callq 0x57240
movq %rax, %rcx
movq %rcx, -0x28(%rbp)
xorl %eax, %eax
cmpq %rcx, %rax
jne 0x579c2
movq $0x0, -0x8(%rbp)
jmp 0x57b6c
movq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpb $0x0, (%rax)
je 0x57afc
movq -0x30(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x7c, %eax
jne 0x579f1
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x579f9
movq -0x30(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
leaq 0x25ce5(%rip), %rsi     # 0x7d6e9
movl $0x4, %edx
callq 0x4290
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x57a4c
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rsi
addq $0x4, %rsi
callq 0x57690
movq %rax, -0x38(%rbp)
cmpq $0x0, %rax
je 0x57a47
movq -0x28(%rbp), %rdi
callq 0x46a0
movq -0x38(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x57b6c
jmp 0x57ae0
movq -0x40(%rbp), %rdi
leaq 0x25c7b(%rip), %rsi     # 0x7d6d2
movl $0x5, %edx
callq 0x4290
cmpl $0x0, %eax
je 0x57a80
movq -0x40(%rbp), %rdi
leaq 0x25c6b(%rip), %rsi     # 0x7d6dc
movl $0x4, %edx
callq 0x4290
cmpl $0x0, %eax
jne 0x57aaf
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x57690
movq %rax, -0x38(%rbp)
cmpq $0x0, %rax
je 0x57aad
movq -0x28(%rbp), %rdi
callq 0x46a0
movq -0x38(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x57b6c
jmp 0x57ade
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x57b80
movq %rax, -0x38(%rbp)
cmpq $0x0, %rax
je 0x57adc
movq -0x28(%rbp), %rdi
callq 0x46a0
movq -0x38(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x57b6c
jmp 0x57ade
jmp 0x57ae0
jmp 0x57ae2
movq -0x30(%rbp), %rdi
callq 0x4230
addq $0x1, %rax
addq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
jmp 0x579ca
movq -0x28(%rbp), %rdi
callq 0x46a0
cmpq $0x0, -0x20(%rbp)
je 0x57b64
leaq -0x1050(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x4530
leaq -0x1050(%rbp), %rdi
movl $0x2f, %esi
callq 0x4640
movq %rax, -0x48(%rbp)
cmpq $0x0, %rax
je 0x57b3e
movq -0x48(%rbp), %rax
movb $0x0, (%rax)
movq -0x10(%rbp), %rdi
leaq -0x1050(%rbp), %rsi
callq 0x57b80
movq %rax, -0x38(%rbp)
cmpq $0x0, %rax
je 0x57b62
movq -0x38(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x57b6c
jmp 0x57b64
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x1050, %rsp           # imm = 0x1050
popq %rbp
retq
nopl (%rax)