// File: /workspace/github_c_makefile_star2_O0/OnionIoT[P]lv_example/lvgl/src/lv_draw/lv_draw_triangle.c
// Function: tri_draw_tall
void tri_draw_tall(const lv_point_t * points, const lv_area_t * mask, const lv_style_t * style, lv_opa_t opa)
{
    /*
     * Better to draw from vertical lines
     * |\
     * | |
     * | |
     * |  \
     * |   |
     * |___|
     */

    lv_point_t tri[3];

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

    /*Sort the vertices according to their x coordinate (0: x max, 1: x mid, 2:x min)*/
    if(tri[1].x < tri[0].x) point_swap(&tri[1], &tri[0]);
    if(tri[2].x < tri[1].x) point_swap(&tri[2], &tri[1]);
    if(tri[1].x < tri[0].x) 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 x1_tmp;
    lv_coord_t x2_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;

        draw_area.x1 = LV_MATH_MIN(act_area.x1, act_area.x2);
        draw_area.x2 = LV_MATH_MAX(act_area.x1, act_area.x2);
        draw_area.y1 = LV_MATH_MIN(act_area.y1, act_area.y2);
        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*/
        x1_tmp = edge1.x;
        do {
            if(edge1.y == tri[1].y && edge1.x == tri[1].x) {

                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.y == tri[2].y && edge1.x == tri[2].x) {
                return;
            }
            err_tmp1 = err1;
            if(err_tmp1 > -dx1) {
                err1 -= dy1;
                edge1.x += sx1;
            }
            if(err_tmp1 < dy1) {
                err1 += dx1;
                edge1.y += sy1;
            }
        } while(edge1.x == x1_tmp);

        /*Calc. the next point of edge2*/
        x2_tmp = edge2.x;
        do {
            if(edge2.y == tri[2].y && edge2.x == tri[2].x) {
                return;
            }

            err_tmp2 = err2;
            if(err_tmp2 > -dx2) {
                err2 -= dy2;
                edge2.x += sx2;
            }
            if(err_tmp2 < dy2) {
                err2 += dx2;
                edge2.y += sy2;
            }
        } while(edge2.x == x2_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
movq (%rax), %rcx
movq %rcx, -0x26(%rbp)
movl 0x8(%rax), %eax
movl %eax, -0x1e(%rbp)
movswl -0x22(%rbp), %eax
movswl -0x26(%rbp), %ecx
cmpl %ecx, %eax
jge 0x6439a
leaq -0x26(%rbp), %rdi
addq $0x4, %rdi
leaq -0x26(%rbp), %rsi
callq 0x64ff0
movswl -0x1e(%rbp), %eax
movswl -0x22(%rbp), %ecx
cmpl %ecx, %eax
jge 0x643bb
leaq -0x26(%rbp), %rdi
addq $0x8, %rdi
leaq -0x26(%rbp), %rsi
addq $0x4, %rsi
callq 0x64ff0
movswl -0x22(%rbp), %eax
movswl -0x26(%rbp), %ecx
cmpl %ecx, %eax
jge 0x643d8
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 0x643f6
movswl -0x26(%rbp), %eax
movswl -0x22(%rbp), %ecx
subl %ecx, %eax
movl %eax, -0x60(%rbp)
jmp 0x64407
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 0x64447
movswl -0x24(%rbp), %eax
movswl -0x20(%rbp), %ecx
subl %ecx, %eax
movl %eax, -0x64(%rbp)
jmp 0x64458
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 0x6448f
movswl -0x2c(%rbp), %eax
movl %eax, -0x68(%rbp)
jmp 0x6449a
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 0x644c7
movswl -0x26(%rbp), %eax
movswl -0x1e(%rbp), %ecx
subl %ecx, %eax
movl %eax, -0x6c(%rbp)
jmp 0x644d8
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 0x64518
movswl -0x24(%rbp), %eax
movswl -0x1c(%rbp), %ecx
subl %ecx, %eax
movl %eax, -0x70(%rbp)
jmp 0x64529
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 0x64560
movswl -0x3c(%rbp), %eax
movl %eax, -0x74(%rbp)
jmp 0x6456b
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 0x645cf
movswl -0x52(%rbp), %eax
movl %eax, -0x78(%rbp)
jmp 0x645d6
movswl -0x4e(%rbp), %eax
movl %eax, -0x78(%rbp)
movl -0x78(%rbp), %eax
movw %ax, -0x5a(%rbp)
movswl -0x52(%rbp), %eax
movswl -0x4e(%rbp), %ecx
cmpl %ecx, %eax
jle 0x645f2
movswl -0x52(%rbp), %eax
movl %eax, -0x7c(%rbp)
jmp 0x645f9
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 0x64615
movswl -0x50(%rbp), %eax
movl %eax, -0x80(%rbp)
jmp 0x6461c
movswl -0x4c(%rbp), %eax
movl %eax, -0x80(%rbp)
movl -0x80(%rbp), %eax
movw %ax, -0x58(%rbp)
movswl -0x50(%rbp), %eax
movswl -0x4c(%rbp), %ecx
cmpl %ecx, %eax
jle 0x6463b
movswl -0x50(%rbp), %eax
movl %eax, -0x84(%rbp)
jmp 0x64645
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 -0x2a(%rbp), %ax
movw %ax, -0x48(%rbp)
movswl -0x28(%rbp), %eax
movswl -0x20(%rbp), %ecx
cmpl %ecx, %eax
jne 0x64783
movswl -0x2a(%rbp), %eax
movswl -0x22(%rbp), %ecx
cmpl %ecx, %eax
jne 0x64783
movswl -0x22(%rbp), %eax
movswl -0x1e(%rbp), %ecx
subl %ecx, %eax
cmpl $0x0, %eax
jle 0x646b6
movswl -0x22(%rbp), %eax
movswl -0x1e(%rbp), %ecx
subl %ecx, %eax
movl %eax, -0x88(%rbp)
jmp 0x646ca
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 0x64710
movswl -0x20(%rbp), %eax
movswl -0x1c(%rbp), %ecx
subl %ecx, %eax
movl %eax, -0x8c(%rbp)
jmp 0x64724
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 0x64761
movswl -0x2c(%rbp), %eax
movl %eax, -0x90(%rbp)
jmp 0x6476f
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 0x647a2
movswl -0x28(%rbp), %eax
movswl -0x1c(%rbp), %ecx
cmpl %ecx, %eax
jne 0x647a0
movswl -0x2a(%rbp), %eax
movswl -0x1e(%rbp), %ecx
cmpl %ecx, %eax
jne 0x647a0
jmp 0x648a5
jmp 0x647a2
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 0x647d6
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 0x647fe
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 0x64800
movswl -0x2a(%rbp), %eax
movswl -0x48(%rbp), %ecx
cmpl %ecx, %eax
je 0x64675
movw -0x3a(%rbp), %ax
movw %ax, -0x4a(%rbp)
movswl -0x38(%rbp), %eax
movswl -0x1c(%rbp), %ecx
cmpl %ecx, %eax
jne 0x64832
movswl -0x3a(%rbp), %eax
movswl -0x1e(%rbp), %ecx
cmpl %ecx, %eax
jne 0x64832
jmp 0x648a5
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 0x64866
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 0x6488e
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 0x64890
movswl -0x3a(%rbp), %eax
movswl -0x4a(%rbp), %ecx
cmpl %ecx, %eax
je 0x64818
jmp 0x6459a
addq $0x90, %rsp
popq %rbp
retq
nop