// File: /workspace/github_c_makefile_star2_O0/OnionIoT[P]lv_example/lvgl/src/lv_misc/lv_txt.c
// Function: lv_txt_get_next_word
static uint16_t lv_txt_get_next_word(const char * txt, const lv_font_t * font,
                              lv_coord_t letter_space, lv_coord_t max_width,
                              lv_txt_flag_t flag, uint32_t *word_w_ptr, lv_txt_cmd_state_t * cmd_state, bool force)
{
    if(txt == NULL || txt[0] == '\0') return 0;
    if(font == NULL) return 0;

    if(flag & LV_TXT_FLAG_EXPAND) max_width = LV_COORD_MAX;

    uint32_t i = 0, i_next = 0, i_next_next = 0;  /* Iterating index into txt */
    uint32_t letter = 0;      /* Letter at i */
    uint32_t letter_next = 0; /* Letter at i_next */
    lv_coord_t letter_w;
    lv_coord_t cur_w = 0;  /* Pixel Width of transversed string */
    uint32_t word_len = 0;   /* Number of characters in the transversed word */
    uint32_t break_index = NO_BREAK_FOUND; /* only used for "long" words */
    uint32_t break_letter_count = 0; /* Number of characters up to the long word break point */

    letter = lv_txt_encoded_next(txt, &i_next);
    i_next_next = i_next;

    /* Obtain the full word, regardless if it fits or not in max_width */
    while(txt[i] != '\0') {
        letter_next = lv_txt_encoded_next(txt, &i_next_next);
        word_len++;

        /*Handle the recolor command*/
        if((flag & LV_TXT_FLAG_RECOLOR) != 0) {
            if(lv_txt_is_cmd(cmd_state, letter) != false) {
                i = i_next;
                i_next = i_next_next;
                letter = letter_next;
                continue;   /*Skip the letter is it is part of a command*/
            }
        }

        letter_w = lv_font_get_glyph_width(font, letter, letter_next);
        cur_w += letter_w;

        /* Test if this character fits within max_width */
        if(break_index == NO_BREAK_FOUND && cur_w > max_width) {
            break_index = i; 
            break_letter_count = word_len - 1;
            /* break_index is now pointing at the character that doesn't fit */
        }

        /*Check for new line chars and breakchars*/
        if(letter == '\n' || letter == '\r' || is_break_char(letter)) {
            /* Update the output width on the first character if it fits.
             * Must do this here incase first letter is a break character. */
            if(i == 0 && break_index == NO_BREAK_FOUND && word_w_ptr != NULL) *word_w_ptr = cur_w;
            word_len--;
            break;
        }

        /* Update the output width */
        if( word_w_ptr != NULL && break_index == NO_BREAK_FOUND ) *word_w_ptr = cur_w;

        if(letter_w > 0) {
            cur_w += letter_space;
        }

        i = i_next;
        i_next = i_next_next;
        letter = letter_next;
    }

    /* Entire Word fits in the provided space */
    if( break_index == NO_BREAK_FOUND ) {
        if( word_len == 0 || (letter == '\r' && letter_next == '\n') ) i = i_next;
        return i;
    }

#if LV_TXT_LINE_BREAK_LONG_LEN > 0
    /* Word doesn't fit in provided space, but isn't "long" */
    if(word_len < LV_TXT_LINE_BREAK_LONG_LEN) {
        if( force ) return break_index;
        if(word_w_ptr != NULL) *word_w_ptr = 0; /* Return no word */
        return 0;
    }

    /* Word is "long," but insufficient amounts can fit in provided space */
    if(break_letter_count < LV_TXT_LINE_BREAK_LONG_PRE_MIN_LEN) {
        if( force ) return break_index;
        if(word_w_ptr != NULL) *word_w_ptr = 0;
        return 0;
    }

    /* Word is a "long", but letters may need to be better distributed */
    {
        i = break_index;
        int32_t n_move = LV_TXT_LINE_BREAK_LONG_POST_MIN_LEN - (word_len - break_letter_count);
        /* Move pointer "i" backwards */
        for(;n_move>0; n_move--){
            lv_txt_encoded_prev(txt, &i);
            // TODO: it would be appropriate to update the returned word width here
            // However, in current usage, this doesn't impact anything.
        }
    }
    return i;
#else
    if( force ) return break_index;
    if(word_w_ptr != NULL) *word_w_ptr = 0; /* Return no word */
    (void) break_letter_count;
    return 0;
#endif
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movl %r8d, -0x68(%rbp)
movl %ecx, %eax
movl -0x68(%rbp), %ecx
movl %eax, -0x64(%rbp)
movl %edx, %eax
movl -0x64(%rbp), %edx
movq %rsi, -0x60(%rbp)
movq %rdi, %r8
movq -0x60(%rbp), %rdi
movw %ax, %si
movb 0x18(%rbp), %al
movq 0x10(%rbp), %r10
movq %r8, -0x10(%rbp)
movq %rdi, -0x18(%rbp)
movw %si, -0x1a(%rbp)
movw %dx, -0x1c(%rbp)
movb %cl, -0x1d(%rbp)
movq %r9, -0x28(%rbp)
andb $0x1, %al
movb %al, -0x29(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x46d5d
movq -0x10(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0x46d68
movw $0x0, -0x2(%rbp)
jmp 0x46fde
cmpq $0x0, -0x18(%rbp)
jne 0x46d7a
movw $0x0, -0x2(%rbp)
jmp 0x46fde
movzbl -0x1d(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x46d8c
movw $0x7c18, -0x1c(%rbp)    # imm = 0x7C18
movl $0x0, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
movw $0x0, -0x44(%rbp)
movl $0x0, -0x48(%rbp)
movl $0xffffffff, -0x4c(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x50(%rbp)
movq 0x358ef(%rip), %rax     # 0x7c6c0
movq -0x10(%rbp), %rdi
leaq -0x34(%rbp), %rsi
callq *%rax
movl %eax, -0x3c(%rbp)
movl -0x34(%rbp), %eax
movl %eax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movl -0x30(%rbp), %ecx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
je 0x46f16
movq 0x358c1(%rip), %rax     # 0x7c6c0
movq -0x10(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq *%rax
movl %eax, -0x40(%rbp)
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
movzbl -0x1d(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x46e4d
movq 0x10(%rbp), %rdi
movl -0x3c(%rbp), %esi
callq 0x46ff0
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
je 0x46e4b
movl -0x34(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x38(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x40(%rbp), %eax
movl %eax, -0x3c(%rbp)
jmp 0x46de4
jmp 0x46e4d
movq -0x18(%rbp), %rdi
movl -0x3c(%rbp), %esi
movl -0x40(%rbp), %edx
callq 0x415e0
movw %ax, -0x42(%rbp)
movswl -0x42(%rbp), %ecx
movswl -0x44(%rbp), %eax
addl %ecx, %eax
movw %ax, -0x44(%rbp)
cmpl $-0x1, -0x4c(%rbp)
jne 0x46e8f
movswl -0x44(%rbp), %eax
movswl -0x1c(%rbp), %ecx
cmpl %ecx, %eax
jle 0x46e8f
movl -0x30(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl -0x48(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x50(%rbp)
cmpl $0xa, -0x3c(%rbp)
je 0x46ea9
cmpl $0xd, -0x3c(%rbp)
je 0x46ea9
movl -0x3c(%rbp), %edi
callq 0x471c0
testb $0x1, %al
jne 0x46ea9
jmp 0x46ed1
cmpl $0x0, -0x30(%rbp)
jne 0x46ec6
cmpl $-0x1, -0x4c(%rbp)
jne 0x46ec6
cmpq $0x0, -0x28(%rbp)
je 0x46ec6
movswl -0x44(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movl -0x48(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x46f16
cmpq $0x0, -0x28(%rbp)
je 0x46ee8
cmpl $-0x1, -0x4c(%rbp)
jne 0x46ee8
movswl -0x44(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movswl -0x42(%rbp), %eax
cmpl $0x0, %eax
jle 0x46eff
movswl -0x1a(%rbp), %ecx
movswl -0x44(%rbp), %eax
addl %ecx, %eax
movw %ax, -0x44(%rbp)
movl -0x34(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x38(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x40(%rbp), %eax
movl %eax, -0x3c(%rbp)
jmp 0x46de4
cmpl $-0x1, -0x4c(%rbp)
jne 0x46f40
cmpl $0x0, -0x48(%rbp)
je 0x46f2e
cmpl $0xd, -0x3c(%rbp)
jne 0x46f34
cmpl $0xa, -0x40(%rbp)
jne 0x46f34
movl -0x34(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
movw %ax, -0x2(%rbp)
jmp 0x46fde
cmpl $0xc, -0x48(%rbp)
jae 0x46f71
testb $0x1, -0x29(%rbp)
je 0x46f58
movl -0x4c(%rbp), %eax
movw %ax, -0x2(%rbp)
jmp 0x46fde
cmpq $0x0, -0x28(%rbp)
je 0x46f69
movq -0x28(%rbp), %rax
movl $0x0, (%rax)
movw $0x0, -0x2(%rbp)
jmp 0x46fde
cmpl $0x3, -0x50(%rbp)
jae 0x46f9f
testb $0x1, -0x29(%rbp)
je 0x46f86
movl -0x4c(%rbp), %eax
movw %ax, -0x2(%rbp)
jmp 0x46fde
cmpq $0x0, -0x28(%rbp)
je 0x46f97
movq -0x28(%rbp), %rax
movl $0x0, (%rax)
movw $0x0, -0x2(%rbp)
jmp 0x46fde
movl -0x4c(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x48(%rbp), %ecx
subl -0x50(%rbp), %ecx
movl $0x3, %eax
subl %ecx, %eax
movl %eax, -0x54(%rbp)
cmpl $0x0, -0x54(%rbp)
jle 0x46fd7
movq 0x35706(%rip), %rax     # 0x7c6c8
movq -0x10(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq *%rax
movl -0x54(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x46fb5
movl -0x30(%rbp), %eax
movw %ax, -0x2(%rbp)
movw -0x2(%rbp), %ax
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax,%rax)