// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
cmpq $0x0, 0x34031(%rip)     # 0x9acd0
je 0x66ce4
movq -0x10(%rbp), %rax
movswl 0x4(%rax), %eax
cmpl $0x0, %eax
jl 0x66ce4
movq -0x10(%rbp), %rax
movswl 0x6(%rax), %eax
cmpl $0x0, %eax
jl 0x66ce4
movq -0x10(%rbp), %rax
movswl (%rax), %eax
movl 0x33f60(%rip), %ecx     # 0x9ac28
subl $0x1, %ecx
cmpl %ecx, %eax
jg 0x66ce4
movq -0x10(%rbp), %rax
movswl 0x2(%rax), %eax
movl 0x33f4f(%rip), %ecx     # 0x9ac2c
subl $0x1, %ecx
cmpl %ecx, %eax
jle 0x66cf2
movq -0x8(%rbp), %rdi
callq 0xdb60
jmp 0x670d5
movq -0x10(%rbp), %rax
movswl (%rax), %eax
cmpl $0x0, %eax
jge 0x66d08
xorl %eax, %eax
movl %eax, -0x8c(%rbp)
jmp 0x66d15
movq -0x10(%rbp), %rax
movswl (%rax), %eax
movl %eax, -0x8c(%rbp)
movl -0x8c(%rbp), %eax
movl %eax, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movswl 0x2(%rax), %eax
cmpl $0x0, %eax
jge 0x66d35
xorl %eax, %eax
movl %eax, -0x90(%rbp)
jmp 0x66d43
movq -0x10(%rbp), %rax
movswl 0x2(%rax), %eax
movl %eax, -0x90(%rbp)
movl -0x90(%rbp), %eax
movl %eax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movswl 0x4(%rax), %eax
movl 0x33ece(%rip), %ecx     # 0x9ac28
subl $0x1, %ecx
cmpl %ecx, %eax
jle 0x66d72
movl 0x33ec1(%rip), %eax     # 0x9ac28
subl $0x1, %eax
movl %eax, -0x94(%rbp)
jmp 0x66d80
movq -0x10(%rbp), %rax
movswl 0x4(%rax), %eax
movl %eax, -0x94(%rbp)
movl -0x94(%rbp), %eax
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rax
movswl 0x6(%rax), %eax
movl 0x33e95(%rip), %ecx     # 0x9ac2c
subl $0x1, %ecx
cmpl %ecx, %eax
jle 0x66daf
movl 0x33e88(%rip), %eax     # 0x9ac2c
subl $0x1, %eax
movl %eax, -0x98(%rbp)
jmp 0x66dbd
movq -0x10(%rbp), %rax
movswl 0x6(%rax), %eax
movl %eax, -0x98(%rbp)
movl -0x98(%rbp), %eax
movl %eax, -0x28(%rbp)
movq -0x10(%rbp), %rdi
callq 0x670e0
movw %ax, -0x2a(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movb $0x0, -0x41(%rbp)
cmpl $0x20, 0x33e52(%rip)    # 0x9ac40
je 0x66dfd
cmpl $0x18, 0x33e49(%rip)    # 0x9ac40
jne 0x66e86
movq 0x33ecc(%rip), %rax     # 0x9acd0
movq %rax, -0x50(%rbp)
movl -0x20(%rbp), %eax
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %eax
cmpl -0x28(%rbp), %eax
jg 0x66e81
movl -0x1c(%rbp), %eax
addl 0x33e19(%rip), %eax     # 0x9ac38
movl -0x54(%rbp), %ecx
addl 0x33e14(%rip), %ecx     # 0x9ac3c
imull 0x33dd9(%rip), %ecx     # 0x9ac08
shrl $0x2, %ecx
addl %ecx, %eax
movl %eax, %eax
movq %rax, -0x38(%rbp)
movq -0x50(%rbp), %rdi
movq -0x38(%rbp), %rax
shlq $0x2, %rax
addq %rax, %rdi
movq -0x18(%rbp), %rsi
movl -0x24(%rbp), %eax
subl -0x1c(%rbp), %eax
addl $0x1, %eax
shll $0x2, %eax
movslq %eax, %rdx
callq 0x20e0
movswl -0x2a(%rbp), %ecx
movq -0x18(%rbp), %rax
movslq %ecx, %rcx
shlq %rcx
addq %rcx, %rax
movq %rax, -0x18(%rbp)
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x66e0e
jmp 0x670cc
cmpl $0x10, 0x33db3(%rip)    # 0x9ac40
jne 0x66f19
movq 0x33e36(%rip), %rax     # 0x9acd0
movq %rax, -0x60(%rbp)
movl -0x20(%rbp), %eax
movl %eax, -0x64(%rbp)
movl -0x64(%rbp), %eax
cmpl -0x28(%rbp), %eax
jg 0x66f14
movl -0x1c(%rbp), %eax
addl 0x33d83(%rip), %eax     # 0x9ac38
movl -0x64(%rbp), %ecx
addl 0x33d7e(%rip), %ecx     # 0x9ac3c
imull 0x33d43(%rip), %ecx     # 0x9ac08
shrl %ecx
addl %ecx, %eax
movl %eax, %eax
movq %rax, -0x38(%rbp)
movq -0x60(%rbp), %rdi
movq -0x38(%rbp), %rax
shlq %rax
addq %rax, %rdi
movq -0x18(%rbp), %rsi
movl -0x24(%rbp), %eax
subl -0x1c(%rbp), %eax
addl $0x1, %eax
shll %eax
movslq %eax, %rdx
callq 0x20e0
movswl -0x2a(%rbp), %ecx
movq -0x18(%rbp), %rax
movslq %ecx, %rcx
shlq %rcx
addq %rcx, %rax
movq %rax, -0x18(%rbp)
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x66ea4
jmp 0x670ca
cmpl $0x8, 0x33d20(%rip)     # 0x9ac40
jne 0x66f9e
movq 0x33da7(%rip), %rax     # 0x9acd0
movq %rax, -0x70(%rbp)
movl -0x20(%rbp), %eax
movl %eax, -0x74(%rbp)
movl -0x74(%rbp), %eax
cmpl -0x28(%rbp), %eax
jg 0x66f99
movl -0x1c(%rbp), %eax
addl 0x33cf4(%rip), %eax     # 0x9ac38
movl -0x74(%rbp), %ecx
addl 0x33cef(%rip), %ecx     # 0x9ac3c
imull 0x33cb4(%rip), %ecx     # 0x9ac08
addl %ecx, %eax
movl %eax, %eax
movq %rax, -0x38(%rbp)
movq -0x70(%rbp), %rdi
addq -0x38(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x24(%rbp), %eax
subl -0x1c(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rdx
callq 0x20e0
movswl -0x2a(%rbp), %ecx
movq -0x18(%rbp), %rax
movslq %ecx, %rcx
shlq %rcx
addq %rcx, %rax
movq %rax, -0x18(%rbp)
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0x66f33
jmp 0x670c8
cmpl $0x1, 0x33c9b(%rip)     # 0x9ac40
jne 0x670c4
movq 0x33d1e(%rip), %rax     # 0x9acd0
movq %rax, -0x80(%rbp)
movl -0x20(%rbp), %eax
movl %eax, -0x88(%rbp)
movl -0x88(%rbp), %eax
cmpl -0x28(%rbp), %eax
jg 0x670c2
movl -0x1c(%rbp), %eax
movl %eax, -0x84(%rbp)
movl -0x84(%rbp), %eax
cmpl -0x24(%rbp), %eax
jg 0x67092
movl -0x84(%rbp), %eax
addl 0x33c46(%rip), %eax     # 0x9ac38
movl -0x88(%rbp), %ecx
addl 0x33c3e(%rip), %ecx     # 0x9ac3c
imull 0x33c23(%rip), %ecx     # 0x9ac28
addl %ecx, %eax
movl %eax, %eax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movl $0x8, %ecx
cqto
idivq %rcx
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rax
movl $0x8, %ecx
cqto
idivq %rcx
movb %dl, %al
movb %al, -0x41(%rbp)
movzbl -0x41(%rbp), %ecx
movl $0x1, %esi
shll %cl, %esi
xorl $-0x1, %esi
movq -0x80(%rbp), %rax
movq -0x40(%rbp), %rcx
movzbl (%rax,%rcx), %edx
andl %esi, %edx
movb %dl, (%rax,%rcx)
movq -0x18(%rbp), %rax
movw (%rax), %ax
movzbl %al, %esi
movzbl -0x41(%rbp), %ecx
shll %cl, %esi
movq -0x80(%rbp), %rax
movq -0x40(%rbp), %rcx
movzbl (%rax,%rcx), %edx
orl %esi, %edx
movb %dl, (%rax,%rcx)
movq -0x18(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x18(%rbp)
movl -0x84(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x84(%rbp)
jmp 0x66fd7
movq -0x10(%rbp), %rax
movswl 0x4(%rax), %ecx
subl -0x24(%rbp), %ecx
movq -0x18(%rbp), %rax
movslq %ecx, %rcx
shlq %rcx
addq %rcx, %rax
movq %rax, -0x18(%rbp)
movl -0x88(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x88(%rbp)
jmp 0x66fbf
jmp 0x670c6
jmp 0x670c6
jmp 0x670c8
jmp 0x670ca
jmp 0x670cc
movq -0x8(%rbp), %rdi
callq 0xdb60
addq $0xa0, %rsp
popq %rbp
retq
nop