// File: /workspace/github_cpp_makefile_star2_O3/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 0x1918(%rip), %rsi      # 0x508b
leaq -0x270(%rbp), %rdi
callq 0x3faa
leaq -0x2f0(%rbp), %rbx
xorps %xmm0, %xmm0
xorps %xmm1, %xmm1
xorps %xmm2, %xmm2
movq %rbx, %rdi
callq 0x293e
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 0x37f7
movss %xmm0, (%r8)
incq %rdi
addq $0x4, %rsi
cmpq $0x4, %rdi
jne 0x37eb
incq %rcx
addq $0x10, %rbx
cmpq $0x4, %rcx
jne 0x37d5
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 0x17b4(%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 0x389f
movss %xmm0, (%r9)
incq %r8
addq $0x4, %rdi
cmpq $0x4, %r8
jne 0x3893
incq %rdx
addq $0x10, %rcx
cmpq $0x4, %rdx
jne 0x387f
movss 0x1754(%rip), %xmm0     # 0x5034
movsd 0x1788(%rip), %xmm4     # 0x5070
leaq -0x2b0(%rbp), %rdi
movss 0x1741(%rip), %xmm1     # 0x5038
xorps %xmm2, %xmm2
xorps %xmm3, %xmm3
xorps %xmm5, %xmm5
callq 0x25ff
movss 0x172f(%rip), %xmm0     # 0x503c
leaq -0xa0(%rbp), %rdi
xorps %xmm2, %xmm2
xorps %xmm3, %xmm3
xorps %xmm5, %xmm5
movss 0x1713(%rip), %xmm1     # 0x5038
movsd 0x1743(%rip), %xmm4     # 0x5070
callq 0x25ff
leaq -0x228(%rbp), %rdi
leaq -0x270(%rbp), %rsi
callq 0x4a72
leaq -0x210(%rbp), %rdi
leaq -0x258(%rbp), %rbx
movq %rbx, %rsi
callq 0x4b0a
leaq -0x1f8(%rbp), %rdi
leaq -0x240(%rbp), %r14
movq %r14, %rsi
callq 0x4a72
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 0x2f94
movq -0x1f8(%rbp), %rdi
testq %rdi, %rdi
je 0x3a6e
callq 0x2170
movq -0x210(%rbp), %rdi
testq %rdi, %rdi
je 0x3a7f
callq 0x2170
movq -0x228(%rbp), %rdi
testq %rdi, %rdi
je 0x3a90
callq 0x2170
leaq -0x1e0(%rbp), %rdi
leaq -0x270(%rbp), %rsi
callq 0x4a72
leaq -0x1c8(%rbp), %rdi
movq %rbx, %rsi
callq 0x4b0a
leaq -0x1b0(%rbp), %rdi
movq %r14, %rsi
callq 0x4a72
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 0x2f94
movq -0x1b0(%rbp), %rdi
testq %rdi, %rdi
je 0x3bae
callq 0x2170
movq -0x1c8(%rbp), %rdi
testq %rdi, %rdi
je 0x3bbf
callq 0x2170
movq -0x1e0(%rbp), %rdi
testq %rdi, %rdi
je 0x3bd0
callq 0x2170
leaq -0x168(%rbp), %rdi
leaq -0x2f0(%rbp), %rsi
callq 0x46e2
leaq -0x150(%rbp), %rdi
leaq -0x198(%rbp), %rsi
callq 0x46e2
leaq -0x180(%rbp), %rdi
leaq -0x168(%rbp), %rsi
leaq -0x150(%rbp), %rdx
callq 0x36ac
movq -0x150(%rbp), %rdi
testq %rdi, %rdi
je 0x3c21
callq 0x2170
movq -0x168(%rbp), %rdi
testq %rdi, %rdi
je 0x3c32
callq 0x2170
leaq -0x138(%rbp), %rdi
leaq -0x180(%rbp), %rsi
callq 0x46e2
leaq -0x138(%rbp), %rdi
callq 0x2c9c
movq -0x138(%rbp), %rdi
testq %rdi, %rdi
je 0x3c62
callq 0x2170
movq -0x180(%rbp), %rdi
testq %rdi, %rdi
je 0x3c73
callq 0x2170
movq -0x198(%rbp), %rdi
testq %rdi, %rdi
je 0x3c84
callq 0x2170
movq -0x2f0(%rbp), %rdi
testq %rdi, %rdi
je 0x3c95
callq 0x2170
movq -0x240(%rbp), %rdi
testq %rdi, %rdi
je 0x3ca6
callq 0x2170
movq -0x258(%rbp), %rdi
testq %rdi, %rdi
je 0x3cb7
callq 0x2170
movq -0x270(%rbp), %rdi
testq %rdi, %rdi
je 0x3cc8
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 0x3cf1
callq 0x2170
jmp 0x3cf1
movq %rax, %rbx
movq -0x180(%rbp), %rdi
jmp 0x3d1a
movq %rax, %rbx
movq -0x150(%rbp), %rdi
testq %rdi, %rdi
je 0x3d13
callq 0x2170
jmp 0x3d13
movq %rax, %rbx
movq -0x168(%rbp), %rdi
testq %rdi, %rdi
je 0x3d29
callq 0x2170
jmp 0x3d29
movq %rax, %rbx
movq -0x198(%rbp), %rdi
jmp 0x3d63
movq %rax, %rbx
leaq -0x1e0(%rbp), %rdi
callq 0x46a6
jmp 0x3d72
movq %rax, %rbx
movq -0x1c8(%rbp), %rdi
testq %rdi, %rdi
je 0x3d5c
callq 0x2170
jmp 0x3d5c
movq %rax, %rbx
movq -0x1e0(%rbp), %rdi
testq %rdi, %rdi
je 0x3d72
callq 0x2170
jmp 0x3d72
movq %rax, %rbx
movq -0x2f0(%rbp), %rdi
testq %rdi, %rdi
je 0x3d83
callq 0x2170
leaq -0x270(%rbp), %rdi
callq 0x46a6
movq %rbx, %rdi
callq 0x22e0
movq %rax, %rbx
leaq -0x228(%rbp), %rdi
callq 0x46a6
jmp 0x3d83
movq %rax, %rbx
movq -0x210(%rbp), %rdi
testq %rdi, %rdi
je 0x3dc1
callq 0x2170
jmp 0x3dc1
movq %rax, %rbx
movq -0x228(%rbp), %rdi
jmp 0x3d79
movq %rax, %rbx
jmp 0x3d83
nop