// File: /workspace/github_cpp_makefile_star2_O2/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 $0x148, %rsp            # imm = 0x148
movq %rdi, %rbx
xorps %xmm0, %xmm0
leaq -0xa0(%rbp), %rax
movaps %xmm0, (%rax)
andq $0x0, 0x10(%rax)
movq (%rdi), %r13
movsd 0x8(%r13), %xmm0
leaq -0x128(%rbp), %r12
leaq -0x140(%rbp), %r15
movsd %xmm0, -0x30(%rbp)
movsd %xmm0, -0x38(%rbp)
movq 0x8(%rbx), %rcx
leaq -0x18(%rcx), %rax
cmpq %rax, %r13
je 0x4ca0
movups (%r13), %xmm0
movq 0x10(%r13), %rax
movq %rax, -0x130(%rbp)
movaps %xmm0, -0x140(%rbp)
movups 0x18(%r13), %xmm0
movq 0x28(%r13), %rax
movq %rax, 0x10(%r12)
movups %xmm0, (%r12)
leaq -0xa0(%rbp), %rdi
movq %r15, %rsi
callq 0x535a
leaq 0x18(%r13), %r14
movq 0x28(%r13), %rax
movq %rax, 0x28(%rsp)
movups 0x18(%r13), %xmm0
movups %xmm0, 0x18(%rsp)
movq 0x10(%r13), %rax
movq %rax, 0x10(%rsp)
movups (%r13), %xmm0
movups %xmm0, (%rsp)
callq 0x4a07
movsd 0x8(%r13), %xmm0
movapd %xmm0, %xmm1
minsd -0x38(%rbp), %xmm1
maxsd -0x30(%rbp), %xmm0
movq %r14, %r13
movsd %xmm0, -0x30(%rbp)
movsd %xmm1, -0x38(%rbp)
jmp 0x4c02
movsd -0x10(%rcx), %xmm0
movsd %xmm0, -0x60(%rbp)
movq (%rbx), %rcx
movq 0x10(%rcx), %rdx
movq %rdx, -0x40(%rbp)
movupd (%rcx), %xmm0
movapd %xmm0, -0x50(%rbp)
movupd (%rax), %xmm1
movq 0x10(%rax), %rax
leaq -0x140(%rbp), %rsi
movq %rax, 0x10(%rsi)
movapd %xmm1, (%rsi)
movupd %xmm0, 0x18(%rsi)
movq %rdx, 0x28(%rsi)
leaq -0xa0(%rbp), %rdi
callq 0x535a
movsd -0x60(%rbp), %xmm1
movapd %xmm1, %xmm0
minsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x88(%rbp)
maxsd -0x30(%rbp), %xmm1
movsd %xmm1, -0x60(%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 0x4a07
movq (%rbx), %rax
movsd -0x60(%rbp), %xmm15
subsd -0x88(%rbp), %xmm15
movsd 0x44a6(%rip), %xmm0     # 0x91f8
subsd 0x4496(%rip), %xmm0     # 0x91f0
movsd %xmm0, -0x70(%rbp)
divsd %xmm0, %xmm15
cvtsi2sdl 0x44bf(%rip), %xmm12 # 0x922c
mulsd %xmm12, %xmm15
xorpd %xmm1, %xmm1
andq $0x0, -0x40(%rbp)
movapd %xmm1, -0x50(%rbp)
movsd (%rax), %xmm11
movsd 0x8(%rax), %xmm5
movsd 0x18(%rax), %xmm8
movsd 0x20(%rax), %xmm0
movsd 0x30(%rax), %xmm10
movsd 0x38(%rax), %xmm6
movapd %xmm8, %xmm13
xorpd 0x15a2(%rip), %xmm13    # 0x6350
movapd %xmm5, %xmm3
mulsd %xmm13, %xmm3
movapd %xmm11, %xmm2
mulsd %xmm0, %xmm2
movapd %xmm2, %xmm7
addsd %xmm3, %xmm7
movapd %xmm11, %xmm1
mulsd %xmm6, %xmm1
subsd %xmm1, %xmm7
movapd %xmm10, %xmm4
mulsd %xmm5, %xmm4
addsd %xmm4, %xmm7
movapd %xmm8, %xmm9
mulsd %xmm6, %xmm9
addsd %xmm9, %xmm7
movapd %xmm10, %xmm1
mulsd %xmm0, %xmm1
subsd %xmm1, %xmm7
movsd 0x43e2(%rip), %xmm1     # 0x91e8
subsd 0x43d2(%rip), %xmm1     # 0x91e0
movsd %xmm1, -0x68(%rbp)
xorpd %xmm14, %xmm14
ucomisd %xmm14, %xmm7
cvtsi2sdl 0x4403(%rip), %xmm1 # 0x9228
movsd %xmm1, -0x30(%rbp)
movapd %xmm15, %xmm1
jne 0x4e37
jnp 0x4f6a
movsd %xmm1, -0x60(%rbp)
movsd %xmm12, -0x38(%rbp)
movsd 0x10(%rax), %xmm12
movsd 0x28(%rax), %xmm14
movapd %xmm12, %xmm1
mulsd %xmm0, %xmm1
movapd %xmm5, %xmm15
mulsd %xmm14, %xmm15
subsd %xmm1, %xmm15
movsd 0x40(%rax), %xmm1
mulsd %xmm1, %xmm5
subsd %xmm5, %xmm15
movapd %xmm6, %xmm5
mulsd %xmm12, %xmm5
addsd %xmm15, %xmm5
movapd %xmm0, %xmm15
mulsd %xmm1, %xmm15
addsd %xmm5, %xmm15
movapd %xmm6, %xmm5
mulsd %xmm14, %xmm5
subsd %xmm5, %xmm15
movapd %xmm11, %xmm5
mulsd %xmm12, %xmm13
mulsd %xmm14, %xmm11
addsd %xmm13, %xmm11
movapd 0x1494(%rip), %xmm13    # 0x6350
xorpd %xmm13, %xmm5
mulsd %xmm5, %xmm6
mulsd %xmm1, %xmm5
addsd %xmm11, %xmm5
xorpd %xmm10, %xmm13
mulsd %xmm12, %xmm10
addsd %xmm5, %xmm10
mulsd %xmm1, %xmm8
addsd %xmm10, %xmm8
movapd %xmm13, %xmm5
mulsd %xmm14, %xmm5
addsd %xmm8, %xmm5
mulsd %xmm14, %xmm6
mulsd %xmm1, %xmm2
addsd %xmm6, %xmm2
mulsd %xmm1, %xmm3
addsd %xmm2, %xmm3
mulsd %xmm12, %xmm9
addsd %xmm3, %xmm9
mulsd %xmm14, %xmm4
xorpd %xmm14, %xmm14
addsd %xmm9, %xmm4
mulsd %xmm13, %xmm0
mulsd %xmm12, %xmm0
movsd -0x38(%rbp), %xmm12
movsd -0x60(%rbp), %xmm1
xorpd 0x140e(%rip), %xmm15    # 0x6350
addsd %xmm4, %xmm0
divsd %xmm7, %xmm15
movapd %xmm15, -0xf0(%rbp)
divsd %xmm7, %xmm5
movsd %xmm5, -0xa8(%rbp)
divsd %xmm7, %xmm0
movapd %xmm0, %xmm2
jmp 0x4f6a
cvttsd2si %xmm1, %eax
movl %eax, -0x7c(%rbp)
movsd -0x68(%rbp), %xmm0
divsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x68(%rbp)
movsd -0x70(%rbp), %xmm1
divsd %xmm12, %xmm1
movsd %xmm1, -0x70(%rbp)
pushq $0x1
popq %rax
xorl %edi, %edi
pushq $0x2
popq %r13
cmpneqsd %xmm14, %xmm7
movsd 0x144a(%rip), %xmm0     # 0x63f0
movapd %xmm7, %xmm1
andnpd %xmm0, %xmm1
movapd %xmm1, -0x100(%rbp)
xorl %r8d, %r8d
movsd %xmm2, -0xb8(%rbp)
movapd %xmm7, -0x110(%rbp)
cmpl -0x7c(%rbp), %eax
jge 0x52d6
cmpq %r8, %rdi
je 0x4fdb
movq %r8, -0x48(%rbp)
movl %eax, -0x80(%rbp)
cvtsi2sd %eax, %xmm4
mulsd -0x70(%rbp), %xmm4
addsd -0x88(%rbp), %xmm4
movq -0xa0(%rbp), %rbx
movsd %xmm4, -0x78(%rbp)
cmpq -0x98(%rbp), %rbx
je 0x508e
movsd (%rbx), %xmm0
movsd 0x8(%rbx), %xmm2
movsd 0x18(%rbx), %xmm1
movsd 0x20(%rbx), %xmm3
ucomisd %xmm2, %xmm4
jb 0x5027
ucomisd %xmm4, %xmm3
jae 0x5033
ucomisd %xmm4, %xmm2
jb 0x5085
ucomisd %xmm3, %xmm4
jb 0x5085
subsd %xmm0, %xmm1
subsd %xmm2, %xmm3
divsd %xmm3, %xmm1
movapd %xmm4, %xmm3
subsd %xmm2, %xmm3
mulsd %xmm1, %xmm3
addsd %xmm0, %xmm3
movsd %xmm3, -0xd8(%rbp)
movsd %xmm4, -0xd0(%rbp)
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, -0xc8(%rbp)
leaq -0x50(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x4042
movsd -0x78(%rbp), %xmm4
addq $0x30, %rbx
jmp 0x4ffb
movq -0x50(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x5772
movq -0x48(%rbp), %rdi
xorl %ebx, %ebx
movq -0x50(%rbp), %r8
movq %rdi, %rcx
subq %r8, %rcx
movq %rcx, %rax
cqto
pushq $0x18
popq %rsi
idivq %rsi
decq %rax
imulq $0x18, %rbx, %rdx
addq $0x18, %rdx
cmpq %rbx, %rax
jbe 0x511a
incq %rbx
leaq 0x18(%rdx), %r9
movsd -0x18(%r8,%rdx), %xmm0
subsd (%r8,%rdx), %xmm0
andpd 0x12fe(%rip), %xmm0     # 0x63e0
movsd -0x68(%rbp), %xmm1
ucomisd %xmm0, %xmm1
movq %r9, %rdx
jb 0x50c1
leaq (%r8,%r9), %rsi
cmpq %rdi, %rsi
je 0x5110
leaq (%r8,%r9), %rdi
addq $-0x18, %rdi
subq %r9, %rcx
movq %rcx, %rdx
callq 0x1140
movq -0x48(%rbp), %rdi
addq $-0x18, %rdi
movq %rdi, -0x48(%rbp)
jmp 0x50a1
movsd -0xa8(%rbp), %xmm0
mulsd -0x78(%rbp), %xmm0
movsd %xmm0, -0xc0(%rbp)
xorl %ebx, %ebx
movq %rdi, %rax
subq %r8, %rax
cqto
pushq $0x18
popq %rcx
idivq %rcx
shrq %rax
cmpq %rbx, %rax
jbe 0x52cc
imulq $0x30, %rbx, %rax
movsd (%r8,%rax), %xmm1
leaq 0x1(,%rbx,2), %rax
imulq $0x18, %rax, %rax
movsd (%r8,%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
movl 0x40b6(%rip), %ecx      # 0x9228
movl %ecx, %eax
cltd
idivl %r13d
cvtsi2sd %eax, %xmm2
movsd %xmm2, -0xb0(%rbp)
cvtsi2sd %ecx, %xmm3
movsd 0x4058(%rip), %xmm0     # 0x91e8
subsd 0x4048(%rip), %xmm0     # 0x91e0
divsd %xmm0, %xmm3
movsd %xmm3, -0x60(%rbp)
movapd %xmm3, %xmm0
movsd %xmm1, -0x30(%rbp)
mulsd %xmm1, %xmm0
addsd %xmm2, %xmm0
callq 0x1090
cvttsd2si %xmm0, %r14d
movsd -0x60(%rbp), %xmm0
mulsd -0x38(%rbp), %xmm0
addsd -0xb0(%rbp), %xmm0
callq 0x1090
cvttsd2si %xmm0, %r12d
decl %r12d
incl %r14d
movsd -0x30(%rbp), %xmm3
movsd -0x38(%rbp), %xmm0
ucomisd %xmm3, %xmm0
jbe 0x52bc
movl 0x4030(%rip), %ecx      # 0x9228
movl %ecx, %eax
cltd
idivl %r13d
cvtsi2sd %eax, %xmm1
cvtsi2sd %ecx, %xmm0
movsd 0x3fda(%rip), %xmm2     # 0x91e8
subsd 0x3fca(%rip), %xmm2     # 0x91e0
addsd -0x68(%rbp), %xmm3
movsd %xmm3, -0x30(%rbp)
divsd %xmm2, %xmm0
mulsd %xmm3, %xmm0
addsd %xmm1, %xmm0
callq 0x1090
cvttsd2si %xmm0, %r15d
cmpl %r15d, %r12d
jle 0x51de
cmpl %r15d, %r14d
jge 0x51de
movapd -0xf0(%rbp), %xmm0
mulsd -0x30(%rbp), %xmm0
addsd -0xc0(%rbp), %xmm0
addsd -0xb8(%rbp), %xmm0
andpd -0x110(%rbp), %xmm0
orpd -0x100(%rbp), %xmm0
movapd %xmm0, -0x60(%rbp)
movl 0x3fb4(%rip), %eax      # 0x922c
cvtsi2sd %eax, %xmm1
movsd 0x3f74(%rip), %xmm0     # 0x91f8
subsd 0x3f64(%rip), %xmm0     # 0x91f0
divsd %xmm0, %xmm1
cltd
idivl %r13d
cvtsi2sd %eax, %xmm0
mulsd -0x78(%rbp), %xmm1
subsd %xmm1, %xmm0
callq 0x1090
cvttsd2si %xmm0, %esi
movl %r15d, %edi
movapd -0x60(%rbp), %xmm0
callq 0x49bb
jmp 0x51de
incq %rbx
movq -0x50(%rbp), %r8
movq -0x48(%rbp), %rdi
jmp 0x5131
movl -0x80(%rbp), %eax
incl %eax
jmp 0x4fc9
leaq -0x50(%rbp), %rdi
callq 0x3ffe
leaq -0xa0(%rbp), %rdi
callq 0x5584
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x5301
jmp 0x5306
movq %rax, %rbx
jmp 0x5312
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x3ffe
leaq -0xa0(%rbp), %rdi
callq 0x5584
movq %rbx, %rdi
callq 0x1160