// File: /workspace/github_c_makefile_star2_O2/OnionIoT[P]lv_example/lvgl/src/lv_core/lv_indev.c
// Function: indev_drag_throw
static void indev_drag_throw(lv_indev_proc_t * proc)
{
    if(proc->types.pointer.drag_in_prog == 0) return;

    lv_obj_t * drag_obj = proc->types.pointer.last_obj;

    /*If drag parent is active check recursively the drag_parent attribute*/
    while(lv_obj_get_drag_parent(drag_obj) != false && drag_obj != NULL) {
        drag_obj = lv_obj_get_parent(drag_obj);
    }

    if(drag_obj == NULL) {
        return;
    }

    /*Return if the drag throw is not enabled*/
    if(lv_obj_get_drag_throw(drag_obj) == false) {
        proc->types.pointer.drag_in_prog = 0;
        drag_obj->signal_cb(drag_obj, LV_SIGNAL_DRAG_END, indev_act);
        lv_event_send(drag_obj, LV_EVENT_DRAG_END, NULL);
        if(indev_reset_check(proc)) return;

        lv_event_send(drag_obj, LV_EVENT_DRAG_END, NULL);
        return;
    }

    lv_drag_dir_t allowed_dirs = lv_obj_get_drag_dir(drag_obj);

    /*Reduce the vectors*/
    proc->types.pointer.drag_throw_vect.x =
        proc->types.pointer.drag_throw_vect.x * (100 - indev_act->driver.drag_throw) / 100;
    proc->types.pointer.drag_throw_vect.y =
        proc->types.pointer.drag_throw_vect.y * (100 - indev_act->driver.drag_throw) / 100;

    if(proc->types.pointer.drag_throw_vect.x != 0 || proc->types.pointer.drag_throw_vect.y != 0) {
        /*Get the coordinates and modify them*/
        lv_area_t coords_ori;
        lv_obj_get_coords(drag_obj, &coords_ori);
        lv_coord_t act_x = lv_obj_get_x(drag_obj) + proc->types.pointer.drag_throw_vect.x;
        lv_coord_t act_y = lv_obj_get_y(drag_obj) + proc->types.pointer.drag_throw_vect.y;

        if(allowed_dirs == LV_DRAG_DIR_ALL)
            lv_obj_set_pos(drag_obj, act_x, act_y);
        else if(allowed_dirs & LV_DRAG_DIR_HOR)
            lv_obj_set_x(drag_obj, act_x);
        else if(allowed_dirs & LV_DRAG_DIR_VER)
            lv_obj_set_y(drag_obj, act_y);

        lv_area_t coord_new;
        lv_obj_get_coords(drag_obj, &coord_new);

        /*If non of the coordinates are changed then do not continue throwing*/
        if((coords_ori.x1 == coord_new.x1 || proc->types.pointer.drag_throw_vect.x == 0) &&
           (coords_ori.y1 == coord_new.y1 || proc->types.pointer.drag_throw_vect.y == 0)) {
            proc->types.pointer.drag_in_prog      = 0;
            proc->types.pointer.vect.x            = 0;
            proc->types.pointer.vect.y            = 0;
            proc->types.pointer.drag_throw_vect.x = 0;
            proc->types.pointer.drag_throw_vect.y = 0;
            drag_obj->signal_cb(drag_obj, LV_SIGNAL_DRAG_END, indev_act);
            if(indev_reset_check(proc)) return;
            lv_event_send(drag_obj, LV_EVENT_DRAG_END, NULL);
            if(indev_reset_check(proc)) return;
        }
    }
    /*If the types.pointer.vectors become 0 -> types.pointer.drag_in_prog = 0 and send a drag end
       signal*/
    else {
        proc->types.pointer.drag_in_prog = 0;
        drag_obj->signal_cb(drag_obj, LV_SIGNAL_DRAG_END, indev_act);
        if(indev_reset_check(proc)) return;
        lv_event_send(drag_obj, LV_EVENT_DRAG_END, NULL);
        if(indev_reset_check(proc)) return;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x18, %rsp
testb $0x2, 0x38(%rdi)
je 0x4135
movq %rdi, %rbx
movq 0x28(%rdi), %r14
movq %r14, %rdi
callq 0x65f2
testb %al, %al
je 0x3fa3
testq %r14, %r14
je 0x3fa3
movq %r14, %rdi
callq 0x47bc
movq %rax, %r14
jmp 0x3f85
testq %r14, %r14
je 0x4135
movq %r14, %rdi
callq 0x65ca
testb %al, %al
je 0x401a
movq %r14, %rdi
callq 0x65a5
movl %eax, %ebp
movswl 0x18(%rbx), %edx
movq 0x59ecb(%rip), %rcx     # 0x5de98
movzbl 0x29(%rcx), %esi
pushq $0x64
popq %rdi
movl %edi, %eax
subl %esi, %eax
imull %edx, %eax
cltd
idivl %edi
movl %eax, %esi
movw %si, 0x18(%rbx)
movswl 0x1a(%rbx), %edx
movzbl 0x29(%rcx), %r8d
movl %edi, %eax
subl %r8d, %eax
imull %edx, %eax
cltd
idivl %edi
movw %ax, 0x1a(%rbx)
testw %si, %si
jne 0x405d
movzwl %ax, %eax
testl %eax, %eax
jne 0x405d
andb $-0x3, 0x38(%rbx)
pushq $0xf
popq %rsi
movq %r14, %rdi
movq %rcx, %rdx
jmp 0x4110
andb $-0x3, 0x38(%rbx)
movq 0x59e73(%rip), %rdx     # 0x5de98
pushq $0xf
popq %rsi
movq %r14, %rdi
callq *0x30(%r14)
pushq $0x9
popq %rsi
movq %r14, %rdi
xorl %edx, %edx
callq 0x4caf
testb $0x2, 0x48(%rbx)
jne 0x412d
pushq $0x9
popq %rsi
movq %r14, %rdi
xorl %edx, %edx
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x4caf
leaq 0x8(%rsp), %rsi
movq %r14, %rdi
callq 0x50e5
movq %r14, %rdi
callq 0x48ca
movl %eax, %r15d
addw 0x18(%rbx), %r15w
movq %r14, %rdi
callq 0x4902
addw 0x1a(%rbx), %ax
cmpb $0x3, %bpl
jne 0x409d
movswl %r15w, %esi
movswl %ax, %edx
movq %r14, %rdi
callq 0x47df
jmp 0x40c2
testb $0x1, %bpl
jne 0x40b6
testb $0x2, %bpl
je 0x40c2
movswl %ax, %esi
movq %r14, %rdi
callq 0x51d0
jmp 0x40c2
movswl %r15w, %esi
movq %r14, %rdi
callq 0x5192
leaq 0x10(%rsp), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x50e5
movzwl 0x8(%rsp), %eax
cmpw (%r15), %ax
je 0x40e4
cmpw $0x0, 0x18(%rbx)
jne 0x4135
movzwl 0xa(%rsp), %eax
cmpw 0x12(%rsp), %ax
je 0x40f7
cmpw $0x0, 0x1a(%rbx)
jne 0x4135
andb $-0x3, 0x38(%rbx)
andl $0x0, 0x10(%rbx)
andl $0x0, 0x18(%rbx)
movq 0x59d8e(%rip), %rdx     # 0x5de98
pushq $0xf
popq %rsi
movq %r14, %rdi
callq *0x30(%r14)
testb $0x2, 0x48(%rbx)
jne 0x412d
pushq $0x9
popq %rsi
movq %r14, %rdi
xorl %edx, %edx
callq 0x4caf
testb $0x2, 0x48(%rbx)
je 0x4135
andq $0x0, 0x59d6b(%rip)     # 0x5dea0
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq