// File: /workspace/github_c_makefile_star2_O0/lb3361[P]dosfs/ff.c
// Function: gen_numname
static void gen_numname (
	BYTE* dst,			/* Pointer to the buffer to store numbered SFN */
	const BYTE* src,	/* Pointer to SFN */
	const WCHAR* lfn,	/* Pointer to LFN */
	UINT seq			/* Sequence number */
)
{
	BYTE ns[8], c;
	UINT i, j;
	WCHAR wc;
	DWORD sreg;


	mem_cpy(dst, src, 11);

	if (seq > 5) {	/* In case of many collisions, generate a hash number instead of sequential number */
		sreg = seq;
		while (*lfn) {	/* Create a CRC as hash value */
			wc = *lfn++;
			for (i = 0; i < 16; i++) {
				sreg = (sreg << 1) + (wc & 1);
				wc >>= 1;
				if (sreg & 0x10000) sreg ^= 0x11021;
			}
		}
		seq = (UINT)sreg;
	}

	/* itoa (hexdecimal) */
	i = 7;
	do {
		c = (BYTE)((seq % 16) + '0');
		if (c > '9') c += 7;
		ns[i--] = c;
		seq /= 16;
	} while (seq);
	ns[i] = '~';

	/* Append the number to the SFN body */
	for (j = 0; j < i && dst[j] != ' '; j++) {
		if (dbc_1st(dst[j])) {
			if (j == i - 1) break;
			j++;
		}
	}
	do {
		dst[j++] = (i < 8) ? ns[i++] : ' ';
	} while (j < 8);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl $0xb, %edx
callq 0x6d20
cmpl $0x5, -0x1c(%rbp)
jbe 0xeeea
movl -0x1c(%rbp), %eax
movl %eax, -0x38(%rbp)
movq -0x18(%rbp), %rax
cmpw $0x0, (%rax)
je 0xeee4
movq -0x18(%rbp), %rax
movq %rax, %rcx
addq $0x2, %rcx
movq %rcx, -0x18(%rbp)
movw (%rax), %ax
movw %ax, -0x32(%rbp)
movl $0x0, -0x2c(%rbp)
cmpl $0x10, -0x2c(%rbp)
jae 0xeee2
movl -0x38(%rbp), %eax
shll %eax
movzwl -0x32(%rbp), %ecx
andl $0x1, %ecx
addl %ecx, %eax
movl %eax, -0x38(%rbp)
movzwl -0x32(%rbp), %eax
sarl %eax
movw %ax, -0x32(%rbp)
movl -0x38(%rbp), %eax
andl $0x10000, %eax          # imm = 0x10000
cmpl $0x0, %eax
je 0xeed5
movl -0x38(%rbp), %eax
xorl $0x11021, %eax          # imm = 0x11021
movl %eax, -0x38(%rbp)
jmp 0xeed7
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0xee9c
jmp 0xee75
movl -0x38(%rbp), %eax
movl %eax, -0x1c(%rbp)
movl $0x7, -0x2c(%rbp)
movl -0x1c(%rbp), %eax
andl $0xf, %eax
addl $0x30, %eax
movb %al, -0x25(%rbp)
movzbl -0x25(%rbp), %eax
cmpl $0x39, %eax
jle 0xef10
movzbl -0x25(%rbp), %eax
addl $0x7, %eax
movb %al, -0x25(%rbp)
movb -0x25(%rbp), %cl
movl -0x2c(%rbp), %eax
movl %eax, %edx
addl $-0x1, %edx
movl %edx, -0x2c(%rbp)
movl %eax, %eax
movb %cl, -0x24(%rbp,%rax)
movl -0x1c(%rbp), %eax
shrl $0x4, %eax
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jne 0xeef1
movl -0x2c(%rbp), %eax
movb $0x7e, -0x24(%rbp,%rax)
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %ecx
xorl %eax, %eax
cmpl -0x2c(%rbp), %ecx
movb %al, -0x39(%rbp)
jae 0xef63
movq -0x8(%rbp), %rax
movl -0x30(%rbp), %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x20, %eax
setne %al
movb %al, -0x39(%rbp)
movb -0x39(%rbp), %al
testb $0x1, %al
jne 0xef6c
jmp 0xefa6
movq -0x8(%rbp), %rax
movl -0x30(%rbp), %ecx
movzbl (%rax,%rcx), %edi
callq 0xa950
cmpl $0x0, %eax
je 0xef99
movl -0x30(%rbp), %eax
movl -0x2c(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jne 0xef90
jmp 0xefa6
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0xef9b
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0xef42
jmp 0xefa8
cmpl $0x8, -0x2c(%rbp)
jae 0xefc5
movl -0x2c(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x2c(%rbp)
movl %eax, %eax
movzbl -0x24(%rbp,%rax), %eax
movl %eax, -0x40(%rbp)
jmp 0xefcf
movl $0x20, %eax
movl %eax, -0x40(%rbp)
jmp 0xefcf
movl -0x40(%rbp), %eax
movb %al, %dl
movq -0x8(%rbp), %rax
movl -0x30(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x30(%rbp)
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
cmpl $0x8, -0x30(%rbp)
jb 0xefa8
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)