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

	for (i = 0; i < src_len && src[i]; i++) {
		uint16_t c = src[i];

		if (c >= 0x800) {
			if (j + 3 >= dst_len)
				return -UFAT_ERR_BAD_ENCODING;

			dst[j++] = 0xe0 | (c >> 12);
			dst[j++] = 0x80 | ((c >> 6) & 0x3f);
			dst[j++] = 0x80 | (c & 0x3f);
		} else if (c >= 0x80) {
			if (j + 2 >= dst_len)
				return -UFAT_ERR_BAD_ENCODING;

			dst[j++] = 0xc0 | c >> 6;
			dst[j++] = 0x80 | (c & 0x3f);
		} else {
			if (j + 1 >= dst_len)
				return -UFAT_ERR_BAD_ENCODING;

			dst[j++] = c;
		}
	}

	if (j >= dst_len)
		return -UFAT_ERR_NAME_TOO_LONG;

	dst[j] = 0;
	return 0;
}

// Assembly:
movq %rdi, -0x10(%rsp)
movl %esi, -0x14(%rsp)
movq %rdx, -0x20(%rsp)
movl %ecx, -0x24(%rsp)
movl $0x0, -0x2c(%rsp)
movl $0x0, -0x28(%rsp)
movl -0x28(%rsp), %ecx
xorl %eax, %eax
cmpl -0x14(%rsp), %ecx
movb %al, -0x2f(%rsp)
jge 0x73aa
movq -0x10(%rsp), %rax
movslq -0x28(%rsp), %rcx
movzwl (%rax,%rcx,2), %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x2f(%rsp)
movb -0x2f(%rsp), %al
testb $0x1, %al
jne 0x73b7
jmp 0x7531
movq -0x10(%rsp), %rax
movslq -0x28(%rsp), %rcx
movw (%rax,%rcx,2), %ax
movw %ax, -0x2e(%rsp)
movzwl -0x2e(%rsp), %eax
cmpl $0x800, %eax            # imm = 0x800
jl 0x7471
movl -0x2c(%rsp), %eax
addl $0x3, %eax
cmpl -0x24(%rsp), %eax
jl 0x73f4
movl $0xfffffff3, -0x4(%rsp) # imm = 0xFFFFFFF3
jmp 0x755b
movzwl -0x2e(%rsp), %eax
sarl $0xc, %eax
orl $0xe0, %eax
movb %al, %dl
movq -0x20(%rsp), %rax
movl -0x2c(%rsp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x2c(%rsp)
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movzwl -0x2e(%rsp), %eax
sarl $0x6, %eax
andl $0x3f, %eax
orl $0x80, %eax
movb %al, %dl
movq -0x20(%rsp), %rax
movl -0x2c(%rsp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x2c(%rsp)
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movzwl -0x2e(%rsp), %eax
andl $0x3f, %eax
orl $0x80, %eax
movb %al, %dl
movq -0x20(%rsp), %rax
movl -0x2c(%rsp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x2c(%rsp)
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
jmp 0x751f
movzwl -0x2e(%rsp), %eax
cmpl $0x80, %eax
jl 0x74e7
movl -0x2c(%rsp), %eax
addl $0x2, %eax
cmpl -0x24(%rsp), %eax
jl 0x7497
movl $0xfffffff3, -0x4(%rsp) # imm = 0xFFFFFFF3
jmp 0x755b
movzwl -0x2e(%rsp), %eax
sarl $0x6, %eax
orl $0xc0, %eax
movb %al, %dl
movq -0x20(%rsp), %rax
movl -0x2c(%rsp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x2c(%rsp)
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movzwl -0x2e(%rsp), %eax
andl $0x3f, %eax
orl $0x80, %eax
movb %al, %dl
movq -0x20(%rsp), %rax
movl -0x2c(%rsp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x2c(%rsp)
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
jmp 0x751d
movl -0x2c(%rsp), %eax
addl $0x1, %eax
cmpl -0x24(%rsp), %eax
jl 0x74fe
movl $0xfffffff3, -0x4(%rsp) # imm = 0xFFFFFFF3
jmp 0x755b
movw -0x2e(%rsp), %ax
movb %al, %dl
movq -0x20(%rsp), %rax
movl -0x2c(%rsp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x2c(%rsp)
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
jmp 0x751f
jmp 0x7521
movl -0x28(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rsp)
jmp 0x7382
movl -0x2c(%rsp), %eax
cmpl -0x24(%rsp), %eax
jl 0x7545
movl $0xfffffffa, -0x4(%rsp) # imm = 0xFFFFFFFA
jmp 0x755b
movq -0x20(%rsp), %rax
movslq -0x2c(%rsp), %rcx
movb $0x0, (%rax,%rcx)
movl $0x0, -0x4(%rsp)
movl -0x4(%rsp), %eax
retq