// File: karel-brinda[P]ococo/ext/htslib/cram/open_trace_file.c
// Function: expand_path
static char *expand_path(char *file, char *dirname) {
    size_t len = strlen(dirname);
    size_t lenf = strlen(file);
    char *cp, *path;

    path = malloc(len+lenf+2); // worst expansion DIR/FILE
    if (!path)
	return NULL;

    if (dirname[len-1] == '/')
	len--;

    /* Special case for "./" or absolute filenames */
    if (*file == '/' || (len==1 && *dirname == '.')) {
	sprintf(path, "%s", file);
    } else {
	/* Handle %[0-9]*s expansions, if required */
	char *path_end = path;
	*path = 0;
	while ((cp = strchr(dirname, '%'))) {
	    char *endp;
	    long l = strtol(cp+1, &endp, 10);
	    if (*endp != 's') {
		strncpy(path_end, dirname, (endp+1)-dirname);
		path_end += (endp+1)-dirname;
		dirname = endp+1;
		continue;
	    }
	    
	    strncpy(path_end, dirname, cp-dirname);
	    path_end += cp-dirname;
	    if (l) {
		strncpy(path_end, file, l);
		path_end += MIN(strlen(file), l);
		file     += MIN(strlen(file), l);
	    } else {
		strcpy(path_end, file);
		path_end += strlen(file);
		file     += strlen(file);
	    }
	    len -= (endp+1) - dirname;
	    dirname = endp+1;
	}
	strncpy(path_end, dirname, len);
	path_end += MIN(strlen(dirname), len);
	*path_end = 0;
	if (*file) {
	    *path_end++ = '/';
	    strcpy(path_end, file);
	}
    }

    //fprintf(stderr, "*PATH=\"%s\"\n", path);
    return path;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x18(%rbp), %rdi
callq 0x4230
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rdi
callq 0x4230
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rdi
addq -0x28(%rbp), %rdi
addq $0x2, %rdi
callq 0x47a0
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x57d93
movq $0x0, -0x8(%rbp)
jmp 0x58002
movq -0x18(%rbp), %rax
movq -0x20(%rbp), %rcx
subq $0x1, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2f, %eax
jne 0x57db4
movq -0x20(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2f, %eax
je 0x57dd3
cmpq $0x1, -0x20(%rbp)
jne 0x57dee
movq -0x18(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2e, %eax
jne 0x57dee
movq -0x38(%rbp), %rdi
movq -0x10(%rbp), %rdx
leaq 0x26139(%rip), %rsi     # 0x7df1b
movb $0x0, %al
callq 0x4100
jmp 0x57ffa
movq -0x38(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rax
movb $0x0, (%rax)
movq -0x18(%rbp), %rdi
movl $0x25, %esi
callq 0x41e0
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
je 0x57f86
movq -0x30(%rbp), %rdi
addq $0x1, %rdi
leaq -0x48(%rbp), %rsi
movl $0xa, %edx
callq 0x4820
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x73, %eax
je 0x57e83
movq -0x40(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x48(%rbp), %rdx
addq $0x1, %rdx
movq -0x18(%rbp), %rax
subq %rax, %rdx
callq 0x42c0
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq -0x18(%rbp), %rcx
subq %rcx, %rax
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0x57dfd
movq -0x40(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq -0x18(%rbp), %rax
subq %rax, %rdx
callq 0x42c0
movq -0x30(%rbp), %rax
movq -0x18(%rbp), %rcx
subq %rcx, %rax
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x50(%rbp)
je 0x57f2c
movq -0x40(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x50(%rbp), %rdx
callq 0x42c0
movq -0x10(%rbp), %rdi
callq 0x4230
cmpq -0x50(%rbp), %rax
jae 0x57ee4
movq -0x10(%rbp), %rdi
callq 0x4230
movq %rax, -0x58(%rbp)
jmp 0x57eec
movq -0x50(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rdi
callq 0x4230
cmpq -0x50(%rbp), %rax
jae 0x57f16
movq -0x10(%rbp), %rdi
callq 0x4230
movq %rax, -0x60(%rbp)
jmp 0x57f1e
movq -0x50(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
addq -0x10(%rbp), %rax
movq %rax, -0x10(%rbp)
jmp 0x57f5b
movq -0x40(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x4530
movq -0x10(%rbp), %rdi
callq 0x4230
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rdi
callq 0x4230
addq -0x10(%rbp), %rax
movq %rax, -0x10(%rbp)
movq -0x48(%rbp), %rcx
addq $0x1, %rcx
movq -0x18(%rbp), %rax
subq %rax, %rcx
movq -0x20(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x20(%rbp)
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0x57dfd
movq -0x40(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x42c0
movq -0x18(%rbp), %rdi
callq 0x4230
cmpq -0x20(%rbp), %rax
jae 0x57fb5
movq -0x18(%rbp), %rdi
callq 0x4230
movq %rax, -0x68(%rbp)
jmp 0x57fbd
movq -0x20(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movb $0x0, (%rax)
movq -0x10(%rbp), %rax
cmpb $0x0, (%rax)
je 0x57ff8
movq -0x40(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x40(%rbp)
movb $0x2f, (%rax)
movq -0x40(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x4530
jmp 0x57ffa
movq -0x38(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax)