// File: IsaacLaw12[P]RayTracer/./src/Transformation.cpp
// Function: Transformation::create_transform_matrix(double*)
void Transformation::create_transform_matrix(double transform_string[]){
    double rot_trans_x = transform_string[0];
    double rot_trans_y = transform_string[1];
    double rot_trans_z = transform_string[2];
    double deg_angle   = transform_string[3];
    double scale       = transform_string[4];
    double translate_x = transform_string[5];
    double translate_y = transform_string[6];
    double translate_z = transform_string[7];

    // Populate rotation matrices
    Eigen::Vector3d Wv = Eigen::Vector3d(rot_trans_x, rot_trans_y, rot_trans_z).normalized();
    Eigen::Vector3d Uv = Eigen::Vector3d(Wv);
    Eigen::Vector3d Vv;

    // Make sure Uv is not parallel to Wv
    int minindex;
    Uv.minCoeff(&minindex);
    if (Uv(minindex) == -1)
        // (-1 0 0) is a special case because it would change to (1 0 0)
        //     which is parallel
        minindex = (minindex + 1) % 3;
    Uv(minindex) = 1.0;

    Uv = Wv.cross(Uv).normalized();
    Vv = Wv.cross(Uv).normalized();

    normalize_z_rotate << Uv[0], Uv[1], Uv[2], 0,
                          Vv[0], Vv[1], Vv[2], 0,
                          Wv[0], Wv[1], Wv[2], 0,
                          0,     0,     0,     1;

    double rad_angle = (deg_angle * M_PI) / 180;
    double cos_angle = cos(rad_angle);
    double sin_angle = sin(rad_angle);
    rotate_matrix(0,0) = cos_angle;
    rotate_matrix(1,1) = cos_angle;
    rotate_matrix(0,1) = -sin_angle;
    rotate_matrix(1,0) = sin_angle;

    // Populate scale matrix
    scale_matrix(0,0) = scale;
    scale_matrix(1,1) = scale;
    scale_matrix(2,2) = scale;

    // Populate translate matrix
    translate_matrix(0,3) = translate_x;
    translate_matrix(1,3) = translate_y;
    translate_matrix(2,3) = translate_z;
}

// Assembly:
subq $0x2d8, %rsp            # imm = 0x2D8
movq %rdi, 0x2d0(%rsp)
movq %rsi, 0x2c8(%rsp)
movq 0x2d0(%rsp), %rax
movq %rax, 0x138(%rsp)
movq 0x2c8(%rsp), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x2c0(%rsp)
movq 0x2c8(%rsp), %rax
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0x2b8(%rsp)
movq 0x2c8(%rsp), %rax
movsd 0x10(%rax), %xmm0
movsd %xmm0, 0x2b0(%rsp)
movq 0x2c8(%rsp), %rax
movsd 0x18(%rax), %xmm0
movsd %xmm0, 0x2a8(%rsp)
movq 0x2c8(%rsp), %rax
movsd 0x20(%rax), %xmm0
movsd %xmm0, 0x2a0(%rsp)
movq 0x2c8(%rsp), %rax
movsd 0x28(%rax), %xmm0
movsd %xmm0, 0x298(%rsp)
movq 0x2c8(%rsp), %rax
movsd 0x30(%rax), %xmm0
movsd %xmm0, 0x290(%rsp)
movq 0x2c8(%rsp), %rax
movsd 0x38(%rax), %xmm0
movsd %xmm0, 0x288(%rsp)
leaq 0x258(%rsp), %rdi
leaq 0x2c0(%rsp), %rsi
leaq 0x2b8(%rsp), %rdx
leaq 0x2b0(%rsp), %rcx
callq 0x9c70
leaq 0x270(%rsp), %rdi
leaq 0x258(%rsp), %rsi
callq 0x9d50
leaq 0x240(%rsp), %rdi
leaq 0x270(%rsp), %rsi
callq 0xa4f0
leaq 0x228(%rsp), %rdi
callq 0x11e20
leaq 0x240(%rsp), %rdi
leaq 0x224(%rsp), %rsi
callq 0x45940
movslq 0x224(%rsp), %rsi
leaq 0x240(%rsp), %rdi
callq 0x6130
movsd (%rax), %xmm0
movsd 0x19388(%rip), %xmm1    # 0x5de60
ucomisd %xmm1, %xmm0
jne 0x44af9
jp 0x44af9
movl 0x224(%rsp), %eax
addl $0x1, %eax
movl $0x3, %ecx
cltd
idivl %ecx
movl %edx, 0x224(%rsp)
movslq 0x224(%rsp), %rsi
leaq 0x240(%rsp), %rdi
movq %rdi, 0x128(%rsp)
callq 0x6130
movq 0x128(%rsp), %rdx
movabsq $0x3ff0000000000000, %rcx # imm = 0x3FF0000000000000
movq %rcx, (%rax)
leaq 0x1f0(%rsp), %rdi
movq %rdi, 0xf8(%rsp)
leaq 0x270(%rsp), %rsi
movq %rsi, 0x108(%rsp)
callq 0xa000
movq 0xf8(%rsp), %rsi
leaq 0x208(%rsp), %rdi
movq %rdi, 0x100(%rsp)
callq 0x9d50
movq 0x100(%rsp), %rsi
movq 0x128(%rsp), %rdi
callq 0x9e50
movq 0x108(%rsp), %rsi
movq 0x128(%rsp), %rdx
leaq 0x1c0(%rsp), %rdi
movq %rdi, 0x110(%rsp)
callq 0xa000
movq 0x110(%rsp), %rsi
leaq 0x1d8(%rsp), %rdi
movq %rdi, 0x118(%rsp)
callq 0x9d50
movq 0x118(%rsp), %rsi
leaq 0x228(%rsp), %rdi
callq 0x9e50
movq 0x128(%rsp), %rdi
movq 0x138(%rsp), %rax
addq $0x50, %rax
movq %rax, 0x120(%rsp)
xorl %eax, %eax
movl %eax, %esi
callq 0x459c0
movq 0x120(%rsp), %rsi
movq %rax, %rdx
leaq 0x1a0(%rsp), %rdi
callq 0x45980
movq 0x128(%rsp), %rdi
movl $0x1, %esi
callq 0x459c0
movq %rax, 0x130(%rsp)
jmp 0x44c32
movq 0x130(%rsp), %rsi
leaq 0x1a0(%rsp), %rdi
callq 0x45a50
movq %rax, 0xf0(%rsp)
jmp 0x44c51
leaq 0x240(%rsp), %rdi
movl $0x2, %esi
callq 0x459c0
movq %rax, 0xe8(%rsp)
jmp 0x44c6d
movq 0xe8(%rsp), %rsi
movq 0xf0(%rsp), %rdi
callq 0x45a50
movq %rax, 0xe0(%rsp)
jmp 0x44c8c
movq 0xe0(%rsp), %rdi
movq $0x0, 0x188(%rsp)
leaq 0x188(%rsp), %rsi
callq 0x45a50
movq %rax, 0xd8(%rsp)
jmp 0x44cb7
xorl %eax, %eax
movl %eax, %esi
leaq 0x228(%rsp), %rdi
callq 0x459c0
movq %rax, 0xd0(%rsp)
jmp 0x44cd2
movq 0xd0(%rsp), %rsi
movq 0xd8(%rsp), %rdi
callq 0x45a50
movq %rax, 0xc8(%rsp)
jmp 0x44cf1
leaq 0x228(%rsp), %rdi
movl $0x1, %esi
callq 0x459c0
movq %rax, 0xc0(%rsp)
jmp 0x44d0d
movq 0xc0(%rsp), %rsi
movq 0xc8(%rsp), %rdi
callq 0x45a50
movq %rax, 0xb8(%rsp)
jmp 0x44d2c
leaq 0x228(%rsp), %rdi
movl $0x2, %esi
callq 0x459c0
movq %rax, 0xb0(%rsp)
jmp 0x44d48
movq 0xb0(%rsp), %rsi
movq 0xb8(%rsp), %rdi
callq 0x45a50
movq %rax, 0xa8(%rsp)
jmp 0x44d67
movq 0xa8(%rsp), %rdi
movq $0x0, 0x180(%rsp)
leaq 0x180(%rsp), %rsi
callq 0x45a50
movq %rax, 0xa0(%rsp)
jmp 0x44d92
xorl %eax, %eax
movl %eax, %esi
leaq 0x270(%rsp), %rdi
callq 0x459c0
movq %rax, 0x98(%rsp)
jmp 0x44dad
movq 0x98(%rsp), %rsi
movq 0xa0(%rsp), %rdi
callq 0x45a50
movq %rax, 0x90(%rsp)
jmp 0x44dcc
leaq 0x270(%rsp), %rdi
movl $0x1, %esi
callq 0x459c0
movq %rax, 0x88(%rsp)
jmp 0x44de8
movq 0x88(%rsp), %rsi
movq 0x90(%rsp), %rdi
callq 0x45a50
movq %rax, 0x80(%rsp)
jmp 0x44e07
leaq 0x270(%rsp), %rdi
movl $0x2, %esi
callq 0x459c0
movq %rax, 0x78(%rsp)
jmp 0x44e20
movq 0x78(%rsp), %rsi
movq 0x80(%rsp), %rdi
callq 0x45a50
movq %rax, 0x70(%rsp)
jmp 0x44e39
movq 0x70(%rsp), %rdi
movq $0x0, 0x178(%rsp)
leaq 0x178(%rsp), %rsi
callq 0x45a50
movq %rax, 0x68(%rsp)
jmp 0x44e5e
movq 0x68(%rsp), %rdi
movq $0x0, 0x170(%rsp)
leaq 0x170(%rsp), %rsi
callq 0x45a50
movq %rax, 0x60(%rsp)
jmp 0x44e83
movq 0x60(%rsp), %rdi
movq $0x0, 0x168(%rsp)
leaq 0x168(%rsp), %rsi
callq 0x45a50
movq %rax, 0x58(%rsp)
jmp 0x44ea8
movq 0x58(%rsp), %rdi
movq $0x0, 0x160(%rsp)
leaq 0x160(%rsp), %rsi
callq 0x45a50
movq %rax, 0x50(%rsp)
jmp 0x44ecd
movq 0x50(%rsp), %rdi
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, 0x158(%rsp)
leaq 0x158(%rsp), %rsi
callq 0x45a50
jmp 0x44ef3
leaq 0x1a0(%rsp), %rdi
callq 0x45bd0
movsd 0x27650(%rip), %xmm0    # 0x6c558
mulsd 0x2a8(%rsp), %xmm0
movsd 0x27637(%rip), %xmm1    # 0x6c550
divsd %xmm1, %xmm0
movsd %xmm0, 0x150(%rsp)
movsd 0x150(%rsp), %xmm0
callq 0x4620
movsd %xmm0, 0x148(%rsp)
movsd 0x150(%rsp), %xmm0
callq 0x40b0
movq 0x138(%rsp), %rdi
movsd %xmm0, 0x140(%rsp)
movsd 0x148(%rsp), %xmm0
movsd %xmm0, (%rsp)
addq $0xd0, %rdi
xorl %eax, %eax
movl %eax, %edx
movq %rdx, %rsi
callq 0x45bf0
movsd (%rsp), %xmm0
movq 0x138(%rsp), %rdi
movsd %xmm0, (%rax)
movsd 0x148(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
addq $0xd0, %rdi
movl $0x1, %edx
movq %rdx, %rsi
callq 0x45bf0
movsd 0x8(%rsp), %xmm0
movq 0x138(%rsp), %rdi
movsd %xmm0, (%rax)
movsd 0x140(%rsp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, 0x10(%rsp)
addq $0xd0, %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x1, %edx
callq 0x45bf0
movsd 0x10(%rsp), %xmm0
movq 0x138(%rsp), %rdi
movsd %xmm0, (%rax)
movsd 0x140(%rsp), %xmm0
movsd %xmm0, 0x18(%rsp)
addq $0xd0, %rdi
movl $0x1, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x45bf0
movsd 0x18(%rsp), %xmm0
movq 0x138(%rsp), %rdi
movsd %xmm0, (%rax)
movsd 0x2a0(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
addq $0x150, %rdi            # imm = 0x150
xorl %eax, %eax
movl %eax, %edx
movq %rdx, %rsi
callq 0x45bf0
movsd 0x20(%rsp), %xmm0
movq 0x138(%rsp), %rdi
movsd %xmm0, (%rax)
movsd 0x2a0(%rsp), %xmm0
movsd %xmm0, 0x28(%rsp)
addq $0x150, %rdi            # imm = 0x150
movl $0x1, %edx
movq %rdx, %rsi
callq 0x45bf0
movsd 0x28(%rsp), %xmm0
movq 0x138(%rsp), %rdi
movsd %xmm0, (%rax)
movsd 0x2a0(%rsp), %xmm0
movsd %xmm0, 0x30(%rsp)
addq $0x150, %rdi            # imm = 0x150
movl $0x2, %edx
movq %rdx, %rsi
callq 0x45bf0
movsd 0x30(%rsp), %xmm0
movq 0x138(%rsp), %rdi
movsd %xmm0, (%rax)
movsd 0x298(%rsp), %xmm0
movsd %xmm0, 0x38(%rsp)
addq $0x1d0, %rdi            # imm = 0x1D0
xorl %eax, %eax
movl %eax, %esi
movl $0x3, %edx
callq 0x45bf0
movsd 0x38(%rsp), %xmm0
movq 0x138(%rsp), %rdi
movsd %xmm0, (%rax)
movsd 0x290(%rsp), %xmm0
movsd %xmm0, 0x40(%rsp)
addq $0x1d0, %rdi            # imm = 0x1D0
movl $0x1, %esi
movl $0x3, %edx
callq 0x45bf0
movsd 0x40(%rsp), %xmm0
movq 0x138(%rsp), %rdi
movsd %xmm0, (%rax)
movsd 0x288(%rsp), %xmm0
movsd %xmm0, 0x48(%rsp)
addq $0x1d0, %rdi            # imm = 0x1D0
movl $0x2, %esi
movl $0x3, %edx
callq 0x45bf0
movsd 0x48(%rsp), %xmm0
movsd %xmm0, (%rax)
addq $0x2d8, %rsp            # imm = 0x2D8
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x198(%rsp)
movl %eax, 0x194(%rsp)
leaq 0x1a0(%rsp), %rdi
callq 0x45bd0
movq 0x198(%rsp), %rdi
callq 0x45e0
nopw %cs:(%rax,%rax)