// File: kryffin[P]software-rasterizer/rasterizer.cpp
// Function: main
int main () {
    Model model("obj/diablo_pose.obj");
    
    // projection matrix 	   near   far    fov   width  height
    Mat4f mProjection = projectionMatrix(0.1f, 1000.f, 90.f, (float)WIDTH, (float)HEIGHT);

    // world matrix, for model transformations (= model matrix - ?)
	Mat4f mWorld = rotation(0.f, 0.f, 0.f) * scale(1.f, 1.f, 1.f) * translation(0.f, 0.f, -5.f);

	// camera matrix, determines where the camera is, what it is facing and where does its upward vector is
	Mat4f mCameraR = lookAt(Vec3f(-0.05f, 0.f, 5.f), Vec3f(0.f, 0.f, 0.f), Vec3f(0.f, 1.f, 0.f));
    Mat4f mCameraB = lookAt(Vec3f(0.05f, 0.f, 5.f), Vec3f(0.f, 0.f, 0.f), Vec3f(0.f, 1.f, 0.f));

    //catching the two buffered image in order to construct the main image
    std::vector<int> frameBufferR = render(model, mProjection, mWorld, mCameraR); //red buffer
	std::vector<int> frameBufferB = render(model, mProjection, mWorld, mCameraB); //blue buffer

    //mixing the channels to render the anaglyph image
    std::vector<int>frameBuffer = mix_channels(frameBufferR, frameBufferB);

    writeImage(frameBuffer);
    
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x680, %rsp            # imm = 0x680
movl $0x0, -0x4(%rbp)
leaq 0x6642(%rip), %rsi      # 0xb06b
leaq -0x50(%rbp), %rdi
callq 0x5fb0
leaq -0x90(%rbp), %rdi
movss 0x65fb(%rip), %xmm0     # 0xb03c
movss 0x65f7(%rip), %xmm1     # 0xb040
movss 0x65f3(%rip), %xmm2     # 0xb044
movss 0x65bf(%rip), %xmm4     # 0xb018
movaps %xmm4, %xmm3
callq 0x25a0
jmp 0x4a63
leaq -0x15c(%rbp), %rdi
xorps %xmm2, %xmm2
movaps %xmm2, %xmm0
movaps %xmm2, %xmm1
callq 0x2c60
jmp 0x4a7a
leaq -0x1a0(%rbp), %rdi
movss 0x657f(%rip), %xmm2     # 0xb008
movaps %xmm2, %xmm0
movaps %xmm2, %xmm1
callq 0x2d70
jmp 0x4a96
movups -0x1a0(%rbp), %xmm0
movups -0x190(%rbp), %xmm1
movups -0x180(%rbp), %xmm2
movups -0x170(%rbp), %xmm3
movq %rsp, %rax
movups %xmm3, 0x30(%rax)
movups %xmm2, 0x20(%rax)
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
leaq -0x11c(%rbp), %rdi
leaq -0x15c(%rbp), %rsi
callq 0x54b0
jmp 0x4ad9
leaq -0x1e0(%rbp), %rdi
xorps %xmm1, %xmm1
movss 0x655d(%rip), %xmm2     # 0xb048
movaps %xmm1, %xmm0
callq 0x2dd0
jmp 0x4af5
movups -0x1e0(%rbp), %xmm0
movups -0x1d0(%rbp), %xmm1
movups -0x1c0(%rbp), %xmm2
movups -0x1b0(%rbp), %xmm3
movq %rsp, %rax
movups %xmm3, 0x30(%rax)
movups %xmm2, 0x20(%rax)
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
leaq -0xdc(%rbp), %rdi
leaq -0x11c(%rbp), %rsi
callq 0x54b0
jmp 0x4b38
leaq -0x22c(%rbp), %rdi
movss 0x6505(%rip), %xmm0     # 0xb04c
xorps %xmm1, %xmm1
movss 0x64fe(%rip), %xmm2     # 0xb050
callq 0x5d40
jmp 0x4b59
leaq -0x238(%rbp), %rdi
xorps %xmm2, %xmm2
movaps %xmm2, %xmm0
movaps %xmm2, %xmm1
callq 0x5d40
jmp 0x4b70
leaq -0x244(%rbp), %rdi
movss 0x6489(%rip), %xmm1     # 0xb008
xorps %xmm2, %xmm2
movaps %xmm2, %xmm0
callq 0x5d40
jmp 0x4b8c
movl -0x224(%rbp), %eax
movl %eax, -0x250(%rbp)
movq -0x22c(%rbp), %rax
movq %rax, -0x258(%rbp)
movsd -0x258(%rbp), %xmm0
movss -0x250(%rbp), %xmm1
movl -0x230(%rbp), %eax
movl %eax, -0x260(%rbp)
movq -0x238(%rbp), %rax
movq %rax, -0x268(%rbp)
movsd -0x268(%rbp), %xmm2
movss -0x260(%rbp), %xmm3
movl -0x23c(%rbp), %eax
movl %eax, -0x270(%rbp)
movq -0x244(%rbp), %rax
movq %rax, -0x278(%rbp)
movsd -0x278(%rbp), %xmm4
movss -0x270(%rbp), %xmm5
leaq -0x220(%rbp), %rdi
callq 0x26a0
jmp 0x4c18
leaq -0x2c4(%rbp), %rdi
movss 0x642d(%rip), %xmm0     # 0xb054
xorps %xmm1, %xmm1
movss 0x641e(%rip), %xmm2     # 0xb050
callq 0x5d40
jmp 0x4c39
leaq -0x2d0(%rbp), %rdi
xorps %xmm2, %xmm2
movaps %xmm2, %xmm0
movaps %xmm2, %xmm1
callq 0x5d40
jmp 0x4c50
leaq -0x2dc(%rbp), %rdi
movss 0x63a9(%rip), %xmm1     # 0xb008
xorps %xmm2, %xmm2
movaps %xmm2, %xmm0
callq 0x5d40
jmp 0x4c6c
movl -0x2bc(%rbp), %eax
movl %eax, -0x2e8(%rbp)
movq -0x2c4(%rbp), %rax
movq %rax, -0x2f0(%rbp)
movsd -0x2f0(%rbp), %xmm0
movss -0x2e8(%rbp), %xmm1
movl -0x2c8(%rbp), %eax
movl %eax, -0x2f8(%rbp)
movq -0x2d0(%rbp), %rax
movq %rax, -0x300(%rbp)
movsd -0x300(%rbp), %xmm2
movss -0x2f8(%rbp), %xmm3
movl -0x2d4(%rbp), %eax
movl %eax, -0x308(%rbp)
movq -0x2dc(%rbp), %rax
movq %rax, -0x310(%rbp)
movsd -0x310(%rbp), %xmm4
movss -0x308(%rbp), %xmm5
leaq -0x2b8(%rbp), %rdi
callq 0x26a0
jmp 0x4cf8
leaq -0x370(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x6740
jmp 0x4d0a
movups -0x90(%rbp), %xmm0
movups -0x80(%rbp), %xmm1
movups -0x70(%rbp), %xmm2
movups -0x60(%rbp), %xmm3
movaps %xmm3, -0x380(%rbp)
movaps %xmm2, -0x390(%rbp)
movaps %xmm1, -0x3a0(%rbp)
movaps %xmm0, -0x3b0(%rbp)
movups -0xdc(%rbp), %xmm0
movups -0xcc(%rbp), %xmm1
movups -0xbc(%rbp), %xmm2
movups -0xac(%rbp), %xmm3
movaps %xmm3, -0x3c0(%rbp)
movaps %xmm2, -0x3d0(%rbp)
movaps %xmm1, -0x3e0(%rbp)
movaps %xmm0, -0x3f0(%rbp)
movups -0x220(%rbp), %xmm0
movups -0x210(%rbp), %xmm1
movups -0x200(%rbp), %xmm2
movups -0x1f0(%rbp), %xmm3
movaps %xmm3, -0x400(%rbp)
movaps %xmm2, -0x410(%rbp)
movaps %xmm1, -0x420(%rbp)
movaps %xmm0, -0x430(%rbp)
movaps -0x430(%rbp), %xmm0
movaps -0x420(%rbp), %xmm1
movaps -0x410(%rbp), %xmm2
movaps -0x400(%rbp), %xmm3
movq %rsp, %rax
movq %rax, -0x5b8(%rbp)
movups %xmm3, 0xb0(%rax)
movups %xmm2, 0xa0(%rax)
movups %xmm1, 0x90(%rax)
movups %xmm0, 0x80(%rax)
movaps -0x3f0(%rbp), %xmm0
movaps -0x3e0(%rbp), %xmm1
movaps -0x3d0(%rbp), %xmm2
movaps -0x3c0(%rbp), %xmm3
movups %xmm3, 0x70(%rax)
movups %xmm2, 0x60(%rax)
movups %xmm1, 0x50(%rax)
movups %xmm0, 0x40(%rax)
movaps -0x3b0(%rbp), %xmm0
movaps -0x3a0(%rbp), %xmm1
movaps -0x390(%rbp), %xmm2
movaps -0x380(%rbp), %xmm3
movups %xmm3, 0x30(%rax)
movups %xmm2, 0x20(%rax)
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
leaq -0x328(%rbp), %rdi
leaq -0x370(%rbp), %rsi
callq 0x3200
jmp 0x4e57
leaq -0x370(%rbp), %rdi
callq 0x67e0
leaq -0x490(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x6740
jmp 0x4e75
movups -0x90(%rbp), %xmm0
movups -0x80(%rbp), %xmm1
movups -0x70(%rbp), %xmm2
movups -0x60(%rbp), %xmm3
movaps %xmm3, -0x4a0(%rbp)
movaps %xmm2, -0x4b0(%rbp)
movaps %xmm1, -0x4c0(%rbp)
movaps %xmm0, -0x4d0(%rbp)
movups -0xdc(%rbp), %xmm0
movups -0xcc(%rbp), %xmm1
movups -0xbc(%rbp), %xmm2
movups -0xac(%rbp), %xmm3
movaps %xmm3, -0x4e0(%rbp)
movaps %xmm2, -0x4f0(%rbp)
movaps %xmm1, -0x500(%rbp)
movaps %xmm0, -0x510(%rbp)
movups -0x2b8(%rbp), %xmm0
movups -0x2a8(%rbp), %xmm1
movups -0x298(%rbp), %xmm2
movups -0x288(%rbp), %xmm3
movaps %xmm3, -0x520(%rbp)
movaps %xmm2, -0x530(%rbp)
movaps %xmm1, -0x540(%rbp)
movaps %xmm0, -0x550(%rbp)
movaps -0x550(%rbp), %xmm0
movaps -0x540(%rbp), %xmm1
movaps -0x530(%rbp), %xmm2
movaps -0x520(%rbp), %xmm3
movq %rsp, %rax
movq %rax, -0x5c0(%rbp)
movups %xmm3, 0xb0(%rax)
movups %xmm2, 0xa0(%rax)
movups %xmm1, 0x90(%rax)
movups %xmm0, 0x80(%rax)
movaps -0x510(%rbp), %xmm0
movaps -0x500(%rbp), %xmm1
movaps -0x4f0(%rbp), %xmm2
movaps -0x4e0(%rbp), %xmm3
movups %xmm3, 0x70(%rax)
movups %xmm2, 0x60(%rax)
movups %xmm1, 0x50(%rax)
movups %xmm0, 0x40(%rax)
movaps -0x4d0(%rbp), %xmm0
movaps -0x4c0(%rbp), %xmm1
movaps -0x4b0(%rbp), %xmm2
movaps -0x4a0(%rbp), %xmm3
movups %xmm3, 0x30(%rax)
movups %xmm2, 0x20(%rax)
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
leaq -0x448(%rbp), %rdi
leaq -0x490(%rbp), %rsi
callq 0x3200
jmp 0x4fc2
leaq -0x490(%rbp), %rdi
callq 0x67e0
leaq -0x580(%rbp), %rdi
leaq -0x328(%rbp), %rsi
callq 0x6820
jmp 0x4fe3
leaq -0x598(%rbp), %rdi
leaq -0x448(%rbp), %rsi
callq 0x6820
jmp 0x4ff8
leaq -0x568(%rbp), %rdi
leaq -0x580(%rbp), %rsi
leaq -0x598(%rbp), %rdx
callq 0x4890
jmp 0x5014
leaq -0x598(%rbp), %rdi
callq 0x5f50
leaq -0x580(%rbp), %rdi
callq 0x5f50
leaq -0x5b0(%rbp), %rdi
leaq -0x568(%rbp), %rsi
callq 0x6820
jmp 0x5041
leaq -0x5b0(%rbp), %rdi
callq 0x2e30
jmp 0x504f
leaq -0x5b0(%rbp), %rdi
callq 0x5f50
movl $0x0, -0x4(%rbp)
leaq -0x568(%rbp), %rdi
callq 0x5f50
leaq -0x448(%rbp), %rdi
callq 0x5f50
leaq -0x328(%rbp), %rdi
callq 0x5f50
leaq -0x50(%rbp), %rdi
callq 0x67e0
movl -0x4(%rbp), %eax
addq $0x680, %rsp            # imm = 0x680
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
jmp 0x51b9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
leaq -0x370(%rbp), %rdi
callq 0x67e0
jmp 0x51b9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
jmp 0x51ad
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
leaq -0x490(%rbp), %rdi
callq 0x67e0
jmp 0x51ad
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
jmp 0x51a1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
jmp 0x5155
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
leaq -0x598(%rbp), %rdi
callq 0x5f50
leaq -0x580(%rbp), %rdi
callq 0x5f50
jmp 0x51a1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
jmp 0x5195
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
leaq -0x5b0(%rbp), %rdi
callq 0x5f50
leaq -0x568(%rbp), %rdi
callq 0x5f50
leaq -0x448(%rbp), %rdi
callq 0x5f50
leaq -0x328(%rbp), %rdi
callq 0x5f50
leaq -0x50(%rbp), %rdi
callq 0x67e0
movq -0x98(%rbp), %rdi
callq 0x2350
nop