// File: /workspace/github_c_makefile_star2_O0/OnionIoT[P]lv_example/lvgl/src/lv_core/lv_refr.c
// Function: lv_disp_refr_task
void lv_disp_refr_task(lv_task_t * task)
{
    LV_LOG_TRACE("lv_refr_task: started");

    uint32_t start = lv_tick_get();

    disp_refr = task->user_data;

    lv_refr_join_area();

    lv_refr_areas();

    /*If refresh happened ...*/
    if(disp_refr->inv_p != 0) {
        /*In true double buffered mode copy the refreshed areas to the new VDB to keep it up to
         * date*/
        if(lv_disp_is_true_double_buf(disp_refr)) {
            lv_disp_buf_t * vdb = lv_disp_get_buf(disp_refr);

            /*Flush the content of the VDB*/
            lv_refr_vdb_flush();

            /* With true double buffering the flushing should be only the address change of the
             * current frame buffer. Wait until the address change is ready and copy the changed
             * content to the other frame buffer (new active VDB) to keep the buffers synchronized*/
            while(vdb->flushing)
                ;

            uint8_t * buf_act = (uint8_t *)vdb->buf_act;
            uint8_t * buf_ina = (uint8_t *)vdb->buf_act == vdb->buf1 ? vdb->buf2 : vdb->buf1;

            lv_coord_t hres = lv_disp_get_hor_res(disp_refr);
            uint16_t a;
            for(a = 0; a < disp_refr->inv_p; a++) {
                if(disp_refr->inv_area_joined[a] == 0) {
                    lv_coord_t y;
                    uint32_t start_offs =
                        (hres * disp_refr->inv_areas[a].y1 + disp_refr->inv_areas[a].x1) * sizeof(lv_color_t);
                    uint32_t line_length = lv_area_get_width(&disp_refr->inv_areas[a]) * sizeof(lv_color_t);

                    for(y = disp_refr->inv_areas[a].y1; y <= disp_refr->inv_areas[a].y2; y++) {
                        memcpy(buf_act + start_offs, buf_ina + start_offs, line_length);
                        start_offs += hres * sizeof(lv_color_t);
                    }
                }
            }
        } /*End of true double buffer handling*/

        /*Clean up*/
        memset(disp_refr->inv_areas, 0, sizeof(disp_refr->inv_areas));
        memset(disp_refr->inv_area_joined, 0, sizeof(disp_refr->inv_area_joined));
        disp_refr->inv_p = 0;

        /*Call monitor cb if present*/
        if(disp_refr->driver.monitor_cb) {
            disp_refr->driver.monitor_cb(&disp_refr->driver, lv_tick_elaps(start), px_num);
        }
    }

    lv_draw_free_buf();

    LV_LOG_TRACE("lv_refr_task: ready");
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
callq 0xdfe0
movl %eax, -0xc(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, 0x7e42d(%rip)     # 0x88f90
callq 0xb010
callq 0xb1c0
movq 0x7e41c(%rip), %rax     # 0x88f90
movw 0x198(%rax), %ax
andw $0x3ff, %ax             # imm = 0x3FF
movzwl %ax, %eax
cmpl $0x0, %eax
je 0xadc3
movq 0x7e3fe(%rip), %rdi     # 0x88f90
callq 0xdcd0
testb $0x1, %al
jne 0xaba0
jmp 0xad30
movq 0x7e3e9(%rip), %rdi     # 0x88f90
callq 0xdbd0
movq %rax, -0x18(%rbp)
callq 0xb280
movq -0x18(%rbp), %rax
movb 0x24(%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
je 0xabc8
jmp 0xabb5
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x18(%rbp), %rcx
cmpq (%rcx), %rax
jne 0xabf3
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x40(%rbp)
jmp 0xabfe
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x28(%rbp)
movq 0x7e383(%rip), %rdi     # 0x88f90
callq 0xd940
movw %ax, -0x2a(%rbp)
movw $0x0, -0x2c(%rbp)
movzwl -0x2c(%rbp), %eax
movq 0x7e369(%rip), %rcx     # 0x88f90
movw 0x198(%rcx), %cx
andw $0x3ff, %cx             # imm = 0x3FF
movzwl %cx, %ecx
cmpl %ecx, %eax
jge 0xad2e
movq 0x7e34b(%rip), %rax     # 0x88f90
movzwl -0x2c(%rbp), %ecx
movzbl 0x178(%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0xad1b
movswl -0x2a(%rbp), %eax
movq 0x7e32b(%rip), %rcx     # 0x88f90
movzwl -0x2c(%rbp), %edx
movswl 0x7a(%rcx,%rdx,8), %ecx
imull %ecx, %eax
movq 0x7e318(%rip), %rcx     # 0x88f90
movzwl -0x2c(%rbp), %edx
movswl 0x78(%rcx,%rdx,8), %ecx
addl %ecx, %eax
cltq
shlq %rax
movl %eax, -0x34(%rbp)
movq 0x7e2fe(%rip), %rdi     # 0x88f90
addq $0x78, %rdi
movzwl -0x2c(%rbp), %eax
shlq $0x3, %rax
addq %rax, %rdi
callq 0xb360
movswq %ax, %rax
shlq %rax
movl %eax, -0x38(%rbp)
movq 0x7e2d9(%rip), %rax     # 0x88f90
movzwl -0x2c(%rbp), %ecx
movw 0x7a(%rax,%rcx,8), %ax
movw %ax, -0x2e(%rbp)
movswl -0x2e(%rbp), %eax
movq 0x7e2c1(%rip), %rcx     # 0x88f90
movzwl -0x2c(%rbp), %edx
movswl 0x7e(%rcx,%rdx,8), %ecx
cmpl %ecx, %eax
jg 0xad19
movq -0x20(%rbp), %rdi
movl -0x34(%rbp), %eax
addq %rax, %rdi
movq -0x28(%rbp), %rsi
movl -0x34(%rbp), %eax
addq %rax, %rsi
movl -0x38(%rbp), %eax
movl %eax, %edx
callq 0x20e0
movswq -0x2a(%rbp), %rcx
shlq %rcx
movl -0x34(%rbp), %eax
addq %rcx, %rax
movl %eax, -0x34(%rbp)
movw -0x2e(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x2e(%rbp)
jmp 0xacc4
jmp 0xad1b
jmp 0xad1d
movw -0x2c(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x2c(%rbp)
jmp 0xac1c
jmp 0xad30
movq 0x7e259(%rip), %rdi     # 0x88f90
addq $0x78, %rdi
xorl %esi, %esi
movl $0x100, %edx            # imm = 0x100
callq 0x2090
movq 0x7e242(%rip), %rdi     # 0x88f90
addq $0x178, %rdi            # imm = 0x178
xorl %esi, %esi
movl $0x20, %edx
callq 0x2090
movq 0x7e228(%rip), %rax     # 0x88f90
movw 0x198(%rax), %cx
andw $0xfc00, %cx            # imm = 0xFC00
orw $0x0, %cx
movw %cx, 0x198(%rax)
movq 0x7e20a(%rip), %rax     # 0x88f90
cmpq $0x0, 0x30(%rax)
je 0xadc1
movq 0x7e1fc(%rip), %rax     # 0x88f90
movq 0x30(%rax), %rax
movq %rax, -0x48(%rbp)
movq 0x7e1ed(%rip), %rax     # 0x88f90
movq %rax, -0x50(%rbp)
movl -0xc(%rbp), %edi
callq 0xe010
movq -0x50(%rbp), %rdi
movl %eax, %esi
movq -0x48(%rbp), %rax
movl 0x7e1d9(%rip), %edx     # 0x88f98
callq *%rax
jmp 0xadc3
callq 0x5a7a0
addq $0x50, %rsp
popq %rbp
retq
nop