// File: /workspace/github_c_makefile_star2_O0/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:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x46369
leaq -0x20(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
movl (%rcx), %ecx
movsbl (%rax,%rcx), %eax
andl $0x80, %eax
cmpl $0x0, %eax
jne 0x463a2
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
movl (%rcx), %ecx
movsbl (%rax,%rcx), %eax
movl %eax, -0x1c(%rbp)
movq -0x18(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x46631
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
movl (%rcx), %ecx
movsbl (%rax,%rcx), %eax
andl $0xe0, %eax
cmpl $0xc0, %eax
jne 0x4642b
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
movl (%rcx), %ecx
movsbl (%rax,%rcx), %eax
andl $0x1f, %eax
shll $0x6, %eax
movl %eax, -0x1c(%rbp)
movq -0x18(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
movl (%rcx), %ecx
movsbl (%rax,%rcx), %eax
andl $0xc0, %eax
cmpl $0x80, %eax
je 0x46404
movl $0x0, -0x4(%rbp)
jmp 0x46637
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
movl (%rcx), %ecx
movsbl (%rax,%rcx), %eax
andl $0x3f, %eax
addl -0x1c(%rbp), %eax
movl %eax, -0x1c(%rbp)
movq -0x18(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x4662f
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
movl (%rcx), %ecx
movsbl (%rax,%rcx), %eax
andl $0xf0, %eax
cmpl $0xe0, %eax
jne 0x46503
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
movl (%rcx), %ecx
movsbl (%rax,%rcx), %eax
andl $0xf, %eax
shll $0xc, %eax
movl %eax, -0x1c(%rbp)
movq -0x18(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
movl (%rcx), %ecx
movsbl (%rax,%rcx), %eax
andl $0xc0, %eax
cmpl $0x80, %eax
je 0x46491
movl $0x0, -0x4(%rbp)
jmp 0x46637
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
movl (%rcx), %ecx
movsbl (%rax,%rcx), %eax
andl $0x3f, %eax
shll $0x6, %eax
addl -0x1c(%rbp), %eax
movl %eax, -0x1c(%rbp)
movq -0x18(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
movl (%rcx), %ecx
movsbl (%rax,%rcx), %eax
andl $0xc0, %eax
cmpl $0x80, %eax
je 0x464dc
movl $0x0, -0x4(%rbp)
jmp 0x46637
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
movl (%rcx), %ecx
movsbl (%rax,%rcx), %eax
andl $0x3f, %eax
addl -0x1c(%rbp), %eax
movl %eax, -0x1c(%rbp)
movq -0x18(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x4662d
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
movl (%rcx), %ecx
movsbl (%rax,%rcx), %eax
andl $0xf8, %eax
cmpl $0xf0, %eax
jne 0x46620
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
movl (%rcx), %ecx
movsbl (%rax,%rcx), %eax
andl $0x7, %eax
shll $0x12, %eax
movl %eax, -0x1c(%rbp)
movq -0x18(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
movl (%rcx), %ecx
movsbl (%rax,%rcx), %eax
andl $0xc0, %eax
cmpl $0x80, %eax
je 0x46569
movl $0x0, -0x4(%rbp)
jmp 0x46637
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
movl (%rcx), %ecx
movsbl (%rax,%rcx), %eax
andl $0x3f, %eax
shll $0xc, %eax
addl -0x1c(%rbp), %eax
movl %eax, -0x1c(%rbp)
movq -0x18(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
movl (%rcx), %ecx
movsbl (%rax,%rcx), %eax
andl $0xc0, %eax
cmpl $0x80, %eax
je 0x465b4
movl $0x0, -0x4(%rbp)
jmp 0x46637
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
movl (%rcx), %ecx
movsbl (%rax,%rcx), %eax
andl $0x3f, %eax
shll $0x6, %eax
addl -0x1c(%rbp), %eax
movl %eax, -0x1c(%rbp)
movq -0x18(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
movl (%rcx), %ecx
movsbl (%rax,%rcx), %eax
andl $0xc0, %eax
cmpl $0x80, %eax
je 0x465fc
movl $0x0, -0x4(%rbp)
jmp 0x46637
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
movl (%rcx), %ecx
movsbl (%rax,%rcx), %eax
andl $0x3f, %eax
addl -0x1c(%rbp), %eax
movl %eax, -0x1c(%rbp)
movq -0x18(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x4662b
movq -0x18(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x4662d
jmp 0x4662f
jmp 0x46631
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
popq %rbp
retq
nopl (%rax)