// File: /workspace/github_c_makefile_star2_O1/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 $0x1d8, %rsp            # imm = 0x1D8
movq %r8, %rbx
movq %rcx, %r12
movq %rdx, %r14
movq %rsi, 0x38(%rsp)
movq %rdi, 0x30(%rsp)
movsd (%rdx), %xmm0
movsd %xmm0, 0x10(%rsp)
callq 0x21d0
movsd %xmm0, 0x28(%rsp)
movsd 0x8(%r14), %xmm0
movsd %xmm0, 0x18(%rsp)
callq 0x21d0
movaps %xmm0, 0x40(%rsp)
movsd 0x10(%r14), %xmm0
movsd %xmm0, 0x58(%rsp)
callq 0x21d0
movsd %xmm0, 0x20(%rsp)
movsd 0x10(%rsp), %xmm0
callq 0x20f0
movsd %xmm0, 0x10(%rsp)
movsd 0x18(%rsp), %xmm0
callq 0x20f0
movsd %xmm0, 0x18(%rsp)
movsd 0x58(%rsp), %xmm0
callq 0x20f0
movsd 0x18(%rsp), %xmm11
movapd %xmm11, %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, 0x90(%rsp)
movsd 0x28(%rsp), %xmm7
movapd %xmm7, %xmm5
movapd 0x40(%rsp), %xmm4
mulsd %xmm4, %xmm5
movapd %xmm5, %xmm2
mulsd %xmm0, %xmm2
movsd 0x10(%rsp), %xmm9
movapd %xmm9, %xmm3
movsd 0x20(%rsp), %xmm12
mulsd %xmm12, %xmm3
subsd %xmm3, %xmm2
movsd %xmm2, 0x98(%rsp)
movapd %xmm4, %xmm3
movapd %xmm4, %xmm10
mulsd %xmm9, %xmm3
movapd %xmm3, %xmm6
mulsd %xmm0, %xmm6
movapd %xmm7, %xmm4
movapd %xmm7, %xmm8
mulsd %xmm12, %xmm4
addsd %xmm6, %xmm4
movsd %xmm4, 0xa0(%rsp)
movapd %xmm12, %xmm6
mulsd %xmm11, %xmm6
movsd %xmm6, 0xa8(%rsp)
mulsd %xmm12, %xmm5
movapd %xmm9, %xmm7
mulsd %xmm0, %xmm7
addsd %xmm5, %xmm7
movsd %xmm7, 0xb0(%rsp)
mulsd %xmm12, %xmm3
mulsd %xmm8, %xmm0
subsd %xmm0, %xmm3
movapd %xmm10, %xmm0
xorpd 0x13b82(%rip), %xmm0    # 0x1d610
movsd %xmm3, 0xb8(%rsp)
movlpd %xmm0, 0xc0(%rsp)
movapd %xmm0, %xmm5
movapd %xmm8, %xmm0
mulsd %xmm11, %xmm0
movsd %xmm0, 0xc8(%rsp)
mulsd %xmm11, %xmm9
movsd %xmm9, 0xd0(%rsp)
leaq 0x1a8(%rsp), %r13
movsd %xmm1, -0x18(%r13)
movsd %xmm6, -0x10(%r13)
movlpd %xmm5, -0x8(%r13)
movsd %xmm2, (%r13)
movsd %xmm7, 0x8(%r13)
movsd %xmm0, 0x10(%r13)
leaq 0x1c0(%rsp), %rbp
movsd %xmm4, (%rbp)
movsd %xmm3, 0x8(%rbp)
movsd %xmm9, 0x10(%rbp)
xorl %eax, %eax
movq %rax, 0xf0(%rsp)
movups 0x13c95(%rip), %xmm0    # 0x1d7b0
movaps %xmm0, 0xe0(%rsp)
movq %rax, 0x108(%rsp)
movups 0x13c96(%rip), %xmm0    # 0x1d7c8
movups %xmm0, 0xf8(%rsp)
movabsq $0x3ff0000000000000, %rcx # imm = 0x3FF0000000000000
movq %rcx, 0x120(%rsp)
movupd 0x13c8c(%rip), %xmm0    # 0x1d7e0
movapd %xmm0, 0x110(%rsp)
movabsq $0x3fe6a09e667f3bcc, %rcx # imm = 0x3FE6A09E667F3BCC
movq %rcx, 0x128(%rsp)
movq %rcx, 0x130(%rsp)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x138(%rsp)
movq %rcx, 0x148(%rsp)
movq %rcx, 0x150(%rsp)
movq %rcx, 0x158(%rsp)
movq %rax, 0x160(%rsp)
movq %rcx, 0x168(%rsp)
movapd %xmm0, 0x80(%rsp)
movapd %xmm0, 0x70(%rsp)
movapd %xmm0, 0x60(%rsp)
movl $0x1d0, %eax            # imm = 0x1D0
movabsq $0x47efffffe0000000, %rcx # imm = 0x47EFFFFFE0000000
movabsq $0x3810000000000000, %rdx # imm = 0x3810000000000000
movq %rcx, (%rbx,%rax)
movq %rdx, 0x8(%rbx,%rax)
addq $0x10, %rax
cmpq $0x200, %rax            # imm = 0x200
jne 0x9bda
leaq 0x1d0(%rbx), %r8
movl 0x8(%rbx), %r9d
movq 0x220(%rbx), %rax
movq %rax, (%rsp)
leaq 0x90(%rsp), %r15
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %rsi
movq %r15, %rdx
movq %r12, 0x20(%rsp)
movq %r12, %rcx
movq %r8, 0x10(%rsp)
callq 0x9e21
movl (%rbx), %esi
movq 0x208(%rbx), %rdx
movq %r15, %rdi
callq 0xa016
movl 0x4(%rbx), %esi
movq 0x218(%rbx), %rdx
movq %r15, %rdi
callq 0xa016
movl 0x8(%rbx), %esi
movq 0x228(%rbx), %rdx
movq %r15, %rdi
callq 0xa016
leaq 0xe0(%rsp), %r15
xorl %r14d, %r14d
leaq 0x190(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0x7f86
movsd %xmm0, 0x28(%rsp)
movq %r13, %rdi
movq %r15, %rsi
callq 0x7f86
movsd %xmm0, 0x40(%rsp)
movq %rbp, %rdi
movq %r15, %rsi
callq 0x7f86
movsd 0x38(%rbx), %xmm1
movsd 0x28(%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, 0x60(%rsp,%r14,8)
incq %r14
addq $0x18, %r15
cmpq $0x6, %r14
jne 0x9c74
movsd 0x60(%rsp), %xmm0
movsd %xmm0, 0x38(%rbx)
movsd 0x78(%rsp), %xmm0
movaps 0x138c1(%rip), %xmm1    # 0x1d610
xorps %xmm1, %xmm0
movlps %xmm0, 0x40(%rbx)
movsd 0x88(%rsp), %xmm2
xorps %xmm1, %xmm2
movaps %xmm2, %xmm3
movlhps %xmm0, %xmm3            # xmm3 = xmm3[0],xmm0[0]
movups %xmm3, 0x48(%rbx)
movsd 0x68(%rsp), %xmm0
movsd %xmm0, 0x58(%rbx)
movsd 0x80(%rsp), %xmm0
xorps %xmm1, %xmm0
movaps %xmm0, %xmm1
movlhps %xmm2, %xmm1            # xmm1 = xmm1[0],xmm2[0]
movups %xmm1, 0x60(%rbx)
movlps %xmm0, 0x70(%rbx)
movsd 0x70(%rsp), %xmm0
movsd %xmm0, 0x78(%rbx)
movsd 0x20(%rbx), %xmm0
leaq 0x170(%rsp), %r14
movsd %xmm0, (%r14)
movsd 0x28(%rbx), %xmm0
movsd %xmm0, 0x8(%r14)
movsd 0x30(%rbx), %xmm0
movsd %xmm0, 0x10(%r14)
movq %r14, (%rsp)
leaq 0x90(%rsp), %rdx
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %rsi
movq 0x20(%rsp), %rcx
movq 0x10(%rsp), %r8
movl $0x1, %r9d
callq 0x9e21
movsd (%r14), %xmm0
movsd %xmm0, 0x20(%rbx)
movsd 0x8(%r14), %xmm0
movsd %xmm0, 0x28(%rbx)
movsd 0x10(%r14), %xmm0
movsd %xmm0, 0x30(%rbx)
addq $0x1d8, %rsp            # imm = 0x1D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq