// File: /workspace/github_c_makefile_star2_O1/mohuangrui[P]ArtraCFD/numerical_test.c
// Function: ComputeSolutionFunctional
void ComputeSolutionFunctional(const Time *time, Space *space, const Model *model)
{
    FILE *fp = Fopen("solution_functional.csv", "a");
    if (0 == time->stepC) { /* initialization step */
        fprintf(fp, "# time, kinetic energy, enstrophy \n");
    }
    const Partition *const part = &(space->part);
    Node *const node = space->node;
    Real *restrict U = NULL; /* numerical solution */
    int idx = 0; /* linear array index math variable */
    const RealVec d = {part->d[X], part->d[Y], part->d[Z]};
    const int h[DIMS][DIMS] = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}; /* direction indicator */
    Real rho = model->refRho; /* density */
    RealVec V = {0.0}; /* velocity */
    RealVec W = {0.0}; /* vorticity */
    Real Vs[DIMS][TTN] = {{0.0}}; /* velocity stencil */
    Real dV[DIMS][DIMS] = {{0.0}}; /* velocity gradient */
    Real Ek = 0.0; /* kinetic energy */
    Real Ee = 0.0; /* enstrophy */
    int N = 0; /* number of nodes */
    for (int k = part->ns[PIN][Z][MIN]; k < part->ns[PIN][Z][MAX]; ++k) {
        for (int j = part->ns[PIN][Y][MIN]; j < part->ns[PIN][Y][MAX]; ++j) {
            for (int i = part->ns[PIN][X][MIN]; i < part->ns[PIN][X][MAX]; ++i) {
                for (int s = 0; s < DIMS; ++s) {
                    for (int n = -TCN; n <= TCN; ++n) {
                        idx = IndexNode(k + n * h[s][Z], j + n * h[s][Y], i + n * h[s][X], part->n[Y], part->n[X]);
                        U = node[idx].U[TO];
                        Vs[X][TCN+n] = U[1] / U[0];
                        Vs[Y][TCN+n] = U[2] / U[0];
                        Vs[Z][TCN+n] = U[3] / U[0];
                    }
                    dV[X][s] = (-Vs[X][TCN+2] + 8.0 * Vs[X][TCN+1] - 8.0 * Vs[X][TCN-1] + Vs[X][TCN-2]) / (12.0 * d[s]);
                    dV[Y][s] = (-Vs[Y][TCN+2] + 8.0 * Vs[Y][TCN+1] - 8.0 * Vs[Y][TCN-1] + Vs[Y][TCN-2]) / (12.0 * d[s]);
                    dV[Z][s] = (-Vs[Z][TCN+2] + 8.0 * Vs[Z][TCN+1] - 8.0 * Vs[Z][TCN-1] + Vs[Z][TCN-2]) / (12.0 * d[s]);
                }
                idx = IndexNode(k, j, i, part->n[Y], part->n[X]);
                U = node[idx].U[TO];
                rho = U[0];
                V[X] = U[1] / U[0];
                V[Y] = U[2] / U[0];
                V[Z] = U[3] / U[0];
                W[X] = dV[Z][Y] - dV[Y][Z];
                W[Y] = dV[X][Z] - dV[Z][X];
                W[Z] = dV[Y][X] - dV[X][Y];
                Ek = Ek + rho * Dot(V,V);
                Ee = Ee + rho * Dot(W,W);
                ++N;
            }
        }
    }
    Ek = 0.5 * Ek / N;
    Ee = 0.5 * Ee / N;
    fprintf(fp, "%.6g, %.6g, %.6g\n", time->now, Ek, Ee);
    fclose(fp);
    return;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1b8, %rsp            # imm = 0x1B8
movq %rsi, %r15
movq %rdi, %r14
leaq 0xb25b(%rip), %rdi      # 0x1f385
leaq 0x96f6(%rip), %rsi      # 0x1d827
callq 0x9269
movq %rax, %rbx
cmpl $0x0, 0x8(%r14)
jne 0x14159
leaq 0xb256(%rip), %rdi      # 0x1f39d
movl $0x23, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x2200
movq (%r15), %r12
movsd 0x58(%r15), %xmm0
movsd %xmm0, 0x1a0(%rsp)
movsd 0x60(%r15), %xmm0
movsd %xmm0, 0x1a8(%rsp)
movsd 0x68(%r15), %xmm0
movsd %xmm0, 0x1b0(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0xa0(%rsp)
movapd %xmm0, 0xb0(%rsp)
movl $0x1, %eax
movl %eax, 0xa0(%rsp)
movl %eax, 0xb0(%rsp)
movl %eax, 0xc0(%rsp)
xorl %ecx, %ecx
movq %rcx, 0x60(%rsp)
movapd %xmm0, 0x50(%rsp)
movq %rcx, 0x40(%rsp)
movapd %xmm0, 0x30(%rsp)
movq %rcx, 0x190(%rsp)
movapd %xmm0, 0x180(%rsp)
movapd %xmm0, 0x170(%rsp)
movapd %xmm0, 0x160(%rsp)
movapd %xmm0, 0x150(%rsp)
movapd %xmm0, 0x140(%rsp)
movapd %xmm0, 0x130(%rsp)
movapd %xmm0, 0x120(%rsp)
movq %rcx, 0x110(%rsp)
movapd %xmm0, 0x100(%rsp)
movapd %xmm0, 0xf0(%rsp)
movapd %xmm0, 0xe0(%rsp)
movapd %xmm0, 0xd0(%rsp)
movslq 0xa0(%r15), %rax
xorpd %xmm1, %xmm1
xorpd %xmm2, %xmm2
xorpd %xmm0, %xmm0
movq %rax, 0x8(%rsp)
cmpl 0xa4(%r15), %eax
jge 0x14601
movq %r14, 0x68(%rsp)
movq %rbx, 0x70(%rsp)
movsd %xmm0, 0x18(%rsp)
movq %r15, 0x28(%rsp)
movq %r12, 0x20(%rsp)
movq 0x20(%rsp), %r13
movl 0x98(%r15), %eax
movl %eax, (%rsp)
cmpl 0x9c(%r15), %eax
jge 0x145bd
movl 0x90(%r15), %eax
movl %eax, 0x4(%rsp)
cmpl 0x94(%r15), %eax
jge 0x145b3
movsd %xmm2, 0x78(%rsp)
movq %rcx, 0x80(%rsp)
xorl %eax, %eax
movq %rax, 0x88(%rsp)
leaq (%rax,%rax,2), %rax
movl 0xa8(%rsp,%rax,4), %ecx
movl 0xa0(%rsp,%rax,4), %edx
movl 0xa4(%rsp,%rax,4), %eax
movq %rax, 0x90(%rsp)
addl %eax, %eax
movl (%rsp), %r14d
subl %eax, %r14d
movq %rdx, 0x98(%rsp)
movl 0x4(%rsp), %ebx
subl %edx, %ebx
subl %edx, %ebx
movq %rcx, 0x10(%rsp)
leal (%rcx,%rcx), %eax
movq 0x8(%rsp), %rcx
movl %ecx, %r12d
subl %eax, %r12d
xorl %ebp, %ebp
movq 0x28(%rsp), %r15
movl 0x34(%r15), %r8d
movl 0x38(%r15), %ecx
movl %r12d, %edi
movl %r14d, %esi
movl %ebx, %edx
callq 0x7ea3
cltq
movq %rax, %rcx
shlq $0x7, %rcx
leaq (%rcx,%rax,8), %rax
movsd 0x10(%r13,%rax), %xmm0
movsd 0x18(%r13,%rax), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x120(%rsp,%rbp,8)
movsd 0x20(%r13,%rax), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x148(%rsp,%rbp,8)
movsd 0x28(%r13,%rax), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x170(%rsp,%rbp,8)
addl 0x90(%rsp), %r14d
addl 0x98(%rsp), %ebx
incq %rbp
addl 0x10(%rsp), %r12d
cmpq $0x5, %rbp
jne 0x14323
movsd 0x138(%rsp), %xmm0
movsd 0xaf66(%rip), %xmm3     # 0x1f320
mulsd %xmm3, %xmm0
subsd 0x140(%rsp), %xmm0
movsd 0x128(%rsp), %xmm1
movsd 0xaf50(%rip), %xmm4     # 0x1f328
mulsd %xmm4, %xmm1
addsd %xmm0, %xmm1
addsd 0x120(%rsp), %xmm1
movsd 0x160(%rsp), %xmm0
mulsd %xmm3, %xmm0
subsd 0x168(%rsp), %xmm0
movsd 0x150(%rsp), %xmm2
mulsd %xmm4, %xmm2
addsd %xmm0, %xmm2
movq 0x88(%rsp), %rax
movsd 0x1a0(%rsp,%rax,8), %xmm0
mulsd 0xaf07(%rip), %xmm0     # 0x1f330
divsd %xmm0, %xmm1
addsd 0x148(%rsp), %xmm2
movsd %xmm1, 0xd0(%rsp,%rax,8)
divsd %xmm0, %xmm2
movsd %xmm2, 0xe8(%rsp,%rax,8)
movsd 0x188(%rsp), %xmm1
mulsd %xmm3, %xmm1
subsd 0x190(%rsp), %xmm1
movsd 0x178(%rsp), %xmm2
mulsd %xmm4, %xmm2
addsd %xmm1, %xmm2
addsd 0x170(%rsp), %xmm2
divsd %xmm0, %xmm2
movsd %xmm2, 0x100(%rsp,%rax,8)
incq %rax
cmpq $0x3, %rax
jne 0x142c7
movq 0x28(%rsp), %r15
movl 0x34(%r15), %r8d
movl 0x38(%r15), %ecx
movq 0x8(%rsp), %rdi
movl (%rsp), %esi
movl 0x4(%rsp), %ebx
movl %ebx, %edx
callq 0x7ea3
cltq
movq %rax, %rcx
shlq $0x7, %rcx
leaq (%rcx,%rax,8), %rax
movq 0x20(%rsp), %r12
movsd 0x10(%r12,%rax), %xmm1
movsd %xmm1, 0x10(%rsp)
movsd 0x18(%r12,%rax), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, 0x50(%rsp)
movsd 0x20(%r12,%rax), %xmm0
divsd 0x10(%r12,%rax), %xmm0
movsd %xmm0, 0x58(%rsp)
movsd 0x28(%r12,%rax), %xmm0
divsd 0x10(%r12,%rax), %xmm0
movsd %xmm0, 0x60(%rsp)
movsd 0xe0(%rsp), %xmm0
movsd 0x108(%rsp), %xmm1
subsd 0xf8(%rsp), %xmm1
movsd %xmm1, 0x30(%rsp)
subsd 0x100(%rsp), %xmm0
movsd %xmm0, 0x38(%rsp)
movsd 0xe8(%rsp), %xmm0
subsd 0xd8(%rsp), %xmm0
movsd %xmm0, 0x40(%rsp)
leaq 0x50(%rsp), %rdi
movq %rdi, %rsi
callq 0x7f86
mulsd 0x10(%rsp), %xmm0
movsd 0x18(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x18(%rsp)
leaq 0x30(%rsp), %rdi
movq %rdi, %rsi
callq 0x7f86
mulsd 0x10(%rsp), %xmm0
movsd 0x78(%rsp), %xmm2
addsd %xmm0, %xmm2
movq 0x80(%rsp), %rcx
incl %ecx
incl %ebx
movl %ebx, 0x4(%rsp)
cmpl 0x94(%r15), %ebx
jl 0x142b7
movl (%rsp), %eax
incl %eax
jmp 0x1428f
movq 0x8(%rsp), %rdx
incq %rdx
movslq 0xa4(%r15), %rax
movq %rdx, 0x8(%rsp)
cmpq %rax, %rdx
jl 0x14288
movsd 0x8fde(%rip), %xmm3     # 0x1d5c0
movsd 0x18(%rsp), %xmm1
mulsd %xmm3, %xmm1
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
mulsd %xmm3, %xmm2
movq 0x70(%rsp), %rbx
movq 0x68(%rsp), %r14
divsd %xmm0, %xmm1
divsd %xmm0, %xmm2
movsd 0x48(%r14), %xmm0
leaq 0xad5d(%rip), %rsi      # 0x1f373
movq %rbx, %rdi
movb $0x3, %al
callq 0x2150
movq %rbx, %rdi
callq 0x2080
addq $0x1b8, %rsp            # imm = 0x1B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop