// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %rbx
subq $0x398, %rsp            # imm = 0x398
leaq 0x181b(%rip), %rsi      # 0x508b
leaq -0x270(%rbp), %rdi
callq 0x40a6
leaq -0x2f0(%rbp), %rbx
xorps %xmm0, %xmm0
xorps %xmm1, %xmm1
xorps %xmm2, %xmm2
movq %rbx, %rdi
callq 0x29e2
xorps %xmm0, %xmm0
leaq -0x2b0(%rbp), %rax
movups %xmm0, 0x4(%rax)
movups %xmm0, 0x18(%rax)
movups %xmm0, 0x2c(%rax)
movl $0x3f800000, %ecx       # imm = 0x3F800000
movl %ecx, (%rax)
movl %ecx, 0x14(%rax)
movl %ecx, 0x28(%rax)
movl %ecx, 0x3c(%rax)
movaps %xmm0, -0xa0(%rbp)
movaps %xmm0, -0x90(%rbp)
movaps %xmm0, -0x80(%rbp)
movaps %xmm0, -0x70(%rbp)
xorl %ecx, %ecx
movq %rcx, %rdx
shlq $0x4, %rdx
addq %rbp, %rdx
addq $-0xa0, %rdx
movq %rax, %rsi
xorl %edi, %edi
leaq (%rdx,%rdi,4), %r8
movss (%r8), %xmm0
xorl %r9d, %r9d
movss (%rbx,%r9), %xmm1
mulss (%rsi,%r9,4), %xmm1
addss %xmm1, %xmm0
addq $0x4, %r9
cmpq $0x10, %r9
jne 0x38f4
movss %xmm0, (%r8)
incq %rdi
addq $0x4, %rsi
cmpq $0x4, %rdi
jne 0x38e8
incq %rcx
addq $0x10, %rbx
cmpq $0x4, %rcx
jne 0x38d2
xorps %xmm0, %xmm0
leaq -0x2b0(%rbp), %rax
movups %xmm0, 0x4(%rax)
movups %xmm0, 0x18(%rax)
movl $0x3f800000, %ecx       # imm = 0x3F800000
movl %ecx, (%rax)
movl %ecx, 0x14(%rax)
movss 0x16b7(%rip), %xmm1     # 0x5008
movups %xmm1, 0x28(%rax)
movabsq $0x3f800000c0a00000, %rcx # imm = 0x3F800000C0A00000
movq %rcx, 0x38(%rax)
movaps %xmm0, -0x60(%rbp)
movaps %xmm0, -0x50(%rbp)
movaps %xmm0, -0x40(%rbp)
movaps %xmm0, -0x30(%rbp)
leaq -0xa0(%rbp), %rcx
xorl %edx, %edx
movq %rdx, %rsi
shlq $0x4, %rsi
addq %rbp, %rsi
addq $-0x60, %rsi
movq %rax, %rdi
xorl %r8d, %r8d
leaq (%rsi,%r8,4), %r9
movss (%r9), %xmm0
xorl %r10d, %r10d
movss (%rcx,%r10), %xmm1
mulss (%rdi,%r10,4), %xmm1
addss %xmm1, %xmm0
addq $0x4, %r10
cmpq $0x10, %r10
jne 0x399c
movss %xmm0, (%r9)
incq %r8
addq $0x4, %rdi
cmpq $0x4, %r8
jne 0x3990
incq %rdx
addq $0x10, %rcx
cmpq $0x4, %rdx
jne 0x397c
movss 0x165b(%rip), %xmm0     # 0x5038
movsd 0x168b(%rip), %xmm4     # 0x5070
leaq -0x2b0(%rbp), %rdi
movss 0x1648(%rip), %xmm1     # 0x503c
xorps %xmm2, %xmm2
xorps %xmm3, %xmm3
xorps %xmm5, %xmm5
callq 0x260b
movss 0x1636(%rip), %xmm0     # 0x5040
leaq -0xa0(%rbp), %rdi
xorps %xmm2, %xmm2
xorps %xmm3, %xmm3
xorps %xmm5, %xmm5
movss 0x161a(%rip), %xmm1     # 0x503c
movsd 0x1646(%rip), %xmm4     # 0x5070
callq 0x260b
leaq -0x228(%rbp), %rdi
leaq -0x270(%rbp), %rsi
callq 0x4b74
leaq -0x210(%rbp), %rdi
leaq -0x258(%rbp), %rbx
movq %rbx, %rsi
callq 0x4c0c
leaq -0x1f8(%rbp), %rdi
leaq -0x240(%rbp), %r14
movq %r14, %rsi
callq 0x4b74
movl $0x3f800000, %eax       # imm = 0x3F800000
movl %eax, -0x120(%rbp)
xorps %xmm0, %xmm0
movups %xmm0, -0x11c(%rbp)
movl %eax, -0x10c(%rbp)
movups %xmm0, -0x108(%rbp)
movabsq $0x3dccd20bbf800347, %r15 # imm = 0x3DCCD20BBF800347
movq %r15, -0xf8(%rbp)
movq $0x0, -0xf0(%rbp)
movl $0xbf800000, %eax       # imm = 0xBF800000
movq %rax, -0xe8(%rbp)
movups -0x2b0(%rbp), %xmm0
movups -0x2a0(%rbp), %xmm1
movups -0x290(%rbp), %xmm2
movups -0x280(%rbp), %xmm3
movups %xmm3, 0xb0(%rsp)
movups %xmm2, 0xa0(%rsp)
movups %xmm1, 0x90(%rsp)
movups %xmm0, 0x80(%rsp)
movaps -0x60(%rbp), %xmm0
movaps -0x50(%rbp), %xmm1
movaps -0x40(%rbp), %xmm2
movaps -0x30(%rbp), %xmm3
movups %xmm3, 0x70(%rsp)
movups %xmm2, 0x60(%rsp)
movups %xmm1, 0x50(%rsp)
movups %xmm0, 0x40(%rsp)
movups -0x120(%rbp), %xmm0
movups -0x110(%rbp), %xmm1
movups -0x100(%rbp), %xmm2
movups -0xf0(%rbp), %xmm3
movups %xmm3, 0x30(%rsp)
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
leaq -0x2f0(%rbp), %rdi
leaq -0x228(%rbp), %rsi
callq 0x3020
movq -0x1f8(%rbp), %rdi
testq %rdi, %rdi
je 0x3b6b
callq 0x2170
movq -0x210(%rbp), %rdi
testq %rdi, %rdi
je 0x3b7c
callq 0x2170
movq -0x228(%rbp), %rdi
testq %rdi, %rdi
je 0x3b8d
callq 0x2170
leaq -0x1e0(%rbp), %rdi
leaq -0x270(%rbp), %rsi
callq 0x4b74
leaq -0x1c8(%rbp), %rdi
movq %rbx, %rsi
callq 0x4c0c
leaq -0x1b0(%rbp), %rdi
movq %r14, %rsi
callq 0x4b74
movl $0x3f800000, %eax       # imm = 0x3F800000
movl %eax, -0xe0(%rbp)
xorps %xmm0, %xmm0
movups %xmm0, -0xdc(%rbp)
movl %eax, -0xcc(%rbp)
movups %xmm0, -0xc8(%rbp)
movq %r15, -0xb8(%rbp)
movq $0x0, -0xb0(%rbp)
movl $0xbf800000, %eax       # imm = 0xBF800000
movq %rax, -0xa8(%rbp)
movups -0xa0(%rbp), %xmm0
movups -0x90(%rbp), %xmm1
movups -0x80(%rbp), %xmm2
movups -0x70(%rbp), %xmm3
movups %xmm3, 0xb0(%rsp)
movups %xmm2, 0xa0(%rsp)
movups %xmm1, 0x90(%rsp)
movups %xmm0, 0x80(%rsp)
movaps -0x60(%rbp), %xmm0
movaps -0x50(%rbp), %xmm1
movaps -0x40(%rbp), %xmm2
movaps -0x30(%rbp), %xmm3
movups %xmm3, 0x70(%rsp)
movups %xmm2, 0x60(%rsp)
movups %xmm1, 0x50(%rsp)
movups %xmm0, 0x40(%rsp)
movups -0xe0(%rbp), %xmm0
movups -0xd0(%rbp), %xmm1
movups -0xc0(%rbp), %xmm2
movups -0xb0(%rbp), %xmm3
movups %xmm3, 0x30(%rsp)
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
leaq -0x198(%rbp), %rdi
leaq -0x1e0(%rbp), %rsi
callq 0x3020
movq -0x1b0(%rbp), %rdi
testq %rdi, %rdi
je 0x3cab
callq 0x2170
movq -0x1c8(%rbp), %rdi
testq %rdi, %rdi
je 0x3cbc
callq 0x2170
movq -0x1e0(%rbp), %rdi
testq %rdi, %rdi
je 0x3ccd
callq 0x2170
leaq -0x168(%rbp), %rdi
leaq -0x2f0(%rbp), %rsi
callq 0x47e4
leaq -0x150(%rbp), %rdi
leaq -0x198(%rbp), %rsi
callq 0x47e4
leaq -0x180(%rbp), %rdi
leaq -0x168(%rbp), %rsi
leaq -0x150(%rbp), %rdx
callq 0x3797
movq -0x150(%rbp), %rdi
testq %rdi, %rdi
je 0x3d1e
callq 0x2170
movq -0x168(%rbp), %rdi
testq %rdi, %rdi
je 0x3d2f
callq 0x2170
leaq -0x138(%rbp), %rdi
leaq -0x180(%rbp), %rsi
callq 0x47e4
leaq -0x138(%rbp), %rdi
callq 0x2d28
movq -0x138(%rbp), %rdi
testq %rdi, %rdi
je 0x3d5f
callq 0x2170
movq -0x180(%rbp), %rdi
testq %rdi, %rdi
je 0x3d70
callq 0x2170
movq -0x198(%rbp), %rdi
testq %rdi, %rdi
je 0x3d81
callq 0x2170
movq -0x2f0(%rbp), %rdi
testq %rdi, %rdi
je 0x3d92
callq 0x2170
movq -0x240(%rbp), %rdi
testq %rdi, %rdi
je 0x3da3
callq 0x2170
movq -0x258(%rbp), %rdi
testq %rdi, %rdi
je 0x3db4
callq 0x2170
movq -0x270(%rbp), %rdi
testq %rdi, %rdi
je 0x3dc5
callq 0x2170
xorl %eax, %eax
addq $0x398, %rsp            # imm = 0x398
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq -0x138(%rbp), %rdi
testq %rdi, %rdi
je 0x3dee
callq 0x2170
jmp 0x3dee
movq %rax, %rbx
movq -0x180(%rbp), %rdi
jmp 0x3e17
movq %rax, %rbx
movq -0x150(%rbp), %rdi
testq %rdi, %rdi
je 0x3e10
callq 0x2170
jmp 0x3e10
movq %rax, %rbx
movq -0x168(%rbp), %rdi
testq %rdi, %rdi
je 0x3e26
callq 0x2170
jmp 0x3e26
movq %rax, %rbx
movq -0x198(%rbp), %rdi
jmp 0x3e60
movq %rax, %rbx
leaq -0x1e0(%rbp), %rdi
callq 0x47a8
jmp 0x3e6f
movq %rax, %rbx
movq -0x1c8(%rbp), %rdi
testq %rdi, %rdi
je 0x3e59
callq 0x2170
jmp 0x3e59
movq %rax, %rbx
movq -0x1e0(%rbp), %rdi
testq %rdi, %rdi
je 0x3e6f
callq 0x2170
jmp 0x3e6f
movq %rax, %rbx
movq -0x2f0(%rbp), %rdi
testq %rdi, %rdi
je 0x3e80
callq 0x2170
leaq -0x270(%rbp), %rdi
callq 0x47a8
movq %rbx, %rdi
callq 0x22e0
movq %rax, %rbx
leaq -0x228(%rbp), %rdi
callq 0x47a8
jmp 0x3e80
movq %rax, %rbx
movq -0x210(%rbp), %rdi
testq %rdi, %rdi
je 0x3ebe
callq 0x2170
jmp 0x3ebe
movq %rax, %rbx
movq -0x228(%rbp), %rdi
jmp 0x3e76
movq %rax, %rbx
jmp 0x3e80