// File: kryffin[P]software-rasterizer/rasterizer.cpp
// Function: render(Model, Mat4f, Mat4f, Mat4f)
std::vector<int> render (Model model, Mat4f P, Mat4f M, Mat4f C) {

    std::vector<int>frameBuffer(WIDTH * HEIGHT); //single colored pixels for the grayscale
    std::vector<float>zBuffer(WIDTH * HEIGHT);

    std::fill(frameBuffer.begin(), frameBuffer.end(), BACKGROUND_COLOR);
    std::fill(zBuffer.begin(), zBuffer.end(), FLT_MIN);

	//
	// iteration through all the triangles of the model
    
    int i;
    for (i = 0; i < model.nTriangles(); i++) {

    	//triangle indices
    	int tv0 = model.triangleVertice(i, 0), tv1 = model.triangleVertice(i, 1), tv2 = model.triangleVertice(i, 2);

    	// triangle vertices
        Vec3f p0 = model.vertice(tv0);
		Vec3f p1 = model.vertice(tv1);
		Vec3f p2 = model.vertice(tv2);

		// vertices normals
		Vec3f vn0 = model.normal(tv0);
		Vec3f vn1 = model.normal(tv1);
		Vec3f vn2 = model.normal(tv2);

		Vec3f tp0 = p0;
		Vec3f tp1 = p1;
		Vec3f tp2 = p2;

		//
		// world transformation

		tp0 = M * tp0;
		tp1 = M * tp1;
		tp2 = M * tp2;

		//
		// transformation to get along with the camera

        tp0 = C * tp0;
		tp1 = C * tp1;
		tp2 = C * tp2;

        //
        // normal of triangle calculation : average of the 3 vertices' normals
        
        Vec3f surfaceNormal = ((vn0 + vn1 + vn2) * (1.f / 3.f)).normalize();

        //
		// projection of the vertices - clean that somehow

        Vec3f pp0 = P * tp0;
		Vec3f pp1 = P * tp1;
		Vec3f pp2 = P * tp2;

		pp0.x += 1.f; pp0.y += 1.f;
		pp1.x += 1.f; pp1.y += 1.f;
		pp2.x += 1.f; pp2.y += 1.f;

		pp0.x /= 2.f; pp0.y /= 2.f;
		pp1.x /= 2.f; pp1.y /= 2.f;
		pp2.x /= 2.f; pp2.y /= 2.f;

		pp0.x *= (float)WIDTH; pp0.y *= (float)HEIGHT; pp0.z *= 2.f;
		pp1.x *= (float)WIDTH; pp1.y *= (float)HEIGHT; pp1.z *= 2.f;
		pp2.x *= (float)WIDTH; pp2.y *= (float)HEIGHT; pp2.z *= 2.f;
        
        //
    	// constant light exposure

        Vec3f lightDirection = Vec3f(0.f, 0.f, 1.f).normalize();

        //
        // angle between triangle normal and light direction

        float dot = surfaceNormal.dot(lightDirection);

        //
        // bounding box init -- clean that somehow

        Vec2f bboxMin(FLT_MAX, FLT_MAX);
        Vec2f bboxMax(FLT_MIN, FLT_MIN);
        
        if (pp0.x < bboxMin.x) bboxMin.x = pp0.x;
        if (pp0.y < bboxMin.y) bboxMin.y = pp0.y;
        if (pp0.x > bboxMax.x) bboxMax.x = pp0.x;
        if (pp0.y > bboxMax.y) bboxMax.y = pp0.y;

        if (pp1.x < bboxMin.x) bboxMin.x = pp1.x;
        if (pp1.y < bboxMin.y) bboxMin.y = pp1.y;
        if (pp1.x > bboxMax.x) bboxMax.x = pp1.x;
        if (pp1.y > bboxMax.y) bboxMax.y = pp1.y;

        if (pp2.x < bboxMin.x) bboxMin.x = pp2.x;
        if (pp2.y < bboxMin.y) bboxMin.y = pp2.y;
        if (pp2.x > bboxMax.x) bboxMax.x = pp2.x;
        if (pp2.y > bboxMax.y) bboxMax.y = pp2.y;
        
        //
        // bounding box clamping in-screen -- clean that somehow

        bboxMin.x = std::max(0.f, std::min(bboxMin.x, (float)WIDTH));
        bboxMin.y = std::max(0.f, std::min(bboxMin.y, (float)HEIGHT));
        bboxMax.x = std::max(0.f, std::min(bboxMax.x, (float)WIDTH));
        bboxMax.y = std::max(0.f, std::min(bboxMax.y, (float)HEIGHT));

        //
        // iterating through the bounding box -- maybe clean that?

        Vec3f pixel;
        for (pixel.x = (int)bboxMin.x; pixel.x < bboxMax.x; pixel.x++) {
            for (pixel.y = (int)bboxMin.y; pixel.y < bboxMax.y; pixel.y++) {

            	// barycenter of the pixel relative to the triangle (whether or not the pixel is in the triangle)
                Vec3f bc = barycenter(pp0, pp1, pp2, pixel);

                if (bc.x >= 0 && bc.y >= 0 && bc.z >= 0) {
                	
                	// depth of the triangle by average of z coordinates
                	pixel.z = (p0.z + p1.z + p2.z) / 3.f;

            		// drawing (only if nearest pixel visited)
                	if (zBuffer[(int)pixel.x + ((int)pixel.y * WIDTH)] < pixel.z) {

                		// updating the zBuffer
                		zBuffer[(int)pixel.x + ((int)pixel.y * WIDTH)] = pixel.z;

                		if (dot < 0.f) dot = 0.f;

	                    frameBuffer[pixel.x + (pixel.y * WIDTH)] = (0.21f * (MODEL_R * dot)) + (0.72f * (MODEL_G * dot)) + (0.07f * (MODEL_B * dot));
                	}
                }

            }
        }
    }

    // return the frame buffer write image outside
    return frameBuffer;

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x8e0, %rsp            # imm = 0x8E0
movq %rsi, -0x5d0(%rbp)
movq %rdi, -0x5a8(%rbp)
movq %rdi, %rax
movq %rax, -0x5c8(%rbp)
leaq 0x90(%rbp), %rax
movq %rax, -0x5c0(%rbp)
leaq 0x50(%rbp), %rax
movq %rax, -0x5b8(%rbp)
leaq 0x10(%rbp), %rax
movq %rax, -0x5b0(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movb $0x0, -0x11(%rbp)
leaq -0x12(%rbp), %rdi
movq %rdi, -0x5a0(%rbp)
callq 0x55e0
movq -0x5a8(%rbp), %rdi
movq -0x5a0(%rbp), %rdx
movl $0x9c400, %esi          # imm = 0x9C400
callq 0x5600
jmp 0x327d
leaq -0x12(%rbp), %rdi
callq 0x5670
leaq -0x41(%rbp), %rdi
movq %rdi, -0x5d8(%rbp)
callq 0x5690
movq -0x5d8(%rbp), %rdx
leaq -0x40(%rbp), %rdi
movl $0x9c400, %esi          # imm = 0x9C400
callq 0x56b0
jmp 0x32ad
leaq -0x41(%rbp), %rdi
callq 0x5720
movq -0x5a8(%rbp), %rdi
callq 0x5780
movq -0x5a8(%rbp), %rdi
movq %rax, -0x50(%rbp)
callq 0x57b0
movq %rax, -0x58(%rbp)
movl $0x0, -0x5c(%rbp)
movq -0x50(%rbp), %rdi
movq -0x58(%rbp), %rsi
leaq -0x5c(%rbp), %rdx
callq 0x5740
jmp 0x32f0
leaq -0x40(%rbp), %rdi
movq %rdi, -0x5e0(%rbp)
callq 0x5820
movq -0x5e0(%rbp), %rdi
movq %rax, -0x68(%rbp)
callq 0x5850
movq %rax, -0x70(%rbp)
callq 0x5880
movss %xmm0, -0x74(%rbp)
movq -0x68(%rbp), %rdi
movq -0x70(%rbp), %rsi
leaq -0x74(%rbp), %rdx
callq 0x57e0
jmp 0x3331
movl $0x0, -0x78(%rbp)
movq -0x5d0(%rbp), %rdi
movl -0x78(%rbp), %eax
movl %eax, -0x5e8(%rbp)
callq 0x5890
movl %eax, -0x5e4(%rbp)
jmp 0x3355
movl -0x5e8(%rbp), %eax
movl -0x5e4(%rbp), %ecx
cmpl %ecx, %eax
jge 0x483f
movq -0x5d0(%rbp), %rdi
movl -0x78(%rbp), %esi
xorl %edx, %edx
callq 0x58b0
movl %eax, -0x5ec(%rbp)
jmp 0x3382
movq -0x5d0(%rbp), %rdi
movl -0x5ec(%rbp), %eax
movl %eax, -0x7c(%rbp)
movl -0x78(%rbp), %esi
movl $0x1, %edx
callq 0x58b0
movl %eax, -0x5f0(%rbp)
jmp 0x33a7
movq -0x5d0(%rbp), %rdi
movl -0x5f0(%rbp), %eax
movl %eax, -0x80(%rbp)
movl -0x78(%rbp), %esi
movl $0x2, %edx
callq 0x58b0
movl %eax, -0x5f4(%rbp)
jmp 0x33cc
movq -0x5d0(%rbp), %rdi
movl -0x5f4(%rbp), %eax
movl %eax, -0x84(%rbp)
movl -0x7c(%rbp), %esi
callq 0x5990
movss %xmm1, -0x614(%rbp)
movaps %xmm0, -0x610(%rbp)
jmp 0x33f8
movq -0x5d0(%rbp), %rdi
movss -0x614(%rbp), %xmm0
movaps -0x610(%rbp), %xmm1
movlpd %xmm1, -0xa0(%rbp)
movss %xmm0, -0x98(%rbp)
movl -0x98(%rbp), %eax
movl %eax, -0x88(%rbp)
movq -0xa0(%rbp), %rax
movq %rax, -0x90(%rbp)
movl -0x80(%rbp), %esi
callq 0x5990
movss %xmm1, -0x634(%rbp)
movaps %xmm0, -0x630(%rbp)
jmp 0x3451
movq -0x5d0(%rbp), %rdi
movss -0x634(%rbp), %xmm0
movaps -0x630(%rbp), %xmm1
movlpd %xmm1, -0xc0(%rbp)
movss %xmm0, -0xb8(%rbp)
movl -0xb8(%rbp), %eax
movl %eax, -0xa8(%rbp)
movq -0xc0(%rbp), %rax
movq %rax, -0xb0(%rbp)
movl -0x84(%rbp), %esi
callq 0x5990
movss %xmm1, -0x654(%rbp)
movaps %xmm0, -0x650(%rbp)
jmp 0x34ad
movq -0x5d0(%rbp), %rdi
movss -0x654(%rbp), %xmm0
movaps -0x650(%rbp), %xmm1
movlpd %xmm1, -0xe0(%rbp)
movss %xmm0, -0xd8(%rbp)
movl -0xd8(%rbp), %eax
movl %eax, -0xc8(%rbp)
movq -0xe0(%rbp), %rax
movq %rax, -0xd0(%rbp)
movl -0x7c(%rbp), %esi
callq 0x5a30
movss %xmm1, -0x674(%rbp)
movaps %xmm0, -0x670(%rbp)
jmp 0x3506
movq -0x5d0(%rbp), %rdi
movss -0x674(%rbp), %xmm0
movaps -0x670(%rbp), %xmm1
movlpd %xmm1, -0x100(%rbp)
movss %xmm0, -0xf8(%rbp)
movl -0xf8(%rbp), %eax
movl %eax, -0xe8(%rbp)
movq -0x100(%rbp), %rax
movq %rax, -0xf0(%rbp)
movl -0x80(%rbp), %esi
callq 0x5a30
movss %xmm1, -0x694(%rbp)
movaps %xmm0, -0x690(%rbp)
jmp 0x355f
movq -0x5d0(%rbp), %rdi
movss -0x694(%rbp), %xmm0
movaps -0x690(%rbp), %xmm1
movlpd %xmm1, -0x120(%rbp)
movss %xmm0, -0x118(%rbp)
movl -0x118(%rbp), %eax
movl %eax, -0x108(%rbp)
movq -0x120(%rbp), %rax
movq %rax, -0x110(%rbp)
movl -0x84(%rbp), %esi
callq 0x5a30
movss %xmm1, -0x6b4(%rbp)
movaps %xmm0, -0x6b0(%rbp)
jmp 0x35bb
movq -0x5b8(%rbp), %rdi
movss -0x6b4(%rbp), %xmm0
movaps -0x6b0(%rbp), %xmm1
movlpd %xmm1, -0x140(%rbp)
movss %xmm0, -0x138(%rbp)
movl -0x138(%rbp), %eax
movl %eax, -0x128(%rbp)
movq -0x140(%rbp), %rax
movq %rax, -0x130(%rbp)
movl -0x88(%rbp), %eax
movl %eax, -0x148(%rbp)
movq -0x90(%rbp), %rax
movq %rax, -0x150(%rbp)
movl -0xa8(%rbp), %eax
movl %eax, -0x158(%rbp)
movq -0xb0(%rbp), %rax
movq %rax, -0x160(%rbp)
movl -0xc8(%rbp), %eax
movl %eax, -0x168(%rbp)
movq -0xd0(%rbp), %rax
movq %rax, -0x170(%rbp)
movl -0x148(%rbp), %eax
movl %eax, -0x188(%rbp)
movq -0x150(%rbp), %rax
movq %rax, -0x190(%rbp)
movl -0x188(%rbp), %eax
movl %eax, -0x198(%rbp)
movq -0x190(%rbp), %rax
movq %rax, -0x1a0(%rbp)
movsd -0x1a0(%rbp), %xmm0
movss -0x198(%rbp), %xmm1
callq 0x5ae0
movss %xmm1, -0x6d4(%rbp)
movaps %xmm0, -0x6d0(%rbp)
jmp 0x36a3
movq -0x5b8(%rbp), %rdi
movss -0x6d4(%rbp), %xmm0
movaps -0x6d0(%rbp), %xmm1
movlpd %xmm1, -0x1b0(%rbp)
movss %xmm0, -0x1a8(%rbp)
movl -0x1a8(%rbp), %eax
movl %eax, -0x178(%rbp)
movq -0x1b0(%rbp), %rax
movq %rax, -0x180(%rbp)
movl -0x178(%rbp), %eax
movl %eax, -0x148(%rbp)
movq -0x180(%rbp), %rax
movq %rax, -0x150(%rbp)
movl -0x158(%rbp), %eax
movl %eax, -0x1c8(%rbp)
movq -0x160(%rbp), %rax
movq %rax, -0x1d0(%rbp)
movl -0x1c8(%rbp), %eax
movl %eax, -0x1d8(%rbp)
movq -0x1d0(%rbp), %rax
movq %rax, -0x1e0(%rbp)
movsd -0x1e0(%rbp), %xmm0
movss -0x1d8(%rbp), %xmm1
callq 0x5ae0
movss %xmm1, -0x6f4(%rbp)
movaps %xmm0, -0x6f0(%rbp)
jmp 0x3757
movq -0x5b8(%rbp), %rdi
movss -0x6f4(%rbp), %xmm0
movaps -0x6f0(%rbp), %xmm1
movlpd %xmm1, -0x1f0(%rbp)
movss %xmm0, -0x1e8(%rbp)
movl -0x1e8(%rbp), %eax
movl %eax, -0x1b8(%rbp)
movq -0x1f0(%rbp), %rax
movq %rax, -0x1c0(%rbp)
movl -0x1b8(%rbp), %eax
movl %eax, -0x158(%rbp)
movq -0x1c0(%rbp), %rax
movq %rax, -0x160(%rbp)
movl -0x168(%rbp), %eax
movl %eax, -0x208(%rbp)
movq -0x170(%rbp), %rax
movq %rax, -0x210(%rbp)
movl -0x208(%rbp), %eax
movl %eax, -0x218(%rbp)
movq -0x210(%rbp), %rax
movq %rax, -0x220(%rbp)
movsd -0x220(%rbp), %xmm0
movss -0x218(%rbp), %xmm1
callq 0x5ae0
movss %xmm1, -0x714(%rbp)
movaps %xmm0, -0x710(%rbp)
jmp 0x380b
movq -0x5c0(%rbp), %rdi
movss -0x714(%rbp), %xmm0
movaps -0x710(%rbp), %xmm1
movlpd %xmm1, -0x230(%rbp)
movss %xmm0, -0x228(%rbp)
movl -0x228(%rbp), %eax
movl %eax, -0x1f8(%rbp)
movq -0x230(%rbp), %rax
movq %rax, -0x200(%rbp)
movl -0x1f8(%rbp), %eax
movl %eax, -0x168(%rbp)
movq -0x200(%rbp), %rax
movq %rax, -0x170(%rbp)
movl -0x148(%rbp), %eax
movl %eax, -0x248(%rbp)
movq -0x150(%rbp), %rax
movq %rax, -0x250(%rbp)
movl -0x248(%rbp), %eax
movl %eax, -0x258(%rbp)
movq -0x250(%rbp), %rax
movq %rax, -0x260(%rbp)
movsd -0x260(%rbp), %xmm0
movss -0x258(%rbp), %xmm1
callq 0x5ae0
movss %xmm1, -0x734(%rbp)
movaps %xmm0, -0x730(%rbp)
jmp 0x38bf
movq -0x5c0(%rbp), %rdi
movss -0x734(%rbp), %xmm0
movaps -0x730(%rbp), %xmm1
movlpd %xmm1, -0x270(%rbp)
movss %xmm0, -0x268(%rbp)
movl -0x268(%rbp), %eax
movl %eax, -0x238(%rbp)
movq -0x270(%rbp), %rax
movq %rax, -0x240(%rbp)
movl -0x238(%rbp), %eax
movl %eax, -0x148(%rbp)
movq -0x240(%rbp), %rax
movq %rax, -0x150(%rbp)
movl -0x158(%rbp), %eax
movl %eax, -0x288(%rbp)
movq -0x160(%rbp), %rax
movq %rax, -0x290(%rbp)
movl -0x288(%rbp), %eax
movl %eax, -0x298(%rbp)
movq -0x290(%rbp), %rax
movq %rax, -0x2a0(%rbp)
movsd -0x2a0(%rbp), %xmm0
movss -0x298(%rbp), %xmm1
callq 0x5ae0
movss %xmm1, -0x754(%rbp)
movaps %xmm0, -0x750(%rbp)
jmp 0x3973
movq -0x5c0(%rbp), %rdi
movss -0x754(%rbp), %xmm0
movaps -0x750(%rbp), %xmm1
movlpd %xmm1, -0x2b0(%rbp)
movss %xmm0, -0x2a8(%rbp)
movl -0x2a8(%rbp), %eax
movl %eax, -0x278(%rbp)
movq -0x2b0(%rbp), %rax
movq %rax, -0x280(%rbp)
movl -0x278(%rbp), %eax
movl %eax, -0x158(%rbp)
movq -0x280(%rbp), %rax
movq %rax, -0x160(%rbp)
movl -0x168(%rbp), %eax
movl %eax, -0x2c8(%rbp)
movq -0x170(%rbp), %rax
movq %rax, -0x2d0(%rbp)
movl -0x2c8(%rbp), %eax
movl %eax, -0x2d8(%rbp)
movq -0x2d0(%rbp), %rax
movq %rax, -0x2e0(%rbp)
movsd -0x2e0(%rbp), %xmm0
movss -0x2d8(%rbp), %xmm1
callq 0x5ae0
movss %xmm1, -0x774(%rbp)
movaps %xmm0, -0x770(%rbp)
jmp 0x3a27
movss -0x774(%rbp), %xmm0
movaps -0x770(%rbp), %xmm1
movlpd %xmm1, -0x2f0(%rbp)
movss %xmm0, -0x2e8(%rbp)
movl -0x2e8(%rbp), %eax
movl %eax, -0x2b8(%rbp)
movq -0x2f0(%rbp), %rax
movq %rax, -0x2c0(%rbp)
movl -0x2b8(%rbp), %eax
movl %eax, -0x168(%rbp)
movq -0x2c0(%rbp), %rax
movq %rax, -0x170(%rbp)
movl -0x108(%rbp), %eax
movl %eax, -0x338(%rbp)
movq -0x110(%rbp), %rax
movq %rax, -0x340(%rbp)
movl -0x338(%rbp), %eax
movl %eax, -0x348(%rbp)
movq -0x340(%rbp), %rax
movq %rax, -0x350(%rbp)
movsd -0x350(%rbp), %xmm0
movss -0x348(%rbp), %xmm1
leaq -0xf0(%rbp), %rdi
callq 0x5c60
movss %xmm1, -0x794(%rbp)
movaps %xmm0, -0x790(%rbp)
jmp 0x3adb
movss -0x794(%rbp), %xmm0
movaps -0x790(%rbp), %xmm1
movlpd %xmm1, -0x360(%rbp)
movss %xmm0, -0x358(%rbp)
movl -0x358(%rbp), %eax
movl %eax, -0x328(%rbp)
movq -0x360(%rbp), %rax
movq %rax, -0x330(%rbp)
movl -0x128(%rbp), %eax
movl %eax, -0x368(%rbp)
movq -0x130(%rbp), %rax
movq %rax, -0x370(%rbp)
movl -0x368(%rbp), %eax
movl %eax, -0x378(%rbp)
movq -0x370(%rbp), %rax
movq %rax, -0x380(%rbp)
movsd -0x380(%rbp), %xmm0
movss -0x378(%rbp), %xmm1
leaq -0x330(%rbp), %rdi
callq 0x5c60
movss %xmm1, -0x7b4(%rbp)
movaps %xmm0, -0x7b0(%rbp)
jmp 0x3b75
movss -0x7b4(%rbp), %xmm0
movaps -0x7b0(%rbp), %xmm1
movlpd %xmm1, -0x390(%rbp)
movss %xmm0, -0x388(%rbp)
movl -0x388(%rbp), %eax
movl %eax, -0x318(%rbp)
movq -0x390(%rbp), %rax
movq %rax, -0x320(%rbp)
leaq -0x320(%rbp), %rdi
movss 0x7453(%rip), %xmm0     # 0xb010
callq 0x5ce0
movss %xmm1, -0x7d4(%rbp)
movaps %xmm0, -0x7d0(%rbp)
jmp 0x3bd3
movss -0x7d4(%rbp), %xmm0
movaps -0x7d0(%rbp), %xmm1
movlpd %xmm1, -0x3a0(%rbp)
movss %xmm0, -0x398(%rbp)
movl -0x398(%rbp), %eax
movl %eax, -0x308(%rbp)
movq -0x3a0(%rbp), %rax
movq %rax, -0x310(%rbp)
leaq -0x310(%rbp), %rdi
callq 0x52e0
movss %xmm1, -0x7f4(%rbp)
movaps %xmm0, -0x7f0(%rbp)
jmp 0x3c29
movq -0x5b0(%rbp), %rdi
movss -0x7f4(%rbp), %xmm0
movaps -0x7f0(%rbp), %xmm1
movlpd %xmm1, -0x3b0(%rbp)
movss %xmm0, -0x3a8(%rbp)
movl -0x3a8(%rbp), %eax
movl %eax, -0x2f8(%rbp)
movq -0x3b0(%rbp), %rax
movq %rax, -0x300(%rbp)
movl -0x148(%rbp), %eax
movl %eax, -0x3c8(%rbp)
movq -0x150(%rbp), %rax
movq %rax, -0x3d0(%rbp)
movl -0x3c8(%rbp), %eax
movl %eax, -0x3d8(%rbp)
movq -0x3d0(%rbp), %rax
movq %rax, -0x3e0(%rbp)
movsd -0x3e0(%rbp), %xmm0
movss -0x3d8(%rbp), %xmm1
callq 0x5ae0
movss %xmm1, -0x814(%rbp)
movaps %xmm0, -0x810(%rbp)
jmp 0x3cc3
movq -0x5b0(%rbp), %rdi
movss -0x814(%rbp), %xmm0
movaps -0x810(%rbp), %xmm1
movlpd %xmm1, -0x3f0(%rbp)
movss %xmm0, -0x3e8(%rbp)
movl -0x3e8(%rbp), %eax
movl %eax, -0x3b8(%rbp)
movq -0x3f0(%rbp), %rax
movq %rax, -0x3c0(%rbp)
movl -0x158(%rbp), %eax
movl %eax, -0x408(%rbp)
movq -0x160(%rbp), %rax
movq %rax, -0x410(%rbp)
movl -0x408(%rbp), %eax
movl %eax, -0x418(%rbp)
movq -0x410(%rbp), %rax
movq %rax, -0x420(%rbp)
movsd -0x420(%rbp), %xmm0
movss -0x418(%rbp), %xmm1
callq 0x5ae0
movss %xmm1, -0x834(%rbp)
movaps %xmm0, -0x830(%rbp)
jmp 0x3d5d
movq -0x5b0(%rbp), %rdi
movss -0x834(%rbp), %xmm0
movaps -0x830(%rbp), %xmm1
movlpd %xmm1, -0x430(%rbp)
movss %xmm0, -0x428(%rbp)
movl -0x428(%rbp), %eax
movl %eax, -0x3f8(%rbp)
movq -0x430(%rbp), %rax
movq %rax, -0x400(%rbp)
movl -0x168(%rbp), %eax
movl %eax, -0x448(%rbp)
movq -0x170(%rbp), %rax
movq %rax, -0x450(%rbp)
movl -0x448(%rbp), %eax
movl %eax, -0x458(%rbp)
movq -0x450(%rbp), %rax
movq %rax, -0x460(%rbp)
movsd -0x460(%rbp), %xmm0
movss -0x458(%rbp), %xmm1
callq 0x5ae0
movss %xmm1, -0x854(%rbp)
movaps %xmm0, -0x850(%rbp)
jmp 0x3df7
movss -0x854(%rbp), %xmm0
movaps -0x850(%rbp), %xmm1
movlpd %xmm1, -0x470(%rbp)
movss %xmm0, -0x468(%rbp)
movl -0x468(%rbp), %eax
movl %eax, -0x438(%rbp)
movq -0x470(%rbp), %rax
movq %rax, -0x440(%rbp)
movss -0x3c0(%rbp), %xmm0
movss 0x71c8(%rip), %xmm2     # 0xb008
addss %xmm2, %xmm0
movss %xmm0, -0x3c0(%rbp)
movss -0x3bc(%rbp), %xmm0
addss %xmm2, %xmm0
movss %xmm0, -0x3bc(%rbp)
movss -0x400(%rbp), %xmm0
addss %xmm2, %xmm0
movss %xmm0, -0x400(%rbp)
movss -0x3fc(%rbp), %xmm0
addss %xmm2, %xmm0
movss %xmm0, -0x3fc(%rbp)
movss -0x440(%rbp), %xmm0
addss %xmm2, %xmm0
movss %xmm0, -0x440(%rbp)
movss -0x43c(%rbp), %xmm0
addss %xmm2, %xmm0
movss %xmm0, -0x43c(%rbp)
movss -0x3c0(%rbp), %xmm0
movss 0x7154(%rip), %xmm1     # 0xb014
mulss %xmm1, %xmm0
movss %xmm0, -0x3c0(%rbp)
movss -0x3bc(%rbp), %xmm0
mulss %xmm1, %xmm0
movss %xmm0, -0x3bc(%rbp)
movss -0x400(%rbp), %xmm0
mulss %xmm1, %xmm0
movss %xmm0, -0x400(%rbp)
movss -0x3fc(%rbp), %xmm0
mulss %xmm1, %xmm0
movss %xmm0, -0x3fc(%rbp)
movss -0x440(%rbp), %xmm0
mulss %xmm1, %xmm0
movss %xmm0, -0x440(%rbp)
movss -0x43c(%rbp), %xmm0
mulss %xmm1, %xmm0
movss %xmm0, -0x43c(%rbp)
movss -0x3c0(%rbp), %xmm0
movss 0x70d8(%rip), %xmm1     # 0xb018
mulss %xmm1, %xmm0
movss %xmm0, -0x3c0(%rbp)
movss -0x3bc(%rbp), %xmm0
mulss %xmm1, %xmm0
movss %xmm0, -0x3bc(%rbp)
movss -0x3b8(%rbp), %xmm0
addss %xmm0, %xmm0
movss %xmm0, -0x3b8(%rbp)
movss -0x400(%rbp), %xmm0
mulss %xmm1, %xmm0
movss %xmm0, -0x400(%rbp)
movss -0x3fc(%rbp), %xmm0
mulss %xmm1, %xmm0
movss %xmm0, -0x3fc(%rbp)
movss -0x3f8(%rbp), %xmm0
addss %xmm0, %xmm0
movss %xmm0, -0x3f8(%rbp)
movss -0x440(%rbp), %xmm0
mulss %xmm1, %xmm0
movss %xmm0, -0x440(%rbp)
movss -0x43c(%rbp), %xmm0
mulss %xmm1, %xmm0
movss %xmm0, -0x43c(%rbp)
movss -0x438(%rbp), %xmm0
addss %xmm0, %xmm0
movss %xmm0, -0x438(%rbp)
leaq -0x48c(%rbp), %rdi
xorps %xmm1, %xmm1
movaps %xmm1, %xmm0
callq 0x5d40
jmp 0x4000
leaq -0x48c(%rbp), %rdi
callq 0x52e0
movss %xmm1, -0x874(%rbp)
movaps %xmm0, -0x870(%rbp)
jmp 0x401d
movss -0x874(%rbp), %xmm0
movaps -0x870(%rbp), %xmm1
movlpd %xmm1, -0x4a0(%rbp)
movss %xmm0, -0x498(%rbp)
movl -0x498(%rbp), %eax
movl %eax, -0x478(%rbp)
movq -0x4a0(%rbp), %rax
movq %rax, -0x480(%rbp)
movl -0x478(%rbp), %eax
movl %eax, -0x4a8(%rbp)
movq -0x480(%rbp), %rax
movq %rax, -0x4b0(%rbp)
movl -0x4a8(%rbp), %eax
movl %eax, -0x4b8(%rbp)
movq -0x4b0(%rbp), %rax
movq %rax, -0x4c0(%rbp)
movsd -0x4c0(%rbp), %xmm0
movss -0x4b8(%rbp), %xmm1
leaq -0x300(%rbp), %rdi
callq 0x5da0
movss %xmm0, -0x878(%rbp)
jmp 0x40b0
movss -0x878(%rbp), %xmm0
movss %xmm0, -0x4a4(%rbp)
callq 0x5e00
movss %xmm0, -0x87c(%rbp)
callq 0x5e00
movaps %xmm0, %xmm1
movss -0x87c(%rbp), %xmm0
leaq -0x4c8(%rbp), %rdi
callq 0x5e10
jmp 0x40eb
callq 0x5880
movss %xmm0, -0x880(%rbp)
callq 0x5880
movaps %xmm0, %xmm1
movss -0x880(%rbp), %xmm0
leaq -0x4d0(%rbp), %rdi
callq 0x5e10
jmp 0x4116
movss -0x3c0(%rbp), %xmm1
movss -0x4c8(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x418b
movss -0x3c0(%rbp), %xmm0
movss %xmm0, -0x4c8(%rbp)
jmp 0x418b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x12(%rbp), %rdi
callq 0x5670
jmp 0x487a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x41(%rbp), %rdi
callq 0x5720
jmp 0x486e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x5ef0
jmp 0x486e
movss -0x3bc(%rbp), %xmm1
movss -0x4c4(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x41b0
movss -0x3bc(%rbp), %xmm0
movss %xmm0, -0x4c4(%rbp)
movss -0x3c0(%rbp), %xmm0
ucomiss -0x4d0(%rbp), %xmm0
jbe 0x41d1
movss -0x3c0(%rbp), %xmm0
movss %xmm0, -0x4d0(%rbp)
movss -0x3bc(%rbp), %xmm0
ucomiss -0x4cc(%rbp), %xmm0
jbe 0x41f2
movss -0x3bc(%rbp), %xmm0
movss %xmm0, -0x4cc(%rbp)
movss -0x400(%rbp), %xmm1
movss -0x4c8(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x4217
movss -0x400(%rbp), %xmm0
movss %xmm0, -0x4c8(%rbp)
movss -0x3fc(%rbp), %xmm1
movss -0x4c4(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x423c
movss -0x3fc(%rbp), %xmm0
movss %xmm0, -0x4c4(%rbp)
movss -0x400(%rbp), %xmm0
ucomiss -0x4d0(%rbp), %xmm0
jbe 0x425d
movss -0x400(%rbp), %xmm0
movss %xmm0, -0x4d0(%rbp)
movss -0x3fc(%rbp), %xmm0
ucomiss -0x4cc(%rbp), %xmm0
jbe 0x427e
movss -0x3fc(%rbp), %xmm0
movss %xmm0, -0x4cc(%rbp)
movss -0x440(%rbp), %xmm1
movss -0x4c8(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x42a3
movss -0x440(%rbp), %xmm0
movss %xmm0, -0x4c8(%rbp)
movss -0x43c(%rbp), %xmm1
movss -0x4c4(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x42c8
movss -0x43c(%rbp), %xmm0
movss %xmm0, -0x4c4(%rbp)
movss -0x440(%rbp), %xmm0
ucomiss -0x4d0(%rbp), %xmm0
jbe 0x42e9
movss -0x440(%rbp), %xmm0
movss %xmm0, -0x4d0(%rbp)
movss -0x43c(%rbp), %xmm0
ucomiss -0x4cc(%rbp), %xmm0
jbe 0x430a
movss -0x43c(%rbp), %xmm0
movss %xmm0, -0x4cc(%rbp)
movl $0x0, -0x4d4(%rbp)
movl $0x44480000, -0x4d8(%rbp) # imm = 0x44480000
leaq -0x4c8(%rbp), %rdi
leaq -0x4d8(%rbp), %rsi
callq 0x5e90
movq %rax, -0x888(%rbp)
jmp 0x433a
movq -0x888(%rbp), %rsi
leaq -0x4d4(%rbp), %rdi
callq 0x5e50
movq %rax, -0x890(%rbp)
jmp 0x4356
movq -0x890(%rbp), %rax
movss (%rax), %xmm0
movss %xmm0, -0x4c8(%rbp)
movl $0x0, -0x4dc(%rbp)
leaq -0x4c4(%rbp), %rdi
movl $0x44480000, -0x4e0(%rbp) # imm = 0x44480000
leaq -0x4e0(%rbp), %rsi
callq 0x5e90
movq %rax, -0x898(%rbp)
jmp 0x4399
movq -0x898(%rbp), %rsi
leaq -0x4dc(%rbp), %rdi
callq 0x5e50
movq %rax, -0x8a0(%rbp)
jmp 0x43b5
movq -0x8a0(%rbp), %rax
movss (%rax), %xmm0
movss %xmm0, -0x4c4(%rbp)
movl $0x0, -0x4e4(%rbp)
movl $0x44480000, -0x4e8(%rbp) # imm = 0x44480000
leaq -0x4d0(%rbp), %rdi
leaq -0x4e8(%rbp), %rsi
callq 0x5e90
movq %rax, -0x8a8(%rbp)
jmp 0x43f8
movq -0x8a8(%rbp), %rsi
leaq -0x4e4(%rbp), %rdi
callq 0x5e50
movq %rax, -0x8b0(%rbp)
jmp 0x4414
movq -0x8b0(%rbp), %rax
movss (%rax), %xmm0
movss %xmm0, -0x4d0(%rbp)
movl $0x0, -0x4ec(%rbp)
leaq -0x4cc(%rbp), %rdi
movl $0x44480000, -0x4f0(%rbp) # imm = 0x44480000
leaq -0x4f0(%rbp), %rsi
callq 0x5e90
movq %rax, -0x8b8(%rbp)
jmp 0x4457
movq -0x8b8(%rbp), %rsi
leaq -0x4ec(%rbp), %rdi
callq 0x5e50
movq %rax, -0x8c0(%rbp)
jmp 0x4473
movq -0x8c0(%rbp), %rax
movss (%rax), %xmm0
movss %xmm0, -0x4cc(%rbp)
leaq -0x4fc(%rbp), %rdi
callq 0x55b0
jmp 0x4494
cvttss2si -0x4c8(%rbp), %eax
cvtsi2ss %eax, %xmm0
movss %xmm0, -0x4fc(%rbp)
movss -0x4fc(%rbp), %xmm1
movss -0x4d0(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x482f
cvttss2si -0x4c4(%rbp), %eax
cvtsi2ss %eax, %xmm0
movss %xmm0, -0x4f8(%rbp)
movss -0x4f8(%rbp), %xmm1
movss -0x4cc(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x4810
movl -0x3b8(%rbp), %eax
movl %eax, -0x510(%rbp)
movq -0x3c0(%rbp), %rax
movq %rax, -0x518(%rbp)
movl -0x3f8(%rbp), %eax
movl %eax, -0x520(%rbp)
movq -0x400(%rbp), %rax
movq %rax, -0x528(%rbp)
movl -0x438(%rbp), %eax
movl %eax, -0x530(%rbp)
movq -0x440(%rbp), %rax
movq %rax, -0x538(%rbp)
movl -0x4f4(%rbp), %eax
movl %eax, -0x540(%rbp)
movq -0x4fc(%rbp), %rax
movq %rax, -0x548(%rbp)
movl -0x510(%rbp), %eax
movl %eax, -0x550(%rbp)
movq -0x518(%rbp), %rax
movq %rax, -0x558(%rbp)
movsd -0x558(%rbp), %xmm0
movss -0x550(%rbp), %xmm1
movl -0x520(%rbp), %eax
movl %eax, -0x560(%rbp)
movq -0x528(%rbp), %rax
movq %rax, -0x568(%rbp)
movsd -0x568(%rbp), %xmm2
movss -0x560(%rbp), %xmm3
movl -0x530(%rbp), %eax
movl %eax, -0x570(%rbp)
movq -0x538(%rbp), %rax
movq %rax, -0x578(%rbp)
movsd -0x578(%rbp), %xmm4
movss -0x570(%rbp), %xmm5
movl -0x540(%rbp), %eax
movl %eax, -0x580(%rbp)
movq -0x548(%rbp), %rax
movq %rax, -0x588(%rbp)
movsd -0x588(%rbp), %xmm6
movss -0x580(%rbp), %xmm7
callq 0x3090
movss %xmm1, -0x8d4(%rbp)
movaps %xmm0, -0x8d0(%rbp)
jmp 0x4614
movss -0x8d4(%rbp), %xmm0
movaps -0x8d0(%rbp), %xmm1
movlpd %xmm1, -0x598(%rbp)
movss %xmm0, -0x590(%rbp)
movq -0x598(%rbp), %rax
movq %rax, -0x508(%rbp)
movl -0x590(%rbp), %eax
movl %eax, -0x500(%rbp)
movss -0x508(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jb 0x47f1
movss -0x504(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jb 0x47f1
movss -0x500(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jb 0x47f1
movss -0x88(%rbp), %xmm0
addss -0xa8(%rbp), %xmm0
addss -0xc8(%rbp), %xmm0
movss 0x6973(%rip), %xmm1     # 0xb01c
divss %xmm1, %xmm0
movss %xmm0, -0x4f4(%rbp)
cvttss2si -0x4fc(%rbp), %eax
cvttss2si -0x4f8(%rbp), %ecx
imull $0x320, %ecx, %ecx      # imm = 0x320
addl %ecx, %eax
movslq %eax, %rsi
leaq -0x40(%rbp), %rdi
callq 0x5ed0
movss (%rax), %xmm1
movss -0x4f4(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x47ef
movss -0x4f4(%rbp), %xmm0
movss %xmm0, -0x8d8(%rbp)
cvttss2si -0x4fc(%rbp), %eax
cvttss2si -0x4f8(%rbp), %ecx
imull $0x320, %ecx, %ecx      # imm = 0x320
addl %ecx, %eax
movslq %eax, %rsi
leaq -0x40(%rbp), %rdi
callq 0x5ed0
movss -0x8d8(%rbp), %xmm0
movss %xmm0, (%rax)
xorps %xmm0, %xmm0
ucomiss -0x4a4(%rbp), %xmm0
jbe 0x4745
xorps %xmm0, %xmm0
movss %xmm0, -0x4a4(%rbp)
movq -0x5a8(%rbp), %rdi
movss -0x4a4(%rbp), %xmm0
movss 0x68c4(%rip), %xmm1     # 0xb020
mulss %xmm1, %xmm0
movss 0x68bc(%rip), %xmm1     # 0xb024
movaps %xmm0, %xmm2
mulss %xmm1, %xmm2
movss 0x68b1(%rip), %xmm3     # 0xb028
movaps %xmm0, %xmm1
mulss %xmm3, %xmm1
addss %xmm2, %xmm1
movss 0x68a2(%rip), %xmm2     # 0xb02c
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
cvttss2si %xmm0, %eax
movl %eax, -0x8dc(%rbp)
movss -0x4fc(%rbp), %xmm1
movss -0x4f8(%rbp), %xmm0
movss 0x6864(%rip), %xmm2     # 0xb018
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movaps %xmm0, %xmm1
cvttss2si %xmm1, %rsi
movq %rsi, %rcx
sarq $0x3f, %rcx
movss 0x685d(%rip), %xmm1     # 0xb030
subss %xmm1, %xmm0
cvttss2si %xmm0, %rax
andq %rcx, %rax
orq %rax, %rsi
callq 0x5590
movl -0x8dc(%rbp), %ecx
movl %ecx, (%rax)
jmp 0x47f1
jmp 0x47f3
movss 0x680d(%rip), %xmm0     # 0xb008
addss -0x4f8(%rbp), %xmm0
movss %xmm0, -0x4f8(%rbp)
jmp 0x44d5
jmp 0x4812
movss 0x67ee(%rip), %xmm0     # 0xb008
addss -0x4fc(%rbp), %xmm0
movss %xmm0, -0x4fc(%rbp)
jmp 0x44a8
jmp 0x4831
movl -0x78(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x78(%rbp)
jmp 0x3338
movb $0x1, -0x11(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x5ef0
testb $0x1, -0x11(%rbp)
jne 0x485e
movq -0x5a8(%rbp), %rdi
callq 0x5f50
movq -0x5c8(%rbp), %rax
addq $0x8e0, %rsp            # imm = 0x8E0
popq %rbp
retq
movq -0x5a8(%rbp), %rdi
callq 0x5f50
movq -0x20(%rbp), %rdi
callq 0x2350
nopw %cs:(%rax,%rax)