// File: /workspace/github_cpp_makefile_star2_O2/andrakis[P]alisp/contrib/linenoise-ng/src/ConvertUTF.cpp
// Function: linenoise_ng::ConvertUTF8toUTF32(unsigned char const**, unsigned char const*, unsigned int**, unsigned int*, linenoise_ng::ConversionFlags)
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 0xdfe4
movzbl (%r15), %ebp
leaq 0xe956(%rip), %rax      # 0x1c830
movsbl (%rbp,%rax), %eax
movzwl %ax, %r13d
leaq (%r15,%r13), %rax
cmpq %rsi, %rax
jae 0xdfe8
movl %ecx, 0x4(%rsp)
leal 0x1(%r13), %r14d
movq %r15, %rdi
movl %r14d, %esi
callq 0xdb26
testb %al, %al
je 0xdff5
xorl %eax, %eax
cmpb $0x5, %r13b
ja 0xdf88
movzbl %r13b, %ecx
leaq 0xe8ea(%rip), %rdx      # 0x1c808
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
movzbl %r13b, %ecx
jmp 0xdf7f
movl %ebp, %eax
shll $0x6, %eax
movb 0x1(%r15), %bpl
incq %r15
movzbl %bpl, %ecx
addl %eax, %ecx
shll $0x6, %ecx
movb 0x1(%r15), %bpl
incq %r15
movl %ecx, %eax
movzbl %bpl, %ecx
addl %eax, %ecx
shll $0x6, %ecx
movb 0x1(%r15), %bpl
incq %r15
movl %ecx, %eax
movzbl %bpl, %ecx
addl %eax, %ecx
shll $0x6, %ecx
movb 0x1(%r15), %bpl
incq %r15
movl %ecx, %eax
movzbl %bpl, %ecx
addl %eax, %ecx
shll $0x6, %ecx
movb 0x1(%r15), %bpl
incq %r15
incq %r15
movzbl %bpl, %eax
addl %ecx, %eax
cmpq 0x20(%rsp), %r12
jae 0xdfec
leaq 0xe99a(%rip), %rcx      # 0x1c930
subl (%rcx,%r13,4), %eax
movl $0xfffd, %edx           # imm = 0xFFFD
movl %ebx, %ecx
cmpl $0x10ffff, %eax         # imm = 0x10FFFF
ja 0xdfd2
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 0xe016
movl %edx, (%r12)
addq $0x4, %r12
movq 0x18(%rsp), %rsi
jmp 0xdec6
movl %ecx, %ebx
jmp 0xdff5
pushq $0x1
jmp 0xdff4
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 0xdff5
nop