// File: /workspace/github_c_makefile_star2_O2/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 0x39403
movl %r9d, %edx
movl %r8d, %esi
jmp 0x3940d
movl %ecx, %edx
movl %eax, %esi
movl %r9d, %ecx
movl %r8d, %eax
movzwl 0xa(%rdi), %edi
cmpw %si, %r10w
jge 0x39421
movl %edx, %r8d
movw %si, 0xc(%rsp)
jmp 0x3942f
movl %edi, %r8d
movw %r10w, 0xc(%rsp)
movl %edx, %edi
movl %esi, %r10d
movw %r8w, 0xe(%rsp)
cmpw %ax, %r10w
jge 0x39443
movl %ecx, %edx
movl %eax, %esi
movl %edi, %ebx
jmp 0x3944d
movl %edi, %edx
movl %r10d, %esi
movl %ecx, %ebx
movl %eax, %r10d
movl %ebx, 0x18(%rsp)
movl %r10d, 0x10(%rsp)
movw %si, 0x1e(%rsp)
movswl %si, %edi
movswl %r10w, %r11d
movl %r11d, %eax
subl %edi, %eax
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
xorl %r9d, %r9d
cmpw %di, %r11w
setl %r9b
movw %dx, 0x1c(%rsp)
movswl %dx, %r8d
movswl %bx, %r12d
movl %r12d, %eax
subl %r8d, %eax
movl %eax, %ebx
negl %ebx
cmovsl %eax, %ebx
xorl %esi, %esi
cmpw %r8w, %r12w
setl %sil
movl %ecx, 0x20(%rsp)
movswl %cx, %r13d
movswl %bx, %edx
movl %edx, %eax
negl %eax
cmpl %edx, %r13d
cmovgl %r13d, %eax
pushq $0x2
popq %rcx
cltd
idivl %ecx
movl %eax, %ebp
xorl %r10d, %r10d
movzwl 0xc(%rsp), %ecx
cmpw %cx, %r11w
setl %r10b
xorl %r15d, %r15d
movzwl 0xe(%rsp), %eax
cmpw %ax, %r12w
setl %r15b
movswl %ax, %r14d
subl %r14d, %r12d
movl %r12d, %eax
negl %eax
cmovsl %r12d, %eax
movswl %ax, %r12d
movl %r12d, %eax
negl %eax
movswl %cx, %ecx
subl %ecx, %r11d
movl %r11d, %edx
negl %edx
cmovsl %r11d, %edx
movl %r12d, 0x40(%rsp)
cmpl %r12d, %r13d
movswl %dx, %r11d
cmovgl %r11d, %eax
cltd
pushq $0x2
popq %r12
idivl %r12d
movl %eax, %r12d
movl %edi, %eax
subl %ecx, %eax
movl %eax, %r13d
negl %r13d
cmovsl %eax, %r13d
xorl %edx, %edx
cmpw %cx, %di
setl %dl
movl %r8d, %eax
subl %r14d, %eax
movl %eax, %edi
negl %edi
cmovsl %eax, %edi
xorl %ecx, %ecx
cmpw %r14w, %r8w
setl %cl
movl %edi, 0x50(%rsp)
movswl %di, %edi
movl %edi, %eax
negl %eax
movl %r13d, 0x54(%rsp)
movswl %r13w, %r8d
cmpl %edi, %r8d
cmovgl %r8d, %eax
leal -0x1(%r9,%r9), %r14d
leal -0x1(%rsi,%rsi), %r13d
leal -0x1(%r10,%r10), %esi
movl 0x10(%rsp), %r9d
leal -0x1(%r15,%r15), %edi
movl %edi, 0x38(%rsp)
leal -0x1(%rdx,%rdx), %edx
movl %edx, 0x4c(%rsp)
leal -0x1(%rcx,%rcx), %ecx
movl %ecx, 0x48(%rsp)
cltd
pushq $0x2
popq %rcx
idivl %ecx
movl %eax, 0x44(%rsp)
movl %r11d, 0x3c(%rsp)
negl %r11d
movl %r11d, 0x34(%rsp)
movswl %si, %eax
movl %eax, 0x2c(%rsp)
leaq 0x24(%rsp), %rdi
movl %r9d, %eax
movl 0x18(%rsp), %esi
movl %esi, %r15d
movl %r9d, 0x10(%rsp)
movl %eax, 0x14(%rsp)
cwtl
movswl %r9w, %ecx
cmpl %ecx, %eax
movl %ecx, %edx
cmovll %eax, %edx
movw %dx, 0x24(%rsp)
cmovgl %eax, %ecx
movswl %r15w, %eax
movl %esi, 0x18(%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 0x32757
movl %r13d, %eax
movl %ebx, %edx
movl %r14d, %esi
movl 0x20(%rsp), %ecx
movl %ecx, %edi
movzwl 0xe(%rsp), %r11d
movl 0x14(%rsp), %ecx
cmpw 0x1e(%rsp), %cx
jne 0x39658
movl 0x44(%rsp), %ecx
movl 0x48(%rsp), %r13d
movl 0x50(%rsp), %ebx
movl 0x4c(%rsp), %r14d
movl 0x54(%rsp), %r10d
cmpw 0x1c(%rsp), %r15w
je 0x3967a
movl %ebp, %ecx
movl %eax, %r13d
movl %edx, %ebx
movl %esi, %r14d
movl %edi, %r10d
cmpw %r11w, %r15w
jne 0x3967a
movl 0x14(%rsp), %eax
cmpw 0xc(%rsp), %ax
je 0x3974b
movswl %cx, %r8d
movswl %r10w, %ebp
movl %ebp, %r9d
negl %r9d
cmpl %r9d, %r8d
movl %ebx, %eax
movl $0x0, %edx
cmovlel %edx, %eax
subl %eax, %ecx
cmpw %bx, %r8w
cmovgel %edx, %ebp
movl %r13d, %eax
cmovgel %edx, %eax
addl %ecx, %ebp
addl %eax, %r15d
movl %r13d, %eax
movl %ebx, %edx
movl %r14d, %esi
movl %r10d, %edi
cmpl %r9d, %r8d
jle 0x3962e
movl %r13d, %eax
movl %ebx, %edx
movl %r14d, %esi
movl %r10d, %edi
testw %r14w, %r14w
je 0x3962e
addl %r14d, 0x14(%rsp)
movl 0x18(%rsp), %esi
movl %esi, %edi
cmpw %r11w, %si
jne 0x396ee
movl 0x10(%rsp), %eax
cmpw 0xc(%rsp), %ax
je 0x3974b
movswl %r12w, %eax
movl 0x34(%rsp), %r9d
cmpl %r9d, %eax
movl $0x0, %ecx
movl 0x40(%rsp), %edx
cmovgl %edx, %ecx
subl %ecx, %r12d
cmpl %eax, %edx
movl $0x0, %ecx
cmovgl 0x38(%rsp), %ecx
movl $0x0, %edx
cmovgl 0x3c(%rsp), %edx
movl %edi, %esi
addl %ecx, %esi
addl %r12d, %edx
movl %edx, %r12d
cmpl %r9d, %eax
jle 0x396db
movl 0x10(%rsp), %r9d
addl 0x2c(%rsp), %r9d
movl %r10d, 0x20(%rsp)
leaq 0x24(%rsp), %rdi
movl 0x14(%rsp), %eax
jmp 0x395bf
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq