// File: /workspace/github_c_makefile_star2_O0/OnionIoT[P]lv_example/lvgl/src/lv_draw/lv_draw_basic.c
// Function: lv_draw_map
void lv_draw_map(const lv_area_t * cords_p, const lv_area_t * mask_p, const uint8_t * map_p, lv_opa_t opa,
                 bool chroma_key, bool alpha_byte, lv_color_t recolor, lv_opa_t recolor_opa)
{

    if(opa < LV_OPA_MIN) return;
    if(opa > LV_OPA_MAX) opa = LV_OPA_COVER;

    lv_area_t masked_a;
    bool union_ok;

    /*Get the union of map size and mask*/
    /* The mask is already truncated to the vdb size
     * in 'lv_refr_area_with_vdb' function */
    union_ok = lv_area_intersect(&masked_a, cords_p, mask_p);

    /*If there are common part of the three area then draw to the vdb*/
    if(union_ok == false) return;

    /*The pixel size in byte is different if an alpha byte is added too*/
    uint8_t px_size_byte = alpha_byte ? LV_IMG_PX_SIZE_ALPHA_BYTE : sizeof(lv_color_t);

    /*If the map starts OUT of the masked area then calc. the first pixel*/
    lv_coord_t map_width = lv_area_get_width(cords_p);
    if(cords_p->y1 < masked_a.y1) {
        map_p += (uint32_t)map_width * ((masked_a.y1 - cords_p->y1)) * px_size_byte;
    }
    if(cords_p->x1 < masked_a.x1) {
        map_p += (masked_a.x1 - cords_p->x1) * px_size_byte;
    }

    lv_disp_t * disp    = lv_refr_get_disp_refreshing();
    lv_disp_buf_t * vdb = lv_disp_get_buf(disp);

    /*Stores coordinates relative to the current VDB*/
    masked_a.x1 = masked_a.x1 - vdb->area.x1;
    masked_a.y1 = masked_a.y1 - vdb->area.y1;
    masked_a.x2 = masked_a.x2 - vdb->area.x1;
    masked_a.y2 = masked_a.y2 - vdb->area.y1;

    lv_coord_t vdb_width     = lv_area_get_width(&vdb->area);
    lv_color_t * vdb_buf_tmp = vdb->buf_act;
    vdb_buf_tmp += (uint32_t)vdb_width * masked_a.y1; /*Move to the first row*/
    vdb_buf_tmp += (uint32_t)masked_a.x1;             /*Move to the first col*/

    lv_coord_t row;
    lv_coord_t map_useful_w = lv_area_get_width(&masked_a);

    bool scr_transp = false;
#if LV_COLOR_DEPTH == 32 && LV_COLOR_SCREEN_TRANSP
    scr_transp = disp->driver.screen_transp;
#endif

    /*The simplest case just copy the pixels into the VDB*/
    if(chroma_key == false && alpha_byte == false && opa == LV_OPA_COVER && recolor_opa == LV_OPA_TRANSP) {

        /*Use the custom VDB write function is exists*/
        if(disp->driver.set_px_cb) {
            lv_coord_t col;
            for(row = masked_a.y1; row <= masked_a.y2; row++) {
                for(col = 0; col < map_useful_w; col++) {
                    lv_color_t px_color = *((lv_color_t *)&map_p[(uint32_t)col * px_size_byte]);
                    disp->driver.set_px_cb(&disp->driver, (uint8_t *)vdb->buf_act, vdb_width, col + masked_a.x1, row,
                                           px_color, opa);
                }
                map_p += map_width * px_size_byte; /*Next row on the map*/
            }
        }
        /*Normal native VDB*/
        else {
            for(row = masked_a.y1; row <= masked_a.y2; row++) {
#if LV_USE_GPU
                if(disp->driver.gpu_blend_cb == false) {
                    sw_mem_blend(vdb_buf_tmp, (lv_color_t *)map_p, map_useful_w, opa);
                } else {
                    disp->driver.gpu_blend_cb(&disp->driver, vdb_buf_tmp, (lv_color_t *)map_p, map_useful_w, opa);
                }
#else
                sw_mem_blend(vdb_buf_tmp, (lv_color_t *)map_p, map_useful_w, opa);
#endif
                map_p += map_width * px_size_byte; /*Next row on the map*/
                vdb_buf_tmp += vdb_width;          /*Next row on the VDB*/
            }
        }
    }

    /*In the other cases every pixel need to be checked one-by-one*/
    else {

        lv_coord_t col;
        lv_color_t last_img_px  = LV_COLOR_BLACK;
        lv_color_t recolored_px = lv_color_mix(recolor, last_img_px, recolor_opa);
        for(row = masked_a.y1; row <= masked_a.y2; row++) {
            for(col = 0; col < map_useful_w; col++) {
                lv_opa_t opa_result  = opa;
                uint8_t * px_color_p = (uint8_t *)&map_p[(uint32_t)col * px_size_byte];
                lv_color_t px_color;

                /*Calculate with the pixel level alpha*/
                if(alpha_byte) {
#if LV_COLOR_DEPTH == 8 || LV_COLOR_DEPTH == 1
                    px_color.full = px_color_p[0];
#elif LV_COLOR_DEPTH == 16
                    /*Because of Alpha byte 16 bit color can start on odd address which can cause
                     * crash*/
                    px_color.full = px_color_p[0] + (px_color_p[1] << 8);
#elif LV_COLOR_DEPTH == 32
                    px_color = *((lv_color_t *)px_color_p);
#endif
                    lv_opa_t px_opa = *(px_color_p + LV_IMG_PX_SIZE_ALPHA_BYTE - 1);
                    if(px_opa == LV_OPA_TRANSP)
                        continue;
                    else if(px_opa != LV_OPA_COVER)
                        opa_result = (uint32_t)((uint32_t)px_opa * opa_result) >> 8;
                } else {
                    px_color = *((lv_color_t *)px_color_p);
                }

                /*Handle chroma key*/
                if(chroma_key && px_color.full == disp->driver.color_chroma_key.full) continue;

                /*Re-color the pixel if required*/
                if(recolor_opa != LV_OPA_TRANSP) {
                    if(last_img_px.full != px_color.full) { /*Minor acceleration: calculate only for
                                                               new colors (save the last)*/
                        last_img_px  = px_color;
                        recolored_px = lv_color_mix(recolor, last_img_px, recolor_opa);
                    }
                    /*Handle custom VDB write is present*/
                    if(disp->driver.set_px_cb) {
                        disp->driver.set_px_cb(&disp->driver, (uint8_t *)vdb->buf_act, vdb_width, col + masked_a.x1,
                                               row, recolored_px, opa_result);
                    }
                    /*Normal native VDB write*/
                    else {
                        if(opa_result == LV_OPA_COVER)
                            vdb_buf_tmp[col].full = recolored_px.full;
                        else
                            vdb_buf_tmp[col] = lv_color_mix(recolored_px, vdb_buf_tmp[col], opa_result);
                    }
                } else {
                    /*Handle custom VDB write is present*/
                    if(disp->driver.set_px_cb) {
                        disp->driver.set_px_cb(&disp->driver, (uint8_t *)vdb->buf_act, vdb_width, col + masked_a.x1,
                                               row, px_color, opa_result);
                    }
                    /*Normal native VDB write*/
                    else {

                        if(opa_result == LV_OPA_COVER)
                            vdb_buf_tmp[col] = px_color;
                        else {
                            if(scr_transp == false) {
                                vdb_buf_tmp[col] = lv_color_mix(px_color, vdb_buf_tmp[col], opa_result);
                            } else {
#if LV_COLOR_DEPTH == 32 && LV_COLOR_SCREEN_TRANSP
                                vdb_buf_tmp[col] = color_mix_2_alpha(vdb_buf_tmp[col], vdb_buf_tmp[col].ch.alpha,
                                                                     px_color, opa_result);
#endif
                            }
                        }
                    }
                }
            }

            map_p += map_width * px_size_byte; /*Next row on the map*/
            vdb_buf_tmp += vdb_width;          /*Next row on the VDB*/
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movl %r8d, -0x98(%rbp)
movl %ecx, %eax
movl -0x98(%rbp), %ecx
movl %eax, -0x94(%rbp)
movq %rdx, %rax
movl -0x94(%rbp), %edx
movq %rax, -0x90(%rbp)
movq %rsi, %rax
movq -0x90(%rbp), %rsi
movq %rax, -0x88(%rbp)
movq %rdi, %r8
movq -0x88(%rbp), %rdi
movb %r9b, %al
movb 0x18(%rbp), %r9b
movw 0x10(%rbp), %r9w
movw %r9w, -0x2(%rbp)
movq %r8, -0x10(%rbp)
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movb %dl, -0x21(%rbp)
andb $0x1, %cl
movb %cl, -0x22(%rbp)
andb $0x1, %al
movb %al, -0x23(%rbp)
movzbl -0x21(%rbp), %eax
cmpl $0x10, %eax
jge 0x59fb4
jmp 0x5a5e2
movzbl -0x21(%rbp), %eax
cmpl $0xfb, %eax
jle 0x59fc3
movb $-0x1, -0x21(%rbp)
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
leaq -0x2c(%rbp), %rdi
callq 0x427d0
andb $0x1, %al
movb %al, -0x2d(%rbp)
movb -0x2d(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x59feb
jmp 0x5a5e2
movb -0x23(%rbp), %dl
movl $0x2, %eax
movl $0x3, %ecx
testb $0x1, %dl
cmovneq %rcx, %rax
movb %al, -0x2e(%rbp)
movq -0x10(%rbp), %rdi
callq 0x58d60
movw %ax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movswl 0x2(%rax), %eax
movswl -0x2a(%rbp), %ecx
cmpl %ecx, %eax
jge 0x5a048
movswl -0x30(%rbp), %ecx
movswl -0x2a(%rbp), %eax
movq -0x10(%rbp), %rdx
movswl 0x2(%rdx), %edx
subl %edx, %eax
imull %eax, %ecx
movzbl -0x2e(%rbp), %eax
imull %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movswl (%rax), %eax
movswl -0x2c(%rbp), %ecx
cmpl %ecx, %eax
jge 0x5a079
movswl -0x2c(%rbp), %ecx
movq -0x10(%rbp), %rax
movswl (%rax), %eax
subl %eax, %ecx
movzbl -0x2e(%rbp), %eax
imull %eax, %ecx
movq -0x20(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
callq 0xafe0
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
callq 0xdbd0
movq %rax, -0x40(%rbp)
movswl -0x2c(%rbp), %eax
movq -0x40(%rbp), %rcx
movswl 0x1c(%rcx), %ecx
subl %ecx, %eax
movw %ax, -0x2c(%rbp)
movswl -0x2a(%rbp), %eax
movq -0x40(%rbp), %rcx
movswl 0x1e(%rcx), %ecx
subl %ecx, %eax
movw %ax, -0x2a(%rbp)
movswl -0x28(%rbp), %eax
movq -0x40(%rbp), %rcx
movswl 0x1c(%rcx), %ecx
subl %ecx, %eax
movw %ax, -0x28(%rbp)
movswl -0x26(%rbp), %eax
movq -0x40(%rbp), %rcx
movswl 0x1e(%rcx), %ecx
subl %ecx, %eax
movw %ax, -0x26(%rbp)
movq -0x40(%rbp), %rdi
addq $0x1c, %rdi
callq 0x58d60
movw %ax, -0x42(%rbp)
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x50(%rbp)
movswl -0x42(%rbp), %ecx
movswl -0x2a(%rbp), %eax
imull %eax, %ecx
movq -0x50(%rbp), %rax
movl %ecx, %ecx
shlq %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movswl -0x2c(%rbp), %ecx
movq -0x50(%rbp), %rax
movl %ecx, %ecx
shlq %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
leaq -0x2c(%rbp), %rdi
callq 0x58d60
movw %ax, -0x54(%rbp)
movb $0x0, -0x55(%rbp)
movb -0x22(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x5a2b0
movb -0x23(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x5a2b0
movzbl -0x21(%rbp), %eax
cmpl $0xff, %eax
jne 0x5a2b0
movzbl 0x18(%rbp), %eax
cmpl $0x0, %eax
jne 0x5a2b0
movq -0x38(%rbp), %rax
cmpq $0x0, 0x28(%rax)
je 0x5a244
movw -0x2a(%rbp), %ax
movw %ax, -0x52(%rbp)
movswl -0x52(%rbp), %eax
movswl -0x26(%rbp), %ecx
cmpl %ecx, %eax
jg 0x5a242
movw $0x0, -0x58(%rbp)
movswl -0x58(%rbp), %eax
movswl -0x54(%rbp), %ecx
cmpl %ecx, %eax
jge 0x5a218
movq -0x20(%rbp), %rax
movswl -0x58(%rbp), %ecx
movzbl -0x2e(%rbp), %edx
imull %edx, %ecx
movl %ecx, %ecx
movw (%rax,%rcx), %ax
movw %ax, -0x5a(%rbp)
movq -0x38(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x38(%rbp), %rdi
movq -0x40(%rbp), %rcx
movq 0x10(%rcx), %rsi
movw -0x42(%rbp), %dx
movswl -0x58(%rbp), %ecx
movswl -0x2c(%rbp), %r8d
addl %r8d, %ecx
movw -0x52(%rbp), %r8w
movb -0x21(%rbp), %r10b
movswl %dx, %edx
movswl %cx, %ecx
movswl %r8w, %r8d
movzwl -0x5a(%rbp), %r9d
movzbl %r10b, %r10d
movl %r10d, (%rsp)
callq *%rax
movw -0x58(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x58(%rbp)
jmp 0x5a19f
movswl -0x30(%rbp), %ecx
movzbl -0x2e(%rbp), %eax
imull %eax, %ecx
movq -0x20(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movw -0x52(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x52(%rbp)
jmp 0x5a189
jmp 0x5a2ab
movw -0x2a(%rbp), %ax
movw %ax, -0x52(%rbp)
movswl -0x52(%rbp), %eax
movswl -0x26(%rbp), %ecx
cmpl %ecx, %eax
jg 0x5a2a9
movq -0x50(%rbp), %rdi
movq -0x20(%rbp), %rsi
movswl -0x54(%rbp), %edx
movzbl -0x21(%rbp), %ecx
callq 0x5a5f0
movswl -0x30(%rbp), %ecx
movzbl -0x2e(%rbp), %eax
imull %eax, %ecx
movq -0x20(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movswl -0x42(%rbp), %ecx
movq -0x50(%rbp), %rax
movslq %ecx, %rcx
shlq %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movw -0x52(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x52(%rbp)
jmp 0x5a24c
jmp 0x5a2ab
jmp 0x5a5e2
leaq -0x5e(%rbp), %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0x2090
movb 0x18(%rbp), %al
movw -0x2(%rbp), %cx
movzwl %cx, %edi
movzwl -0x5e(%rbp), %esi
movzbl %al, %edx
callq 0x58d80
movw %ax, -0x60(%rbp)
movw -0x2a(%rbp), %ax
movw %ax, -0x52(%rbp)
movswl -0x52(%rbp), %eax
movswl -0x26(%rbp), %ecx
cmpl %ecx, %eax
jg 0x5a5e0
movw $0x0, -0x5c(%rbp)
movswl -0x5c(%rbp), %eax
movswl -0x54(%rbp), %ecx
cmpl %ecx, %eax
jge 0x5a5a1
movb -0x21(%rbp), %al
movb %al, -0x61(%rbp)
movq -0x20(%rbp), %rax
movswl -0x5c(%rbp), %ecx
movzbl -0x2e(%rbp), %edx
imull %edx, %ecx
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, -0x70(%rbp)
testb $0x1, -0x23(%rbp)
je 0x5a37c
movq -0x70(%rbp), %rax
movzbl (%rax), %eax
movq -0x70(%rbp), %rcx
movzbl 0x1(%rcx), %ecx
shll $0x8, %ecx
addl %ecx, %eax
movw %ax, -0x72(%rbp)
movq -0x70(%rbp), %rax
movb 0x2(%rax), %al
movb %al, -0x73(%rbp)
movzbl -0x73(%rbp), %eax
cmpl $0x0, %eax
jne 0x5a35c
jmp 0x5a590
movzbl -0x73(%rbp), %eax
cmpl $0xff, %eax
je 0x5a378
movzbl -0x73(%rbp), %eax
movzbl -0x61(%rbp), %ecx
imull %ecx, %eax
shrl $0x8, %eax
movb %al, -0x61(%rbp)
jmp 0x5a37a
jmp 0x5a387
movq -0x70(%rbp), %rax
movw (%rax), %ax
movw %ax, -0x72(%rbp)
testb $0x1, -0x22(%rbp)
je 0x5a3a2
movzwl -0x72(%rbp), %eax
movq -0x38(%rbp), %rcx
movzwl 0x38(%rcx), %ecx
cmpl %ecx, %eax
jne 0x5a3a2
jmp 0x5a590
movzbl 0x18(%rbp), %eax
cmpl $0x0, %eax
je 0x5a4b0
movzwl -0x5e(%rbp), %eax
movzwl -0x72(%rbp), %ecx
cmpl %ecx, %eax
je 0x5a3e5
movw -0x72(%rbp), %ax
movw %ax, -0x5e(%rbp)
movb 0x18(%rbp), %al
movw -0x2(%rbp), %cx
movzwl %cx, %edi
movzwl -0x5e(%rbp), %esi
movzbl %al, %edx
callq 0x58d80
movw %ax, -0x76(%rbp)
movw -0x76(%rbp), %ax
movw %ax, -0x60(%rbp)
movq -0x38(%rbp), %rax
cmpq $0x0, 0x28(%rax)
je 0x5a438
movq -0x38(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x38(%rbp), %rdi
movq -0x40(%rbp), %rcx
movq 0x10(%rcx), %rsi
movw -0x42(%rbp), %dx
movswl -0x5c(%rbp), %ecx
movswl -0x2c(%rbp), %r8d
addl %r8d, %ecx
movw -0x52(%rbp), %r8w
movb -0x61(%rbp), %r10b
movswl %dx, %edx
movswl %cx, %ecx
movswl %r8w, %r8d
movzwl -0x60(%rbp), %r9d
movzbl %r10b, %r10d
movl %r10d, (%rsp)
callq *%rax
jmp 0x5a4ab
movzbl -0x61(%rbp), %eax
cmpl $0xff, %eax
jne 0x5a456
movw -0x60(%rbp), %dx
movq -0x50(%rbp), %rax
movswq -0x5c(%rbp), %rcx
movw %dx, (%rax,%rcx,2)
jmp 0x5a4a9
movq -0x50(%rbp), %rax
movq %rax, -0xa0(%rbp)
movswq -0x5c(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x50(%rbp), %rcx
movswq -0x5c(%rbp), %rdx
movb -0x61(%rbp), %al
movw -0x60(%rbp), %si
movzwl %si, %edi
movzwl (%rcx,%rdx,2), %esi
movzbl %al, %edx
callq 0x58d80
movq -0xa8(%rbp), %rcx
movw %ax, %dx
movq -0xa0(%rbp), %rax
movw %dx, -0x78(%rbp)
movw -0x78(%rbp), %dx
movw %dx, (%rax,%rcx,2)
jmp 0x5a4ab
jmp 0x5a58e
movq -0x38(%rbp), %rax
cmpq $0x0, 0x28(%rax)
je 0x5a506
movq -0x38(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x38(%rbp), %rdi
movq -0x40(%rbp), %rcx
movq 0x10(%rcx), %rsi
movw -0x42(%rbp), %dx
movswl -0x5c(%rbp), %ecx
movswl -0x2c(%rbp), %r8d
addl %r8d, %ecx
movw -0x52(%rbp), %r8w
movb -0x61(%rbp), %r10b
movswl %dx, %edx
movswl %cx, %ecx
movswl %r8w, %r8d
movzwl -0x72(%rbp), %r9d
movzbl %r10b, %r10d
movl %r10d, (%rsp)
callq *%rax
jmp 0x5a58c
movzbl -0x61(%rbp), %eax
cmpl $0xff, %eax
jne 0x5a524
movq -0x50(%rbp), %rax
movswq -0x5c(%rbp), %rcx
movw -0x72(%rbp), %dx
movw %dx, (%rax,%rcx,2)
jmp 0x5a58a
movb -0x55(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x5a586
movq -0x50(%rbp), %rax
movq %rax, -0xb0(%rbp)
movswq -0x5c(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0x50(%rbp), %rcx
movswq -0x5c(%rbp), %rdx
movb -0x61(%rbp), %al
movw -0x72(%rbp), %si
movzwl %si, %edi
movzwl (%rcx,%rdx,2), %esi
movzbl %al, %edx
callq 0x58d80
movq -0xb8(%rbp), %rcx
movw %ax, %dx
movq -0xb0(%rbp), %rax
movw %dx, -0x7a(%rbp)
movw -0x7a(%rbp), %dx
movw %dx, (%rax,%rcx,2)
jmp 0x5a588
jmp 0x5a588
jmp 0x5a58a
jmp 0x5a58c
jmp 0x5a58e
jmp 0x5a590
movw -0x5c(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x5c(%rbp)
jmp 0x5a2f8
movswl -0x30(%rbp), %ecx
movzbl -0x2e(%rbp), %eax
imull %eax, %ecx
movq -0x20(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movswl -0x42(%rbp), %ecx
movq -0x50(%rbp), %rax
movslq %ecx, %rcx
shlq %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movw -0x52(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x52(%rbp)
jmp 0x5a2e2
jmp 0x5a5e2
addq $0xc0, %rsp
popq %rbp
retq
nopl (%rax,%rax)