// File: /workspace/github_c_makefile_star2_O1/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
movq %rsi, (%rsp)
testb $0x1, 0x80(%rdi)
jne 0x29b2
movq %rdx, %r14
movq %rdi, %rbx
movq 0x18(%rdi), %r12
movb $0x1, %bpl
xorl %r15d, %r15d
testq %r12, %r12
je 0x28a6
movq %r12, %r13
jmp 0x28cd
testb $0x10, 0x80(%rbx)
jne 0x28b8
testq %r15, %r15
jne 0x29b2
testb $0x1, %bpl
je 0x29b2
movq %rbx, %rdi
callq *(%rsp)
movq %rax, %r13
xorl %ebp, %ebp
testq %r15, %r15
jne 0x28de
movq %r13, %r15
testq %r13, %r13
je 0x29b2
testq %r12, %r12
je 0x28f8
movq %rbx, %rdi
movq %r13, %rsi
callq *%r14
movq %rax, %r13
cmpq %r15, %rax
je 0x29b2
movl $0x0, %r12d
testq %r13, %r13
je 0x289c
movq (%r13), %rdi
callq 0x51ee
movq %r13, %r12
testb %al, %al
jne 0x289c
movq 0x18(%rbx), %rax
cmpq %rax, %r13
je 0x29b2
testq %rax, %rax
je 0x2955
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 0x4fea
cmpb $0x1, %al
jne 0x29b2
movq 0x18(%rbx), %rax
movq (%rax), %rdi
callq 0x4c36
movq %r13, 0x18(%rbx)
movq (%r13), %rdi
movl $0x10, %esi
xorl %edx, %edx
callq *0x30(%rdi)
movq 0x18(%rbx), %rax
movq (%rax), %rdi
movl $0xc, %esi
xorl %edx, %edx
callq 0x4fea
cmpb $0x1, %al
jne 0x29b2
movq 0x18(%rbx), %rax
movq (%rax), %rdi
callq 0x2829
movq 0x18(%rbx), %rax
movq (%rax), %rdi
callq 0x4c36
movq 0x30(%rbx), %rax
testq %rax, %rax
je 0x29b2
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