// File: /workspace/github_c_makefile_star2_O0/OnionIoT[P]lv_example/lvgl/src/lv_draw/lv_draw_triangle.c
// Function: tri_draw_flat
void tri_draw_flat(const lv_point_t * points, const lv_area_t * mask, const lv_style_t * style, lv_opa_t opa)
{
    /*Return if the points are out of the mask*/
    if(points[0].x < mask->x1 && points[1].x < mask->x1 && points[2].x < mask->x1) {
        return;
    }

    if(points[0].x > mask->x2 && points[1].x > mask->x2 && points[2].x > mask->x2) {
        return;
    }

    if(points[0].y < mask->y1 && points[1].y < mask->y1 && points[2].y < mask->y1) {
        return;
    }

    if(points[0].y > mask->y2 && points[1].y > mask->y2 && points[2].y > mask->y2) {
        return;
    }

    lv_point_t tri[3];

    memcpy(tri, points, sizeof(tri));

    /*Sort the vertices according to their y coordinate (0: y max, 1: y mid, 2:y min)*/
    if(tri[1].y < tri[0].y) point_swap(&tri[1], &tri[0]);
    if(tri[2].y < tri[1].y) point_swap(&tri[2], &tri[1]);
    if(tri[1].y < tri[0].y) point_swap(&tri[1], &tri[0]);

    /*Draw the triangle*/
    lv_point_t edge1;
    lv_coord_t dx1  = LV_MATH_ABS(tri[0].x - tri[1].x);
    lv_coord_t sx1  = tri[0].x < tri[1].x ? 1 : -1;
    lv_coord_t dy1  = LV_MATH_ABS(tri[0].y - tri[1].y);
    lv_coord_t sy1  = tri[0].y < tri[1].y ? 1 : -1;
    lv_coord_t err1 = (dx1 > dy1 ? dx1 : -dy1) / 2;
    lv_coord_t err_tmp1;

    lv_point_t edge2;
    lv_coord_t dx2  = LV_MATH_ABS(tri[0].x - tri[2].x);
    lv_coord_t sx2  = tri[0].x < tri[2].x ? 1 : -1;
    lv_coord_t dy2  = LV_MATH_ABS(tri[0].y - tri[2].y);
    lv_coord_t sy2  = tri[0].y < tri[2].y ? 1 : -1;
    lv_coord_t err2 = (dx1 > dy2 ? dx2 : -dy2) / 2;
    lv_coord_t err_tmp2;

    lv_coord_t y1_tmp;
    lv_coord_t y2_tmp;

    edge1.x = tri[0].x;
    edge1.y = tri[0].y;
    edge2.x = tri[0].x;
    edge2.y = tri[0].y;
    lv_area_t act_area;
    lv_area_t draw_area;

    while(1) {
        act_area.x1 = edge1.x;
        act_area.x2 = edge2.x;
        act_area.y1 = edge1.y;
        act_area.y2 = edge2.y;

        /* Get the area of a line.
         * Adjust it a little bit to perfectly match (no redrawn pixels) with the adjacent triangles*/
        draw_area.x1 = LV_MATH_MIN(act_area.x1, act_area.x2) + 1;
        draw_area.x2 = LV_MATH_MAX(act_area.x1, act_area.x2);
        draw_area.y1 = LV_MATH_MIN(act_area.y1, act_area.y2) - 1;
        draw_area.y2 = LV_MATH_MAX(act_area.y1, act_area.y2) - 1;

        lv_draw_fill(&draw_area, mask, style->body.main_color, opa);

        /*Calc. the next point of edge1*/
        y1_tmp = edge1.y;
        do {
            if(edge1.x == tri[1].x && edge1.y == tri[1].y) {

                dx1  = LV_MATH_ABS(tri[1].x - tri[2].x);
                sx1  = tri[1].x < tri[2].x ? 1 : -1;
                dy1  = LV_MATH_ABS(tri[1].y - tri[2].y);
                sy1  = tri[1].y < tri[2].y ? 1 : -1;
                err1 = (dx1 > dy1 ? dx1 : -dy1) / 2;
            } else if(edge1.x == tri[2].x && edge1.y == tri[2].y) {
                return;
            }
            err_tmp1 = err1;
            if(err_tmp1 > -dx1) {
                err1 -= dy1;
                edge1.x += sx1;
            }
            if(err_tmp1 < dy1) {
                err1 += dx1;
                edge1.y += sy1;
            }
        } while(edge1.y == y1_tmp);

        /*Calc. the next point of edge2*/
        y2_tmp = edge2.y;
        do {
            if(edge2.x == tri[2].x && edge2.y == tri[2].y) return;
            err_tmp2 = err2;
            if(err_tmp2 > -dx2) {
                err2 -= dy2;
                edge2.x += sx2;
            }
            if(err_tmp2 < dy2) {
                err2 += dx2;
                edge2.y += sy2;
            }
        } while(edge2.y == y2_tmp);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movb %cl, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movb %al, -0x19(%rbp)
movq -0x8(%rbp), %rax
movswl (%rax), %eax
movq -0x10(%rbp), %rcx
movswl (%rcx), %ecx
cmpl %ecx, %eax
jge 0x64909
movq -0x8(%rbp), %rax
movswl 0x4(%rax), %eax
movq -0x10(%rbp), %rcx
movswl (%rcx), %ecx
cmpl %ecx, %eax
jge 0x64909
movq -0x8(%rbp), %rax
movswl 0x8(%rax), %eax
movq -0x10(%rbp), %rcx
movswl (%rcx), %ecx
cmpl %ecx, %eax
jge 0x64909
jmp 0x64f0a
movq -0x8(%rbp), %rax
movswl (%rax), %eax
movq -0x10(%rbp), %rcx
movswl 0x4(%rcx), %ecx
cmpl %ecx, %eax
jle 0x64949
movq -0x8(%rbp), %rax
movswl 0x4(%rax), %eax
movq -0x10(%rbp), %rcx
movswl 0x4(%rcx), %ecx
cmpl %ecx, %eax
jle 0x64949
movq -0x8(%rbp), %rax
movswl 0x8(%rax), %eax
movq -0x10(%rbp), %rcx
movswl 0x4(%rcx), %ecx
cmpl %ecx, %eax
jle 0x64949
jmp 0x64f0a
movq -0x8(%rbp), %rax
movswl 0x2(%rax), %eax
movq -0x10(%rbp), %rcx
movswl 0x2(%rcx), %ecx
cmpl %ecx, %eax
jge 0x6498a
movq -0x8(%rbp), %rax
movswl 0x6(%rax), %eax
movq -0x10(%rbp), %rcx
movswl 0x2(%rcx), %ecx
cmpl %ecx, %eax
jge 0x6498a
movq -0x8(%rbp), %rax
movswl 0xa(%rax), %eax
movq -0x10(%rbp), %rcx
movswl 0x2(%rcx), %ecx
cmpl %ecx, %eax
jge 0x6498a
jmp 0x64f0a
movq -0x8(%rbp), %rax
movswl 0x2(%rax), %eax
movq -0x10(%rbp), %rcx
movswl 0x6(%rcx), %ecx
cmpl %ecx, %eax
jle 0x649cb
movq -0x8(%rbp), %rax
movswl 0x6(%rax), %eax
movq -0x10(%rbp), %rcx
movswl 0x6(%rcx), %ecx
cmpl %ecx, %eax
jle 0x649cb
movq -0x8(%rbp), %rax
movswl 0xa(%rax), %eax
movq -0x10(%rbp), %rcx
movswl 0x6(%rcx), %ecx
cmpl %ecx, %eax
jle 0x649cb
jmp 0x64f0a
movq -0x8(%rbp), %rax
movq (%rax), %rcx
movq %rcx, -0x26(%rbp)
movl 0x8(%rax), %eax
movl %eax, -0x1e(%rbp)
movswl -0x20(%rbp), %eax
movswl -0x24(%rbp), %ecx
cmpl %ecx, %eax
jge 0x649f9
leaq -0x26(%rbp), %rdi
addq $0x4, %rdi
leaq -0x26(%rbp), %rsi
callq 0x64ff0
movswl -0x1c(%rbp), %eax
movswl -0x20(%rbp), %ecx
cmpl %ecx, %eax
jge 0x64a1a
leaq -0x26(%rbp), %rdi
addq $0x8, %rdi
leaq -0x26(%rbp), %rsi
addq $0x4, %rsi
callq 0x64ff0
movswl -0x20(%rbp), %eax
movswl -0x24(%rbp), %ecx
cmpl %ecx, %eax
jge 0x64a37
leaq -0x26(%rbp), %rdi
addq $0x4, %rdi
leaq -0x26(%rbp), %rsi
callq 0x64ff0
movswl -0x26(%rbp), %eax
movswl -0x22(%rbp), %ecx
subl %ecx, %eax
cmpl $0x0, %eax
jle 0x64a55
movswl -0x26(%rbp), %eax
movswl -0x22(%rbp), %ecx
subl %ecx, %eax
movl %eax, -0x60(%rbp)
jmp 0x64a66
movswl -0x26(%rbp), %ecx
movswl -0x22(%rbp), %eax
subl %eax, %ecx
xorl %eax, %eax
subl %ecx, %eax
movl %eax, -0x60(%rbp)
movl -0x60(%rbp), %eax
movw %ax, -0x2c(%rbp)
movswl -0x26(%rbp), %edx
movswl -0x22(%rbp), %esi
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl $0x1, %ecx
cmpl %esi, %edx
cmovll %ecx, %eax
movw %ax, -0x2e(%rbp)
movswl -0x24(%rbp), %eax
movswl -0x20(%rbp), %ecx
subl %ecx, %eax
cmpl $0x0, %eax
jle 0x64aa6
movswl -0x24(%rbp), %eax
movswl -0x20(%rbp), %ecx
subl %ecx, %eax
movl %eax, -0x64(%rbp)
jmp 0x64ab7
movswl -0x24(%rbp), %ecx
movswl -0x20(%rbp), %eax
subl %eax, %ecx
xorl %eax, %eax
subl %ecx, %eax
movl %eax, -0x64(%rbp)
movl -0x64(%rbp), %eax
movw %ax, -0x30(%rbp)
movswl -0x24(%rbp), %edx
movswl -0x20(%rbp), %esi
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl $0x1, %ecx
cmpl %esi, %edx
cmovll %ecx, %eax
movw %ax, -0x32(%rbp)
movswl -0x2c(%rbp), %eax
movswl -0x30(%rbp), %ecx
cmpl %ecx, %eax
jle 0x64aee
movswl -0x2c(%rbp), %eax
movl %eax, -0x68(%rbp)
jmp 0x64af9
movswl -0x30(%rbp), %ecx
xorl %eax, %eax
subl %ecx, %eax
movl %eax, -0x68(%rbp)
movl -0x68(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movw %ax, -0x34(%rbp)
movswl -0x26(%rbp), %eax
movswl -0x1e(%rbp), %ecx
subl %ecx, %eax
cmpl $0x0, %eax
jle 0x64b26
movswl -0x26(%rbp), %eax
movswl -0x1e(%rbp), %ecx
subl %ecx, %eax
movl %eax, -0x6c(%rbp)
jmp 0x64b37
movswl -0x26(%rbp), %ecx
movswl -0x1e(%rbp), %eax
subl %eax, %ecx
xorl %eax, %eax
subl %ecx, %eax
movl %eax, -0x6c(%rbp)
movl -0x6c(%rbp), %eax
movw %ax, -0x3c(%rbp)
movswl -0x26(%rbp), %edx
movswl -0x1e(%rbp), %esi
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl $0x1, %ecx
cmpl %esi, %edx
cmovll %ecx, %eax
movw %ax, -0x3e(%rbp)
movswl -0x24(%rbp), %eax
movswl -0x1c(%rbp), %ecx
subl %ecx, %eax
cmpl $0x0, %eax
jle 0x64b77
movswl -0x24(%rbp), %eax
movswl -0x1c(%rbp), %ecx
subl %ecx, %eax
movl %eax, -0x70(%rbp)
jmp 0x64b88
movswl -0x24(%rbp), %ecx
movswl -0x1c(%rbp), %eax
subl %eax, %ecx
xorl %eax, %eax
subl %ecx, %eax
movl %eax, -0x70(%rbp)
movl -0x70(%rbp), %eax
movw %ax, -0x40(%rbp)
movswl -0x24(%rbp), %edx
movswl -0x1c(%rbp), %esi
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl $0x1, %ecx
cmpl %esi, %edx
cmovll %ecx, %eax
movw %ax, -0x42(%rbp)
movswl -0x2c(%rbp), %eax
movswl -0x40(%rbp), %ecx
cmpl %ecx, %eax
jle 0x64bbf
movswl -0x3c(%rbp), %eax
movl %eax, -0x74(%rbp)
jmp 0x64bca
movswl -0x40(%rbp), %ecx
xorl %eax, %eax
subl %ecx, %eax
movl %eax, -0x74(%rbp)
movl -0x74(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movw %ax, -0x44(%rbp)
movw -0x26(%rbp), %ax
movw %ax, -0x2a(%rbp)
movw -0x24(%rbp), %ax
movw %ax, -0x28(%rbp)
movw -0x26(%rbp), %ax
movw %ax, -0x3a(%rbp)
movw -0x24(%rbp), %ax
movw %ax, -0x38(%rbp)
movw -0x2a(%rbp), %ax
movw %ax, -0x52(%rbp)
movw -0x3a(%rbp), %ax
movw %ax, -0x4e(%rbp)
movw -0x28(%rbp), %ax
movw %ax, -0x50(%rbp)
movw -0x38(%rbp), %ax
movw %ax, -0x4c(%rbp)
movswl -0x52(%rbp), %eax
movswl -0x4e(%rbp), %ecx
cmpl %ecx, %eax
jge 0x64c2e
movswl -0x52(%rbp), %eax
movl %eax, -0x78(%rbp)
jmp 0x64c35
movswl -0x4e(%rbp), %eax
movl %eax, -0x78(%rbp)
movl -0x78(%rbp), %eax
addl $0x1, %eax
movw %ax, -0x5a(%rbp)
movswl -0x52(%rbp), %eax
movswl -0x4e(%rbp), %ecx
cmpl %ecx, %eax
jle 0x64c54
movswl -0x52(%rbp), %eax
movl %eax, -0x7c(%rbp)
jmp 0x64c5b
movswl -0x4e(%rbp), %eax
movl %eax, -0x7c(%rbp)
movl -0x7c(%rbp), %eax
movw %ax, -0x56(%rbp)
movswl -0x50(%rbp), %eax
movswl -0x4c(%rbp), %ecx
cmpl %ecx, %eax
jge 0x64c77
movswl -0x50(%rbp), %eax
movl %eax, -0x80(%rbp)
jmp 0x64c7e
movswl -0x4c(%rbp), %eax
movl %eax, -0x80(%rbp)
movl -0x80(%rbp), %eax
subl $0x1, %eax
movw %ax, -0x58(%rbp)
movswl -0x50(%rbp), %eax
movswl -0x4c(%rbp), %ecx
cmpl %ecx, %eax
jle 0x64ca0
movswl -0x50(%rbp), %eax
movl %eax, -0x84(%rbp)
jmp 0x64caa
movswl -0x4c(%rbp), %eax
movl %eax, -0x84(%rbp)
movl -0x84(%rbp), %eax
subl $0x1, %eax
movw %ax, -0x54(%rbp)
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rcx
movb -0x19(%rbp), %al
leaq -0x5a(%rbp), %rdi
movzwl 0x2(%rcx), %edx
movzbl %al, %ecx
callq 0x58ea0
movw -0x28(%rbp), %ax
movw %ax, -0x48(%rbp)
movswl -0x2a(%rbp), %eax
movswl -0x22(%rbp), %ecx
cmpl %ecx, %eax
jne 0x64de8
movswl -0x28(%rbp), %eax
movswl -0x20(%rbp), %ecx
cmpl %ecx, %eax
jne 0x64de8
movswl -0x22(%rbp), %eax
movswl -0x1e(%rbp), %ecx
subl %ecx, %eax
cmpl $0x0, %eax
jle 0x64d1b
movswl -0x22(%rbp), %eax
movswl -0x1e(%rbp), %ecx
subl %ecx, %eax
movl %eax, -0x88(%rbp)
jmp 0x64d2f
movswl -0x22(%rbp), %ecx
movswl -0x1e(%rbp), %eax
subl %eax, %ecx
xorl %eax, %eax
subl %ecx, %eax
movl %eax, -0x88(%rbp)
movl -0x88(%rbp), %eax
movw %ax, -0x2c(%rbp)
movswl -0x22(%rbp), %edx
movswl -0x1e(%rbp), %esi
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl $0x1, %ecx
cmpl %esi, %edx
cmovll %ecx, %eax
movw %ax, -0x2e(%rbp)
movswl -0x20(%rbp), %eax
movswl -0x1c(%rbp), %ecx
subl %ecx, %eax
cmpl $0x0, %eax
jle 0x64d75
movswl -0x20(%rbp), %eax
movswl -0x1c(%rbp), %ecx
subl %ecx, %eax
movl %eax, -0x8c(%rbp)
jmp 0x64d89
movswl -0x20(%rbp), %ecx
movswl -0x1c(%rbp), %eax
subl %eax, %ecx
xorl %eax, %eax
subl %ecx, %eax
movl %eax, -0x8c(%rbp)
movl -0x8c(%rbp), %eax
movw %ax, -0x30(%rbp)
movswl -0x20(%rbp), %edx
movswl -0x1c(%rbp), %esi
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl $0x1, %ecx
cmpl %esi, %edx
cmovll %ecx, %eax
movw %ax, -0x32(%rbp)
movswl -0x2c(%rbp), %eax
movswl -0x30(%rbp), %ecx
cmpl %ecx, %eax
jle 0x64dc6
movswl -0x2c(%rbp), %eax
movl %eax, -0x90(%rbp)
jmp 0x64dd4
movswl -0x30(%rbp), %ecx
xorl %eax, %eax
subl %ecx, %eax
movl %eax, -0x90(%rbp)
movl -0x90(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movw %ax, -0x34(%rbp)
jmp 0x64e07
movswl -0x2a(%rbp), %eax
movswl -0x1e(%rbp), %ecx
cmpl %ecx, %eax
jne 0x64e05
movswl -0x28(%rbp), %eax
movswl -0x1c(%rbp), %ecx
cmpl %ecx, %eax
jne 0x64e05
jmp 0x64f0a
jmp 0x64e07
movw -0x34(%rbp), %ax
movw %ax, -0x36(%rbp)
movswl -0x36(%rbp), %eax
movswl -0x2c(%rbp), %edx
xorl %ecx, %ecx
subl %edx, %ecx
cmpl %ecx, %eax
jle 0x64e3b
movswl -0x30(%rbp), %ecx
movswl -0x34(%rbp), %eax
subl %ecx, %eax
movw %ax, -0x34(%rbp)
movswl -0x2e(%rbp), %ecx
movswl -0x2a(%rbp), %eax
addl %ecx, %eax
movw %ax, -0x2a(%rbp)
movswl -0x36(%rbp), %eax
movswl -0x30(%rbp), %ecx
cmpl %ecx, %eax
jge 0x64e63
movswl -0x2c(%rbp), %ecx
movswl -0x34(%rbp), %eax
addl %ecx, %eax
movw %ax, -0x34(%rbp)
movswl -0x32(%rbp), %ecx
movswl -0x28(%rbp), %eax
addl %ecx, %eax
movw %ax, -0x28(%rbp)
jmp 0x64e65
movswl -0x28(%rbp), %eax
movswl -0x48(%rbp), %ecx
cmpl %ecx, %eax
je 0x64cda
movw -0x38(%rbp), %ax
movw %ax, -0x4a(%rbp)
movswl -0x3a(%rbp), %eax
movswl -0x1e(%rbp), %ecx
cmpl %ecx, %eax
jne 0x64e97
movswl -0x38(%rbp), %eax
movswl -0x1c(%rbp), %ecx
cmpl %ecx, %eax
jne 0x64e97
jmp 0x64f0a
movw -0x44(%rbp), %ax
movw %ax, -0x46(%rbp)
movswl -0x46(%rbp), %eax
movswl -0x3c(%rbp), %edx
xorl %ecx, %ecx
subl %edx, %ecx
cmpl %ecx, %eax
jle 0x64ecb
movswl -0x40(%rbp), %ecx
movswl -0x44(%rbp), %eax
subl %ecx, %eax
movw %ax, -0x44(%rbp)
movswl -0x3e(%rbp), %ecx
movswl -0x3a(%rbp), %eax
addl %ecx, %eax
movw %ax, -0x3a(%rbp)
movswl -0x46(%rbp), %eax
movswl -0x40(%rbp), %ecx
cmpl %ecx, %eax
jge 0x64ef3
movswl -0x3c(%rbp), %ecx
movswl -0x44(%rbp), %eax
addl %ecx, %eax
movw %ax, -0x44(%rbp)
movswl -0x42(%rbp), %ecx
movswl -0x38(%rbp), %eax
addl %ecx, %eax
movw %ax, -0x38(%rbp)
jmp 0x64ef5
movswl -0x38(%rbp), %eax
movswl -0x4a(%rbp), %ecx
cmpl %ecx, %eax
je 0x64e7d
jmp 0x64bf9
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)