// File: /workspace/github_c_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %ecx, 0x30(%rsp)
movq %rdx, 0x60(%rsp)
movq %rsi, 0x58(%rsp)
movzwl (%rdi), %r8d
movzwl 0x2(%rdi), %r9d
movzwl 0x4(%rdi), %eax
movzwl 0x6(%rdi), %ecx
movzwl 0x8(%rdi), %r10d
cmpw %r8w, %ax
jge 0x3d2fb
movl %r9d, %edx
movl %r8d, %esi
jmp 0x3d305
movl %ecx, %edx
movl %eax, %esi
movl %r9d, %ecx
movl %r8d, %eax
movzwl 0xa(%rdi), %edi
cmpw %si, %r10w
jge 0x3d319
movl %edx, %r8d
movw %si, 0x8(%rsp)
jmp 0x3d327
movl %edi, %r8d
movw %r10w, 0x8(%rsp)
movl %edx, %edi
movl %esi, %r10d
movw %r8w, 0xa(%rsp)
cmpw %ax, %r10w
jge 0x3d339
movl %ecx, %esi
movl %eax, %edx
jmp 0x3d343
movl %edi, %esi
movl %r10d, %edx
movl %ecx, %edi
movl %eax, %r10d
movl %r10d, 0xc(%rsp)
movl %edi, 0x10(%rsp)
movw %dx, 0x16(%rsp)
movswl %dx, %edx
movswl %r10w, %r9d
movl %r9d, %eax
subl %edx, %eax
movl %eax, %r8d
negl %r8d
cmovsl %eax, %r8d
xorl %eax, %eax
cmpw %dx, %r9w
setl %al
movq %rax, 0x18(%rsp)
movw %si, 0x14(%rsp)
movswl %si, %esi
movswl %di, %r11d
movl %r11d, %ecx
subl %esi, %ecx
movl %ecx, %ebx
negl %ebx
cmovsl %ecx, %ebx
xorl %r13d, %r13d
cmpw %si, %r11w
setl %r13b
movl %r8d, 0x20(%rsp)
movswl %r8w, %ebp
movswl %bx, %edi
movl %edi, %r8d
negl %r8d
cmpl %edi, %ebp
cmovgl %ebp, %r8d
movl %r8d, %r14d
shrl $0x1f, %r14d
addl %r8d, %r14d
shrl %r14d
xorl %edi, %edi
movzwl 0x8(%rsp), %r12d
cmpw %r12w, %r9w
setl %dil
xorl %r8d, %r8d
movzwl 0xa(%rsp), %r15d
cmpw %r15w, %r11w
setl %r8b
movswl %r15w, %r10d
subl %r10d, %r11d
movl %r11d, %r15d
negl %r15d
cmovsl %r11d, %r15d
movswl %r15w, %eax
movl %eax, %r11d
negl %r11d
movswl %r12w, %r12d
subl %r12d, %r9d
movl %r9d, %r15d
negl %r15d
cmovsl %r9d, %r15d
movl %eax, 0x40(%rsp)
cmpl %eax, %ebp
movswl %r15w, %ecx
cmovgl %ecx, %r11d
movl %r11d, %r15d
shrl $0x1f, %r15d
addl %r11d, %r15d
shrl %r15d
movl %edx, %r9d
subl %r12d, %r9d
movl %r9d, %eax
negl %eax
cmovsl %r9d, %eax
xorl %r9d, %r9d
cmpw %r12w, %dx
setl %r9b
movl %esi, %edx
subl %r10d, %edx
movl %edx, %r11d
negl %r11d
cmovsl %edx, %r11d
xorl %edx, %edx
cmpw %r10w, %si
setl %dl
movl %r11d, 0x50(%rsp)
movswl %r11w, %esi
movl %esi, %r10d
negl %r10d
movl %eax, 0x54(%rsp)
movswl %ax, %r11d
cmpl %esi, %r11d
cmovgl %r11d, %r10d
movl %r10d, %r11d
shrl $0x1f, %r11d
addl %r10d, %r11d
movl 0xc(%rsp), %r10d
movq 0x18(%rsp), %rax
leal -0x1(,%rax,2), %ebp
leal -0x1(,%r13,2), %r12d
leal -0x1(%rdi,%rdi), %eax
movl 0x10(%rsp), %esi
leal -0x1(%r8,%r8), %edi
movl %edi, 0x38(%rsp)
leal -0x1(%r9,%r9), %edi
movl %edi, 0x48(%rsp)
leal -0x1(,%rdx,2), %edx
movl %edx, 0x44(%rsp)
shrl %r11d
movl %r11d, 0x4c(%rsp)
movl %ecx, 0x3c(%rsp)
negl %ecx
movl %ecx, 0x34(%rsp)
cwtl
movl %eax, 0x2c(%rsp)
leaq 0x24(%rsp), %rdi
movl %r10d, %eax
movl %esi, %r13d
movl %r10d, 0xc(%rsp)
movl %eax, 0x18(%rsp)
cwtl
movswl %r10w, %ecx
cmpl %ecx, %eax
movl %ecx, %edx
cmovll %eax, %edx
movw %dx, 0x24(%rsp)
cmovgl %eax, %ecx
movswl %r13w, %eax
movl %esi, 0x10(%rsp)
movswl %si, %edx
cmpl %edx, %eax
movl %edx, %esi
cmovll %eax, %esi
movw %cx, 0x28(%rsp)
movw %si, 0x26(%rsp)
cmovgl %eax, %edx
decl %edx
movw %dx, 0x2a(%rsp)
movq 0x60(%rsp), %rax
movzwl 0x2(%rax), %edx
movzbl 0x30(%rsp), %ecx
movq 0x58(%rsp), %rsi
callq 0x35793
movl %r12d, %eax
movl %ebx, %edx
movl %ebp, %esi
movl 0x20(%rsp), %ecx
movl %ecx, %edi
movzwl 0xa(%rsp), %r11d
movl 0x18(%rsp), %ecx
cmpw 0x16(%rsp), %cx
jne 0x3d576
movl 0x4c(%rsp), %ecx
movl 0x44(%rsp), %r12d
movl 0x50(%rsp), %ebx
movl 0x48(%rsp), %ebp
movl 0x54(%rsp), %r10d
cmpw 0x14(%rsp), %r13w
je 0x3d598
movl %r14d, %ecx
movl %eax, %r12d
movl %edx, %ebx
movl %esi, %ebp
movl %edi, %r10d
cmpw %r11w, %r13w
jne 0x3d598
movl 0x18(%rsp), %eax
cmpw 0x8(%rsp), %ax
je 0x3d66a
movswl %cx, %r8d
movswl %r10w, %r14d
movl %r14d, %r9d
negl %r9d
cmpl %r9d, %r8d
movl %ebx, %eax
movl $0x0, %edx
cmovlel %edx, %eax
subl %eax, %ecx
cmpw %bx, %r8w
cmovgel %edx, %r14d
movl %r12d, %eax
cmovgel %edx, %eax
addl %ecx, %r14d
addl %eax, %r13d
movl %r12d, %eax
movl %ebx, %edx
movl %ebp, %esi
movl %r10d, %edi
cmpl %r9d, %r8d
jle 0x3d54d
movl %r10d, %r8d
movl %r12d, %eax
movl %ebx, %edx
movl %ebp, %esi
movl %r8d, %edi
testw %bp, %bp
je 0x3d54d
addl %ebp, 0x18(%rsp)
movl 0x10(%rsp), %esi
movl %esi, %edi
cmpw %r11w, %si
jne 0x3d60d
movl 0xc(%rsp), %eax
cmpw 0x8(%rsp), %ax
je 0x3d66a
movswl %r15w, %eax
movl 0x34(%rsp), %r9d
cmpl %r9d, %eax
movl $0x0, %ecx
movl 0x40(%rsp), %edx
cmovgl %edx, %ecx
subl %ecx, %r15d
cmpl %eax, %edx
movl $0x0, %ecx
cmovgl 0x38(%rsp), %ecx
movl $0x0, %edx
cmovgl 0x3c(%rsp), %edx
movl %edi, %esi
addl %ecx, %esi
addl %r15d, %edx
movl %edx, %r15d
cmpl %r9d, %eax
jle 0x3d5fa
movl 0xc(%rsp), %r10d
addl 0x2c(%rsp), %r10d
movl %r8d, 0x20(%rsp)
leaq 0x24(%rsp), %rdi
movl 0x18(%rsp), %eax
jmp 0x3d4df
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq