// File: /workspace/github_cpp_makefile_star2_O1/kryffin[P]software-rasterizer/./geometry.cpp
// Function: lookAt(Vec3f, Vec3f, Vec3f)
Mat4f lookAt (Vec3f eye, Vec3f target, Vec3f upDir) {
    // compute the forward vector from target to eye
    Vec3f forward = (eye - target).normalize();

    // compute the left vector
    Vec3f left = (upDir.cross(forward)).normalize(); // cross product

    // recompute the orthonormal up vector
    Vec3f up = forward.cross(left);    // cross product

    // init 4x4 matrix
    Mat4f M = Mat4f(1.f);

    // set rotation part, inverse rotation matrix: M^-1 = M^T for Euclidean transform
    M.m[0][0] = left.x;
    M.m[1][0] = left.y;
    M.m[2][0] = left.z;
    M.m[0][1] = up.x;
    M.m[1][1] = up.y;
    M.m[2][1] = up.z;
    M.m[0][2] = forward.x;
    M.m[1][2] = forward.y;
    M.m[2][2] = forward.z;

    // set translation part
    M.m[3][0] = -left.x * eye.x - left.y * eye.y - left.z * eye.z;
    M.m[3][1] = -up.x * eye.x - up.y * eye.y - up.z * eye.z;
    M.m[3][2] = -forward.x * eye.x - forward.y * eye.y - forward.z * eye.z;

    return M;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
subq $0x78, %rsp
movq %rdi, %rbx
movaps %xmm0, %xmm7
subps %xmm2, %xmm7
movaps %xmm0, -0x80(%rbp)
shufps $0x55, %xmm0, %xmm0     # xmm0 = xmm0[1,1,1,1]
movaps %xmm0, -0x70(%rbp)
movaps %xmm7, %xmm9
shufps $0x55, %xmm7, %xmm9     # xmm9 = xmm9[1,1],xmm7[1,1]
movss %xmm1, -0x14(%rbp)
movaps %xmm1, %xmm8
subss %xmm3, %xmm8
movaps %xmm9, %xmm0
mulss %xmm9, %xmm0
movaps %xmm7, %xmm1
mulss %xmm7, %xmm1
addss %xmm0, %xmm1
movaps %xmm8, %xmm0
mulss %xmm8, %xmm0
addss %xmm1, %xmm0
xorps %xmm2, %xmm2
ucomiss %xmm2, %xmm0
jb 0x266f
sqrtss %xmm0, %xmm0
jmp 0x26a7
movss %xmm8, -0x10(%rbp)
movaps %xmm9, -0x50(%rbp)
movaps %xmm4, -0x40(%rbp)
movss %xmm5, -0xc(%rbp)
movaps %xmm7, -0x30(%rbp)
callq 0x22f0
xorps %xmm2, %xmm2
movaps -0x30(%rbp), %xmm7
movss -0xc(%rbp), %xmm5
movaps -0x40(%rbp), %xmm4
movaps -0x50(%rbp), %xmm9
movss -0x10(%rbp), %xmm8
divss %xmm0, %xmm7
divss %xmm0, %xmm9
divss %xmm0, %xmm8
movaps %xmm4, %xmm11
shufps $0x55, %xmm4, %xmm11    # xmm11 = xmm11[1,1],xmm4[1,1]
movaps %xmm9, %xmm0
mulss %xmm5, %xmm0
movaps %xmm7, %xmm1
mulss %xmm11, %xmm1
mulss %xmm8, %xmm11
subss %xmm0, %xmm11
movaps %xmm8, %xmm0
mulss %xmm4, %xmm0
mulss %xmm7, %xmm5
subss %xmm0, %xmm5
mulss %xmm9, %xmm4
subss %xmm1, %xmm4
movaps %xmm5, %xmm0
mulss %xmm5, %xmm0
movaps %xmm11, %xmm1
mulss %xmm11, %xmm1
addss %xmm0, %xmm1
movaps %xmm4, %xmm0
mulss %xmm4, %xmm0
addss %xmm1, %xmm0
ucomiss %xmm2, %xmm0
jb 0x271b
sqrtss %xmm0, %xmm0
jmp 0x275a
movss %xmm8, -0x10(%rbp)
movaps %xmm9, -0x50(%rbp)
movaps %xmm4, -0x40(%rbp)
movss %xmm5, -0xc(%rbp)
movaps %xmm7, -0x30(%rbp)
movaps %xmm11, -0x60(%rbp)
callq 0x22f0
movaps -0x60(%rbp), %xmm11
movaps -0x30(%rbp), %xmm7
movss -0xc(%rbp), %xmm5
movaps -0x40(%rbp), %xmm4
movaps -0x50(%rbp), %xmm9
movss -0x10(%rbp), %xmm8
divss %xmm0, %xmm11
divss %xmm0, %xmm5
divss %xmm0, %xmm4
movaps %xmm5, %xmm0
mulss %xmm8, %xmm0
movaps %xmm9, %xmm1
mulss %xmm4, %xmm1
subss %xmm0, %xmm1
movaps 0x28ce(%rip), %xmm3     # 0x5050
movaps %xmm7, %xmm0
xorps %xmm3, %xmm0
movaps %xmm4, %xmm6
mulss %xmm7, %xmm6
movaps %xmm8, %xmm2
mulss %xmm11, %xmm2
subss %xmm6, %xmm2
movaps %xmm11, %xmm6
mulss %xmm9, %xmm6
movaps %xmm7, %xmm10
mulss %xmm5, %xmm10
subss %xmm6, %xmm10
xorps %xmm6, %xmm6
movups %xmm6, 0x30(%rbx)
movups %xmm6, (%rbx)
movups %xmm6, 0x10(%rbx)
movups %xmm6, 0x20(%rbx)
movl $0x3f800000, 0x3c(%rbx) # imm = 0x3F800000
movss %xmm11, (%rbx)
movss %xmm5, 0x10(%rbx)
movss %xmm4, 0x20(%rbx)
movss %xmm1, 0x4(%rbx)
movss %xmm2, 0x14(%rbx)
movss %xmm10, 0x24(%rbx)
movss %xmm7, 0x8(%rbx)
movss %xmm9, 0x18(%rbx)
movss %xmm8, 0x28(%rbx)
xorps %xmm3, %xmm11
movaps -0x70(%rbp), %xmm7
mulss %xmm7, %xmm5
movaps -0x80(%rbp), %xmm6
mulss %xmm6, %xmm11
subss %xmm5, %xmm11
movss -0x14(%rbp), %xmm5
mulss %xmm5, %xmm4
subss %xmm4, %xmm11
movss %xmm11, 0x30(%rbx)
xorps %xmm3, %xmm1
mulss %xmm7, %xmm2
mulss %xmm6, %xmm1
subss %xmm2, %xmm1
mulss %xmm5, %xmm10
subss %xmm10, %xmm1
movss %xmm1, 0x34(%rbx)
mulss %xmm9, %xmm7
mulss %xmm6, %xmm0
subss %xmm7, %xmm0
mulss %xmm5, %xmm8
subss %xmm8, %xmm0
movss %xmm0, 0x38(%rbx)
movq %rbx, %rax
addq $0x78, %rsp
popq %rbx
popq %rbp
retq