// File: /workspace/github_c_makefile_star2_O1/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, 0x2c(%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 0x3cf38
movl %r9d, %edx
movl %r8d, %esi
jmp 0x3cf42
movl %ecx, %edx
movl %eax, %esi
movl %r9d, %ecx
movl %r8d, %eax
movzwl 0xa(%rdi), %edi
cmpw %si, %r10w
jge 0x3cf56
movl %edx, %r8d
movw %si, 0xe(%rsp)
jmp 0x3cf64
movl %edi, %r8d
movw %r10w, 0xe(%rsp)
movl %edx, %edi
movl %esi, %r10d
movw %r8w, 0x12(%rsp)
cmpw %ax, %r10w
jge 0x3cf76
movl %ecx, %esi
movl %eax, %edx
jmp 0x3cf80
movl %edi, %esi
movl %r10d, %edx
movl %ecx, %edi
movl %eax, %r10d
movw %r10w, 0x10(%rsp)
movl %edi, 0x18(%rsp)
movw %dx, 0x22(%rsp)
movswl %dx, %edx
movswl %r10w, %r9d
movl %r9d, %eax
subl %edx, %eax
movl %eax, %r8d
negl %r8d
cmovsl %eax, %r8d
xorl %r13d, %r13d
cmpw %dx, %r9w
setl %r13b
movw %si, 0x1e(%rsp)
movswl %si, %esi
movswl %di, %r11d
movl %r11d, %ecx
subl %esi, %ecx
movl %ecx, %ebx
negl %ebx
cmovsl %ecx, %ebx
xorl %ecx, %ecx
cmpw %si, %r11w
setl %cl
movl %r8d, 0x14(%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 0xe(%rsp), %r12d
cmpw %r12w, %r9w
setl %dil
xorl %r8d, %r8d
movzwl 0x12(%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, %r15d
subl %r15d, %r9d
movl %r9d, %r12d
negl %r12d
cmovsl %r9d, %r12d
movl %eax, 0x40(%rsp)
cmpl %eax, %ebp
movswl %r12w, %eax
cmovgl %eax, %r11d
movl %r11d, %ebp
shrl $0x1f, %ebp
addl %r11d, %ebp
shrl %ebp
movl %edx, %r9d
subl %r15d, %r9d
movl %r9d, %r11d
negl %r11d
cmovsl %r9d, %r11d
xorl %r9d, %r9d
cmpw %r15w, %dx
setl %r9b
movl %esi, %edx
subl %r10d, %edx
movl %edx, %r15d
negl %r15d
cmovsl %edx, %r15d
xorl %edx, %edx
cmpw %r10w, %si
setl %dl
movl %r15d, 0x50(%rsp)
movswl %r15w, %esi
movl %esi, %r10d
negl %r10d
movl %r11d, 0x54(%rsp)
movswl %r11w, %r11d
cmpl %esi, %r11d
cmovgl %r11d, %r10d
movl %r10d, %r11d
shrl $0x1f, %r11d
addl %r10d, %r11d
movzwl 0x10(%rsp), %esi
leal -0x1(,%r13,2), %r13d
leal -0x1(,%rcx,2), %r12d
leal -0x1(,%rdi,2), %ecx
movl %ecx, 0x38(%rsp)
movl 0x18(%rsp), %r10d
leal -0x1(%r8,%r8), %ecx
movl %ecx, 0x34(%rsp)
leal -0x1(%r9,%r9), %ecx
movl %ecx, 0x48(%rsp)
leal -0x1(,%rdx,2), %ecx
movl %ecx, 0x44(%rsp)
shrl %r11d
movl %r11d, 0x4c(%rsp)
movl %eax, 0x3c(%rsp)
negl %eax
movl %eax, 0x30(%rsp)
leaq 0x24(%rsp), %rdi
movl %esi, %eax
movl %r10d, %r15d
movw %ax, 0x20(%rsp)
cwtl
movw %si, 0x10(%rsp)
movswl %si, %ecx
cmpl %ecx, %eax
movl %ecx, %edx
cmovll %eax, %edx
movw %dx, 0x24(%rsp)
cmovgl %eax, %ecx
movswl %r15w, %eax
movl %r10d, 0x18(%rsp)
movswl %r10w, %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 0x2c(%rsp), %ecx
movq 0x58(%rsp), %rsi
callq 0x35310
movzwl 0x20(%rsp), %eax
movl %eax, %r9d
movzwl 0x1e(%rsp), %r11d
movl 0x14(%rsp), %r8d
movl %r8d, %edx
movl %r13d, %esi
movl %ebx, %edi
movl %r12d, %r8d
cmpw 0x22(%rsp), %ax
jne 0x3d1ba
movl 0x4c(%rsp), %ecx
movl 0x44(%rsp), %r12d
movl 0x50(%rsp), %ebx
movl 0x48(%rsp), %r13d
movl 0x54(%rsp), %r10d
movl %r10d, 0x14(%rsp)
cmpw %r11w, %r15w
je 0x3d1ec
cmpw 0x12(%rsp), %r15w
jne 0x3d1dd
movl %r14d, %ecx
movl %r8d, %r12d
movl %edi, %ebx
movl %esi, %r13d
movl %edx, 0x14(%rsp)
cmpw 0xe(%rsp), %ax
jne 0x3d1ec
jmp 0x3d2a9
movl %r14d, %ecx
movl %r8d, %r12d
movl %edi, %ebx
movl %esi, %r13d
movl %edx, 0x14(%rsp)
movswl %cx, %edx
movl 0x14(%rsp), %r8d
movswl %r8w, %r14d
movl %r14d, %esi
negl %esi
cmpl %esi, %edx
movl $0x0, %esi
cmovgl %ebx, %esi
movl %r13d, %edi
movl $0x0, %r10d
cmovlel %r10d, %edi
subl %esi, %ecx
addl %edi, %eax
cmpw %bx, %dx
cmovgel %r10d, %r14d
movl %r12d, %edx
cmovgel %r10d, %edx
addl %ecx, %r14d
addl %edx, %r15d
cmpw %r9w, %ax
je 0x3d186
movzwl 0x10(%rsp), %ecx
movl 0x18(%rsp), %r10d
movl %r10d, %r8d
cmpw 0x12(%rsp), %r10w
jne 0x3d252
cmpw 0xe(%rsp), %cx
je 0x3d2a9
movswl %bp, %edx
cmpl 0x30(%rsp), %edx
movl $0x0, %esi
cmovgl 0x38(%rsp), %esi
movl $0x0, %edi
movl 0x40(%rsp), %r10d
cmovgl %r10d, %edi
addl %esi, %ecx
subl %edi, %ebp
cmpl %edx, %r10d
movl $0x0, %edx
cmovgl 0x34(%rsp), %edx
movl $0x0, %esi
cmovgl 0x3c(%rsp), %esi
movl %r8d, %r10d
addl %edx, %r10d
addl %ebp, %esi
movl %esi, %ebp
cmpw 0x10(%rsp), %cx
je 0x3d240
movl %ecx, %esi
leaq 0x24(%rsp), %rdi
jmp 0x3d116
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq