// File: /workspace/github_c_makefile_star2_O0/lb3361[P]dosfs/ff.c
// Function: create_name
static FRESULT create_name (	/* FR_OK: successful, FR_INVALID_NAME: could not create */
	DIR* dp,					/* Pointer to the directory object */
	const TCHAR** path			/* Pointer to pointer to the segment in the path string */
)
{
#if FF_USE_LFN		/* LFN configuration */
	BYTE b, cf;
	WCHAR wc, *lfn;
	DWORD uc;
	UINT i, ni, si, di;
	const TCHAR *p;


	/* Create LFN into LFN working buffer */
	p = *path; lfn = dp->obj.fs->lfnbuf; di = 0;
	for (;;) {
		uc = tchar2uni(&p);			/* Get a character */
		if (uc == 0xFFFFFFFF) return FR_INVALID_NAME;		/* Invalid code or UTF decode error */
		if (uc >= 0x10000) lfn[di++] = (WCHAR)(uc >> 16);	/* Store high surrogate if needed */
		wc = (WCHAR)uc;
		if (wc < ' ' || wc == '/' || wc == '\\') break;	/* Break if end of the path or a separator is found */
		if (wc < 0x80 && chk_chr("\"*:<>\?|\x7F", wc)) return FR_INVALID_NAME;	/* Reject illegal characters for LFN */
		if (di >= FF_MAX_LFN) return FR_INVALID_NAME;	/* Reject too long name */
		lfn[di++] = wc;					/* Store the Unicode character */
	}
	if (wc < ' ') {				/* End of path? */
		cf = NS_LAST;			/* Set last segment flag */
	} else {
		cf = 0;					/* Next segment follows */
		while (*p == '/' || *p == '\\') p++;	/* Skip duplicated separators if exist */
	}
	*path = p;					/* Return pointer to the next segment */

#if FF_FS_RPATH != 0
	if ((di == 1 && lfn[di - 1] == '.') ||
		(di == 2 && lfn[di - 1] == '.' && lfn[di - 2] == '.')) {	/* Is this segment a dot name? */
		lfn[di] = 0;
		for (i = 0; i < 11; i++) {		/* Create dot name for SFN entry */
			dp->fn[i] = (i < di) ? '.' : ' ';
		}
		dp->fn[i] = cf | NS_DOT;		/* This is a dot entry */
		return FR_OK;
	}
#endif
	while (di) {						/* Snip off trailing spaces and dots if exist */
		wc = lfn[di - 1];
		if (wc != ' ' && wc != '.') break;
		di--;
	}
	lfn[di] = 0;							/* LFN is created into the working buffer */
	if (di == 0) return FR_INVALID_NAME;	/* Reject null name */

	/* Create SFN in directory form */
	for (si = 0; lfn[si] == ' '; si++) ;	/* Remove leading spaces */
	if (si > 0 || lfn[si] == '.') cf |= NS_LOSS | NS_LFN;	/* Is there any leading space or dot? */
	while (di > 0 && lfn[di - 1] != '.') di--;	/* Find last dot (di<=si: no extension) */

	mem_set(dp->fn, ' ', 11);
	i = b = 0; ni = 8;
	for (;;) {
		wc = lfn[si++];					/* Get an LFN character */
		if (wc == 0) break;				/* Break on end of the LFN */
		if (wc == ' ' || (wc == '.' && si != di)) {	/* Remove embedded spaces and dots */
			cf |= NS_LOSS | NS_LFN;
			continue;
		}

		if (i >= ni || si == di) {		/* End of field? */
			if (ni == 11) {				/* Name extension overflow? */
				cf |= NS_LOSS | NS_LFN;
				break;
			}
			if (si != di) cf |= NS_LOSS | NS_LFN;	/* Name body overflow? */
			if (si > di) break;						/* No name extension? */
			si = di; i = 8; ni = 11; b <<= 2;		/* Enter name extension */
			continue;
		}

		if (wc >= 0x80) {	/* Is this a non-ASCII character? */
			cf |= NS_LFN;	/* LFN entry needs to be created */
#if FF_CODE_PAGE == 0
			if (ExCvt) {	/* At SBCS */
				wc = ff_uni2oem(wc, CODEPAGE);			/* Unicode ==> ANSI/OEM code */
				if (wc & 0x80) wc = ExCvt[wc & 0x7F];	/* Convert extended character to upper (SBCS) */
			} else {		/* At DBCS */
				wc = ff_uni2oem(ff_wtoupper(wc), CODEPAGE);	/* Unicode ==> Upper convert ==> ANSI/OEM code */
			}
#elif FF_CODE_PAGE < 900	/* SBCS cfg */
			wc = ff_uni2oem(wc, CODEPAGE);			/* Unicode ==> ANSI/OEM code */
			if (wc & 0x80) wc = ExCvt[wc & 0x7F];	/* Convert extended character to upper (SBCS) */
#else						/* DBCS cfg */
			wc = ff_uni2oem(ff_wtoupper(wc), CODEPAGE);	/* Unicode ==> Upper convert ==> ANSI/OEM code */
#endif
		}

		if (wc >= 0x100) {				/* Is this a DBC? */
			if (i >= ni - 1) {			/* Field overflow? */
				cf |= NS_LOSS | NS_LFN;
				i = ni; continue;		/* Next field */
			}
			dp->fn[i++] = (BYTE)(wc >> 8);	/* Put 1st byte */
		} else {						/* SBC */
			if (wc == 0 || chk_chr("+,;=[]", wc)) {	/* Replace illegal characters for SFN if needed */
				wc = '_'; cf |= NS_LOSS | NS_LFN;/* Lossy conversion */
			} else {
				if (IsUpper(wc)) {		/* ASCII upper case? */
					b |= 2;
				}
				if (IsLower(wc)) {		/* ASCII lower case? */
					b |= 1; wc -= 0x20;
				}
			}
		}
		dp->fn[i++] = (BYTE)wc;
	}

	if (dp->fn[0] == DDEM) dp->fn[0] = RDDEM;	/* If the first character collides with DDEM, replace it with RDDEM */

	if (ni == 8) b <<= 2;				/* Shift capital flags if no extension */
	if ((b & 0x0C) == 0x0C || (b & 0x03) == 0x03) cf |= NS_LFN;	/* LFN entry needs to be created if composite capitals */
	if (!(cf & NS_LFN)) {				/* When LFN is in 8.3 format without extended character, NT flags are created */
		if (b & 0x01) cf |= NS_EXT;		/* NT flag (Extension has small capital letters only) */
		if (b & 0x04) cf |= NS_BODY;	/* NT flag (Body has small capital letters only) */
	}

	dp->fn[NSFLAG] = cf;	/* SFN is created into dp->fn[] */

	return FR_OK;


#else	/* FF_USE_LFN : Non-LFN configuration */
	BYTE c, d, *sfn;
	UINT ni, si, i;
	const char *p;

	/* Create file name in directory form */
	p = *path; sfn = dp->fn;
	mem_set(sfn, ' ', 11);
	si = i = 0; ni = 8;
#if FF_FS_RPATH != 0
	if (p[si] == '.') { /* Is this a dot entry? */
		for (;;) {
			c = (BYTE)p[si++];
			if (c != '.' || si >= 3) break;
			sfn[i++] = c;
		}
		if (c != '/' && c != '\\' && c > ' ') return FR_INVALID_NAME;
		*path = p + si;								/* Return pointer to the next segment */
		sfn[NSFLAG] = (c <= ' ') ? NS_LAST | NS_DOT : NS_DOT;	/* Set last segment flag if end of the path */
		return FR_OK;
	}
#endif
	for (;;) {
		c = (BYTE)p[si++];				/* Get a byte */
		if (c <= ' ') break; 			/* Break if end of the path name */
		if (c == '/' || c == '\\') {	/* Break if a separator is found */
			while (p[si] == '/' || p[si] == '\\') si++;	/* Skip duplicated separator if exist */
			break;
		}
		if (c == '.' || i >= ni) {		/* End of body or field overflow? */
			if (ni == 11 || c != '.') return FR_INVALID_NAME;	/* Field overflow or invalid dot? */
			i = 8; ni = 11;				/* Enter file extension field */
			continue;
		}
#if FF_CODE_PAGE == 0
		if (ExCvt && c >= 0x80) {		/* Is SBC extended character? */
			c = ExCvt[c & 0x7F];		/* To upper SBC extended character */
		}
#elif FF_CODE_PAGE < 900
		if (c >= 0x80) {				/* Is SBC extended character? */
			c = ExCvt[c & 0x7F];		/* To upper SBC extended character */
		}
#endif
		if (dbc_1st(c)) {				/* Check if it is a DBC 1st byte */
			d = (BYTE)p[si++];			/* Get 2nd byte */
			if (!dbc_2nd(d) || i >= ni - 1) return FR_INVALID_NAME;	/* Reject invalid DBC */
			sfn[i++] = c;
			sfn[i++] = d;
		} else {						/* SBC */
			if (chk_chr("\"*+,:;<=>\?[]|\x7F", c)) return FR_INVALID_NAME;	/* Reject illegal chrs for SFN */
			if (IsLower(c)) c -= 0x20;	/* To upper */
			sfn[i++] = c;
		}
	}
	*path = p + si;						/* Return pointer to the next segment */
	if (i == 0) return FR_INVALID_NAME;	/* Reject nul string */

	if (sfn[0] == DDEM) sfn[0] = RDDEM;	/* If the first character collides with DDEM, replace it with RDDEM */
	sfn[NSFLAG] = (c <= ' ') ? NS_LAST : 0;		/* Set last segment flag if end of the path */

	return FR_OK;
#endif /* FF_USE_LFN */
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
movq %rax, -0x28(%rbp)
movl $0x0, -0x3c(%rbp)
leaq -0x48(%rbp), %rdi
callq 0xae00
movl %eax, -0x2c(%rbp)
cmpl $-0x1, -0x2c(%rbp)
jne 0xe30f
movl $0x6, -0x4(%rbp)
jmp 0xe78c
cmpl $0x10000, -0x2c(%rbp)   # imm = 0x10000
jb 0xe336
movl -0x2c(%rbp), %eax
shrl $0x10, %eax
movw %ax, %dx
movq -0x28(%rbp), %rax
movl -0x3c(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x3c(%rbp)
movl %ecx, %ecx
movw %dx, (%rax,%rcx,2)
movl -0x2c(%rbp), %eax
movw %ax, -0x1c(%rbp)
movzwl -0x1c(%rbp), %eax
cmpl $0x20, %eax
jl 0xe358
movzwl -0x1c(%rbp), %eax
cmpl $0x2f, %eax
je 0xe358
movzwl -0x1c(%rbp), %eax
cmpl $0x5c, %eax
jne 0xe35a
jmp 0xe3b9
movzwl -0x1c(%rbp), %eax
cmpl $0x80, %eax
jge 0xe386
movzwl -0x1c(%rbp), %esi
leaq 0x41d0(%rip), %rdi      # 0x12540
callq 0xaf70
cmpl $0x0, %eax
je 0xe386
movl $0x6, -0x4(%rbp)
jmp 0xe78c
cmpl $0xff, -0x3c(%rbp)
jb 0xe39b
movl $0x6, -0x4(%rbp)
jmp 0xe78c
movw -0x1c(%rbp), %dx
movq -0x28(%rbp), %rax
movl -0x3c(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x3c(%rbp)
movl %ecx, %ecx
movw %dx, (%rax,%rcx,2)
jmp 0xe2f1
movzwl -0x1c(%rbp), %eax
cmpl $0x20, %eax
jge 0xe3c8
movb $0x4, -0x1a(%rbp)
jmp 0xe406
movb $0x0, -0x1a(%rbp)
movq -0x48(%rbp), %rax
movsbl (%rax), %ecx
movb $0x1, %al
cmpl $0x2f, %ecx
movb %al, -0x49(%rbp)
je 0xe3ed
movq -0x48(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x5c, %eax
sete %al
movb %al, -0x49(%rbp)
movb -0x49(%rbp), %al
testb $0x1, %al
jne 0xe3f6
jmp 0xe404
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0xe3cc
jmp 0xe406
movq -0x48(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
cmpl $0x0, -0x3c(%rbp)
je 0xe44a
movq -0x28(%rbp), %rax
movl -0x3c(%rbp), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
movw (%rax,%rcx,2), %ax
movw %ax, -0x1c(%rbp)
movzwl -0x1c(%rbp), %eax
cmpl $0x20, %eax
je 0xe43f
movzwl -0x1c(%rbp), %eax
cmpl $0x2e, %eax
je 0xe43f
jmp 0xe44a
movl -0x3c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0xe411
movq -0x28(%rbp), %rax
movl -0x3c(%rbp), %ecx
movw $0x0, (%rax,%rcx,2)
cmpl $0x0, -0x3c(%rbp)
jne 0xe469
movl $0x6, -0x4(%rbp)
jmp 0xe78c
movl $0x0, -0x38(%rbp)
movq -0x28(%rbp), %rax
movl -0x38(%rbp), %ecx
movzwl (%rax,%rcx,2), %eax
cmpl $0x20, %eax
jne 0xe48d
jmp 0xe482
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0xe470
cmpl $0x0, -0x38(%rbp)
ja 0xe4a3
movq -0x28(%rbp), %rax
movl -0x38(%rbp), %ecx
movzwl (%rax,%rcx,2), %eax
cmpl $0x2e, %eax
jne 0xe4ad
movzbl -0x1a(%rbp), %eax
orl $0x3, %eax
movb %al, -0x1a(%rbp)
jmp 0xe4af
xorl %eax, %eax
cmpl $0x0, -0x3c(%rbp)
movb %al, -0x4a(%rbp)
jbe 0xe4d3
movq -0x28(%rbp), %rax
movl -0x3c(%rbp), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
movzwl (%rax,%rcx,2), %eax
cmpl $0x2e, %eax
setne %al
movb %al, -0x4a(%rbp)
movb -0x4a(%rbp), %al
testb $0x1, %al
jne 0xe4dc
jmp 0xe4e7
movl -0x3c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0xe4af
movq -0x10(%rbp), %rdi
addq $0x48, %rdi
movl $0x20, %esi
movl $0xb, %edx
callq 0x5f80
movb $0x0, -0x19(%rbp)
movl $0x0, -0x30(%rbp)
movl $0x8, -0x34(%rbp)
movq -0x28(%rbp), %rax
movl -0x38(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x38(%rbp)
movl %ecx, %ecx
movw (%rax,%rcx,2), %ax
movw %ax, -0x1c(%rbp)
movzwl -0x1c(%rbp), %eax
cmpl $0x0, %eax
jne 0xe537
jmp 0xe6f8
movzwl -0x1c(%rbp), %eax
cmpl $0x20, %eax
je 0xe551
movzwl -0x1c(%rbp), %eax
cmpl $0x2e, %eax
jne 0xe55d
movl -0x38(%rbp), %eax
cmpl -0x3c(%rbp), %eax
je 0xe55d
movzbl -0x1a(%rbp), %eax
orl $0x3, %eax
movb %al, -0x1a(%rbp)
jmp 0xe510
movl -0x30(%rbp), %eax
cmpl -0x34(%rbp), %eax
jae 0xe56d
movl -0x38(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jne 0xe5c4
cmpl $0xb, -0x34(%rbp)
jne 0xe582
movzbl -0x1a(%rbp), %eax
orl $0x3, %eax
movb %al, -0x1a(%rbp)
jmp 0xe6f8
movl -0x38(%rbp), %eax
cmpl -0x3c(%rbp), %eax
je 0xe594
movzbl -0x1a(%rbp), %eax
orl $0x3, %eax
movb %al, -0x1a(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jbe 0xe5a1
jmp 0xe6f8
movl -0x3c(%rbp), %eax
movl %eax, -0x38(%rbp)
movl $0x8, -0x30(%rbp)
movl $0xb, -0x34(%rbp)
movzbl -0x19(%rbp), %eax
shll $0x2, %eax
movb %al, -0x19(%rbp)
jmp 0xe510
movzwl -0x1c(%rbp), %eax
cmpl $0x80, %eax
jl 0xe614
movzbl -0x1a(%rbp), %eax
orl $0x2, %eax
movb %al, -0x1a(%rbp)
movzwl -0x1c(%rbp), %edi
movl $0x1b5, %esi            # imm = 0x1B5
callq 0xfe30
movw %ax, -0x1c(%rbp)
movzwl -0x1c(%rbp), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0xe612
movzwl -0x1c(%rbp), %eax
andl $0x7f, %eax
movslq %eax, %rcx
leaq 0x3e56(%rip), %rax      # 0x12460
movzbl (%rax,%rcx), %eax
movw %ax, -0x1c(%rbp)
jmp 0xe614
movzwl -0x1c(%rbp), %eax
cmpl $0x100, %eax            # imm = 0x100
jl 0xe661
movl -0x30(%rbp), %eax
movl -0x34(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jb 0xe641
movzbl -0x1a(%rbp), %eax
orl $0x3, %eax
movb %al, -0x1a(%rbp)
movl -0x34(%rbp), %eax
movl %eax, -0x30(%rbp)
jmp 0xe510
movzwl -0x1c(%rbp), %eax
sarl $0x8, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movl -0x30(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x30(%rbp)
movl %ecx, %ecx
movb %dl, 0x48(%rax,%rcx)
jmp 0xe6d8
movzwl -0x1c(%rbp), %eax
cmpl $0x0, %eax
je 0xe67f
movzwl -0x1c(%rbp), %esi
leaq 0x3ed4(%rip), %rdi      # 0x12549
callq 0xaf70
cmpl $0x0, %eax
je 0xe691
movw $0x5f, -0x1c(%rbp)
movzbl -0x1a(%rbp), %eax
orl $0x3, %eax
movb %al, -0x1a(%rbp)
jmp 0xe6d6
movzwl -0x1c(%rbp), %eax
cmpl $0x41, %eax
jl 0xe6ad
movzwl -0x1c(%rbp), %eax
cmpl $0x5a, %eax
jg 0xe6ad
movzbl -0x19(%rbp), %eax
orl $0x2, %eax
movb %al, -0x19(%rbp)
movzwl -0x1c(%rbp), %eax
cmpl $0x61, %eax
jl 0xe6d4
movzwl -0x1c(%rbp), %eax
cmpl $0x7a, %eax
jg 0xe6d4
movzbl -0x19(%rbp), %eax
orl $0x1, %eax
movb %al, -0x19(%rbp)
movzwl -0x1c(%rbp), %eax
subl $0x20, %eax
movw %ax, -0x1c(%rbp)
jmp 0xe6d6
jmp 0xe6d8
movw -0x1c(%rbp), %ax
movb %al, %dl
movq -0x10(%rbp), %rax
movl -0x30(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x30(%rbp)
movl %ecx, %ecx
movb %dl, 0x48(%rax,%rcx)
jmp 0xe510
movq -0x10(%rbp), %rax
movzbl 0x48(%rax), %eax
cmpl $0xe5, %eax
jne 0xe70f
movq -0x10(%rbp), %rax
movb $0x5, 0x48(%rax)
cmpl $0x8, -0x34(%rbp)
jne 0xe71f
movzbl -0x19(%rbp), %eax
shll $0x2, %eax
movb %al, -0x19(%rbp)
movzbl -0x19(%rbp), %eax
andl $0xc, %eax
cmpl $0xc, %eax
je 0xe737
movzbl -0x19(%rbp), %eax
andl $0x3, %eax
cmpl $0x3, %eax
jne 0xe741
movzbl -0x1a(%rbp), %eax
orl $0x2, %eax
movb %al, -0x1a(%rbp)
movzbl -0x1a(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
jne 0xe77b
movzbl -0x19(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0xe763
movzbl -0x1a(%rbp), %eax
orl $0x10, %eax
movb %al, -0x1a(%rbp)
movzbl -0x19(%rbp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0xe779
movzbl -0x1a(%rbp), %eax
orl $0x8, %eax
movb %al, -0x1a(%rbp)
jmp 0xe77b
movb -0x1a(%rbp), %cl
movq -0x10(%rbp), %rax
movb %cl, 0x53(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)