// File: karel-brinda[P]ococo/ext/htslib/cram/open_trace_file.c
// Function: find_file_url
mFILE *find_file_url(char *file, char *url) {
    char buf[8192], *cp;
    mFILE *mf = NULL;
    int maxlen = 8190 - strlen(file), len;
    hFILE *hf;

    /* Expand %s for the trace name */
    for (cp = buf; *url && cp - buf < maxlen; url++) {
	if (*url == '%' && *(url+1) == 's') {
	    url++;
	    cp += strlen(strcpy(cp, file));
	} else {
	    *cp++ = *url;
	}
    }
    *cp++ = 0;

    if (!(hf = hopen(buf, "r")))
	return NULL;

    if (NULL == (mf = mfcreate(NULL, 0)))
	return NULL;
    while ((len = hread(hf, buf, 8192)) > 0) {
	if (mfwrite(buf, len, 1, mf) <= 0) {
	    hclose_abruptly(hf);
	    mfdestroy(mf);
	    return NULL;
	}
    }
    if (hclose(hf) < 0 || len < 0) {
	mfdestroy(mf);
	return NULL;
    }

    mrewind(mf);
    return mf;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2050, %rsp           # imm = 0x2050
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq $0x0, -0x2030(%rbp)
movq -0x10(%rbp), %rdi
callq 0x4230
movq %rax, %rcx
movl $0x1ffe, %eax           # imm = 0x1FFE
subq %rcx, %rax
movl %eax, -0x2034(%rbp)
leaq -0x2020(%rbp), %rax
movq %rax, -0x2028(%rbp)
movq -0x18(%rbp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x2041(%rbp)
je 0x5770e
movq -0x2028(%rbp), %rax
leaq -0x2020(%rbp), %rcx
subq %rcx, %rax
movslq -0x2034(%rbp), %rcx
cmpq %rcx, %rax
setl %al
movb %al, -0x2041(%rbp)
movb -0x2041(%rbp), %al
testb $0x1, %al
jne 0x5771a
jmp 0x57797
movq -0x18(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x25, %eax
jne 0x57767
movq -0x18(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x73, %eax
jne 0x57767
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
movq -0x2028(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x4530
movq %rax, %rdi
callq 0x4230
addq -0x2028(%rbp), %rax
movq %rax, -0x2028(%rbp)
jmp 0x57784
movq -0x18(%rbp), %rax
movb (%rax), %cl
movq -0x2028(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x2028(%rbp)
movb %cl, (%rax)
jmp 0x57786
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0x576d6
movq -0x2028(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x2028(%rbp)
movb $0x0, (%rax)
leaq -0x2020(%rbp), %rdi
leaq 0x24232(%rip), %rsi     # 0x7b9ef
callq 0x6b3f0
movq %rax, -0x2040(%rbp)
cmpq $0x0, %rax
jne 0x577dc
movq $0x0, -0x8(%rbp)
jmp 0x578ba
xorl %eax, %eax
movl %eax, %edi
xorl %esi, %esi
callq 0x55ec0
movq %rax, %rcx
movq %rcx, -0x2030(%rbp)
xorl %eax, %eax
cmpq %rcx, %rax
jne 0x57805
movq $0x0, -0x8(%rbp)
jmp 0x578ba
jmp 0x57807
movq -0x2040(%rbp), %rdi
leaq -0x2020(%rbp), %rsi
movl $0x2000, %edx           # imm = 0x2000
callq 0x578d0
movl %eax, -0x2038(%rbp)
cmpl $0x0, %eax
jle 0x57873
leaq -0x2020(%rbp), %rdi
movslq -0x2038(%rbp), %rsi
movq -0x2030(%rbp), %rcx
movl $0x1, %edx
callq 0x56c50
cmpq $0x0, %rax
ja 0x57871
movq -0x2040(%rbp), %rdi
callq 0x6ae00
movq -0x2030(%rbp), %rdi
callq 0x56820
movq $0x0, -0x8(%rbp)
jmp 0x578ba
jmp 0x57807
movq -0x2040(%rbp), %rdi
callq 0x6ad60
cmpl $0x0, %eax
jl 0x5788d
cmpl $0x0, -0x2038(%rbp)
jge 0x578a3
movq -0x2030(%rbp), %rdi
callq 0x56820
movq $0x0, -0x8(%rbp)
jmp 0x578ba
movq -0x2030(%rbp), %rdi
callq 0x56a30
movq -0x2030(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x2050, %rsp           # imm = 0x2050
popq %rbp
retq
nopw (%rax,%rax)