// File: karel-brinda[P]ococo/ext/htslib/cram/cram_io.c
// Function: expand_cache_path
void expand_cache_path(char *path, char *dir, char *fn) {
    char *cp;

    while ((cp = strchr(dir, '%'))) {
	strncpy(path, dir, cp-dir);
	path += cp-dir;

	if (*++cp == 's') {
	    strcpy(path, fn);
	    path += strlen(fn);
	    fn += strlen(fn);
	    cp++;
	} else if (*cp >= '0' && *cp <= '9') {
	    char *endp;
	    long l;

	    l = strtol(cp, &endp, 10);
	    l = MIN(l, strlen(fn));
	    if (*endp == 's') {
		strncpy(path, fn, l);
		path += l;
		fn += l;
		*path = 0;
		cp = endp+1;
	    } else {
		*path++ = '%';
		*path++ = *cp++;
	    }
	} else {
	    *path++ = '%';
	    *path++ = *cp++;
	}
	dir = cp;
    }
    strcpy(path, dir);
    path += strlen(dir);
    if (*fn && path[-1] != '/')
	*path++ = '/';
    strcpy(path, fn);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x10(%rbp), %rdi
movl $0x25, %esi
callq 0x41e0
movq %rax, -0x20(%rbp)
cmpq $0x0, %rax
je 0x48e68
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x10(%rbp), %rax
subq %rax, %rdx
callq 0x42c0
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
subq %rcx, %rax
addq -0x8(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x20(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x20(%rbp)
movsbl 0x1(%rax), %eax
cmpl $0x73, %eax
jne 0x48d33
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x4530
movq -0x18(%rbp), %rdi
callq 0x4230
addq -0x8(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x18(%rbp), %rdi
callq 0x4230
addq -0x18(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x48e5b
movq -0x20(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x30, %eax
jl 0x48e25
movq -0x20(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x39, %eax
jg 0x48e25
movq -0x20(%rbp), %rdi
leaq -0x28(%rbp), %rsi
movl $0xa, %edx
callq 0x4820
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rdi
callq 0x4230
movq %rax, %rcx
movq -0x38(%rbp), %rax
cmpq %rcx, %rax
jae 0x48d90
movq -0x30(%rbp), %rax
movq %rax, -0x40(%rbp)
jmp 0x48d9d
movq -0x18(%rbp), %rdi
callq 0x4230
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x73, %eax
jne 0x48def
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x30(%rbp), %rdx
callq 0x42c0
movq -0x30(%rbp), %rax
addq -0x8(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x30(%rbp), %rax
addq -0x18(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rax
movb $0x0, (%rax)
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x48e23
movq -0x8(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x8(%rbp)
movb $0x25, (%rax)
movq -0x20(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x20(%rbp)
movb (%rax), %cl
movq -0x8(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x8(%rbp)
movb %cl, (%rax)
jmp 0x48e59
movq -0x8(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x8(%rbp)
movb $0x25, (%rax)
movq -0x20(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x20(%rbp)
movb (%rax), %cl
movq -0x8(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x8(%rbp)
movb %cl, (%rax)
jmp 0x48e5b
movq -0x20(%rbp), %rax
movq %rax, -0x10(%rbp)
jmp 0x48c94
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x4530
movq -0x10(%rbp), %rdi
callq 0x4230
addq -0x8(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x18(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x48eb1
movq -0x8(%rbp), %rax
movsbl -0x1(%rax), %eax
cmpl $0x2f, %eax
je 0x48eb1
movq -0x8(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x8(%rbp)
movb $0x2f, (%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x4530
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)