// File: /workspace/github_c_makefile_star2_O2/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 $0x1e8, %rsp            # imm = 0x1E8
movq %r8, %rbx
movq %rcx, %r12
movq %rdx, %r14
movq %rsi, %rbp
movq %rdi, 0x28(%rsp)
movsd (%rdx), %xmm0
movsd %xmm0, 0x10(%rsp)
callq 0x21e0
movaps %xmm0, 0x50(%rsp)
movsd 0x8(%r14), %xmm0
movsd %xmm0, 0x8(%rsp)
callq 0x21e0
movaps %xmm0, 0x30(%rsp)
movsd 0x10(%r14), %xmm0
movsd %xmm0, 0x68(%rsp)
callq 0x21e0
movaps %xmm0, 0x40(%rsp)
movsd 0x10(%rsp), %xmm0
callq 0x20f0
movaps %xmm0, 0x10(%rsp)
movsd 0x8(%rsp), %xmm0
callq 0x20f0
movsd %xmm0, 0x8(%rsp)
movsd 0x68(%rsp), %xmm0
callq 0x20f0
movsd 0x8(%rsp), %xmm6
movapd %xmm6, %xmm2
mulsd %xmm0, %xmm2
movsd %xmm2, 0xa0(%rsp)
movapd 0x125c4(%rip), %xmm3    # 0x1b510
movapd 0x10(%rsp), %xmm10
movapd %xmm10, %xmm1
xorpd %xmm3, %xmm1
movapd 0x30(%rsp), %xmm9
movapd %xmm9, %xmm4
unpcklpd %xmm9, %xmm4            # xmm4 = xmm4[0],xmm9[0]
movapd 0x50(%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 0x40(%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, 0xa8(%rsp)
movapd %xmm8, %xmm5
mulsd %xmm6, %xmm5
movapd %xmm6, %xmm11
movsd %xmm5, 0xb8(%rsp)
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, 0xc0(%rsp)
movapd %xmm9, %xmm0
xorpd %xmm3, %xmm0
movlpd %xmm0, 0xd0(%rsp)
movapd %xmm0, %xmm4
movapd %xmm7, %xmm0
mulsd %xmm11, %xmm0
movsd %xmm0, 0xd8(%rsp)
movapd %xmm0, %xmm3
movapd %xmm10, %xmm0
mulsd %xmm11, %xmm0
movsd %xmm0, 0xe0(%rsp)
movapd %xmm0, %xmm5
leaq 0x1b8(%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 0x1d0(%rsp), %r14
movhlps %xmm1, %xmm6            # xmm6 = xmm1[1],xmm6[1]
movaps %xmm6, (%r14)
movsd %xmm5, 0x10(%r14)
movups 0x1269b(%rip), %xmm0    # 0x1b718
movaps %xmm0, 0xf0(%rsp)
andq $0x0, 0x100(%rsp)
movups 0x1269b(%rip), %xmm0    # 0x1b730
andq $0x0, 0x118(%rsp)
movups %xmm0, 0x108(%rsp)
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, 0x130(%rsp)
movups 0x12689(%rip), %xmm0    # 0x1b748
movaps %xmm0, 0x120(%rsp)
movaps 0x125d2(%rip), %xmm0    # 0x1b6a0
movups %xmm0, 0x138(%rsp)
xorpd %xmm1, %xmm1
movupd %xmm1, 0x148(%rsp)
movups %xmm0, 0x158(%rsp)
movsd 0x125fd(%rip), %xmm0    # 0x1b6f0
movups %xmm0, 0x168(%rsp)
movabsq $0x3fe6a09e667f3bcc, %rax # imm = 0x3FE6A09E667F3BCC
movq %rax, 0x178(%rsp)
movapd %xmm1, 0x90(%rsp)
movapd %xmm1, 0x80(%rsp)
movapd %xmm1, 0x70(%rsp)
leaq 0x1d0(%rbx), %r8
movl $0x1d0, %eax            # imm = 0x1D0
movapd 0x12577(%rip), %xmm0    # 0x1b6b0
cmpq $0x200, %rax            # imm = 0x200
je 0x914c
movupd %xmm0, (%rbx,%rax)
addq $0x10, %rax
jmp 0x9139
movl 0x8(%rbx), %r9d
movq 0x220(%rbx), %rax
movq %rax, (%rsp)
leaq 0xa0(%rsp), %r15
movq 0x28(%rsp), %rdi
movq %rbp, 0x10(%rsp)
movq %rbp, %rsi
movq %r15, %rdx
movq %r12, 0x30(%rsp)
movq %r12, %rcx
movq %r8, 0x8(%rsp)
callq 0x935c
movl (%rbx), %esi
movq 0x208(%rbx), %rdx
movq %r15, %rdi
callq 0x94de
movl 0x4(%rbx), %esi
movq 0x218(%rbx), %rdx
movq %r15, %rdi
callq 0x94de
movl 0x8(%rbx), %esi
movq 0x228(%rbx), %rdx
movq %r15, %rdi
callq 0x94de
leaq 0xf0(%rsp), %r15
xorl %ebp, %ebp
leaq 0x1a0(%rsp), %r12
cmpq $0x6, %rbp
je 0x9293
movq %r12, %rdi
movq %r15, %rsi
callq 0x76cc
movsd %xmm0, 0x50(%rsp)
movq %r13, %rdi
movq %r15, %rsi
callq 0x76cc
movsd %xmm0, 0x40(%rsp)
movq %r14, %rdi
movq %r15, %rsi
callq 0x76cc
movsd 0x38(%rbx), %xmm1
movsd 0x50(%rsp), %xmm4
mulsd %xmm4, %xmm1
movsd 0x58(%rbx), %xmm2
movsd 0x40(%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, 0x70(%rsp,%rbp,8)
incq %rbp
addq $0x18, %r15
jmp 0x91cc
movsd 0x70(%rsp), %xmm0
movsd %xmm0, 0x38(%rbx)
movq 0x88(%rsp), %xmm0
movdqa 0x12261(%rip), %xmm1    # 0x1b510
pxor %xmm1, %xmm0
movq %xmm0, 0x40(%rbx)
movq %xmm0, 0x50(%rbx)
movsd 0x78(%rsp), %xmm0
movsd %xmm0, 0x58(%rbx)
pxor 0x90(%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 0x80(%rsp), %xmm0
movsd %xmm0, 0x78(%rbx)
movups 0x20(%rbx), %xmm0
leaq 0x180(%rsp), %r14
movaps %xmm0, (%r14)
movsd 0x30(%rbx), %xmm0
movsd %xmm0, 0x10(%r14)
movq %r14, (%rsp)
leaq 0xa0(%rsp), %rdx
pushq $0x1
popq %r9
movq 0x28(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq 0x30(%rsp), %rcx
movq 0x8(%rsp), %r8
callq 0x935c
movaps (%r14), %xmm0
movups %xmm0, 0x20(%rbx)
movsd 0x10(%r14), %xmm0
movsd %xmm0, 0x30(%rbx)
addq $0x1e8, %rsp            # imm = 0x1E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq