// File: /workspace/github_c_makefile_star2_O3/OnionIoT[P]lv_example/lvgl/src/lv_misc/lv_txt.c
// Function: lv_txt_utf8_next
static uint32_t lv_txt_utf8_next(const char * txt, uint32_t * i)
{
    /* Unicode to UTF-8
     * 00000000 00000000 00000000 0xxxxxxx -> 0xxxxxxx
     * 00000000 00000000 00000yyy yyxxxxxx -> 110yyyyy 10xxxxxx
     * 00000000 00000000 zzzzyyyy yyxxxxxx -> 1110zzzz 10yyyyyy 10xxxxxx
     * 00000000 000wwwzz zzzzyyyy yyxxxxxx -> 11110www 10zzzzzz 10yyyyyy 10xxxxxx
     * */

    uint32_t result = 0;

    /*Dummy 'i' pointer is required*/
    uint32_t i_tmp = 0;
    if(i == NULL) i = &i_tmp;

    /*Normal ASCII*/
    if((txt[*i] & 0x80) == 0) {
        result = txt[*i];
        (*i)++;
    }
    /*Real UTF-8 decode*/
    else {
        /*2 bytes UTF-8 code*/
        if((txt[*i] & 0xE0) == 0xC0) {
            result = (uint32_t)(txt[*i] & 0x1F) << 6;
            (*i)++;
            if((txt[*i] & 0xC0) != 0x80) return 0; /*Invalid UTF-8 code*/
            result += (txt[*i] & 0x3F);
            (*i)++;
        }
        /*3 bytes UTF-8 code*/
        else if((txt[*i] & 0xF0) == 0xE0) {
            result = (uint32_t)(txt[*i] & 0x0F) << 12;
            (*i)++;

            if((txt[*i] & 0xC0) != 0x80) return 0; /*Invalid UTF-8 code*/
            result += (uint32_t)(txt[*i] & 0x3F) << 6;
            (*i)++;

            if((txt[*i] & 0xC0) != 0x80) return 0; /*Invalid UTF-8 code*/
            result += (txt[*i] & 0x3F);
            (*i)++;
        }
        /*4 bytes UTF-8 code*/
        else if((txt[*i] & 0xF8) == 0xF0) {
            result = (uint32_t)(txt[*i] & 0x07) << 18;
            (*i)++;

            if((txt[*i] & 0xC0) != 0x80) return 0; /*Invalid UTF-8 code*/
            result += (uint32_t)(txt[*i] & 0x3F) << 12;
            (*i)++;

            if((txt[*i] & 0xC0) != 0x80) return 0; /*Invalid UTF-8 code*/
            result += (uint32_t)(txt[*i] & 0x3F) << 6;
            (*i)++;

            if((txt[*i] & 0xC0) != 0x80) return 0; /*Invalid UTF-8 code*/
            result += txt[*i] & 0x3F;
            (*i)++;
        } else {
            (*i)++; /*Not UTF-8 char. Go the next.*/
        }
    }
    return result;
}

// Assembly:
testq %rsi, %rsi
je 0x2a9b7
movl (%rsi), %edx
movsbl (%rdi,%rdx), %ecx
testl %ecx, %ecx
js 0x2a9e0
incl %edx
jmp 0x2aabd
movsbl (%rdi), %ecx
testl %ecx, %ecx
jns 0x2aabf
movl %ecx, %eax
andl $0xe0, %eax
cmpl $0xc0, %eax
jne 0x2aa56
movl $0x2, %edx
movl $0x1, %eax
jmp 0x2a9f6
movl %ecx, %eax
andl $0xe0, %eax
cmpl $0xc0, %eax
jne 0x2aa1d
leal 0x1(%rdx), %eax
movl %eax, (%rsi)
addl $0x2, %edx
movzbl (%rdi,%rax), %eax
movl %eax, %edi
andl $-0x40, %edi
cmpl $0x80, %edi
jne 0x2abaa
andl $0x1f, %ecx
shll $0x6, %ecx
andl $0x3f, %eax
orl %eax, %ecx
movl %ecx, %eax
jmp 0x2aab8
movl %ecx, %eax
andl $0xf0, %eax
cmpl $0xe0, %eax
jne 0x2aac2
leal 0x1(%rdx), %eax
movl %eax, (%rsi)
movsbl (%rdi,%rax), %r8d
movl %r8d, %eax
andl $0xc0, %eax
cmpl $0x80, %eax
jne 0x2abaa
leal 0x2(%rdx), %eax
movl %eax, (%rsi)
addl $0x3, %edx
jmp 0x2aa8a
movl %ecx, %eax
andl $0xf0, %eax
cmpl $0xe0, %eax
jne 0x2ab22
movsbl 0x1(%rdi), %r8d
movl %r8d, %eax
andl $0xc0, %eax
cmpl $0x80, %eax
jne 0x2abaa
movl $0x3, %edx
movl $0x2, %eax
movzbl (%rdi,%rax), %eax
movl %eax, %edi
andl $-0x40, %edi
cmpl $0x80, %edi
jne 0x2abaa
shll $0xc, %ecx
movzwl %cx, %ecx
andl $0x3f, %r8d
shll $0x6, %r8d
orl %ecx, %r8d
andl $0x3f, %eax
orl %r8d, %eax
movl %eax, %ecx
testq %rsi, %rsi
je 0x2aac1
movl %edx, (%rsi)
movl %ecx, %eax
retq
movl %ecx, %r9d
andl $0xf8, %r9d
leal 0x1(%rdx), %r8d
xorl %eax, %eax
movl %r8d, (%rsi)
cmpl $0xf0, %r9d
jne 0x2aac1
movl %r8d, %r8d
movsbl (%rdi,%r8), %r8d
movl %r8d, %r9d
andl $0xc0, %r9d
cmpl $0x80, %r9d
jne 0x2aac1
leal 0x2(%rdx), %r9d
movl %r9d, (%rsi)
movsbl (%rdi,%r9), %r9d
movl %r9d, %r10d
andl $0xc0, %r10d
cmpl $0x80, %r10d
jne 0x2aac1
leal 0x3(%rdx), %eax
movl %eax, (%rsi)
addl $0x4, %edx
jmp 0x2ab72
movl %ecx, %edx
andl $0xf8, %edx
xorl %eax, %eax
cmpl $0xf0, %edx
jne 0x2aac1
movsbl 0x1(%rdi), %r8d
movl %r8d, %edx
andl $0xc0, %edx
cmpl $0x80, %edx
jne 0x2aac1
movsbl 0x2(%rdi), %r9d
movl %r9d, %edx
andl $0xc0, %edx
cmpl $0x80, %edx
jne 0x2aac1
movl $0x4, %edx
movl $0x3, %eax
movzbl (%rdi,%rax), %eax
movl %eax, %edi
andl $-0x40, %edi
cmpl $0x80, %edi
jne 0x2abaa
andl $0x7, %ecx
shll $0x12, %ecx
andl $0x3f, %r8d
shll $0xc, %r8d
orl %ecx, %r8d
andl $0x3f, %r9d
shll $0x6, %r9d
orl %r8d, %r9d
andl $0x3f, %eax
orl %r9d, %eax
jmp 0x2aab6
xorl %eax, %eax
retq