// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/cram/open_trace_file.c
// Function: expand_path
static char *expand_path(const char *file, const char *dirname,
                         int max_s_digits) {
    size_t len = strlen(dirname);
    size_t lenf = strlen(file);
    const char *end_dirname = dirname + len, *cp;
    char *path;

    path = malloc(len+lenf+2); // worst expansion DIR/FILE
    if (!path) {
        hts_log_error("Out of memory");
        return NULL;
    }

    // Remove trailing '/'s, unless the path matches "/"
    while (len > 1 && dirname[len-1] == '/') {
        len--;
        end_dirname--;
    }

    /* Special case for "./" or absolute filenames */
    if (*file == '/' || (len==1 && *dirname == '.')) {
        memcpy(path, file, lenf + 1);
    } else {
        /* Handle %[0-9]*s expansions, if required */
        char *path_end = path;

        while ((cp = strchr(dirname, '%'))) {
            char *endp;
            // Get optional length
            long l = strtol(cp+1, &endp, 10);
            if (*endp != 's' || l < 0 || endp - cp - 1 > max_s_digits) {
                // Not %[0-9]s. Copy over directly, taking care of edge cases
                // like the string ending with '%' or '%[0-9]*'.
                const char *e = MIN(endp+1, end_dirname);
                memcpy(path_end, dirname, e - dirname);
                path_end += e - dirname;
                dirname = e;
                continue;
            }

            // Copy part up to '%'
            memcpy(path_end, dirname, cp-dirname);
            path_end += cp-dirname;

            // Insert segment from file
            size_t to_copy = l > 0 ? MIN(lenf, l) : lenf;
            memcpy(path_end, file, to_copy);
            path_end += to_copy;
            file     += to_copy;
            lenf     -= to_copy;

            // Skip to part of dirname after the 's'
            dirname = endp+1;
        }

        // Add anything left in dirname
        if (dirname < end_dirname) {
            memcpy(path_end, dirname, end_dirname - dirname);
            path_end += end_dirname - dirname;
        }

        if (*file) {
            // Add remainder of file
            if (path_end > path && *(path_end - 1) != '/')
                *path_end++ = '/';
            memcpy(path_end, file, lenf);
            path_end += lenf;
        }
        // Terminate string
        *path_end = '\0';
    }

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

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq -0x18(%rbp), %rdi
callq 0x41b0
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rdi
callq 0x41b0
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rax
addq -0x28(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x28(%rbp), %rdi
addq -0x30(%rbp), %rdi
addq $0x2, %rdi
callq 0x4650
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0x8174f
movl $0x1, %edi
leaq 0x74a95(%rip), %rsi     # 0xf61c9
leaq 0x70475(%rip), %rdx     # 0xf1bb0
movb $0x0, %al
callq 0x1b030
movq $0x0, -0x8(%rbp)
jmp 0x819f5
jmp 0x81751
xorl %eax, %eax
cmpq $0x1, -0x28(%rbp)
movb %al, -0x71(%rbp)
jbe 0x81776
movq -0x18(%rbp), %rax
movq -0x28(%rbp), %rcx
subq $0x1, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2f, %eax
sete %al
movb %al, -0x71(%rbp)
movb -0x71(%rbp), %al
testb $0x1, %al
jne 0x8177f
jmp 0x81799
movq -0x28(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x28(%rbp)
movq -0x38(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x81751
movq -0x10(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2f, %eax
je 0x817b8
cmpq $0x1, -0x28(%rbp)
jne 0x817d2
movq -0x18(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2e, %eax
jne 0x817d2
movq -0x48(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x30(%rbp), %rdx
addq $0x1, %rdx
callq 0x43b0
jmp 0x819ed
movq -0x48(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x18(%rbp), %rdi
movl $0x25, %esi
callq 0x4170
movq %rax, -0x40(%rbp)
cmpq $0x0, %rax
je 0x81962
movq -0x40(%rbp), %rdi
addq $0x1, %rdi
leaq -0x58(%rbp), %rsi
movl $0xa, %edx
callq 0x46a0
movq %rax, -0x60(%rbp)
movq -0x58(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x73, %eax
jne 0x8183b
cmpq $0x0, -0x60(%rbp)
jl 0x8183b
movq -0x58(%rbp), %rax
movq -0x40(%rbp), %rcx
subq %rcx, %rax
subq $0x1, %rax
movslq -0x1c(%rbp), %rcx
cmpq %rcx, %rax
jle 0x8189f
movq -0x58(%rbp), %rax
addq $0x1, %rax
cmpq -0x38(%rbp), %rax
jae 0x81857
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x80(%rbp)
jmp 0x8185f
movq -0x38(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x50(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x68(%rbp), %rdx
movq -0x18(%rbp), %rax
subq %rax, %rdx
callq 0x43b0
movq -0x68(%rbp), %rax
movq -0x18(%rbp), %rcx
subq %rcx, %rax
addq -0x50(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x68(%rbp), %rax
movq %rax, -0x18(%rbp)
jmp 0x817da
movq -0x50(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq -0x18(%rbp), %rax
subq %rax, %rdx
callq 0x43b0
movq -0x40(%rbp), %rax
movq -0x18(%rbp), %rcx
subq %rcx, %rax
addq -0x50(%rbp), %rax
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x60(%rbp)
jle 0x81903
movq -0x30(%rbp), %rax
cmpq -0x60(%rbp), %rax
jae 0x818e8
movq -0x30(%rbp), %rax
movq %rax, -0x88(%rbp)
jmp 0x818f3
movq -0x60(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rax
movq %rax, -0x90(%rbp)
jmp 0x8190e
movq -0x30(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x50(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x70(%rbp), %rdx
callq 0x43b0
movq -0x70(%rbp), %rax
addq -0x50(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x70(%rbp), %rax
addq -0x10(%rbp), %rax
movq %rax, -0x10(%rbp)
movq -0x70(%rbp), %rcx
movq -0x30(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0x817da
movq -0x18(%rbp), %rax
cmpq -0x38(%rbp), %rax
jae 0x81997
movq -0x50(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x18(%rbp), %rax
subq %rax, %rdx
callq 0x43b0
movq -0x38(%rbp), %rax
movq -0x18(%rbp), %rcx
subq %rcx, %rax
addq -0x50(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rax
cmpb $0x0, (%rax)
je 0x819e6
movq -0x50(%rbp), %rax
cmpq -0x48(%rbp), %rax
jbe 0x819c9
movq -0x50(%rbp), %rax
movsbl -0x1(%rax), %eax
cmpl $0x2f, %eax
je 0x819c9
movq -0x50(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x50(%rbp)
movb $0x2f, (%rax)
movq -0x50(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x30(%rbp), %rdx
callq 0x43b0
movq -0x30(%rbp), %rax
addq -0x50(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movb $0x0, (%rax)
movq -0x48(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)