// File: /workspace/github_cpp_makefile_star2_O3/XuhuiSun95[P]My-OpenGL/primitive.cpp
// Function: surfaceCheck(std::vector<pixel, std::allocator<pixel>>)
void surfaceCheck(vector<pixel> pointList){
    vector<line> edgeList;
    vector<pixel>::iterator it=pointList.begin();
    double xmin = it -> x, xmax = it -> x, ymin = it -> y, ymax = it -> y, zvalueAverage = it -> zDepth;
    for (; it != pointList.end() - 1; it++){
        line e(*it, *(it + 1));
        edgeList.push_back(e);
        lineCheck(*it, *(it + 1));
        if(it -> x < xmin)	xmin = it -> x;
        if(it -> x > xmax)	xmax = it -> x;
        if(it -> y < ymin)	ymin = it -> y;
        if(it -> y > ymax)	ymax = it -> y;
        zvalueAverage += it -> zDepth;
    }
    it = pointList.end() - 1;
    if(it -> x < xmin)	xmin = it -> x;
    if(it -> x > xmax)	xmax = it -> x;
    if(it -> y < ymin)	ymin = it -> y;
    if(it -> y > ymax)	ymax = it -> y;
    line e(*(pointList.end()-1), *pointList.begin());
    edgeList.push_back(e);
    lineCheck(*(pointList.end()-1), *pointList.begin());
    zvalueAverage /= pointList.size();
    int numLine = (ymax - ymin) / (frustumTop - frustumBottom) * dimy;
    double xInc = (frustumRight - frustumLeft) / dimx, yInc = (frustumTop - frustumBottom) / dimy, x, y, x1, y1, x2, y2;
    vector<pixel> insecPoint;
    pixel pleft, pright;
    double x_1 = pointList[0].x;
    double y_1 = pointList[0].y;
    double z_1 = pointList[0].zDepth;
    double x_2 = pointList[1].x;
    double y_2 = pointList[1].y;
    double z_2 = pointList[1].zDepth;
    double x_3 = pointList[2].x;
    double y_3 = pointList[2].y;
    double z_3 = pointList[2].zDepth;
    double xvalue = x_1 * y_2 - x_2 * y_1 - x_1 * y_3 + x_3 * y_1 + x_2 * y_3 - x_3 * y_2;
    double avalue, bvalue, cvalue;
    if(xvalue != 0){
        avalue = - (y_1 * z_2 - y_2 * z_1 - y_1 * z_3 + y_3 * z_1 + y_2 * z_3 - y_3 * z_2) / xvalue;
        bvalue = (x_1 * z_2 - x_2 * z_1 - x_1 * z_3 + x_3 * z_1 + x_2 * z_3 - x_3 * z_2) / xvalue;
        cvalue = (x_1 * y_2 * z_3 - x_1 * y_3 * z_2 - x_2 * y_1 * z_3 + x_2 * y_3 * z_1 + x_3 * y_1 * z_2 - x_3 * y_2 * z_1) / xvalue;
    }
    for(int i = 1; i < numLine; i++){
        insecPoint.clear();
        y = ymin + yInc * i;
        for(vector<line>::iterator it = edgeList.begin(); it != edgeList.end(); it++){
            x1 = it -> p1.x;
            x2 = it -> p2.x;
            y1 = it -> p1.y;
            y2 = it -> p2.y;
            if((y >= y1 && y <= y2) || (y <= y1 && y >= y2)){
                x = (x2 - x1) / (y2 - y1) * (y - y1) + x1;
                insecPoint.push_back(pixel(x, y, 1));
            }
        }
        sort(insecPoint.begin(), insecPoint.end());
        for(int i = 0; i < insecPoint.size() - 1; i++){
            if(fabs(insecPoint[i].x - insecPoint[i+1].x) <= xInc)
                insecPoint.erase(insecPoint.begin()+i+1);
        }
        for(int i = 0; i < insecPoint.size() / 2; i++){
            pleft = insecPoint[2*i];
            pright = insecPoint[2*i + 1];
            x = pleft.x;
            int pxleft  = round(dimx / 2 + dimx / (frustumRight - frustumLeft) * pleft.x);
            int pxright  = round(dimx / 2 + dimx / (frustumRight - frustumLeft) * pright.x);
            while(x < pright.x){
                x += xInc;
                int px = round(dimx / 2 + dimx / (frustumRight - frustumLeft) * x);
                int py = round(dimy / 2 - dimy / (frustumTop - frustumBottom) * y);
                double zDepth = -100;
                if(xvalue != 0)
                    zDepth = avalue * x + bvalue * y + cvalue;
                if(px < (pxright - 1) && px > (pxleft + 1))
                    hidenSurface(px, py, zDepth);
            }
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x178, %rsp            # imm = 0x178
movq %rdi, %rbx
xorps %xmm0, %xmm0
movaps %xmm0, -0x90(%rbp)
movq $0x0, -0x80(%rbp)
movq (%rdi), %r12
movq 0x8(%rdi), %rcx
movsd 0x8(%r12), %xmm0
leaq -0x18(%rcx), %rax
cmpq %rax, %r12
movsd %xmm0, -0x30(%rbp)
je 0x4ff0
leaq -0xd8(%rbp), %r13
leaq -0xf0(%rbp), %r15
movsd %xmm0, -0x40(%rbp)
movups (%r12), %xmm0
movq 0x10(%r12), %rax
movq %rax, -0xe0(%rbp)
movaps %xmm0, -0xf0(%rbp)
movups 0x18(%r12), %xmm0
movq 0x28(%r12), %rax
movq %rax, 0x10(%r13)
movups %xmm0, (%r13)
movq -0x88(%rbp), %rsi
cmpq -0x80(%rbp), %rsi
je 0x4f62
movaps -0xf0(%rbp), %xmm0
movaps -0xe0(%rbp), %xmm1
movapd -0xd0(%rbp), %xmm2
movupd %xmm2, 0x20(%rsi)
movups %xmm1, 0x10(%rsi)
movups %xmm0, (%rsi)
addq $0x30, %rsi
movq %rsi, -0x88(%rbp)
jmp 0x4f71
leaq -0x90(%rbp), %rdi
movq %r15, %rdx
callq 0x5a4e
leaq 0x18(%r12), %r14
movq 0x28(%r12), %rax
movq %rax, 0x28(%rsp)
movups 0x18(%r12), %xmm0
movups %xmm0, 0x18(%rsp)
movq 0x10(%r12), %rax
movq %rax, 0x10(%rsp)
movups (%r12), %xmm0
movups %xmm0, (%rsp)
callq 0x4ccb
movsd 0x8(%r12), %xmm0
movapd %xmm0, %xmm1
minsd -0x30(%rbp), %xmm1
maxsd -0x40(%rbp), %xmm0
movq 0x8(%rbx), %rcx
leaq -0x18(%rcx), %rax
movsd %xmm1, -0x30(%rbp)
movsd %xmm0, -0x40(%rbp)
movq %r14, %r12
cmpq %rax, %r14
jne 0x4efa
movsd %xmm1, -0x68(%rbp)
movq (%rbx), %r12
movq -0x88(%rbp), %rsi
movq -0x80(%rbp), %rdx
movsd %xmm0, -0x30(%rbp)
jmp 0x4ff9
xorl %edx, %edx
xorl %esi, %esi
movsd %xmm0, -0x68(%rbp)
movsd -0x10(%rcx), %xmm0
movsd %xmm0, -0x40(%rbp)
movq 0x10(%r12), %rcx
movq %rcx, -0x50(%rbp)
movupd (%r12), %xmm0
movapd %xmm0, -0x60(%rbp)
movupd (%rax), %xmm1
movq 0x10(%rax), %rax
movq %rax, -0xe0(%rbp)
movapd %xmm1, -0xf0(%rbp)
movupd %xmm0, -0xd8(%rbp)
movq %rcx, -0xc8(%rbp)
cmpq %rdx, %rsi
je 0x5075
movapd -0xf0(%rbp), %xmm0
movapd -0xe0(%rbp), %xmm1
movapd -0xd0(%rbp), %xmm2
movupd %xmm2, 0x20(%rsi)
movupd %xmm1, 0x10(%rsi)
movupd %xmm0, (%rsi)
addq $0x30, %rsi
movq %rsi, -0x88(%rbp)
jmp 0x5088
leaq -0x90(%rbp), %rdi
leaq -0xf0(%rbp), %rdx
callq 0x5a4e
movsd -0x40(%rbp), %xmm0
movapd %xmm0, %xmm1
minsd -0x68(%rbp), %xmm1
movsd %xmm1, -0xb8(%rbp)
maxsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
movq 0x10(%rax), %rdx
movq %rdx, 0x28(%rsp)
movups (%rax), %xmm0
movups %xmm0, 0x18(%rsp)
movq -0x8(%rcx), %rax
movq %rax, 0x10(%rsp)
movups -0x18(%rcx), %xmm0
movups %xmm0, (%rsp)
callq 0x4ccb
movq (%rbx), %rax
movsd -0x40(%rbp), %xmm1
subsd -0xb8(%rbp), %xmm1
movsd 0x510a(%rip), %xmm0     # 0xa1f8
subsd 0x50fa(%rip), %xmm0     # 0xa1f0
movsd %xmm0, -0xa0(%rbp)
divsd %xmm0, %xmm1
cvtsi2sdl 0x5121(%rip), %xmm13 # 0xa22c
mulsd %xmm13, %xmm1
cvttsd2si %xmm1, %ecx
movl %ecx, -0x6c(%rbp)
xorpd %xmm1, %xmm1
movapd %xmm1, -0x60(%rbp)
movq $0x0, -0x50(%rbp)
movsd (%rax), %xmm10
movsd 0x8(%rax), %xmm4
movsd 0x18(%rax), %xmm7
movsd 0x20(%rax), %xmm1
movsd 0x30(%rax), %xmm9
movsd 0x38(%rax), %xmm5
movapd %xmm7, %xmm12
xorpd 0x21fb(%rip), %xmm12    # 0x7350
movapd %xmm4, %xmm0
mulsd %xmm12, %xmm0
movapd %xmm10, %xmm11
mulsd %xmm1, %xmm11
movapd %xmm11, %xmm6
addsd %xmm0, %xmm6
movapd %xmm10, %xmm2
mulsd %xmm5, %xmm2
subsd %xmm2, %xmm6
movapd %xmm9, %xmm3
mulsd %xmm4, %xmm3
addsd %xmm3, %xmm6
movapd %xmm7, %xmm8
mulsd %xmm5, %xmm8
addsd %xmm8, %xmm6
movapd %xmm9, %xmm2
mulsd %xmm1, %xmm2
subsd %xmm2, %xmm6
xorpd %xmm2, %xmm2
ucomisd %xmm2, %xmm6
movsd 0x5031(%rip), %xmm2     # 0xa1e8
subsd 0x5021(%rip), %xmm2     # 0xa1e0
movsd %xmm2, -0x98(%rbp)
xorps %xmm2, %xmm2
cvtsi2sdl 0x5056(%rip), %xmm2 # 0xa228
jne 0x51da
jnp 0x5308
movsd %xmm2, -0x40(%rbp)
movsd 0x10(%rax), %xmm2
movsd %xmm13, -0x30(%rbp)
movsd 0x28(%rax), %xmm13
movapd %xmm2, %xmm15
mulsd %xmm1, %xmm15
movapd %xmm4, %xmm14
mulsd %xmm13, %xmm14
subsd %xmm15, %xmm14
movsd 0x40(%rax), %xmm15
mulsd %xmm15, %xmm4
subsd %xmm4, %xmm14
movapd %xmm5, %xmm4
mulsd %xmm2, %xmm4
addsd %xmm14, %xmm4
movapd %xmm1, %xmm14
mulsd %xmm15, %xmm14
addsd %xmm4, %xmm14
movapd %xmm5, %xmm4
mulsd %xmm13, %xmm4
subsd %xmm4, %xmm14
movapd %xmm10, %xmm4
mulsd %xmm2, %xmm12
mulsd %xmm13, %xmm10
addsd %xmm12, %xmm10
movapd 0x20f0(%rip), %xmm12    # 0x7350
xorpd %xmm12, %xmm4
mulsd %xmm4, %xmm5
mulsd %xmm15, %xmm4
addsd %xmm10, %xmm4
xorpd %xmm9, %xmm12
mulsd %xmm2, %xmm9
addsd %xmm4, %xmm9
mulsd %xmm15, %xmm7
addsd %xmm9, %xmm7
movapd %xmm12, %xmm4
mulsd %xmm13, %xmm4
addsd %xmm7, %xmm4
mulsd %xmm13, %xmm5
mulsd %xmm15, %xmm11
addsd %xmm5, %xmm11
mulsd %xmm15, %xmm0
addsd %xmm11, %xmm0
mulsd %xmm2, %xmm8
addsd %xmm0, %xmm8
mulsd %xmm13, %xmm3
movsd -0x30(%rbp), %xmm13
addsd %xmm8, %xmm3
mulsd %xmm12, %xmm1
mulsd %xmm2, %xmm1
movsd -0x40(%rbp), %xmm2
xorpd 0x206c(%rip), %xmm14    # 0x7350
addsd %xmm3, %xmm1
divsd %xmm6, %xmm14
movapd %xmm14, -0x170(%rbp)
divsd %xmm6, %xmm4
movsd %xmm4, -0xf8(%rbp)
divsd %xmm6, %xmm1
jmp 0x5308
cmpl $0x2, -0x6c(%rbp)
jl 0x57dc
movsd %xmm1, -0x110(%rbp)
movsd -0x98(%rbp), %xmm0
divsd %xmm2, %xmm0
movsd %xmm0, -0x98(%rbp)
movsd -0xa0(%rbp), %xmm0
divsd %xmm13, %xmm0
movsd %xmm0, -0xa0(%rbp)
movl $0x1, %r14d
xorl %r15d, %r15d
xorpd %xmm0, %xmm0
cmpneqsd %xmm0, %xmm6
movsd 0x2093(%rip), %xmm0     # 0x73f0
movapd %xmm6, -0x160(%rbp)
andnpd %xmm0, %xmm6
movapd %xmm6, -0x150(%rbp)
movabsq $0x3ff0000000000000, %r13 # imm = 0x3FF0000000000000
xorl %r12d, %r12d
cmpq %r15, %r12
je 0x538a
movq %r15, -0x58(%rbp)
movq %r15, %r12
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
mulsd -0xa0(%rbp), %xmm0
addsd -0xb8(%rbp), %xmm0
movsd %xmm0, -0xa8(%rbp)
movq -0x90(%rbp), %rbx
movq -0x88(%rbp), %rax
cmpq %rax, %rbx
je 0x547b
movsd (%rbx), %xmm0
movsd 0x8(%rbx), %xmm2
movsd 0x18(%rbx), %xmm1
movsd 0x20(%rbx), %xmm3
movsd -0xa8(%rbp), %xmm4
ucomisd %xmm2, %xmm4
jb 0x53e8
ucomisd %xmm4, %xmm3
jae 0x53f4
ucomisd %xmm4, %xmm2
jb 0x5466
ucomisd %xmm3, %xmm4
jb 0x5466
subsd %xmm0, %xmm1
subsd %xmm2, %xmm3
divsd %xmm3, %xmm1
movapd %xmm4, %xmm3
subsd %xmm2, %xmm3
mulsd %xmm1, %xmm3
addsd %xmm0, %xmm3
movsd %xmm3, -0x138(%rbp)
movsd %xmm4, -0x130(%rbp)
movq %r13, -0x128(%rbp)
movq -0x58(%rbp), %rsi
cmpq -0x50(%rbp), %rsi
je 0x544f
movq -0x128(%rbp), %rax
movq %rax, 0x10(%rsi)
movupd -0x138(%rbp), %xmm0
movupd %xmm0, (%rsi)
addq $0x18, -0x58(%rbp)
jmp 0x545f
leaq -0x60(%rbp), %rdi
leaq -0x138(%rbp), %rdx
callq 0x4470
movq -0x88(%rbp), %rax
addq $0x30, %rbx
cmpq %rax, %rbx
jne 0x53c1
movq -0x60(%rbp), %r15
movq -0x58(%rbp), %r12
cmpq %r12, %r15
movl %r14d, -0xac(%rbp)
je 0x54ca
movq %r12, %rax
subq %r15, %rax
sarq $0x3, %rax
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r15, %rdi
movq %r12, %rsi
callq 0x5c12
movq %r15, %rdi
movq %r12, %rsi
callq 0x5d43
movq -0x60(%rbp), %r15
movq -0x58(%rbp), %r12
movq %r12, %rax
subq %r15, %rax
cmpq $0x18, %rax
je 0x57b4
movl $0x30, %r14d
movq $-0x30, %r13
xorl %ebx, %ebx
movsd -0x30(%r15,%r14), %xmm0
subsd -0x18(%r15,%r14), %xmm0
andpd 0x1ee1(%rip), %xmm0     # 0x73e0
movsd -0x98(%rbp), %xmm1
ucomisd %xmm0, %xmm1
jb 0x553c
leaq (%r15,%r14), %rsi
cmpq %r12, %rsi
je 0x5534
leaq (%r15,%r14), %rdi
addq $-0x18, %rdi
subq %r15, %r12
addq %r13, %r12
movq %r12, %rdx
callq 0x1140
movq -0x60(%rbp), %r15
movq -0x58(%rbp), %r12
addq $-0x18, %r12
movq %r12, -0x58(%rbp)
incq %rbx
movq %r12, %rax
subq %r15, %rax
sarq $0x3, %rax
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rax
decq %rax
addq $0x18, %r14
addq $-0x18, %r13
cmpq %rbx, %rax
ja 0x54e9
movq %r12, %rax
subq %r15, %rax
sarq $0x3, %rax
imulq %rcx, %rax
cmpq $0x2, %rax
movabsq $0x3ff0000000000000, %r13 # imm = 0x3FF0000000000000
jb 0x57b4
movsd -0xf8(%rbp), %xmm0
mulsd -0xa8(%rbp), %xmm0
movsd %xmm0, -0x118(%rbp)
xorl %r14d, %r14d
leaq (%r14,%r14,2), %rax
shlq $0x4, %rax
movsd (%r15,%rax), %xmm1
leaq 0x1(,%r14,2), %rax
leaq (%rax,%rax,2), %rax
movsd (%r15,%rax,8), %xmm2
ucomisd %xmm1, %xmm2
jbe 0x578d
movl 0x4c54(%rip), %ebx      # 0xa228
xorps %xmm4, %xmm4
cvtsi2sd %ebx, %xmm4
movsd 0x4c05(%rip), %xmm0     # 0xa1e8
movsd 0x4bf5(%rip), %xmm3     # 0xa1e0
movsd %xmm0, -0x40(%rbp)
movsd %xmm3, -0x68(%rbp)
subsd %xmm3, %xmm0
movl %ebx, %eax
shrl $0x1f, %eax
addl %ebx, %eax
sarl %eax
xorps %xmm3, %xmm3
cvtsi2sd %eax, %xmm3
movsd %xmm3, -0x100(%rbp)
divsd %xmm0, %xmm4
movsd %xmm4, -0x108(%rbp)
movapd %xmm4, %xmm0
movsd %xmm2, -0x120(%rbp)
mulsd %xmm2, %xmm0
addsd %xmm3, %xmm0
movsd %xmm1, -0x30(%rbp)
callq 0x1090
cvttsd2si %xmm0, %r12d
movsd -0x108(%rbp), %xmm0
mulsd -0x30(%rbp), %xmm0
addsd -0x100(%rbp), %xmm0
callq 0x1090
movsd -0x30(%rbp), %xmm3
cvttsd2si %xmm0, %r13d
decl %r12d
incl %r13d
movl %ebx, %eax
shrl $0x1f, %eax
addl %ebx, %eax
sarl %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
addsd -0x98(%rbp), %xmm3
xorps %xmm0, %xmm0
cvtsi2sd %ebx, %xmm0
movsd -0x40(%rbp), %xmm2
subsd -0x68(%rbp), %xmm2
divsd %xmm2, %xmm0
movsd %xmm3, -0x30(%rbp)
mulsd %xmm3, %xmm0
addsd %xmm1, %xmm0
callq 0x1090
cvttsd2si %xmm0, %r15d
cmpl %r15d, %r12d
jle 0x5764
cmpl %r15d, %r13d
jge 0x5764
movapd -0x170(%rbp), %xmm0
mulsd -0x30(%rbp), %xmm0
addsd -0x118(%rbp), %xmm0
addsd -0x110(%rbp), %xmm0
andpd -0x160(%rbp), %xmm0
orpd -0x150(%rbp), %xmm0
movapd %xmm0, -0x40(%rbp)
movl 0x4b34(%rip), %eax      # 0xa22c
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
movsd 0x4af1(%rip), %xmm0     # 0xa1f8
subsd 0x4ae1(%rip), %xmm0     # 0xa1f0
divsd %xmm0, %xmm1
movl %eax, %ecx
shrl $0x1f, %ecx
addl %eax, %ecx
sarl %ecx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
mulsd -0xa8(%rbp), %xmm1
subsd %xmm1, %xmm0
callq 0x1090
cvttsd2si %xmm0, %esi
movl %r15d, %edi
movaps -0x40(%rbp), %xmm0
callq 0x4c7f
movl 0x4ade(%rip), %ebx      # 0xa228
movsd 0x4a96(%rip), %xmm0     # 0xa1e8
movsd %xmm0, -0x40(%rbp)
movsd 0x4a81(%rip), %xmm0     # 0xa1e0
movsd %xmm0, -0x68(%rbp)
movsd -0x30(%rbp), %xmm3
movsd -0x120(%rbp), %xmm0
ucomisd %xmm3, %xmm0
ja 0x566a
movq -0x60(%rbp), %r15
movq -0x58(%rbp), %r12
movabsq $0x3ff0000000000000, %r13 # imm = 0x3FF0000000000000
incq %r14
movq %r12, %rax
subq %r15, %rax
sarq $0x3, %rax
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rax
shrq %rax
cmpq %r14, %rax
ja 0x55a4
movl -0xac(%rbp), %r14d
incl %r14d
cmpl -0x6c(%rbp), %r14d
jne 0x537e
testq %r15, %r15
je 0x57dc
movq -0x50(%rbp), %rsi
subq %r15, %rsi
movq %r15, %rdi
callq 0x1100
movq -0x90(%rbp), %rdi
testq %rdi, %rdi
je 0x57f4
movq -0x80(%rbp), %rsi
subq %rdi, %rsi
callq 0x1100
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x5808
movq %rax, %rbx
jmp 0x5827
jmp 0x580f
movq %rax, %rbx
movq -0x60(%rbp), %rdi
testq %rdi, %rdi
je 0x5827
movq -0x50(%rbp), %rsi
subq %rdi, %rsi
callq 0x1100
movq -0x90(%rbp), %rdi
testq %rdi, %rdi
je 0x583f
movq -0x80(%rbp), %rsi
subq %rdi, %rsi
callq 0x1100
movq %rbx, %rdi
callq 0x1160
nop