// File: /workspace/github_cpp_makefile_star2_O2/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 %rbx
subq $0x398, %rsp            # imm = 0x398
leaq 0x1bfe(%rip), %rsi      # 0x508b
leaq -0x250(%rbp), %rdi
callq 0x3cb2
leaq -0x208(%rbp), %rbx
xorps %xmm0, %xmm0
xorps %xmm1, %xmm1
xorps %xmm2, %xmm2
movq %rbx, %rdi
callq 0x2839
xorps %xmm0, %xmm0
leaq -0x1c8(%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, -0x90(%rbp)
movaps %xmm0, -0x80(%rbp)
movaps %xmm0, -0x70(%rbp)
movaps %xmm0, -0x60(%rbp)
xorl %ecx, %ecx
cmpq $0x4, %rcx
je 0x354d
movq %rcx, %rdx
shlq $0x4, %rdx
addq %rbp, %rdx
addq $-0x90, %rdx
movq %rax, %rsi
xorl %edi, %edi
cmpq $0x4, %rdi
je 0x3544
leaq (%rdx,%rdi,4), %r8
movss (%r8), %xmm0
xorl %r9d, %r9d
cmpq $0x10, %r9
je 0x3536
movss (%rbx,%r9), %xmm1
mulss (%rsi,%r9,4), %xmm1
addss %xmm1, %xmm0
addq $0x4, %r9
jmp 0x351a
movss %xmm0, (%r8)
incq %rdi
addq $0x4, %rsi
jmp 0x3508
incq %rcx
addq $0x10, %rbx
jmp 0x34ec
xorps %xmm0, %xmm0
leaq -0x1c8(%rbp), %rax
movups %xmm0, 0x4(%rax)
movups %xmm0, 0x18(%rax)
movl $0x3f800000, %ecx       # imm = 0x3F800000
movl %ecx, (%rax)
movl %ecx, 0x14(%rax)
movss 0x1a97(%rip), %xmm1     # 0x5008
movups %xmm1, 0x28(%rax)
movabsq $0x3f800000c0a00000, %rcx # imm = 0x3F800000C0A00000
movq %rcx, 0x38(%rax)
movaps %xmm0, -0x50(%rbp)
movaps %xmm0, -0x40(%rbp)
movaps %xmm0, -0x30(%rbp)
movaps %xmm0, -0x20(%rbp)
leaq -0x90(%rbp), %rcx
xorl %edx, %edx
cmpq $0x4, %rdx
je 0x35fb
movq %rdx, %rsi
shlq $0x4, %rsi
addq %rbp, %rsi
addq $-0x50, %rsi
movq %rax, %rdi
xorl %r8d, %r8d
cmpq $0x4, %r8
je 0x35f2
leaq (%rsi,%r8,4), %r9
movss (%r9), %xmm0
xorl %r10d, %r10d
cmpq $0x10, %r10
je 0x35e4
movss (%rcx,%r10), %xmm1
mulss (%rdi,%r10,4), %xmm1
addss %xmm1, %xmm0
addq $0x4, %r10
jmp 0x35c8
movss %xmm0, (%r9)
incq %r8
addq $0x4, %rdi
jmp 0x35b6
incq %rdx
addq $0x10, %rcx
jmp 0x359c
movss 0x1a31(%rip), %xmm0     # 0x5034
movsd 0x1a65(%rip), %xmm4     # 0x5070
leaq -0x1c8(%rbp), %rdi
movss 0x1a1e(%rip), %xmm1     # 0x5038
xorps %xmm2, %xmm2
xorps %xmm3, %xmm3
xorps %xmm5, %xmm5
callq 0x2526
movss 0x1a0c(%rip), %xmm0     # 0x503c
movsd 0x1a38(%rip), %xmm4     # 0x5070
leaq -0x90(%rbp), %rdi
movss 0x19f1(%rip), %xmm1     # 0x5038
xorps %xmm2, %xmm2
xorps %xmm3, %xmm3
xorps %xmm5, %xmm5
callq 0x2526
leaq -0x2e0(%rbp), %rdi
leaq -0x250(%rbp), %rsi
callq 0x410c
movl $0x3f800000, %eax       # imm = 0x3F800000
movl %eax, -0x110(%rbp)
xorps %xmm0, %xmm0
movups %xmm0, -0x10c(%rbp)
movl %eax, -0xfc(%rbp)
movups %xmm0, -0xf8(%rbp)
movabsq $0x3dccd20bbf800347, %rbx # imm = 0x3DCCD20BBF800347
movq %rbx, -0xe8(%rbp)
andq $0x0, -0xe0(%rbp)
movl $0xbf800000, %eax       # imm = 0xBF800000
movq %rax, -0xd8(%rbp)
movups -0x1c8(%rbp), %xmm0
movups -0x1b8(%rbp), %xmm1
movups -0x1a8(%rbp), %xmm2
movups -0x198(%rbp), %xmm3
movups %xmm3, 0xb0(%rsp)
movups %xmm2, 0xa0(%rsp)
movups %xmm1, 0x90(%rsp)
movups %xmm0, 0x80(%rsp)
movaps -0x50(%rbp), %xmm0
movaps -0x40(%rbp), %xmm1
movaps -0x30(%rbp), %xmm2
movaps -0x20(%rbp), %xmm3
movups %xmm3, 0x70(%rsp)
movups %xmm2, 0x60(%rsp)
movups %xmm1, 0x50(%rsp)
movups %xmm0, 0x40(%rsp)
movups -0x110(%rbp), %xmm0
movups -0x100(%rbp), %xmm1
movups -0xf0(%rbp), %xmm2
movups -0xe0(%rbp), %xmm3
movups %xmm3, 0x30(%rsp)
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
leaq -0x208(%rbp), %rdi
leaq -0x2e0(%rbp), %rsi
callq 0x2d92
leaq -0x2e0(%rbp), %rdi
callq 0x416c
leaq -0x298(%rbp), %rdi
leaq -0x250(%rbp), %rsi
callq 0x410c
movl $0x3f800000, %eax       # imm = 0x3F800000
movl %eax, -0xd0(%rbp)
xorps %xmm0, %xmm0
movups %xmm0, -0xcc(%rbp)
movl %eax, -0xbc(%rbp)
movups %xmm0, -0xb8(%rbp)
movq %rbx, -0xa8(%rbp)
andq $0x0, -0xa0(%rbp)
movl $0xbf800000, %eax       # imm = 0xBF800000
movq %rax, -0x98(%rbp)
movups -0x90(%rbp), %xmm0
movups -0x80(%rbp), %xmm1
movups -0x70(%rbp), %xmm2
movups -0x60(%rbp), %xmm3
movups %xmm3, 0xb0(%rsp)
movups %xmm2, 0xa0(%rsp)
movups %xmm1, 0x90(%rsp)
movups %xmm0, 0x80(%rsp)
movaps -0x50(%rbp), %xmm0
movaps -0x40(%rbp), %xmm1
movaps -0x30(%rbp), %xmm2
movaps -0x20(%rbp), %xmm3
movups %xmm3, 0x70(%rsp)
movups %xmm2, 0x60(%rsp)
movups %xmm1, 0x50(%rsp)
movups %xmm0, 0x40(%rsp)
movups -0xd0(%rbp), %xmm0
movups -0xc0(%rbp), %xmm1
movups -0xb0(%rbp), %xmm2
movups -0xa0(%rbp), %xmm3
movups %xmm3, 0x30(%rsp)
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
leaq -0x188(%rbp), %rdi
leaq -0x298(%rbp), %rsi
callq 0x2d92
leaq -0x298(%rbp), %rdi
callq 0x416c
leaq -0x158(%rbp), %rdi
leaq -0x208(%rbp), %rsi
callq 0x4196
leaq -0x140(%rbp), %rdi
leaq -0x188(%rbp), %rsi
callq 0x4196
leaq -0x170(%rbp), %rdi
leaq -0x158(%rbp), %rsi
leaq -0x140(%rbp), %rdx
callq 0x33f0
leaq -0x140(%rbp), %rdi
callq 0x4794
leaq -0x158(%rbp), %rdi
callq 0x4794
leaq -0x128(%rbp), %rdi
leaq -0x170(%rbp), %rsi
callq 0x4196
leaq -0x128(%rbp), %rdi
callq 0x2b8c
leaq -0x128(%rbp), %rdi
callq 0x4794
leaq -0x170(%rbp), %rdi
callq 0x4794
leaq -0x188(%rbp), %rdi
callq 0x4794
leaq -0x208(%rbp), %rdi
callq 0x4794
leaq -0x250(%rbp), %rdi
callq 0x416c
xorl %eax, %eax
addq $0x398, %rsp            # imm = 0x398
popq %rbx
popq %rbp
retq
movq %rax, %rbx
leaq -0x128(%rbp), %rdi
callq 0x4794
jmp 0x3925
movq %rax, %rbx
leaq -0x170(%rbp), %rdi
jmp 0x3949
movq %rax, %rbx
leaq -0x140(%rbp), %rdi
callq 0x4794
jmp 0x3942
movq %rax, %rbx
leaq -0x158(%rbp), %rdi
callq 0x4794
jmp 0x3953
movq %rax, %rbx
leaq -0x188(%rbp), %rdi
callq 0x4794
leaq -0x208(%rbp), %rdi
callq 0x4794
jmp 0x399b
movq %rax, %rbx
leaq -0x298(%rbp), %rdi
callq 0x416c
jmp 0x395f
movq %rax, %rbx
jmp 0x395f
movq %rax, %rbx
leaq -0x2e0(%rbp), %rdi
callq 0x416c
jmp 0x399b
jmp 0x3998
jmp 0x3998
movq %rax, %rbx
leaq -0x250(%rbp), %rdi
callq 0x416c
movq %rbx, %rdi
callq 0x2290
nop