// File: /workspace/github_c_makefile_star2_O3/mohuangrui[P]ArtraCFD/computational_geometry.c
// Function: TransformPolyhedron
void TransformPolyhedron(const Real O[restrict], const Real scale[restrict],
        const Real angle[restrict], const Real offset[restrict], Polyhedron *poly)
{
    const RealVec Sin = {sin(angle[X]), sin(angle[Y]), sin(angle[Z])};
    const RealVec Cos = {cos(angle[X]), cos(angle[Y]), cos(angle[Z])};
    const Real rotate[DIMS][DIMS] = { /* point rotation matrix */
        {Cos[Y]*Cos[Z], -Cos[X]*Sin[Z]+Sin[X]*Sin[Y]*Cos[Z], Sin[X]*Sin[Z]+Cos[X]*Sin[Y]*Cos[Z]},
        {Cos[Y]*Sin[Z], Cos[X]*Cos[Z]+Sin[X]*Sin[Y]*Sin[Z], -Sin[X]*Cos[Z]+Cos[X]*Sin[Y]*Sin[Z]},
        {-Sin[Y], Sin[X]*Cos[Y], Cos[X]*Cos[Y]}};
    const Real invrot[DIMS][DIMS] = { /* inverse rotation matrix */
        {rotate[0][0], rotate[1][0], rotate[2][0]},
        {rotate[0][1], rotate[1][1], rotate[2][1]},
        {rotate[0][2], rotate[1][2], rotate[2][2]}};
    const Real num = 1.0 / sqrt(2.0);
    const Real axe[6][DIMS] = { /* direction vector of axis xx, yy, zz, xy, yz, zx */
        {1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0},
        {num, num, 0.0}, {0.0, num, num}, {num, 0.0, num}};
    RealVec axis = {0.0}; /* direction vector of axis in rotated frame */
    Real I[6] = {0.0}; /* inertia tensor after rotation */
    /* transforming vertex and build the new bounding box */
    for (int s = 0; s < DIMS; ++s) {
        poly->box[s][MIN] = FLT_MAX;
        poly->box[s][MAX] = FLT_MIN;
    }
    TransformVertex(O, scale, rotate, offset, poly->box, poly->vertN, poly->v);
    /* transforming normal assuming pure rotation and translation */
    TransformNormal(rotate, poly->faceN, poly->Nf);
    TransformNormal(rotate, poly->edgeN, poly->Ne);
    TransformNormal(rotate, poly->vertN, poly->Nv);
    /* transform inertial tensor */
    for (int n = 0; n < 6; ++n) {
        axis[X] = Dot(invrot[X], axe[n]);
        axis[Y] = Dot(invrot[Y], axe[n]);
        axis[Z] = Dot(invrot[Z], axe[n]);
        I[n] = TransformInertia(axis, poly->I);
    }
    poly->I[X][X] = I[0];  poly->I[X][Y] = -I[3]; poly->I[X][Z] = -I[5];
    poly->I[Y][X] = -I[3]; poly->I[Y][Y] = I[1];  poly->I[Y][Z] = -I[4];
    poly->I[Z][X] = -I[5]; poly->I[Z][Y] = -I[4]; poly->I[Z][Z] = I[2];
    /* centroid should be transformed at last */
    Real Oc[1][DIMS] = {{poly->O[X], poly->O[Y], poly->O[Z]}};
    TransformVertex(O, scale, rotate, offset, poly->box, 1, Oc);
    poly->O[X] = Oc[0][X];
    poly->O[Y] = Oc[0][Y];
    poly->O[Z] = Oc[0][Z];
    return;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x208, %rsp            # imm = 0x208
movq %r8, %rbx
movq %rcx, 0x28(%rsp)
movq %rdx, %r14
movq %rsi, 0x20(%rsp)
movq %rdi, 0x18(%rsp)
movsd (%rdx), %xmm0
movsd %xmm0, 0x30(%rsp)
callq 0x21d0
movaps %xmm0, 0x60(%rsp)
movsd 0x8(%r14), %xmm0
movsd %xmm0, 0x10(%rsp)
callq 0x21d0
movaps %xmm0, 0x40(%rsp)
movsd 0x10(%r14), %xmm0
movsd %xmm0, 0x78(%rsp)
callq 0x21d0
movaps %xmm0, 0x50(%rsp)
movsd 0x30(%rsp), %xmm0
callq 0x20f0
movaps %xmm0, 0x30(%rsp)
movsd 0x10(%rsp), %xmm0
callq 0x20f0
movsd %xmm0, 0x10(%rsp)
movsd 0x78(%rsp), %xmm0
callq 0x20f0
movsd 0x10(%rsp), %xmm6
movapd %xmm6, %xmm2
mulsd %xmm0, %xmm2
leaq 0x120(%rsp), %r12
movsd %xmm2, (%r12)
movapd 0x12eab(%rip), %xmm3    # 0x1c620
movapd 0x30(%rsp), %xmm10
movapd %xmm10, %xmm1
xorpd %xmm3, %xmm1
movapd 0x40(%rsp), %xmm9
movapd %xmm9, %xmm4
unpcklpd %xmm9, %xmm4            # xmm4 = xmm4[0],xmm9[0]
movapd 0x60(%rsp), %xmm7
movapd %xmm7, %xmm5
unpcklpd %xmm10, %xmm5           # xmm5 = xmm5[0],xmm10[0]
mulpd %xmm4, %xmm5
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
unpcklpd %xmm7, %xmm1            # xmm1 = xmm1[0],xmm7[0]
movapd 0x50(%rsp), %xmm8
movapd %xmm8, %xmm4
unpcklpd %xmm8, %xmm4            # xmm4 = xmm4[0],xmm8[0]
mulpd %xmm4, %xmm1
mulpd %xmm5, %xmm4
mulpd %xmm0, %xmm5
addpd %xmm5, %xmm1
movupd %xmm1, 0x8(%r12)
movapd %xmm8, %xmm5
mulsd %xmm6, %xmm5
movapd %xmm6, %xmm11
movsd %xmm5, 0x18(%r12)
movapd %xmm5, %xmm8
movapd %xmm7, %xmm5
xorpd %xmm3, %xmm5
movapd %xmm10, %xmm6
unpcklpd %xmm5, %xmm6            # xmm6 = xmm6[0],xmm5[0]
mulpd %xmm0, %xmm6
addpd %xmm4, %xmm6
movapd %xmm6, 0x20(%r12)
movapd %xmm9, %xmm0
xorpd %xmm3, %xmm0
movlpd %xmm0, 0x30(%r12)
movapd %xmm0, %xmm4
movapd %xmm7, %xmm0
mulsd %xmm11, %xmm0
movsd %xmm0, 0x38(%r12)
movapd %xmm0, %xmm3
movapd %xmm10, %xmm0
mulsd %xmm11, %xmm0
movsd %xmm0, 0x40(%r12)
movapd %xmm0, %xmm5
leaq 0xe8(%rsp), %r13
movsd %xmm2, -0x18(%r13)
movsd %xmm8, -0x10(%r13)
movlpd %xmm4, -0x8(%r13)
movapd %xmm1, %xmm0
unpcklpd %xmm6, %xmm0            # xmm0 = xmm0[0],xmm6[0]
movupd %xmm0, (%r13)
movsd %xmm3, 0x10(%r13)
leaq 0x100(%rsp), %r14
movhlps %xmm1, %xmm6            # xmm6 = xmm1[1],xmm6[1]
movaps %xmm6, (%r14)
movsd %xmm5, 0x10(%r14)
xorl %ebp, %ebp
leaq 0x170(%rsp), %r15
movq %rbp, 0x10(%r15)
movups 0x12f88(%rip), %xmm0    # 0x1c830
movaps %xmm0, (%r15)
movq %rbp, 0x28(%r15)
movups 0x12f91(%rip), %xmm0    # 0x1c848
movups %xmm0, 0x18(%r15)
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, 0x40(%r15)
movups 0x12f8f(%rip), %xmm0    # 0x1c860
movaps %xmm0, 0x30(%r15)
movaps 0x12ed3(%rip), %xmm0    # 0x1c7b0
movups %xmm0, 0x48(%r15)
xorpd %xmm1, %xmm1
movupd %xmm1, 0x58(%r15)
movups %xmm0, 0x68(%r15)
movsd 0x12f07(%rip), %xmm0    # 0x1c800
movups %xmm0, 0x78(%r15)
movabsq $0x3fe6a09e667f3bcc, %rax # imm = 0x3FE6A09E667F3BCC
movq %rax, 0x88(%r15)
movapd %xmm1, 0xa0(%rsp)
movapd %xmm1, 0x90(%rsp)
movapd %xmm1, 0x80(%rsp)
leaq 0x1d0(%rbx), %r8
movapd 0x12e87(%rip), %xmm0    # 0x1c7c0
movupd %xmm0, 0x1d0(%rbx)
movupd %xmm0, 0x1e0(%rbx)
movupd %xmm0, 0x1f0(%rbx)
movl 0x8(%rbx), %r9d
movq 0x220(%rbx), %rax
movq %rax, (%rsp)
movq 0x18(%rsp), %rdi
movq 0x20(%rsp), %rsi
movq %r12, %rdx
movq 0x28(%rsp), %rcx
movq %r8, 0x40(%rsp)
callq 0x9b4f
movl (%rbx), %esi
movq 0x208(%rbx), %rdx
movq %r12, %rdi
callq 0x9cdd
movl 0x4(%rbx), %esi
movq 0x218(%rbx), %rdx
movq %r12, %rdi
callq 0x9cdd
movl 0x8(%rbx), %esi
movq 0x228(%rbx), %rdx
movq %r12, %rdi
callq 0x9cdd
leaq 0xd0(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0x7e36
movsd %xmm0, 0x60(%rsp)
movq %r13, %rdi
movq %r15, %rsi
callq 0x7e36
movsd %xmm0, 0x50(%rsp)
movq %r14, %rdi
movq %r15, %rsi
callq 0x7e36
movsd 0x38(%rbx), %xmm1
movsd 0x60(%rsp), %xmm4
mulsd %xmm4, %xmm1
movsd 0x58(%rbx), %xmm2
movsd 0x50(%rsp), %xmm3
mulsd %xmm3, %xmm2
mulsd %xmm3, %xmm2
movapd %xmm3, %xmm5
mulsd %xmm4, %xmm1
addsd %xmm2, %xmm1
movsd 0x78(%rbx), %xmm2
mulsd %xmm0, %xmm2
mulsd %xmm0, %xmm2
addsd %xmm1, %xmm2
movsd 0x40(%rbx), %xmm1
movsd 0x60(%rbx), %xmm3
addsd %xmm1, %xmm1
mulsd %xmm4, %xmm1
mulsd %xmm5, %xmm1
addsd %xmm2, %xmm1
addsd %xmm3, %xmm3
mulsd %xmm5, %xmm3
mulsd %xmm0, %xmm3
addsd %xmm1, %xmm3
movsd 0x68(%rbx), %xmm1
addsd %xmm1, %xmm1
mulsd %xmm0, %xmm1
mulsd %xmm4, %xmm1
addsd %xmm3, %xmm1
movsd %xmm1, 0x80(%rsp,%rbp,8)
incq %rbp
addq $0x18, %r15
cmpq $0x6, %rbp
jne 0x99b9
movsd 0x80(%rsp), %xmm0
movsd %xmm0, 0x38(%rbx)
movq 0x98(%rsp), %xmm0
movdqa 0x12b83(%rip), %xmm1    # 0x1c620
pxor %xmm1, %xmm0
movq %xmm0, 0x40(%rbx)
movq %xmm0, 0x50(%rbx)
movsd 0x88(%rsp), %xmm0
movsd %xmm0, 0x58(%rbx)
pxor 0xa0(%rsp), %xmm1
pshufd $0xee, %xmm1, %xmm0     # xmm0 = xmm1[2,3,2,3]
movq %xmm0, 0x48(%rbx)
movdqu %xmm1, 0x60(%rbx)
movq %xmm1, 0x70(%rbx)
movsd 0x90(%rsp), %xmm0
movsd %xmm0, 0x78(%rbx)
movups 0x20(%rbx), %xmm0
leaq 0xb0(%rsp), %r14
movaps %xmm0, (%r14)
movsd 0x30(%rbx), %xmm0
movsd %xmm0, 0x10(%r14)
movq %r14, (%rsp)
leaq 0x120(%rsp), %rdx
movq 0x18(%rsp), %rdi
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rcx
movq 0x40(%rsp), %r8
movl $0x1, %r9d
callq 0x9b4f
movaps (%r14), %xmm0
movups %xmm0, 0x20(%rbx)
movsd 0x10(%r14), %xmm0
movsd %xmm0, 0x30(%rbx)
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq