// File: /workspace/github_c_makefile_star2_O0/OnionIoT[P]lv_example/lvgl/src/lv_objx/lv_sw.c
// Function: lv_sw_signal
static lv_res_t lv_sw_signal(lv_obj_t * sw, lv_signal_t sign, void * param)
{
    lv_sw_ext_t * ext = lv_obj_get_ext_attr(sw);

    /*Save the current (old) value before slider signal modifies it. It will be required in the
     * later calculations*/
    int16_t old_val;
    if(sign == LV_SIGNAL_PRESSING)
        old_val = ext->slider.drag_value;
    else
        old_val = lv_slider_get_value(sw);

    /*Don't let the slider to call the action. Switch handles it differently*/
    lv_event_cb_t event_cb = sw->event_cb;
    sw->event_cb           = NULL;

    lv_res_t res;
    /* Include the ancient signal function */

    res = ancestor_signal(sw, 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);

    sw->event_cb = event_cb;

    if(sign == LV_SIGNAL_CLEANUP) {
        /*Nothing to cleanup. (No dynamically allocated memory in 'ext')*/
    } else if(sign == LV_SIGNAL_PRESSED) {

        /*Save the x coordinate of the pressed point to see if the switch was slid*/
        lv_indev_t * indev = lv_indev_get_act();
        if(indev) {
            lv_point_t p;
            lv_indev_get_point(indev, &p);
            ext->start_x = p.x;
        }
        ext->slided  = 0;
        ext->changed = 0;
    } else if(sign == LV_SIGNAL_PRESSING) {
        /*See if the switch was slid (moved at least a little)*/
        lv_indev_t * indev = lv_indev_get_act();
        if(indev) {
            lv_point_t p = {0, 0};
            lv_indev_get_point(indev, &p);
            if(LV_MATH_ABS(p.x - ext->start_x) > LV_INDEV_DEF_DRAG_LIMIT) ext->slided = 1;
        }

        /*If didn't slide then revert the min/max value. So click without slide won't move the
         * switch as a slider*/
        if(ext->slided == 0) {
            if(lv_sw_get_state(sw))
                ext->slider.drag_value = LV_SW_MAX_VALUE;
            else
                ext->slider.drag_value = 0;
        }

        /*If explicitly changed (by slide) don't need to be toggled on release*/
        int16_t threshold = LV_SW_MAX_VALUE / 2;
        if((old_val < threshold && ext->slider.drag_value > threshold) ||
           (old_val > threshold && ext->slider.drag_value < threshold)) {
            ext->changed = 1;
        }
    } else if(sign == LV_SIGNAL_PRESS_LOST) {
        if(lv_sw_get_state(sw)) {
            lv_slider_set_style(sw, LV_SLIDER_STYLE_KNOB, ext->style_knob_on);
            lv_slider_set_value(sw, LV_SW_MAX_VALUE, LV_ANIM_ON);
            if(res != LV_RES_OK) return res;
        } else {
            lv_slider_set_style(sw, LV_SLIDER_STYLE_KNOB, ext->style_knob_off);
            lv_slider_set_value(sw, 0, LV_ANIM_ON);
            if(res != LV_RES_OK) return res;
        }
    } else if(sign == LV_SIGNAL_RELEASED) {
        /*If not dragged then toggle the switch*/
        if(ext->changed == 0) {
            int32_t state;
            if(lv_sw_get_state(sw)) {
                lv_sw_off(sw, LV_ANIM_ON);
                state = 0;
            } else {
                lv_sw_on(sw, LV_ANIM_ON);
                state = 1;
            }

            res = lv_event_send(sw, LV_EVENT_VALUE_CHANGED, &state);
            if(res != LV_RES_OK) return res;
        }
        /*If the switch was dragged then calculate the new state based on the current position*/
        else {
            int16_t v = lv_slider_get_value(sw);
            int32_t state;
            if(v > LV_SW_MAX_VALUE / 2) {
                lv_sw_on(sw, LV_ANIM_ON);
                state = 1;
            } else {
                lv_sw_off(sw, LV_ANIM_ON);
                state = 0;
            }
            res = lv_event_send(sw, LV_EVENT_VALUE_CHANGED, &state);
            if(res != LV_RES_OK) return res;
        }
    } else if(sign == LV_SIGNAL_CONTROL) {
        char c = *((char *)param);
        uint32_t state;
        if(c == LV_KEY_RIGHT || c == LV_KEY_UP) {
            lv_slider_set_value(sw, LV_SW_MAX_VALUE, true);
            state = 1;
            res   = lv_event_send(sw, LV_EVENT_VALUE_CHANGED, &state);
            if(res != LV_RES_OK) return res;
        } else if(c == LV_KEY_LEFT || c == LV_KEY_DOWN) {
            lv_slider_set_value(sw, 0, true);
            state = 0;
            res   = lv_event_send(sw, LV_EVENT_VALUE_CHANGED, &state);
            if(res != LV_RES_OK) return res;
        }
    } else if(sign == LV_SIGNAL_GET_EDITABLE) {
        bool * editable = (bool *)param;
        *editable       = false; /*The ancestor slider is editable the switch is not*/
    }

    return res;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movb %sil, %al
movq %rdi, -0x10(%rbp)
movb %al, -0x11(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rdi
callq 0xa8f0
movq %rax, -0x28(%rbp)
movzbl -0x11(%rbp), %eax
cmpl $0x9, %eax
jne 0x3f90d
movq -0x28(%rbp), %rax
movw 0x20(%rax), %ax
movw %ax, -0x2a(%rbp)
jmp 0x3f91a
movq -0x10(%rbp), %rdi
callq 0x30430
movw %ax, -0x2a(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq $0x0, 0x28(%rax)
movq 0x49c0f(%rip), %rax     # 0x89548
movq -0x10(%rbp), %rdi
movb -0x11(%rbp), %cl
movq -0x20(%rbp), %rdx
movzbl %cl, %esi
callq *%rax
movb %al, -0x39(%rbp)
movzbl -0x39(%rbp), %eax
cmpl $0x1, %eax
je 0x3f960
movb -0x39(%rbp), %al
movb %al, -0x1(%rbp)
jmp 0x3fd95
movzbl -0x11(%rbp), %eax
cmpl $0x7, %eax
jne 0x3f981
movq -0x20(%rbp), %rdi
leaq 0x28de4(%rip), %rsi     # 0x68758
callq 0xaa80
movb %al, -0x1(%rbp)
jmp 0x3fd95
movq -0x38(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x28(%rax)
movzbl -0x11(%rbp), %eax
cmpl $0x0, %eax
jne 0x3f99b
jmp 0x3fd8f
movzbl -0x11(%rbp), %eax
cmpl $0x8, %eax
jne 0x3f9f2
callq 0x4b70
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
je 0x3f9cd
movq -0x48(%rbp), %rdi
leaq -0x4c(%rbp), %rsi
callq 0x4d30
movw -0x4c(%rbp), %cx
movq -0x28(%rbp), %rax
movw %cx, 0x38(%rax)
movq -0x28(%rbp), %rax
movb 0x3a(%rax), %cl
andb $-0x3, %cl
orb $0x0, %cl
movb %cl, 0x3a(%rax)
movq -0x28(%rbp), %rax
movb 0x3a(%rax), %cl
andb $-0x2, %cl
orb $0x0, %cl
movb %cl, 0x3a(%rax)
jmp 0x3fd8d
movzbl -0x11(%rbp), %eax
cmpl $0x9, %eax
jne 0x3fb17
callq 0x4b70
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
je 0x3fa8a
leaq -0x5c(%rbp), %rdi
xorl %esi, %esi
movl $0x4, %edx
callq 0x2090
movq -0x58(%rbp), %rdi
leaq -0x5c(%rbp), %rsi
callq 0x4d30
movswl -0x5c(%rbp), %eax
movq -0x28(%rbp), %rcx
movswl 0x38(%rcx), %ecx
subl %ecx, %eax
cmpl $0x0, %eax
jle 0x3fa55
movswl -0x5c(%rbp), %eax
movq -0x28(%rbp), %rcx
movswl 0x38(%rcx), %ecx
subl %ecx, %eax
movl %eax, -0x84(%rbp)
jmp 0x3fa6d
movswl -0x5c(%rbp), %ecx
movq -0x28(%rbp), %rax
movswl 0x38(%rax), %eax
subl %eax, %ecx
xorl %eax, %eax
subl %ecx, %eax
movl %eax, -0x84(%rbp)
movl -0x84(%rbp), %eax
cmpl $0xa, %eax
jle 0x3fa88
movq -0x28(%rbp), %rax
movb 0x3a(%rax), %cl
andb $-0x3, %cl
orb $0x2, %cl
movb %cl, 0x3a(%rax)
jmp 0x3fa8a
movq -0x28(%rbp), %rax
movb 0x3a(%rax), %al
shrb %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x3fac4
movq -0x10(%rbp), %rdi
callq 0x3fef0
testb $0x1, %al
jne 0x3faac
jmp 0x3fab8
movq -0x28(%rbp), %rax
movw $0x64, 0x20(%rax)
jmp 0x3fac2
movq -0x28(%rbp), %rax
movw $0x0, 0x20(%rax)
jmp 0x3fac4
movw $0x32, -0x5e(%rbp)
movswl -0x2a(%rbp), %eax
movswl -0x5e(%rbp), %ecx
cmpl %ecx, %eax
jge 0x3fae6
movq -0x28(%rbp), %rax
movswl 0x20(%rax), %eax
movswl -0x5e(%rbp), %ecx
cmpl %ecx, %eax
jg 0x3fb02
movswl -0x2a(%rbp), %eax
movswl -0x5e(%rbp), %ecx
cmpl %ecx, %eax
jle 0x3fb12
movq -0x28(%rbp), %rax
movswl 0x20(%rax), %eax
movswl -0x5e(%rbp), %ecx
cmpl %ecx, %eax
jge 0x3fb12
movq -0x28(%rbp), %rax
movb 0x3a(%rax), %cl
andb $-0x2, %cl
orb $0x1, %cl
movb %cl, 0x3a(%rax)
jmp 0x3fd8b
movzbl -0x11(%rbp), %eax
cmpl $0xa, %eax
jne 0x3fbb3
movq -0x10(%rbp), %rdi
callq 0x3fef0
testb $0x1, %al
jne 0x3fb33
jmp 0x3fb72
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rdx
movl $0x2, %esi
callq 0x302e0
movq -0x10(%rbp), %rdi
movl $0x64, %esi
movl $0x1, %edx
callq 0x3ffa0
movzbl -0x39(%rbp), %eax
cmpl $0x1, %eax
je 0x3fb70
movb -0x39(%rbp), %al
movb %al, -0x1(%rbp)
jmp 0x3fd95
jmp 0x3fbae
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rax
movq 0x28(%rax), %rdx
movl $0x2, %esi
callq 0x302e0
movq -0x10(%rbp), %rdi
xorl %esi, %esi
movl $0x1, %edx
callq 0x3ffa0
movzbl -0x39(%rbp), %eax
cmpl $0x1, %eax
je 0x3fbac
movb -0x39(%rbp), %al
movb %al, -0x1(%rbp)
jmp 0x3fd95
jmp 0x3fbae
jmp 0x3fd89
movzbl -0x11(%rbp), %eax
cmpl $0xb, %eax
jne 0x3fca9
movq -0x28(%rbp), %rax
movb 0x3a(%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x3fc37
movq -0x10(%rbp), %rdi
callq 0x3fef0
testb $0x1, %al
jne 0x3fbe0
jmp 0x3fbf7
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0x3ffe0
movl $0x0, -0x64(%rbp)
jmp 0x3fc0c
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0x3ff30
movl $0x1, -0x64(%rbp)
movq -0x10(%rbp), %rdi
movl $0xe, %esi
leaq -0x64(%rbp), %rdx
callq 0x7990
movb %al, -0x39(%rbp)
movzbl -0x39(%rbp), %eax
cmpl $0x1, %eax
je 0x3fc35
movb -0x39(%rbp), %al
movb %al, -0x1(%rbp)
jmp 0x3fd95
jmp 0x3fca4
movq -0x10(%rbp), %rdi
callq 0x30430
movw %ax, -0x66(%rbp)
movswl -0x66(%rbp), %eax
cmpl $0x32, %eax
jle 0x3fc64
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0x3ff30
movl $0x1, -0x6c(%rbp)
jmp 0x3fc79
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0x3ffe0
movl $0x0, -0x6c(%rbp)
movq -0x10(%rbp), %rdi
movl $0xe, %esi
leaq -0x6c(%rbp), %rdx
callq 0x7990
movb %al, -0x39(%rbp)
movzbl -0x39(%rbp), %eax
cmpl $0x1, %eax
je 0x3fca2
movb -0x39(%rbp), %al
movb %al, -0x1(%rbp)
jmp 0x3fd95
jmp 0x3fca4
jmp 0x3fd87
movzbl -0x11(%rbp), %eax
cmpl $0x12, %eax
jne 0x3fd6b
movq -0x20(%rbp), %rax
movb (%rax), %al
movb %al, -0x6d(%rbp)
movsbl -0x6d(%rbp), %eax
cmpl $0x13, %eax
je 0x3fcd1
movsbl -0x6d(%rbp), %eax
cmpl $0x11, %eax
jne 0x3fd16
movq -0x10(%rbp), %rdi
movl $0x64, %esi
movl $0x1, %edx
callq 0x3ffa0
movl $0x1, -0x74(%rbp)
movq -0x10(%rbp), %rdi
movl $0xe, %esi
leaq -0x74(%rbp), %rdx
callq 0x7990
movb %al, -0x39(%rbp)
movzbl -0x39(%rbp), %eax
cmpl $0x1, %eax
je 0x3fd14
movb -0x39(%rbp), %al
movb %al, -0x1(%rbp)
jmp 0x3fd95
jmp 0x3fd69
movsbl -0x6d(%rbp), %eax
cmpl $0x14, %eax
je 0x3fd28
movsbl -0x6d(%rbp), %eax
cmpl $0x12, %eax
jne 0x3fd67
movq -0x10(%rbp), %rdi
xorl %esi, %esi
movl $0x1, %edx
callq 0x3ffa0
movl $0x0, -0x74(%rbp)
movq -0x10(%rbp), %rdi
movl $0xe, %esi
leaq -0x74(%rbp), %rdx
callq 0x7990
movb %al, -0x39(%rbp)
movzbl -0x39(%rbp), %eax
cmpl $0x1, %eax
je 0x3fd65
movb -0x39(%rbp), %al
movb %al, -0x1(%rbp)
jmp 0x3fd95
jmp 0x3fd67
jmp 0x3fd69
jmp 0x3fd85
movzbl -0x11(%rbp), %eax
cmpl $0x13, %eax
jne 0x3fd83
movq -0x20(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rax
movb $0x0, (%rax)
jmp 0x3fd85
jmp 0x3fd87
jmp 0x3fd89
jmp 0x3fd8b
jmp 0x3fd8d
jmp 0x3fd8f
movb -0x39(%rbp), %al
movb %al, -0x1(%rbp)
movb -0x1(%rbp), %al
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)