// File: /workspace/github_cpp_makefile_star2_O1/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 $0x198, %rsp            # imm = 0x198
movq %rdi, %rbx
xorps %xmm0, %xmm0
movaps %xmm0, -0x80(%rbp)
movq $0x0, -0x70(%rbp)
movq (%rdi), %r13
movq 0x8(%rdi), %rax
movsd 0x8(%r13), %xmm0
leaq -0x18(%rax), %rcx
cmpq %rcx, %r13
je 0x50d6
leaq -0xb8(%rbp), %r12
leaq -0xd0(%rbp), %r15
movsd %xmm0, -0x30(%rbp)
movsd %xmm0, -0x38(%rbp)
movups (%r13), %xmm0
movq 0x10(%r13), %rax
movq %rax, -0xc0(%rbp)
movaps %xmm0, -0xd0(%rbp)
movups 0x18(%r13), %xmm0
movq 0x28(%r13), %rax
movq %rax, 0x10(%r12)
movups %xmm0, (%r12)
movq -0x78(%rbp), %rsi
cmpq -0x70(%rbp), %rsi
je 0x5069
movaps -0xd0(%rbp), %xmm0
movaps -0xc0(%rbp), %xmm1
movaps -0xb0(%rbp), %xmm2
movups %xmm2, 0x20(%rsi)
movups %xmm1, 0x10(%rsi)
movups %xmm0, (%rsi)
addq $0x30, %rsi
movq %rsi, -0x78(%rbp)
jmp 0x5075
leaq -0x80(%rbp), %rdi
movq %r15, %rdx
callq 0x5ad2
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 0x4dd7
movsd 0x8(%r13), %xmm1
movapd %xmm1, %xmm2
minsd -0x38(%rbp), %xmm2
maxsd -0x30(%rbp), %xmm1
movq 0x8(%rbx), %rax
leaq -0x18(%rax), %rcx
movapd %xmm2, %xmm0
movsd %xmm1, -0x30(%rbp)
movq %r14, %r13
cmpq %rcx, %r14
jne 0x5006
jmp 0x50de
movapd %xmm0, %xmm1
movapd %xmm0, %xmm2
movsd %xmm2, -0x58(%rbp)
movsd %xmm1, -0x38(%rbp)
movsd -0x10(%rax), %xmm0
movsd %xmm0, -0x30(%rbp)
movupd (%rcx), %xmm0
movapd %xmm0, -0x170(%rbp)
movq 0x10(%rcx), %rax
movq %rax, -0x160(%rbp)
movq (%rbx), %rcx
movq 0x10(%rcx), %rdx
movupd (%rcx), %xmm1
movapd %xmm0, -0xd0(%rbp)
movq %rax, -0xc0(%rbp)
movupd %xmm1, -0xb8(%rbp)
movq %rdx, -0xa8(%rbp)
movq -0x78(%rbp), %rsi
cmpq -0x70(%rbp), %rsi
je 0x516c
movapd -0xd0(%rbp), %xmm0
movapd -0xc0(%rbp), %xmm1
movapd -0xb0(%rbp), %xmm2
movupd %xmm2, 0x20(%rsi)
movupd %xmm1, 0x10(%rsi)
movupd %xmm0, (%rsi)
addq $0x30, %rsi
movq %rsi, -0x78(%rbp)
jmp 0x517c
leaq -0x80(%rbp), %rdi
leaq -0xd0(%rbp), %rdx
callq 0x5ad2
movsd -0x30(%rbp), %xmm0
movapd %xmm0, %xmm1
minsd -0x58(%rbp), %xmm1
movsd %xmm1, -0xa0(%rbp)
maxsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x30(%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 0x4dd7
movq (%rbx), %rax
movsd -0x30(%rbp), %xmm1
subsd -0xa0(%rbp), %xmm1
movsd 0x5016(%rip), %xmm0     # 0xa1f8
subsd 0x5006(%rip), %xmm0     # 0xa1f0
movsd %xmm0, -0x88(%rbp)
divsd %xmm0, %xmm1
cvtsi2sdl 0x502d(%rip), %xmm13 # 0xa22c
mulsd %xmm13, %xmm1
cvttsd2si %xmm1, %ecx
movl %ecx, -0x5c(%rbp)
xorpd %xmm1, %xmm1
movapd %xmm1, -0x50(%rbp)
movq $0x0, -0x40(%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 0x2107(%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 0x4f3d(%rip), %xmm2     # 0xa1e8
subsd 0x4f2d(%rip), %xmm2     # 0xa1e0
movsd %xmm2, -0x58(%rbp)
xorps %xmm2, %xmm2
cvtsi2sdl 0x4f65(%rip), %xmm2 # 0xa228
jne 0x52cb
jnp 0x5401
movsd %xmm2, -0x38(%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 0x1fff(%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 -0x38(%rbp), %xmm2
xorpd 0x1f7b(%rip), %xmm14    # 0x7350
addsd %xmm3, %xmm1
divsd %xmm6, %xmm14
movapd %xmm14, -0x150(%rbp)
divsd %xmm6, %xmm4
movsd %xmm4, -0xe8(%rbp)
divsd %xmm6, %xmm1
movsd %xmm1, -0xf8(%rbp)
jmp 0x5401
movapd %xmm6, %xmm1
cmpl $0x2, -0x5c(%rbp)
jl 0x585d
movsd -0x58(%rbp), %xmm0
divsd %xmm2, %xmm0
movsd %xmm0, -0x58(%rbp)
movsd -0x88(%rbp), %xmm0
divsd %xmm13, %xmm0
movsd %xmm0, -0x88(%rbp)
movl $0x1, %r13d
movabsq $-0x5555555555555555, %rbx # imm = 0xAAAAAAAAAAAAAAAB
xorpd %xmm0, %xmm0
cmpneqsd %xmm0, %xmm1
movsd 0x1f9d(%rip), %xmm0     # 0x73f0
movapd %xmm1, -0x140(%rbp)
andnpd %xmm0, %xmm1
movapd %xmm1, -0x130(%rbp)
movabsq $0x3ff0000000000000, %r15 # imm = 0x3FF0000000000000
leaq -0x50(%rbp), %r12
movq -0x50(%rbp), %rax
cmpq %rax, -0x48(%rbp)
je 0x5483
movq %rax, -0x48(%rbp)
xorps %xmm0, %xmm0
cvtsi2sd %r13d, %xmm0
mulsd -0x88(%rbp), %xmm0
addsd -0xa0(%rbp), %xmm0
movsd %xmm0, -0x90(%rbp)
movq -0x80(%rbp), %r14
cmpq -0x78(%rbp), %r14
je 0x555b
movsd (%r14), %xmm0
movsd 0x8(%r14), %xmm2
movsd 0x18(%r14), %xmm1
movsd 0x20(%r14), %xmm3
movsd -0x90(%rbp), %xmm4
ucomisd %xmm2, %xmm4
jb 0x54dc
ucomisd %xmm4, %xmm3
jae 0x54e8
ucomisd %xmm4, %xmm2
jb 0x5552
ucomisd %xmm3, %xmm4
jb 0x5552
subsd %xmm0, %xmm1
subsd %xmm2, %xmm3
divsd %xmm3, %xmm1
movapd %xmm4, %xmm3
subsd %xmm2, %xmm3
mulsd %xmm1, %xmm3
addsd %xmm0, %xmm3
movsd %xmm3, -0x118(%rbp)
movsd %xmm4, -0x110(%rbp)
movq %r15, -0x108(%rbp)
movq -0x48(%rbp), %rsi
cmpq -0x40(%rbp), %rsi
je 0x5543
movq -0x108(%rbp), %rax
movq %rax, 0x10(%rsi)
movupd -0x118(%rbp), %xmm0
movupd %xmm0, (%rsi)
addq $0x18, -0x48(%rbp)
jmp 0x5552
movq %r12, %rdi
leaq -0x118(%rbp), %rdx
callq 0x4578
addq $0x30, %r14
jmp 0x54a7
movq -0x50(%rbp), %r15
movq -0x48(%rbp), %r12
cmpq %r12, %r15
je 0x5599
movq %r12, %rax
subq %r15, %rax
sarq $0x3, %rax
imulq %rbx, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r15, %rdi
movq %r12, %rsi
callq 0x5c96
movq %r15, %rdi
movq %r12, %rsi
callq 0x5dc7
movq -0x50(%rbp), %rax
movq -0x48(%rbp), %rdx
movq %rdx, %rcx
subq %rax, %rcx
cmpq $0x18, %rcx
je 0x5628
movl $0x30, %r14d
movq $-0x30, %r15
xorl %r12d, %r12d
movsd -0x30(%rax,%r14), %xmm0
subsd -0x18(%rax,%r14), %xmm0
andpd 0x1e0d(%rip), %xmm0     # 0x73e0
movsd -0x58(%rbp), %xmm1
ucomisd %xmm0, %xmm1
jb 0x55ff
leaq (%rax,%r14), %rsi
cmpq %rdx, %rsi
je 0x55fa
leaq (%rax,%r14), %rdi
addq $-0x18, %rdi
subq %rax, %rdx
addq %r15, %rdx
callq 0x1150
addq $-0x18, -0x48(%rbp)
incq %r12
movq -0x50(%rbp), %rax
movq -0x48(%rbp), %rdx
movq %rdx, %rcx
subq %rax, %rcx
sarq $0x3, %rcx
imulq %rbx, %rcx
decq %rcx
addq $0x18, %r14
addq $-0x18, %r15
cmpq %r12, %rcx
ja 0x55bd
movl %r13d, -0x94(%rbp)
movq -0x50(%rbp), %rax
movq -0x48(%rbp), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
imulq %rbx, %rcx
cmpq $0x2, %rcx
jb 0x583b
movsd -0xe8(%rbp), %xmm0
mulsd -0x90(%rbp), %xmm0
movsd %xmm0, -0x100(%rbp)
xorl %r12d, %r12d
leaq (%r12,%r12,2), %rcx
shlq $0x4, %rcx
movsd (%rax,%rcx), %xmm1
leaq 0x1(,%r12,2), %rcx
leaq (%rcx,%rcx,2), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x38(%rbp)
ucomisd %xmm1, %xmm0
jbe 0x5819
movl 0x4b8e(%rip), %eax      # 0xa228
xorps %xmm2, %xmm2
cvtsi2sd %eax, %xmm2
movsd 0x4b3f(%rip), %xmm0     # 0xa1e8
subsd 0x4b2f(%rip), %xmm0     # 0xa1e0
movl %eax, %ecx
shrl $0x1f, %ecx
addl %eax, %ecx
sarl %ecx
xorps %xmm3, %xmm3
cvtsi2sd %ecx, %xmm3
movsd %xmm3, -0xf0(%rbp)
divsd %xmm0, %xmm2
movsd %xmm2, -0xe0(%rbp)
movapd %xmm2, %xmm0
mulsd -0x38(%rbp), %xmm0
addsd %xmm3, %xmm0
movsd %xmm1, -0x30(%rbp)
callq 0x1090
cvttsd2si %xmm0, %r14d
movsd -0xe0(%rbp), %xmm0
mulsd -0x30(%rbp), %xmm0
addsd -0xf0(%rbp), %xmm0
callq 0x1090
movsd -0x30(%rbp), %xmm3
cvttsd2si %xmm0, %r13d
decl %r14d
incl %r13d
movl 0x4b07(%rip), %eax      # 0xa228
movl %eax, %ecx
shrl $0x1f, %ecx
addl %eax, %ecx
sarl %ecx
xorps %xmm1, %xmm1
cvtsi2sd %ecx, %xmm1
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd 0x4aa8(%rip), %xmm2     # 0xa1e8
subsd 0x4a98(%rip), %xmm2     # 0xa1e0
addsd -0x58(%rbp), %xmm3
divsd %xmm2, %xmm0
movsd %xmm3, -0x30(%rbp)
mulsd %xmm3, %xmm0
addsd %xmm1, %xmm0
callq 0x1090
cvttsd2si %xmm0, %r15d
cmpl %r15d, %r14d
jle 0x5805
cmpl %r15d, %r13d
jge 0x5805
movapd -0x150(%rbp), %xmm0
mulsd -0x30(%rbp), %xmm0
addsd -0x100(%rbp), %xmm0
addsd -0xf8(%rbp), %xmm0
andpd -0x140(%rbp), %xmm0
orpd -0x130(%rbp), %xmm0
movapd %xmm0, -0xe0(%rbp)
movl 0x4a77(%rip), %eax      # 0xa22c
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
movsd 0x4a34(%rip), %xmm0     # 0xa1f8
subsd 0x4a24(%rip), %xmm0     # 0xa1f0
divsd %xmm0, %xmm1
movl %eax, %ecx
shrl $0x1f, %ecx
addl %eax, %ecx
sarl %ecx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
mulsd -0x90(%rbp), %xmm1
subsd %xmm1, %xmm0
callq 0x1090
cvttsd2si %xmm0, %esi
movl %r15d, %edi
movapd -0xe0(%rbp), %xmm0
callq 0x4d8b
movsd -0x30(%rbp), %xmm3
movsd -0x38(%rbp), %xmm0
ucomisd %xmm3, %xmm0
ja 0x571b
incq %r12
movq -0x50(%rbp), %rax
movq -0x48(%rbp), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
imulq %rbx, %rcx
shrq %rcx
cmpq %r12, %rcx
ja 0x5667
movl -0x94(%rbp), %r13d
incl %r13d
cmpl -0x5c(%rbp), %r13d
movabsq $0x3ff0000000000000, %r15 # imm = 0x3FF0000000000000
leaq -0x50(%rbp), %r12
jne 0x5475
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x5872
movq -0x40(%rbp), %rsi
subq %rdi, %rsi
callq 0x1110
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0x5887
movq -0x70(%rbp), %rsi
subq %rdi, %rsi
callq 0x1110
addq $0x198, %rsp            # imm = 0x198
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x589b
movq %rax, %rbx
jmp 0x58ba
jmp 0x58a2
movq %rax, %rbx
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x58ba
movq -0x40(%rbp), %rsi
subq %rdi, %rsi
callq 0x1110
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0x58cf
movq -0x70(%rbp), %rsi
subq %rdi, %rsi
callq 0x1110
movq %rbx, %rdi
callq 0x1170
nop