// File: /workspace/github_c_makefile_star2_O3/OnionIoT[P]lv_example/lvgl/src/lv_core/lv_group.c
// Function: focus_next_core
static void focus_next_core(lv_group_t * group, void * (*begin)(const lv_ll_t *),
                            void * (*move)(const lv_ll_t *, const void *))
{
    if(group->frozen) return;

    lv_obj_t ** obj_next     = group->obj_focus;
    lv_obj_t ** obj_sentinel = NULL;
    bool can_move            = true;
    bool can_begin           = true;

    for(;;) {
        if(obj_next == NULL) {
            if(group->wrap || obj_sentinel == NULL) {
                if(!can_begin) return;
                obj_next  = begin(&group->obj_ll);
                can_move  = false;
                can_begin = false;
            } else {
                /*Currently focused object is the last/first in the group, keep it that way*/
                return;
            }
        }

        if(obj_sentinel == NULL) {
            obj_sentinel = obj_next;
            if(obj_sentinel == NULL) return; /*Group is empty*/
        }

        if(can_move) {
            obj_next = move(&group->obj_ll, obj_next);

            /*Give up if we walked the entire list and haven't found another visible object*/
            if(obj_next == obj_sentinel) return;
        }

        can_move = true;

        if(obj_next == NULL) continue;

        /*Hidden objects don't receive focus*/
        if(!lv_obj_get_hidden(*obj_next)) break;
    }

    if(obj_next == group->obj_focus) return; /*There's only one visible object and it's already focused*/

    if(group->obj_focus) {
        (*group->obj_focus)->signal_cb(*group->obj_focus, LV_SIGNAL_DEFOCUS, NULL);
        lv_res_t res = lv_event_send(*group->obj_focus, LV_EVENT_DEFOCUSED, NULL);
        if(res != LV_RES_OK) return;
        lv_obj_invalidate(*group->obj_focus);
    }

    group->obj_focus = obj_next;

    (*group->obj_focus)->signal_cb(*group->obj_focus, LV_SIGNAL_FOCUS, NULL);
    lv_res_t res = lv_event_send(*group->obj_focus, LV_EVENT_FOCUSED, NULL);
    if(res != LV_RES_OK) return;

    /*If the object or its parent has `top == true` bring it to the foregorund*/
    obj_to_foreground(*group->obj_focus);

    lv_obj_invalidate(*group->obj_focus);

    if(group->focus_cb) group->focus_cb(group);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
testb $0x1, 0x80(%rdi)
jne 0x2998
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %rbx
movq 0x18(%rdi), %r14
movb $0x1, %bpl
xorl %r13d, %r13d
testq %r14, %r14
je 0x2893
movq %r14, %rsi
jmp 0x28bd
movb 0x80(%rbx), %al
andb $0x10, %al
shrb $0x4, %al
testq %r13, %r13
sete %cl
orb %al, %cl
andb %bpl, %cl
cmpb $0x1, %cl
jne 0x2998
movq %rbx, %rdi
callq *%r12
movq %rax, %rsi
xorl %ebp, %ebp
testq %r13, %r13
jne 0x28ce
movq %rsi, %r13
testq %rsi, %rsi
je 0x2998
testq %r14, %r14
je 0x28e6
movq %rbx, %rdi
callq *%r15
movq %rax, %r14
cmpq %r13, %rax
jne 0x28e9
jmp 0x2998
movq %rsi, %r14
testq %r14, %r14
je 0x2889
movq (%r14), %rdi
callq 0x51f2
testb %al, %al
jne 0x2889
movq 0x18(%rbx), %rax
cmpq %rax, %r14
je 0x2998
testq %rax, %rax
je 0x293c
movq (%rax), %rdi
movl $0x11, %esi
xorl %edx, %edx
callq *0x30(%rdi)
movq 0x18(%rbx), %rax
movq (%rax), %rdi
movl $0xd, %esi
xorl %edx, %edx
callq 0x5018
cmpb $0x1, %al
jne 0x2998
movq 0x18(%rbx), %rax
movq (%rax), %rdi
callq 0x4c4d
movq %r14, 0x18(%rbx)
movq (%r14), %rdi
movl $0x10, %esi
xorl %edx, %edx
callq *0x30(%rdi)
movq 0x18(%rbx), %rax
movq (%rax), %rdi
movl $0xc, %esi
xorl %edx, %edx
callq 0x5018
cmpb $0x1, %al
jne 0x2998
movq 0x18(%rbx), %rax
movq (%rax), %rdi
callq 0x281b
movq 0x18(%rbx), %rax
movq (%rax), %rdi
callq 0x4c4d
movq 0x30(%rbx), %rax
testq %rax, %rax
je 0x2998
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmpq *%rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq