// File: /workspace/github_cpp_makefile_star2_O2/codebrainz[P]libutfxx/utf/utf.cxx
// Function: ConvertUTF8toUTF32
ConversionResult ConvertUTF8toUTF32 (
	const UTF8** sourceStart, const UTF8* sourceEnd,
	UTF32** targetStart, UTF32* targetEnd, ConversionFlags flags) {
	ConversionResult result = conversionOK;
	const UTF8* source = *sourceStart;
	UTF32* target = *targetStart;
	while (source < sourceEnd) {
	UTF32 ch = 0;
	unsigned short extraBytesToRead = trailingBytesForUTF8[*source];
	if (source + extraBytesToRead >= sourceEnd) {
		result = sourceExhausted; break;
	}
	/* Do this check whether lenient or strict */
	if (! isLegalUTF8(source, extraBytesToRead+1)) {
		result = sourceIllegal;
		break;
	}
	/*
	 * The cases all fall through. See "Note A" below.
	 */
	switch (extraBytesToRead) {
		case 5: ch += *source++; ch <<= 6;
		case 4: ch += *source++; ch <<= 6;
		case 3: ch += *source++; ch <<= 6;
		case 2: ch += *source++; ch <<= 6;
		case 1: ch += *source++; ch <<= 6;
		case 0: ch += *source++;
	}
	ch -= offsetsFromUTF8[extraBytesToRead];

	if (target >= targetEnd) {
		source -= (extraBytesToRead+1); /* Back up the source pointer! */
		result = targetExhausted; break;
	}
	if (ch <= UNI_MAX_LEGAL_UTF32) {
		/*
		 * UTF-16 surrogate values are illegal in UTF-32, and anything
		 * over Plane 17 (> 0x10FFFF) is illegal.
		 */
		if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_LOW_END) {
		if (flags == strictConversion) {
			source -= (extraBytesToRead+1); /* return to the illegal value itself */
			result = sourceIllegal;
			break;
		} else {
			*target++ = UNI_REPLACEMENT_CHAR;
		}
		} else {
		*target++ = ch;
		}
	} else { /* i.e., ch > UNI_MAX_LEGAL_UTF32 */
		result = sourceIllegal;
		*target++ = UNI_REPLACEMENT_CHAR;
	}
	}
	*sourceStart = source;
	*targetStart = target;
	return result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %r8d, (%rsp)
movq %rcx, 0x20(%rsp)
movq %rdi, 0x8(%rsp)
movq (%rdi), %r15
movq %rdx, 0x10(%rsp)
movq (%rdx), %r12
xorl %ecx, %ecx
pushq $0x3
popq %rbx
movq %rsi, 0x18(%rsp)
cmpq %rsi, %r15
jae 0x4c88
movsbq (%r15), %rbp
leaq 0x24e2(%rip), %rax      # 0x7060
movsbl (%rbp,%rax), %eax
movzwl %ax, %r13d
leaq (%r15,%r13), %rax
cmpq %rsi, %rax
jae 0x4c8c
movl %ecx, 0x4(%rsp)
leal 0x1(%r13), %r14d
movq %r15, %rdi
movl %r14d, %esi
callq 0x483b
testb %al, %al
je 0x4c99
xorl %eax, %eax
cmpb $0x5, %r13b
ja 0x4c2c
movzbl %r13b, %ecx
leaq 0x2476(%rip), %rdx      # 0x7038
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
movzbl %r13b, %ecx
jmp 0x4c23
movl %ebp, %eax
shll $0x6, %eax
movb 0x1(%r15), %bpl
incq %r15
movsbl %bpl, %ecx
addl %eax, %ecx
shll $0x6, %ecx
movb 0x1(%r15), %bpl
incq %r15
movl %ecx, %eax
movsbl %bpl, %ecx
addl %eax, %ecx
shll $0x6, %ecx
movb 0x1(%r15), %bpl
incq %r15
movl %ecx, %eax
movsbl %bpl, %ecx
addl %eax, %ecx
shll $0x6, %ecx
movb 0x1(%r15), %bpl
incq %r15
movl %ecx, %eax
movsbl %bpl, %ecx
addl %eax, %ecx
shll $0x6, %ecx
movb 0x1(%r15), %bpl
incq %r15
incq %r15
movsbl %bpl, %eax
addl %ecx, %eax
cmpq 0x20(%rsp), %r12
jae 0x4c90
leaq 0x2526(%rip), %rcx      # 0x7160
subl (%rcx,%r13,4), %eax
movl $0xfffd, %edx           # imm = 0xFFFD
movl %ebx, %ecx
cmpl $0x10ffff, %eax         # imm = 0x10FFFF
ja 0x4c76
cmpl $0x0, (%rsp)
setne %cl
movl %eax, %edx
andl $0x1ff800, %edx         # imm = 0x1FF800
cmpl $0xd800, %edx           # imm = 0xD800
movl $0xfffd, %edx           # imm = 0xFFFD
cmovel %edx, %eax
setne %dl
orb %cl, %dl
movl %eax, %edx
movl 0x4(%rsp), %ecx
je 0x4cba
movl %edx, (%r12)
addq $0x4, %r12
movq 0x18(%rsp), %rsi
jmp 0x4b6a
movl %ecx, %ebx
jmp 0x4c99
pushq $0x1
jmp 0x4c98
movl %r14d, %eax
subq %rax, %r15
pushq $0x2
popq %rbx
movq 0x8(%rsp), %rax
movq %r15, (%rax)
movq 0x10(%rsp), %rax
movq %r12, (%rax)
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %r14d, %eax
subq %rax, %r15
jmp 0x4c99