// File: /workspace/github_c_makefile_star2_O1/OnionIoT[P]lv_example/lv_drivers/display/fbdev.c
// Function: fbdev_flush
void fbdev_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_p)
{
    if(fbp == NULL ||
            area->x2 < 0 ||
            area->y2 < 0 ||
            area->x1 > (int32_t)vinfo.xres - 1 ||
            area->y1 > (int32_t)vinfo.yres - 1) {
        lv_disp_flush_ready(drv);
        return;
    }

    /*Truncate the area to the screen*/
    int32_t act_x1 = area->x1 < 0 ? 0 : area->x1;
    int32_t act_y1 = area->y1 < 0 ? 0 : area->y1;
    int32_t act_x2 = area->x2 > (int32_t)vinfo.xres - 1 ? (int32_t)vinfo.xres - 1 : area->x2;
    int32_t act_y2 = area->y2 > (int32_t)vinfo.yres - 1 ? (int32_t)vinfo.yres - 1 : area->y2;


    lv_coord_t w = lv_area_get_width(area);
    long int location = 0;
    long int byte_location = 0;
    unsigned char bit_location = 0;

    /*32 or 24 bit per pixel*/
    if(vinfo.bits_per_pixel == 32 || vinfo.bits_per_pixel == 24) {
        uint32_t * fbp32 = (uint32_t *)fbp;
        int32_t y;
        for(y = act_y1; y <= act_y2; y++) {
            location = (act_x1 + vinfo.xoffset) + (y + vinfo.yoffset) * finfo.line_length / 4;
            memcpy(&fbp32[location], (uint32_t *)color_p, (act_x2 - act_x1 + 1) * 4);
            color_p += w;
        }
    }
    /*16 bit per pixel*/
    else if(vinfo.bits_per_pixel == 16) {
        uint16_t * fbp16 = (uint16_t *)fbp;
        int32_t y;
        for(y = act_y1; y <= act_y2; y++) {
            location = (act_x1 + vinfo.xoffset) + (y + vinfo.yoffset) * finfo.line_length / 2;
            memcpy(&fbp16[location], (uint32_t *)color_p, (act_x2 - act_x1 + 1) * 2);
            color_p += w;
        }
    }
    /*8 bit per pixel*/
    else if(vinfo.bits_per_pixel == 8) {
        uint8_t * fbp8 = (uint8_t *)fbp;
        int32_t y;
        for(y = act_y1; y <= act_y2; y++) {
            location = (act_x1 + vinfo.xoffset) + (y + vinfo.yoffset) * finfo.line_length;
            memcpy(&fbp8[location], (uint32_t *)color_p, (act_x2 - act_x1 + 1));
            color_p += w;
        }
    }
    /*1 bit per pixel*/
    else if(vinfo.bits_per_pixel == 1) {
        uint8_t * fbp8 = (uint8_t *)fbp;
        int32_t x;
        int32_t y;
        for(y = act_y1; y <= act_y2; y++) {
            for(x = act_x1; x <= act_x2; x++) {
                location = (x + vinfo.xoffset) + (y + vinfo.yoffset) * vinfo.xres;
                byte_location = location / 8; /* find the byte we need to change */
                bit_location = location % 8; /* inside the byte found, find the bit we need to change */
                fbp8[byte_location] &= ~(((uint8_t)(1)) << bit_location);
                fbp8[byte_location] |= ((uint8_t)(color_p->full)) << bit_location;
                color_p++;
            }

            color_p += area->x2 - act_x2;
        }
    } else {
        /*Not supported bit per pixel*/
    }

    //May be some direct update command is required
    //ret = ioctl(state->fd, FBIO_UPDATE, (unsigned long)((uintptr_t)rect));

    lv_disp_flush_ready(drv);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %r14
movq 0x33523(%rip), %r12     # 0x71bf8
testq %r12, %r12
je 0x3e965
movswl 0x4(%rsi), %ecx
testl %ecx, %ecx
js 0x3e965
movq %rdx, %rbx
movswl 0x6(%rsi), %edx
testl %edx, %edx
js 0x3e965
movswl (%rsi), %edi
movl 0x3344d(%rip), %r8d     # 0x71b50
cmpl %edi, %r8d
jle 0x3e965
movswl 0x2(%rsi), %r13d
movl 0x3343c(%rip), %r9d     # 0x71b54
cmpl %r13d, %r9d
jle 0x3e965
xorl %eax, %eax
testw %di, %di
movl $0x0, %r11d
cmovgl %edi, %r11d
movl $0xffff, %r10d          # imm = 0xFFFF
andl %r10d, %r11d
testw %r13w, %r13w
cmovlel %eax, %r13d
andl %r10d, %r13d
leal -0x1(%r8), %eax
cmpl %ecx, %r8d
cmovgl %ecx, %eax
leal -0x1(%r9), %r8d
cmpl %edx, %r9d
cmovgl %edx, %r8d
subl %edi, %ecx
incl %ecx
movl 0x33405(%rip), %edx     # 0x71b68
cmpl $0xf, %edx
movl %r11d, 0xc(%rsp)
jle 0x3e7f6
cmpl $0x10, %edx
je 0x3e86d
cmpl $0x18, %edx
je 0x3e788
cmpl $0x20, %edx
jne 0x3e965
cmpl %r13d, %r8d
jl 0x3e965
subl %r11d, %eax
leal 0x4(,%rax,4), %eax
cltq
movq %rax, 0x10(%rsp)
movswq %cx, %rbp
addq %rbp, %rbp
incl %r8d
movl 0x333ae(%rip), %eax     # 0x71b60
movl 0x333ac(%rip), %ecx     # 0x71b64
addl %r13d, %ecx
imull 0x3336e(%rip), %ecx     # 0x71b30
addl %r11d, %eax
shrl $0x2, %ecx
addl %eax, %ecx
leaq (%r12,%rcx,4), %rdi
movq %rbx, %rsi
movq 0x10(%rsp), %rdx
movl %r8d, %r15d
callq 0x20f0
movl %r15d, %r8d
movl 0xc(%rsp), %r11d
incl %r13d
addq %rbp, %rbx
cmpl %r13d, %r15d
jne 0x3e7ac
jmp 0x3e965
cmpl $0x1, %edx
je 0x3e8da
cmpl $0x8, %edx
jne 0x3e965
cmpl %r13d, %r8d
jl 0x3e965
subl %r11d, %eax
incl %eax
cltq
movq %rax, 0x10(%rsp)
movswq %cx, %rbp
addq %rbp, %rbp
incl %r8d
movl 0x33333(%rip), %eax     # 0x71b60
addl %r11d, %eax
movl 0x3332e(%rip), %edi     # 0x71b64
addl %r13d, %edi
imull 0x332f0(%rip), %edi     # 0x71b30
addl %eax, %edi
addq %r12, %rdi
movq %rbx, %rsi
movq 0x10(%rsp), %rdx
movl %r8d, %r15d
callq 0x20f0
movl %r15d, %r8d
movl 0xc(%rsp), %r11d
incl %r13d
addq %rbp, %rbx
cmpl %r13d, %r15d
jne 0x3e827
jmp 0x3e965
cmpl %r13d, %r8d
jl 0x3e965
subl %r11d, %eax
leal 0x2(,%rax,2), %eax
cltq
movq %rax, 0x10(%rsp)
movswq %cx, %r15
addq %r15, %r15
incl %r8d
movl 0x332c9(%rip), %eax     # 0x71b60
movl 0x332c7(%rip), %ecx     # 0x71b64
addl %r13d, %ecx
imull 0x33289(%rip), %ecx     # 0x71b30
addl %r11d, %eax
shrl %ecx
addl %eax, %ecx
leaq (%r12,%rcx,2), %rdi
movq %rbx, %rsi
movq 0x10(%rsp), %rdx
movl %r8d, %ebp
callq 0x20f0
movl %ebp, %r8d
movl 0xc(%rsp), %r11d
incl %r13d
addq %r15, %rbx
cmpl %r13d, %ebp
jne 0x3e891
jmp 0x3e965
cmpl %r13d, %r8d
jl 0x3e965
leal 0x1(%rax), %edx
movslq %eax, %rdi
movl %r8d, %ebp
cmpl %r11d, %eax
jl 0x3e945
movl %r11d, %r8d
movl 0x3326a(%rip), %ecx     # 0x71b64
addl %r13d, %ecx
imull 0x3324c(%rip), %ecx     # 0x71b50
addl 0x33256(%rip), %ecx     # 0x71b60
addl %r8d, %ecx
movl %ecx, %r9d
andb $0x7, %cl
movl $0x1, %r10d
shll %cl, %r10d
shrl $0x3, %r9d
notb %r10b
andb (%r12,%r9), %r10b
movb %r10b, (%r12,%r9)
movzwl (%rbx), %r11d
shll %cl, %r11d
orb %r10b, %r11b
movb %r11b, (%r12,%r9)
addq $0x2, %rbx
incl %r8d
cmpl %r8d, %edx
jne 0x3e8f4
movswq 0x4(%rsi), %rcx
subq %rdi, %rcx
leaq (%rbx,%rcx,2), %rbx
leal 0x1(%r13), %ecx
movl %ebp, %r8d
cmpl %ebp, %r13d
movl %ecx, %r13d
movl 0xc(%rsp), %r11d
jne 0x3e8e9
movq %r14, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8637
nop