// File: /workspace/github_c_makefile_star2_O0/lb3361[P]dosfs/ff.c
// Function: put_utf
static BYTE put_utf (	/* Returns number of encoding units written (0:buffer overflow or wrong encoding) */
	DWORD chr,	/* UTF-16 encoded character (Surrogate pair if >=0x10000) */
	TCHAR* buf,	/* Output buffer */
	UINT szb	/* Size of the buffer */
)
{
#if FF_LFN_UNICODE == 1	/* UTF-16 output */
	WCHAR hs, wc;

	hs = (WCHAR)(chr >> 16);
	wc = (WCHAR)chr;
	if (hs == 0) {	/* Single encoding unit? */
		if (szb < 1 || IsSurrogate(wc)) return 0;	/* Buffer overflow or wrong code? */
		*buf = wc;
		return 1;
	}
	if (szb < 2 || !IsSurrogateH(hs) || !IsSurrogateL(wc)) return 0;	/* Buffer overflow or wrong surrogate? */
	*buf++ = hs;
	*buf++ = wc;
	return 2;

#elif FF_LFN_UNICODE == 2	/* UTF-8 output */
	DWORD hc;

	if (chr < 0x80) {	/* Single byte code? */
		if (szb < 1) return 0;	/* Buffer overflow? */
		*buf = (TCHAR)chr;
		return 1;
	}
	if (chr < 0x800) {	/* 2-byte sequence? */
		if (szb < 2) return 0;	/* Buffer overflow? */
		*buf++ = (TCHAR)(0xC0 | (chr >> 6 & 0x1F));
		*buf++ = (TCHAR)(0x80 | (chr >> 0 & 0x3F));
		return 2;
	}
	if (chr < 0x10000) {	/* 3-byte sequence? */
		if (szb < 3 || IsSurrogate(chr)) return 0;	/* Buffer overflow or wrong code? */
		*buf++ = (TCHAR)(0xE0 | (chr >> 12 & 0x0F));
		*buf++ = (TCHAR)(0x80 | (chr >> 6 & 0x3F));
		*buf++ = (TCHAR)(0x80 | (chr >> 0 & 0x3F));
		return 3;
	}
	/* 4-byte sequence */
	if (szb < 4) return 0;	/* Buffer overflow? */
	hc = ((chr & 0xFFFF0000) - 0xD8000000) >> 6;	/* Get high 10 bits */
	chr = (chr & 0xFFFF) - 0xDC00;					/* Get low 10 bits */
	if (hc >= 0x100000 || chr >= 0x400) return 0;	/* Wrong surrogate? */
	chr = (hc | chr) + 0x10000;
	*buf++ = (TCHAR)(0xF0 | (chr >> 18 & 0x07));
	*buf++ = (TCHAR)(0x80 | (chr >> 12 & 0x3F));
	*buf++ = (TCHAR)(0x80 | (chr >> 6 & 0x3F));
	*buf++ = (TCHAR)(0x80 | (chr >> 0 & 0x3F));
	return 4;

#elif FF_LFN_UNICODE == 3	/* UTF-32 output */
	DWORD hc;

	if (szb < 1) return 0;	/* Buffer overflow? */
	if (chr >= 0x10000) {	/* Out of BMP? */
		hc = ((chr & 0xFFFF0000) - 0xD8000000) >> 6;	/* Get high 10 bits */
		chr = (chr & 0xFFFF) - 0xDC00;					/* Get low 10 bits */
		if (hc >= 0x100000 || chr >= 0x400) return 0;	/* Wrong surrogate? */
		chr = (hc | chr) + 0x10000;
	}
	*buf++ = (TCHAR)chr;
	return 1;

#else						/* ANSI/OEM output */
	WCHAR wc;

	wc = ff_uni2oem(chr, CODEPAGE);
	if (wc >= 0x100) {	/* Is this a DBC? */
		if (szb < 2) return 0;
		*buf++ = (char)(wc >> 8);	/* Store DBC 1st byte */
		*buf++ = (TCHAR)wc;			/* Store DBC 2nd byte */
		return 2;
	}
	if (wc == 0 || szb < 1) return 0;	/* Invalid char or buffer overflow? */
	*buf++ = (TCHAR)wc;					/* Store the character */
	return 1;
#endif
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
cmpl $0x80, -0x8(%rbp)
jae 0xa76a
cmpl $0x1, -0x14(%rbp)
jae 0xa756
movb $0x0, -0x1(%rbp)
jmp 0xa94a
movl -0x8(%rbp), %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, (%rax)
movb $0x1, -0x1(%rbp)
jmp 0xa94a
cmpl $0x800, -0x8(%rbp)      # imm = 0x800
jae 0xa7cd
cmpl $0x2, -0x14(%rbp)
jae 0xa782
movb $0x0, -0x1(%rbp)
jmp 0xa94a
movl -0x8(%rbp), %eax
shrl $0x6, %eax
andl $0x1f, %eax
orl $0xc0, %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x10(%rbp)
movb %cl, (%rax)
movl -0x8(%rbp), %eax
shrl $0x0, %eax
andl $0x3f, %eax
orl $0x80, %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x10(%rbp)
movb %cl, (%rax)
movb $0x2, -0x1(%rbp)
jmp 0xa94a
cmpl $0x10000, -0x8(%rbp)    # imm = 0x10000
jae 0xa867
cmpl $0x3, -0x14(%rbp)
jb 0xa7f2
cmpl $0xd800, -0x8(%rbp)     # imm = 0xD800
jb 0xa7fb
cmpl $0xdfff, -0x8(%rbp)     # imm = 0xDFFF
ja 0xa7fb
movb $0x0, -0x1(%rbp)
jmp 0xa94a
movl -0x8(%rbp), %eax
shrl $0xc, %eax
andl $0xf, %eax
orl $0xe0, %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x10(%rbp)
movb %cl, (%rax)
movl -0x8(%rbp), %eax
shrl $0x6, %eax
andl $0x3f, %eax
orl $0x80, %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x10(%rbp)
movb %cl, (%rax)
movl -0x8(%rbp), %eax
shrl $0x0, %eax
andl $0x3f, %eax
orl $0x80, %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x10(%rbp)
movb %cl, (%rax)
movb $0x3, -0x1(%rbp)
jmp 0xa94a
cmpl $0x4, -0x14(%rbp)
jae 0xa876
movb $0x0, -0x1(%rbp)
jmp 0xa94a
movl -0x8(%rbp), %eax
andl $0xffff0000, %eax       # imm = 0xFFFF0000
subl $0xd8000000, %eax       # imm = 0xD8000000
shrl $0x6, %eax
movl %eax, -0x18(%rbp)
movl -0x8(%rbp), %eax
andl $0xffff, %eax           # imm = 0xFFFF
subl $0xdc00, %eax           # imm = 0xDC00
movl %eax, -0x8(%rbp)
cmpl $0x100000, -0x18(%rbp)  # imm = 0x100000
jae 0xa8ab
cmpl $0x400, -0x8(%rbp)      # imm = 0x400
jb 0xa8b4
movb $0x0, -0x1(%rbp)
jmp 0xa94a
movl -0x18(%rbp), %eax
orl -0x8(%rbp), %eax
addl $0x10000, %eax          # imm = 0x10000
movl %eax, -0x8(%rbp)
movl -0x8(%rbp), %eax
shrl $0x12, %eax
andl $0x7, %eax
orl $0xf0, %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x10(%rbp)
movb %cl, (%rax)
movl -0x8(%rbp), %eax
shrl $0xc, %eax
andl $0x3f, %eax
orl $0x80, %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x10(%rbp)
movb %cl, (%rax)
movl -0x8(%rbp), %eax
shrl $0x6, %eax
andl $0x3f, %eax
orl $0x80, %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x10(%rbp)
movb %cl, (%rax)
movl -0x8(%rbp), %eax
shrl $0x0, %eax
andl $0x3f, %eax
orl $0x80, %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x10(%rbp)
movb %cl, (%rax)
movb $0x4, -0x1(%rbp)
movb -0x1(%rbp), %al
popq %rbp
retq
nop