// File: /workspace/github_c_makefile_star2_O3/serge-404[P]CPM32/cpm.c
// Function: mk_filename
char *mk_filename( char *s, byte *fcb)
{
    int i, j;
    char *dir;
#ifdef __linux__
    char *dot=NULL;
#endif
    i = fcb[ 0];
    if ( i == '?' || i == 0) i = cpm_disk_no;
    else i--;
    if ( i >= MAXDRV) return NULL;
    if ( cpm_drive[ i] == NULL) {
	if ( cpm_disk_vct == 0) setup_disk_vct();
	if ( cpm_drive[ i] == NULL) return NULL;
    }
    strcpy( s, cpm_drive[ i]);
    s += i = strlen( s);
    if ( i && s[ -1] != CH_SLASH && s[ -1] != '/' && s[ -1] != ':') *s++ = '/';
    dir = s;

    for ( j = 8; j >= 1 && fcb[ j] == '?'; j--);
    j++;
    for ( i = 1; i < j; i++) {
		if ( fcb[ i] == ' ') break;
		*s++ = fcb[ i];
    }
    if ( i == j && i <= 8) *s++ = '*';

#ifdef __linux__
	dot=s;
#endif
    *s++ = '.';

    for ( j = 11; j >= 9 && fcb[ j] == '?'; j--);
    j++;
    for ( i = 9; i < j; i++) {
	if ( fcb[ i] == ' ') break;
		*s++ = fcb[ i];
#ifdef __linux__
		dot=NULL;
#endif
    }
    if ( i == j && i <= 11) *s++ = '*';
#ifdef __linux__
	if (dot) s=dot;
#endif
	*s = '\0';
    return dir;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %rbx
movzbl (%rsi), %eax
cmpl $0x3f, %eax
je 0x9200
testl %eax, %eax
jne 0x9209
movzbl 0xb001(%rip), %eax      # 0x14208
jmp 0x920b
decl %eax
cmpl $0xf, %eax
jbe 0x9217
xorl %ebx, %ebx
jmp 0x935f
movl %eax, %r15d
leaq 0x10b21f(%rip), %r12    # 0x114440
movq (%r12,%r15,8), %rsi
testq %rsi, %rsi
je 0x9283
movq %rbx, %rdi
callq 0x2090
movq %rbx, %rdi
callq 0x20e0
cltq
addq %rax, %rbx
testl %eax, %eax
je 0x9257
movzbl -0x1(%rbx), %eax
cmpl $0x2f, %eax
je 0x9257
cmpl $0x3a, %eax
je 0x9257
movb $0x2f, (%rbx)
incq %rbx
movl $0x8, %edx
movl $0x9, %ecx
movl %edx, %eax
cmpb $0x3f, (%r14,%rax)
jne 0x92a0
decq %rdx
decl %ecx
cmpl $0x1, %ecx
ja 0x9261
movl $0x1, %ecx
movq %rbx, %rax
movl $0x1, %edx
jmp 0x92d4
cmpw $0x0, 0x10b08f(%rip)    # 0x11431a
jne 0x9210
callq 0x8825
movq (%r12,%r15,8), %rsi
testq %rsi, %rsi
jne 0x922a
jmp 0x9210
testl %edx, %edx
jle 0x92c4
xorl %eax, %eax
movb 0x1(%r14,%rax), %sil
cmpb $0x20, %sil
je 0x92ce
movb %sil, (%rbx,%rax)
incq %rax
decq %rdx
jne 0x92a6
addq %rbx, %rax
movl %ecx, %edx
jmp 0x92d4
movl $0x1, %edx
movq %rbx, %rax
jmp 0x92d4
leal 0x1(%rax), %edx
addq %rbx, %rax
cmpl %ecx, %edx
setne %cl
cmpl $0x9, %edx
setae %dl
orb %cl, %dl
jne 0x92e9
movb $0x2a, (%rax)
incq %rax
movb $0x2e, (%rax)
movl $0x2, %edi
movl $0xc, %ecx
leal 0x9(%rdi), %edx
cmpb $0x3f, (%r14,%rdx)
jne 0x931a
decq %rdi
decl %ecx
cmpl $0x9, %ecx
ja 0x92f6
leaq 0x1(%rax), %rdx
movl $0x9, %ecx
movl $0x9, %esi
jmp 0x9337
leaq 0x1(%rax), %rdx
leal 0x9(%rdi), %r8d
movl $0x9, %esi
cmpl $0x9, %r8d
jl 0x9337
movb 0x9(%r14), %r8b
cmpb $0x20, %r8b
jne 0x936e
movq %rax, %rdi
cmpl %ecx, %esi
setne %cl
cmpl $0xc, %esi
setae %sil
orb %cl, %sil
jne 0x9355
addq $0x2, %rax
movb $0x2a, (%rdx)
movq %rax, %rdx
testq %rdi, %rdi
cmovneq %rdi, %rdx
movb $0x0, (%rdx)
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movl $0xa, %esi
movq %rdx, %rax
movb %r8b, (%rdx)
incq %rdx
subq $0x1, %rdi
jb 0x9399
movb (%r14,%rsi), %r8b
incq %rsi
cmpb $0x20, %r8b
jne 0x9373
leaq 0x1(%rax), %rdx
decl %esi
xorl %edi, %edi
jmp 0x933a
xorl %edi, %edi
movl %ecx, %esi
jmp 0x933a