// File: intheswim[P]FractalTubes/infra.cpp
// Function: adjustNormals()
static void adjustNormals()
{
    long core_cnt = m3d_pt_count / m3d_pt_cycle;
    
    for (int core = 0; core < core_cnt; core++)
    {
        struct corePointData *cpd = &(corePoints[core]);
        
        for (int mode = 0; mode < 2; mode++)
        {
            for (int j = 0; j < m3d_pt_cycle; j++)
            {

                int i = cpd->index + j;
                int next = i + grid_step;
                
                if (next >= m3d_pt_count - 1)
                {
                    continue;
                }
                
                struct pointData *pd = pointData + i;
                struct pointData *pdNext1 = pointData + (next + 1);                
                
                if (j + 1 == m3d_pt_cycle) // last point connects to first on this "ring"
                {
                    pdNext1 = pointData + (next + 1 - grid_step);                    
                }
                
                pd->normx = pd->normx + pdNext1->normx;
                pd->normy = pd->normy + pdNext1->normy;
                pd->normz = pd->normz + pdNext1->normz;
                
                double r = sqrt (pd->normx * pd->normx + pd->normy * pd->normy + pd->normz * pd->normz);
                
                pd->normx = pd->normx / r;
                pd->normy = pd->normy / r;
                pd->normz = pd->normz / r;
            }
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq 0xd609(%rip), %rax      # 0x13568
movslq 0xd60a(%rip), %rcx      # 0x13570
cqto
idivq %rcx
movq %rax, -0x8(%rbp)
movl $0x0, -0xc(%rbp)
movslq -0xc(%rbp), %rax
cmpq -0x8(%rbp), %rax
jge 0x6167
movq 0xd5ad(%rip), %rax      # 0x13538
movslq -0xc(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
cmpl $0x2, -0x1c(%rbp)
jge 0x6157
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
cmpl 0xd5b5(%rip), %eax      # 0x13570
jge 0x6147
movq -0x18(%rbp), %rax
movl 0x20(%rax), %eax
addl -0x20(%rbp), %eax
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
addl 0xd59d(%rip), %eax      # 0x13574
movl %eax, -0x28(%rbp)
movslq -0x28(%rbp), %rax
movq 0xd583(%rip), %rcx      # 0x13568
subq $0x1, %rcx
cmpq %rcx, %rax
jl 0x5ff3
jmp 0x6139
movq 0xd536(%rip), %rax      # 0x13530
movslq -0x24(%rbp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq 0xd520(%rip), %rax      # 0x13530
movl -0x28(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movl -0x20(%rbp), %eax
addl $0x1, %eax
cmpl 0xd540(%rip), %eax      # 0x13570
jne 0x6053
movq 0xd4f7(%rip), %rax      # 0x13530
movl -0x28(%rbp), %ecx
addl $0x1, %ecx
subl 0xd52f(%rip), %ecx      # 0x13574
movslq %ecx, %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rax
movsd 0x20(%rax), %xmm0
movq -0x38(%rbp), %rax
addsd 0x20(%rax), %xmm0
movq -0x30(%rbp), %rax
movsd %xmm0, 0x20(%rax)
movq -0x30(%rbp), %rax
movsd 0x28(%rax), %xmm0
movq -0x38(%rbp), %rax
addsd 0x28(%rax), %xmm0
movq -0x30(%rbp), %rax
movsd %xmm0, 0x28(%rax)
movq -0x30(%rbp), %rax
movsd 0x30(%rax), %xmm0
movq -0x38(%rbp), %rax
addsd 0x30(%rax), %xmm0
movq -0x30(%rbp), %rax
movsd %xmm0, 0x30(%rax)
movq -0x30(%rbp), %rax
movsd 0x20(%rax), %xmm1
movq -0x30(%rbp), %rax
movsd 0x20(%rax), %xmm2
movq -0x30(%rbp), %rax
movsd 0x28(%rax), %xmm0
movq -0x30(%rbp), %rax
mulsd 0x28(%rax), %xmm0
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movq -0x30(%rbp), %rax
movsd 0x30(%rax), %xmm0
movq -0x30(%rbp), %rax
movsd 0x30(%rax), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
callq 0x32a0
movsd %xmm0, -0x40(%rbp)
movq -0x30(%rbp), %rax
movsd 0x20(%rax), %xmm0
divsd -0x40(%rbp), %xmm0
movq -0x30(%rbp), %rax
movsd %xmm0, 0x20(%rax)
movq -0x30(%rbp), %rax
movsd 0x28(%rax), %xmm0
divsd -0x40(%rbp), %xmm0
movq -0x30(%rbp), %rax
movsd %xmm0, 0x28(%rax)
movq -0x30(%rbp), %rax
movsd 0x30(%rax), %xmm0
divsd -0x40(%rbp), %xmm0
movq -0x30(%rbp), %rax
movsd %xmm0, 0x30(%rax)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x5fb2
jmp 0x6149
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x5fa1
jmp 0x6159
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x5f76
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)