// File: /workspace/github_cpp_makefile_star2_O1/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
movq (%rdi), %r9
movq (%rdx), %r10
xorl %r15d, %r15d
leaq 0x25ec(%rip), %r11      # 0x6060
leaq 0x25bd(%rip), %r14      # 0x6038
cmpq %rsi, %r9
jae 0x3bc9
movsbq (%r9), %rbp
movsbl (%rbp,%r11), %eax
movzwl %ax, %r13d
leaq (%r9,%r13), %rax
cmpq %rsi, %rax
jae 0x3ae8
movzbl %r13b, %ebx
testb %r13b, %r13b
je 0x3b38
movl $0x3, %eax
cmpl $0x1, %ebx
jne 0x3b9d
xorl %r12d, %r12d
cmpb $-0xc, %bpl
je 0x3acf
movzbl %bpl, %ebx
cmpl $0xed, %ebx
jne 0x3ba0
cmpb $0x5, %r13b
ja 0x3b42
movzbl %r13b, %eax
movslq (%r14,%rax,4), %rax
addq %r14, %rax
jmpq *%rax
movzbl %r13b, %ebx
jmp 0x3b38
movl $0x1, %eax
jmp 0x3b9d
incq %r9
shll $0x6, %ebp
movl %ebp, %r12d
movsbl (%r9), %eax
incq %r9
addl %r12d, %eax
shll $0x6, %eax
movl %eax, %r12d
movsbl (%r9), %eax
incq %r9
addl %r12d, %eax
shll $0x6, %eax
movl %eax, %r12d
movsbl (%r9), %eax
incq %r9
addl %r12d, %eax
shll $0x6, %eax
movl %eax, %r12d
movsbl (%r9), %ebx
incq %r9
addl %r12d, %ebx
shll $0x6, %ebx
movsbl (%r9), %r12d
incq %r9
addl %ebx, %r12d
leal 0x1(%r13), %eax
cmpq %rcx, %r10
jae 0x3b93
leaq 0x260e(%rip), %rbx      # 0x6160
subl (%rbx,%r13,4), %r12d
cmpl $0x10ffff, %r12d        # imm = 0x10FFFF
ja 0x3bae
testl %r8d, %r8d
setne %bl
movl %r12d, %ebp
andl $0x1ff800, %ebp         # imm = 0x1FF800
cmpl $0xd800, %ebp           # imm = 0xD800
setne %bpl
movl $0xfffd, %r13d          # imm = 0xFFFD
cmovel %r13d, %r12d
orb %bl, %bpl
jne 0x3bba
movl %eax, %eax
subq %rax, %r9
movl $0x3, %eax
jmp 0x3b9d
movl %eax, %eax
subq %rax, %r9
movl $0x2, %eax
xorl %r12d, %r12d
movl %eax, %r15d
testb %r12b, %r12b
jne 0x3a7b
jmp 0x3bcc
movl $0x3, %r15d
movl $0xfffd, %r12d          # imm = 0xFFFD
movl %r12d, (%r10)
addq $0x4, %r10
movb $0x1, %r12b
movl %r15d, %eax
jmp 0x3ba0
movl %r15d, %eax
movq %r9, (%rdi)
movq %r10, (%rdx)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq