// File: /workspace/github_c_makefile_star2_O1/OnionIoT[P]lv_example/lvgl/src/lv_objx/lv_btn.c
// Function: lv_btn_signal
static lv_res_t lv_btn_signal(lv_obj_t * btn, lv_signal_t sign, void * param)
{
    lv_res_t res;

    /* Include the ancient signal function */
    res = ancestor_signal(btn, sign, param);
    if(res != LV_RES_OK) return res;
    if(sign == LV_SIGNAL_GET_TYPE) return lv_obj_handle_get_type_signal(param, LV_OBJX_NAME);

    lv_btn_ext_t * ext = lv_obj_get_ext_attr(btn);
    bool tgl           = lv_btn_get_toggle(btn);

    if(sign == LV_SIGNAL_PRESSED) {
        /*Refresh the state*/
        if(ext->state == LV_BTN_STATE_REL) {
            lv_btn_set_state(btn, LV_BTN_STATE_PR);
#if LV_USE_ANIMATION && LV_BTN_INK_EFFECT
            ink_bg_state  = LV_BTN_STATE_REL;
            ink_top_state = LV_BTN_STATE_PR;
#endif
        } else if(ext->state == LV_BTN_STATE_TGL_REL) {
            lv_btn_set_state(btn, LV_BTN_STATE_TGL_PR);
#if LV_USE_ANIMATION && LV_BTN_INK_EFFECT
            ink_bg_state  = LV_BTN_STATE_TGL_REL;
            ink_top_state = LV_BTN_STATE_TGL_PR;
#endif
        }

#if LV_USE_ANIMATION && LV_BTN_INK_EFFECT
        /*Forget the old inked button*/
        if(ink_obj != NULL && ink_obj != btn) {
            lv_anim_del(ink_obj, (lv_anim_exec_xcb_t)lv_btn_ink_effect_anim);
            lv_obj_invalidate(ink_obj);
            ink_obj = NULL;
        }
        /*Save the new data for inking and start it's animation if enabled*/
        if(ext->ink_in_time > 0) {
            ink_obj      = btn;
            ink_playback = false;
            ink_ready    = false;
            lv_indev_get_point(lv_indev_get_act(), &ink_point);

            lv_anim_t a;
            a.var            = btn;
            a.start          = 0;
            a.end            = LV_BTN_INK_VALUE_MAX;
            a.exec_cb        = (lv_anim_exec_xcb_t)lv_btn_ink_effect_anim;
            a.path_cb        = lv_anim_path_linear;
            a.ready_cb       = lv_btn_ink_effect_anim_ready;
            a.act_time       = 0;
            a.time           = ext->ink_in_time;
            a.playback       = 0;
            a.playback_pause = 0;
            a.repeat         = 0;
            a.repeat_pause   = 0;
            lv_anim_create(&a);
        }
#endif
    } else if(sign == LV_SIGNAL_PRESS_LOST) {
        /*Refresh the state*/
        if(ext->state == LV_BTN_STATE_PR)
            lv_btn_set_state(btn, LV_BTN_STATE_REL);
        else if(ext->state == LV_BTN_STATE_TGL_PR)
            lv_btn_set_state(btn, LV_BTN_STATE_TGL_REL);
    } else if(sign == LV_SIGNAL_PRESSING) {
        /*When the button begins to drag revert pressed states to released*/
        if(lv_indev_is_dragging(param) != false) {
            if(ext->state == LV_BTN_STATE_PR)
                lv_btn_set_state(btn, LV_BTN_STATE_REL);
            else if(ext->state == LV_BTN_STATE_TGL_PR)
                lv_btn_set_state(btn, LV_BTN_STATE_TGL_REL);
        }
    } else if(sign == LV_SIGNAL_RELEASED) {
        /*If not dragged and it was not long press action then
         *change state and run the action*/
        if(lv_indev_is_dragging(param) == false) {
            uint32_t toggled = 0;
            if(ext->state == LV_BTN_STATE_PR && tgl == false) {
                lv_btn_set_state(btn, LV_BTN_STATE_REL);
                toggled = 0;
            } else if(ext->state == LV_BTN_STATE_TGL_PR && tgl == false) {
                lv_btn_set_state(btn, LV_BTN_STATE_TGL_REL);
                toggled = 1;
            } else if(ext->state == LV_BTN_STATE_PR && tgl == true) {
                lv_btn_set_state(btn, LV_BTN_STATE_TGL_REL);
                toggled = 1;
            } else if(ext->state == LV_BTN_STATE_TGL_PR && tgl == true) {
                lv_btn_set_state(btn, LV_BTN_STATE_REL);
                toggled = 0;
            }

            if(tgl) {
                res = lv_event_send(btn, LV_EVENT_VALUE_CHANGED, &toggled);
                if(res != LV_RES_OK) return res;
            }

        } else { /*If dragged change back the state*/
            if(ext->state == LV_BTN_STATE_PR) {
                lv_btn_set_state(btn, LV_BTN_STATE_REL);
            } else if(ext->state == LV_BTN_STATE_TGL_PR) {
                lv_btn_set_state(btn, LV_BTN_STATE_TGL_REL);
            }
        }

#if LV_USE_ANIMATION && LV_BTN_INK_EFFECT
        /*Draw the toggled state in the inking instead*/
        if(ext->toggle) {
            ink_top_state = ext->state;
        }
        /*If not a toggle button and the "IN" inking is ready then start an "OUT" inking*/
        else if(ink_ready && ext->ink_out_time > 0) {
            ink_obj      = btn;
            ink_playback = true; /*It is the playback. If not set `lv_btn_ink_effect_anim_ready`
                                    will start its own playback*/
            lv_indev_get_point(lv_indev_get_act(), &ink_point);

            lv_anim_t a;
            a.var            = ink_obj;
            a.start          = LV_BTN_INK_VALUE_MAX;
            a.end            = 0;
            a.exec_cb        = (lv_anim_exec_xcb_t)lv_btn_ink_effect_anim;
            a.path_cb        = lv_anim_path_linear;
            a.ready_cb       = lv_btn_ink_effect_anim_ready;
            a.act_time       = 0;
            a.time           = ext->ink_out_time;
            a.playback       = 0;
            a.playback_pause = 0;
            a.repeat         = 0;
            a.repeat_pause   = 0;
            lv_anim_create(&a);
        }
#endif
    } else if(sign == LV_SIGNAL_CONTROL) {
        char c = *((char *)param);
        if(c == LV_KEY_RIGHT || c == LV_KEY_UP) {
            if(lv_btn_get_toggle(btn)) {
                lv_btn_set_state(btn, LV_BTN_STATE_TGL_REL);

                uint32_t state = 1;
                res            = lv_event_send(btn, LV_EVENT_VALUE_CHANGED, &state);
                if(res != LV_RES_OK) return res;
            }

        } else if(c == LV_KEY_LEFT || c == LV_KEY_DOWN) {
            if(lv_btn_get_toggle(btn)) {
                lv_btn_set_state(btn, LV_BTN_STATE_REL);

                uint32_t state = 0;
                res            = lv_event_send(btn, LV_EVENT_VALUE_CHANGED, &state);
                if(res != LV_RES_OK) return res;
            }
        }
    } else if(sign == LV_SIGNAL_CLEANUP) {
#if LV_USE_ANIMATION && LV_BTN_INK_EFFECT
        if(btn == ink_obj) {
            lv_anim_del(ink_obj, (lv_anim_exec_xcb_t)lv_btn_ink_effect_anim);
            ink_obj = NULL;
        }
#endif
    }

    return res;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %r15
movl %esi, %r13d
movq %rdi, %r14
callq *0x4d05e(%rip)          # 0x60360
movl %eax, %ebx
cmpb $0x1, %al
jne 0x134d7
cmpb $0x7, %r13b
jne 0x1332f
leaq 0x2c2df(%rip), %rsi     # 0x3f5f8
movq %r15, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x6bf5
movq %r14, %rdi
callq 0x6ad8
movq %rax, %r12
movq %r14, %rdi
callq 0x1370b
movl %eax, %ebp
movzbl %r13b, %eax
addl $-0x8, %eax
cmpl $0xa, %eax
ja 0x134d7
leaq 0x2c25d(%rip), %rcx     # 0x3f5b8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movzbl 0x30(%r12), %eax
andl $0x7, %eax
je 0x134ca
cmpl $0x2, %eax
jne 0x134d7
movb $0x3, %al
jmp 0x134cc
movq %r15, %rdi
callq 0x3863
testb %al, %al
jne 0x133a0
jmp 0x134d7
movq %r15, %rdi
callq 0x3863
testb %al, %al
je 0x1341d
movzbl 0x30(%r12), %eax
andl $0x7, %eax
cmpl $0x1, %eax
je 0x13416
cmpl $0x3, %eax
jne 0x134d7
movb $0x2, %al
jmp 0x134cc
movzbl (%r15), %eax
movl %eax, %ecx
andb $-0x3, %cl
cmpb $0x11, %cl
jne 0x13482
movq %r14, %rdi
callq 0x1370b
testb %al, %al
je 0x134c2
movq %r14, %rdi
movl $0x2, %esi
callq 0x135d2
leaq 0x14(%rsp), %rdx
movl $0x1, (%rdx)
movq %r14, %rdi
movl $0xe, %esi
callq 0x4fea
movl %eax, %ebx
cmpb $0x1, %al
je 0x134c2
xorl %ebp, %ebp
jmp 0x134c5
xorl %eax, %eax
jmp 0x134cc
movl $0x0, 0xc(%rsp)
movb 0x30(%r12), %al
andb $0x7, %al
cmpb $0x1, %al
setne %cl
orb %bpl, %cl
testb $0x1, %cl
je 0x1346e
cmpb $0x3, %al
setne %cl
orb %bpl, %cl
testb $0x1, %cl
je 0x134e8
cmpb $0x1, %al
setne %dl
movl %ebp, %ecx
xorb $0x1, %cl
orb %cl, %dl
testb $0x1, %dl
je 0x134e8
cmpb $0x3, %al
setne %al
orb %cl, %al
testb $0x1, %al
jne 0x134fd
movq %r14, %rdi
xorl %esi, %esi
callq 0x135d2
movl $0x0, 0xc(%rsp)
jmp 0x134fd
cmpl $0x14, %eax
je 0x1348c
cmpl $0x12, %eax
jne 0x134c2
movq %r14, %rdi
callq 0x1370b
testb %al, %al
je 0x134c2
xorl %ebp, %ebp
movq %r14, %rdi
xorl %esi, %esi
callq 0x135d2
leaq 0x10(%rsp), %rdx
movl $0x0, (%rdx)
movq %r14, %rdi
movl $0xe, %esi
callq 0x4fea
movl %eax, %ebx
cmpb $0x1, %al
jne 0x134c5
movb $0x1, %bpl
testb %bpl, %bpl
jmp 0x134d7
movb $0x1, %al
movzbl %al, %esi
movq %r14, %rdi
callq 0x135d2
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %rdi
movl $0x2, %esi
callq 0x135d2
movl $0x1, 0xc(%rsp)
testb %bpl, %bpl
je 0x1351d
leaq 0xc(%rsp), %rdx
movq %r14, %rdi
movl $0xe, %esi
callq 0x4fea
movl %eax, %ebx
cmpb $0x1, %al
sete %al
jmp 0x1351f
movb $0x1, %al
testb %al, %al
jmp 0x134d7