// File: /workspace/github_c_makefile_star2_O0/dlbeer[P]ufat/ufat_ent.c
// Function: ufat_utf8_to_ucs2
int ufat_utf8_to_ucs2(const char *src, uint16_t *dst)
{
	int len = 0;
	int i;

	while (*src && len < UFAT_LFN_MAX_CHARS) {
		unsigned int c = *src;

		if ((c & 0xf0) == 0xf0)
			return -UFAT_ERR_ILLEGAL_NAME;

		if ((c & 0xe0) == 0xe0) {
			unsigned int b = src[1];
			unsigned int a = src[2];

			if ((a & 0xc0) != 0xc0 ||
			    (b & 0xc0) != 0xc0)
				return -UFAT_ERR_BAD_ENCODING;

			dst[len++] = ((c & 0xf) << 12) |
				((b & 0x3f) << 6) |
				(a & 0x3f);
			src += 3;
		} else if ((c & 0xc0) == 0xc0) {
			unsigned int b = src[1];

			if ((b & 0xc0) != 0xc0)
				return -UFAT_ERR_BAD_ENCODING;

			dst[len++] = ((c & 0x1f) << 6) | (b & 0x3f);
			src += 2;
		} else if (c & 0x80) {
			return -UFAT_ERR_BAD_ENCODING;
		} else {
			dst[len++] = c;
			src++;
		}
	}

	if (*src)
		return -UFAT_ERR_NAME_TOO_LONG;

	/* Pad out to full length */
	for (i = len; i < UFAT_LFN_MAX_CHARS; i++)
		dst[i] = 0;

	return len;
}

// Assembly:
movq %rdi, -0x10(%rsp)
movq %rsi, -0x18(%rsp)
movl $0x0, -0x1c(%rsp)
movq -0x10(%rsp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x31(%rsp)
je 0x76b4
cmpl $0xff, -0x1c(%rsp)
setl %al
movb %al, -0x31(%rsp)
movb -0x31(%rsp), %al
testb $0x1, %al
jne 0x76c1
jmp 0x785e
movq -0x10(%rsp), %rax
movsbl (%rax), %eax
movl %eax, -0x24(%rsp)
movl -0x24(%rsp), %eax
andl $0xf0, %eax
cmpl $0xf0, %eax
jne 0x76ea
movl $0xfffffff5, -0x4(%rsp) # imm = 0xFFFFFFF5
jmp 0x78a9
movl -0x24(%rsp), %eax
andl $0xe0, %eax
cmpl $0xe0, %eax
jne 0x7793
movq -0x10(%rsp), %rax
movsbl 0x1(%rax), %eax
movl %eax, -0x28(%rsp)
movq -0x10(%rsp), %rax
movsbl 0x2(%rax), %eax
movl %eax, -0x2c(%rsp)
movl -0x2c(%rsp), %eax
andl $0xc0, %eax
cmpl $0xc0, %eax
jne 0x7738
movl -0x28(%rsp), %eax
andl $0xc0, %eax
cmpl $0xc0, %eax
je 0x7745
movl $0xfffffff3, -0x4(%rsp) # imm = 0xFFFFFFF3
jmp 0x78a9
movl -0x24(%rsp), %eax
andl $0xf, %eax
shll $0xc, %eax
movl -0x28(%rsp), %ecx
andl $0x3f, %ecx
shll $0x6, %ecx
orl %ecx, %eax
movl -0x2c(%rsp), %ecx
andl $0x3f, %ecx
orl %ecx, %eax
movw %ax, %dx
movq -0x18(%rsp), %rax
movl -0x1c(%rsp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x1c(%rsp)
movslq %ecx, %rcx
movw %dx, (%rax,%rcx,2)
movq -0x10(%rsp), %rax
addq $0x3, %rax
movq %rax, -0x10(%rsp)
jmp 0x7859
movl -0x24(%rsp), %eax
andl $0xc0, %eax
cmpl $0xc0, %eax
jne 0x780c
movq -0x10(%rsp), %rax
movsbl 0x1(%rax), %eax
movl %eax, -0x30(%rsp)
movl -0x30(%rsp), %eax
andl $0xc0, %eax
cmpl $0xc0, %eax
je 0x77cd
movl $0xfffffff3, -0x4(%rsp) # imm = 0xFFFFFFF3
jmp 0x78a9
movl -0x24(%rsp), %eax
andl $0x1f, %eax
shll $0x6, %eax
movl -0x30(%rsp), %ecx
andl $0x3f, %ecx
orl %ecx, %eax
movw %ax, %dx
movq -0x18(%rsp), %rax
movl -0x1c(%rsp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x1c(%rsp)
movslq %ecx, %rcx
movw %dx, (%rax,%rcx,2)
movq -0x10(%rsp), %rax
addq $0x2, %rax
movq %rax, -0x10(%rsp)
jmp 0x7857
movl -0x24(%rsp), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0x7827
movl $0xfffffff3, -0x4(%rsp) # imm = 0xFFFFFFF3
jmp 0x78a9
movl -0x24(%rsp), %eax
movw %ax, %dx
movq -0x18(%rsp), %rax
movl -0x1c(%rsp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x1c(%rsp)
movslq %ecx, %rcx
movw %dx, (%rax,%rcx,2)
movq -0x10(%rsp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rsp)
jmp 0x7857
jmp 0x7859
jmp 0x7692
movq -0x10(%rsp), %rax
cmpb $0x0, (%rax)
je 0x7872
movl $0xfffffffa, -0x4(%rsp) # imm = 0xFFFFFFFA
jmp 0x78a9
movl -0x1c(%rsp), %eax
movl %eax, -0x20(%rsp)
cmpl $0xff, -0x20(%rsp)
jge 0x78a1
movq -0x18(%rsp), %rax
movslq -0x20(%rsp), %rcx
movw $0x0, (%rax,%rcx,2)
movl -0x20(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rsp)
jmp 0x787a
movl -0x1c(%rsp), %eax
movl %eax, -0x4(%rsp)
movl -0x4(%rsp), %eax
retq
nop