// File: /workspace/github_c_makefile_star2_O1/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 0x2a35f
movl (%rsi), %ecx
jmp 0x2a361
xorl %ecx, %ecx
movl %ecx, %eax
movsbl (%rdi,%rax), %edx
testl %edx, %edx
js 0x2a386
movl $0x1, %edi
movl %edx, %eax
testq %rsi, %rsi
je 0x2a506
addl %edi, %ecx
movl %ecx, (%rsi)
movl %edx, %eax
jmp 0x2a506
movl %edx, %eax
andl $0xe0, %eax
cmpl $0xc0, %eax
jne 0x2a3cc
leal 0x1(%rcx), %eax
testq %rsi, %rsi
je 0x2a39e
movl %eax, (%rsi)
movl %eax, %eax
movzbl (%rdi,%rax), %edi
movl %edi, %r8d
andl $-0x40, %r8d
xorl %eax, %eax
cmpl $0x80, %r8d
jne 0x2a506
andl $0x1f, %edx
shll $0x6, %edx
andl $0x3f, %edi
orl %edi, %edx
movl $0x2, %edi
jmp 0x2a370
movl %edx, %eax
andl $0xf0, %eax
cmpl $0xe0, %eax
jne 0x2a452
leal 0x1(%rcx), %eax
testq %rsi, %rsi
je 0x2a3e4
movl %eax, (%rsi)
movl %eax, %eax
movsbl (%rdi,%rax), %r8d
movl %r8d, %r9d
andl $0xc0, %r9d
xorl %eax, %eax
cmpl $0x80, %r9d
jne 0x2a506
leal 0x2(%rcx), %r9d
testq %rsi, %rsi
je 0x2a410
movl %r9d, (%rsi)
movl %r9d, %r9d
movzbl (%rdi,%r9), %r9d
movl %r9d, %edi
andl $-0x40, %edi
cmpl $0x80, %edi
jne 0x2a506
shll $0xc, %edx
movzwl %dx, %eax
andl $0x3f, %r8d
shll $0x6, %r8d
orl %eax, %r8d
andl $0x3f, %r9d
orl %r8d, %r9d
movl $0x3, %edi
movl %r9d, %edx
movl %r9d, %eax
jmp 0x2a372
movl %edx, %eax
andl $0xf8, %eax
cmpl $0xf0, %eax
jne 0x2a507
leal 0x1(%rcx), %eax
testq %rsi, %rsi
je 0x2a46e
movl %eax, (%rsi)
movl %eax, %eax
movsbl (%rdi,%rax), %r8d
movl %r8d, %r9d
andl $0xc0, %r9d
xorl %eax, %eax
cmpl $0x80, %r9d
jne 0x2a506
leal 0x2(%rcx), %r9d
testq %rsi, %rsi
je 0x2a496
movl %r9d, (%rsi)
movl %r9d, %r9d
movsbl (%rdi,%r9), %r9d
movl %r9d, %r10d
andl $0xc0, %r10d
cmpl $0x80, %r10d
jne 0x2a506
leal 0x3(%rcx), %r10d
testq %rsi, %rsi
je 0x2a4bd
movl %r10d, (%rsi)
movl %r10d, %r10d
movzbl (%rdi,%r10), %r10d
movl %r10d, %edi
andl $-0x40, %edi
cmpl $0x80, %edi
jne 0x2a506
andl $0x7, %edx
shll $0x12, %edx
andl $0x3f, %r8d
shll $0xc, %r8d
orl %edx, %r8d
andl $0x3f, %r9d
shll $0x6, %r9d
orl %r8d, %r9d
andl $0x3f, %r10d
orl %r9d, %r10d
movl $0x4, %edi
movl %r10d, %edx
movl %r10d, %eax
jmp 0x2a372
retq
movl $0x1, %edi
xorl %edx, %edx
movl $0x0, %eax
jmp 0x2a372