// File: /workspace/github_c_makefile_star2_O2/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 0x283f5
movl (%rsi), %ecx
movsbl (%rdi,%rcx), %edx
testl %edx, %edx
js 0x283ff
incl %ecx
movl %ecx, (%rsi)
jmp 0x283fc
movsbl (%rdi), %edx
testl %edx, %edx
js 0x28417
movl %edx, %eax
retq
movl %edx, %eax
andl $0xe0, %eax
cmpl $0xc0, %eax
jne 0x28455
leal 0x1(%rcx), %eax
movl %eax, (%rsi)
addl $0x2, %ecx
jmp 0x2842b
movl %edx, %eax
andl $0xe0, %eax
cmpl $0xc0, %eax
jne 0x2846c
pushq $0x2
popq %rcx
pushq $0x1
popq %rax
movzbl (%rdi,%rax), %edi
movl %edi, %r8d
andl $-0x40, %r8d
xorl %eax, %eax
cmpl $0x80, %r8d
jne 0x283fe
andl $0x1f, %edx
shll $0x6, %edx
andl $0x3f, %edi
orl %edi, %edx
movl %edx, %eax
testq %rsi, %rsi
jne 0x283f1
jmp 0x283fe
movl %edx, %eax
andl $0xf0, %eax
cmpl $0xe0, %eax
jne 0x28500
leal 0x1(%rcx), %eax
jmp 0x2848c
movl %edx, %eax
andl $0xf0, %eax
cmpl $0xe0, %eax
jne 0x28517
xorl %ecx, %ecx
testq %rsi, %rsi
je 0x285f8
pushq $0x1
popq %rax
movl %eax, (%rsi)
movl %eax, %eax
movsbl (%rdi,%rax), %r8d
movl %r8d, %r9d
andl $0xc0, %r9d
xorl %eax, %eax
cmpl $0x80, %r9d
jne 0x283fe
leal 0x2(%rcx), %r9d
testq %rsi, %rsi
je 0x284ba
movl %r9d, (%rsi)
movl %r9d, %r9d
movzbl (%rdi,%r9), %edi
movl %edi, %r9d
andl $-0x40, %r9d
cmpl $0x80, %r9d
jne 0x283fe
shll $0xc, %edx
movzwl %dx, %eax
andl $0x3f, %r8d
shll $0x6, %r8d
orl %eax, %r8d
andl $0x3f, %edi
movl %edi, %edx
orl %r8d, %edx
testq %rsi, %rsi
je 0x283fc
addl $0x3, %ecx
jmp 0x283f1
movl %edx, %eax
andl $0xf8, %eax
cmpl $0xf0, %eax
jne 0x285ef
leal 0x1(%rcx), %eax
jmp 0x28537
movl %edx, %eax
andl $0xf8, %eax
xorl %ecx, %ecx
cmpl $0xf0, %eax
jne 0x285e1
testq %rsi, %rsi
je 0x28600
pushq $0x1
popq %rax
movl %eax, (%rsi)
movl %eax, %eax
movsbl (%rdi,%rax), %r8d
movl %r8d, %r9d
andl $0xc0, %r9d
xorl %eax, %eax
cmpl $0x80, %r9d
jne 0x283fe
leal 0x2(%rcx), %r9d
testq %rsi, %rsi
je 0x28565
movl %r9d, (%rsi)
movl %r9d, %r9d
movsbl (%rdi,%r9), %r9d
movl %r9d, %r10d
andl $0xc0, %r10d
cmpl $0x80, %r10d
jne 0x283fe
leal 0x3(%rcx), %r10d
testq %rsi, %rsi
je 0x28590
movl %r10d, (%rsi)
movl %r10d, %r10d
movzbl (%rdi,%r10), %edi
movl %edi, %r10d
andl $-0x40, %r10d
cmpl $0x80, %r10d
jne 0x283fe
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, %edi
movl %edi, %edx
orl %r9d, %edx
testq %rsi, %rsi
je 0x283fc
addl $0x4, %ecx
jmp 0x283f1
movl $0x0, %eax
testq %rsi, %rsi
je 0x283fe
incl %ecx
xorl %edx, %edx
jmp 0x283f1
pushq $0x1
popq %rax
jmp 0x28490
pushq $0x1
popq %rax
jmp 0x2853b