// File: /workspace/github_c_makefile_star2_O3/icebert[P]pblat/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movq %rsi, %rdi
callq 0x62d0
movq %rax, %r15
movq %r14, %rdi
callq 0x62d0
leaq (%r15,%rax), %rdi
addq $0x2, %rdi
callq 0x69d0
movq %rax, %r12
testq %rax, %rax
je 0x5f8bf
xorl %eax, %eax
cmpb $0x2f, -0x1(%rbx,%r15)
sete %cl
cmpb $0x2f, (%r14)
jne 0x5f778
movq %r12, %rdi
movq %r14, %rsi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x6680
movb %cl, %al
subq %rax, %r15
cmpq $0x1, %r15
jne 0x5f788
cmpb $0x2e, (%rbx)
je 0x5f75f
movq %r14, (%rsp)
movb $0x0, (%r12)
movq %rbx, %rdi
movl $0x25, %esi
callq 0x6270
testq %rax, %rax
movq %r12, 0x8(%rsp)
je 0x5f87a
movq %rax, %rbp
movq %r12, %r14
leaq 0x1(%rbp), %rdi
leaq 0x10(%rsp), %rsi
movl $0xa, %edx
callq 0x6a60
movq 0x10(%rsp), %r12
cmpb $0x73, (%r12)
jne 0x5f810
movq %rax, %r13
subq %rbx, %rbp
movq %r14, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
callq 0x6380
addq %r14, %rbp
movq %rbp, %rdi
testq %r13, %r13
je 0x5f82f
movq (%rsp), %r14
movq %r14, %rsi
movq %r13, %rdx
callq 0x6380
movq %r14, %rdi
callq 0x62d0
cmpq %r13, %rax
cmovbq %rax, %r13
jmp 0x5f846
incq %r12
movq %r12, %r13
subq %rbx, %r13
movq %r14, %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x6380
addq %r13, %r14
movq %r12, %rbx
jmp 0x5f85f
movq (%rsp), %r14
movq %r14, %rsi
callq 0x6680
movq %r14, %rdi
callq 0x62d0
movq %rax, %r13
addq %r13, %rbp
addq %r13, %r14
movq %r14, (%rsp)
incq %r12
addq %rbx, %r15
subq %r12, %r15
movq %r12, %rbx
movq %rbp, %r14
movq %rbx, %rdi
movl $0x25, %esi
callq 0x6270
movq %rax, %rbp
testq %rax, %rax
jne 0x5f7b2
jmp 0x5f87d
movq %r12, %r14
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x6380
movq %rbx, %rdi
callq 0x62d0
cmpq %r15, %rax
cmovbq %rax, %r15
movb $0x0, (%r14,%r15)
movq (%rsp), %rsi
cmpb $0x0, (%rsi)
movq 0x8(%rsp), %r12
je 0x5f8bf
addq %r15, %r14
movb $0x2f, (%r14)
incq %r14
movq %r14, %rdi
callq 0x6680
movq %r12, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)