// File: Luthaf[P]zeopp/grid.cc
// Function: GaussianCube::GaussianCube(ATOM_NETWORK*)
GaussianCube::GaussianCube(ATOM_NETWORK *atmnet){

 // calculate desired cube size
 na=(int)ceil(atmnet->a/GRIDRES)+1;
 nb=(int)ceil(atmnet->b/GRIDRES)+1;
 nc=(int)ceil(atmnet->c/GRIDRES)+1;

 // define the grid and allocate memory
 gridsize = na*nb*nc;

 if(gridsize<2)
    {
    cout << "Grid size is 1 or less. Aborting..." << "\n";
//    abort();
    } else
    {
    cout << "Gaussian cube grid - " << na << " x " << nb << " x " << nc << " = " << gridsize << " points.\n";
    };

 allocate(na, nb, nc);

 o = XYZ (0.0,0.0,0.0);
 va=atmnet->v_a;
 vb=atmnet->v_b;
 vc=atmnet->v_c;

 va=va.scale(1.0/(na-1.0)); // substracting 1.0 from na in denominator to make sure va reaches 1.0 after na steps (starting from 0)
 vb=vb.scale(1.0/(nb-1.0));
 vc=vc.scale(1.0/(nc-1.0));

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x78(%rbp)
xorps %xmm2, %xmm2
movaps %xmm2, %xmm0
movaps %xmm2, %xmm1
callq 0xea8e0
movq -0x78(%rbp), %rdi
addq $0x18, %rdi
xorps %xmm2, %xmm2
movaps %xmm2, %xmm0
movaps %xmm2, %xmm1
callq 0xea8e0
movq -0x78(%rbp), %rdi
addq $0x30, %rdi
xorps %xmm2, %xmm2
movaps %xmm2, %xmm0
movaps %xmm2, %xmm1
callq 0xea8e0
movq -0x78(%rbp), %rdi
addq $0x48, %rdi
xorps %xmm2, %xmm2
movaps %xmm2, %xmm0
movaps %xmm2, %xmm1
callq 0xea8e0
movq -0x78(%rbp), %rdi
addq $0x60, %rdi
xorps %xmm2, %xmm2
movaps %xmm2, %xmm0
movaps %xmm2, %xmm1
callq 0xea8e0
movq -0x10(%rbp), %rax
movsd 0x8(%rax), %xmm0
movsd 0x1097fe(%rip), %xmm1   # 0x1fc400
divsd %xmm1, %xmm0
callq 0x50e0
movq -0x78(%rbp), %rax
cvttsd2si %xmm0, %ecx
addl $0x1, %ecx
movl %ecx, 0x78(%rax)
movq -0x10(%rbp), %rax
movsd 0x10(%rax), %xmm0
movsd 0x1097d6(%rip), %xmm1   # 0x1fc400
divsd %xmm1, %xmm0
callq 0x50e0
movq -0x78(%rbp), %rax
cvttsd2si %xmm0, %ecx
addl $0x1, %ecx
movl %ecx, 0x7c(%rax)
movq -0x10(%rbp), %rax
movsd 0x18(%rax), %xmm0
movsd 0x1097ae(%rip), %xmm1   # 0x1fc400
divsd %xmm1, %xmm0
callq 0x50e0
movq -0x78(%rbp), %rax
cvttsd2si %xmm0, %ecx
addl $0x1, %ecx
movl %ecx, 0x80(%rax)
movl 0x78(%rax), %ecx
imull 0x7c(%rax), %ecx
imull 0x80(%rax), %ecx
movl %ecx, 0x84(%rax)
cmpl $0x2, 0x84(%rax)
jge 0xf2cb0
movq 0x180330(%rip), %rdi    # 0x272fc0
leaq 0x1098b7(%rip), %rsi    # 0x1fc54e
callq 0x5540
movq %rax, %rdi
leaq 0x10697f(%rip), %rsi    # 0x1f9625
callq 0x5540
jmp 0xf2d41
movq 0x180309(%rip), %rdi    # 0x272fc0
leaq 0x1098b4(%rip), %rsi    # 0x1fc572
callq 0x5540
movq %rax, %rdi
movq -0x78(%rbp), %rax
movl 0x78(%rax), %esi
callq 0x58d0
movq %rax, %rdi
leaq 0x1098ac(%rip), %rsi    # 0x1fc588
callq 0x5540
movq %rax, %rdi
movq -0x78(%rbp), %rax
movl 0x7c(%rax), %esi
callq 0x58d0
movq %rax, %rdi
leaq 0x10988e(%rip), %rsi    # 0x1fc588
callq 0x5540
movq %rax, %rdi
movq -0x78(%rbp), %rax
movl 0x80(%rax), %esi
callq 0x58d0
movq %rax, %rdi
leaq 0x116f54(%rip), %rsi    # 0x209c6f
callq 0x5540
movq %rax, %rdi
movq -0x78(%rbp), %rax
movl 0x84(%rax), %esi
callq 0x58d0
movq %rax, %rdi
leaq 0x109850(%rip), %rsi    # 0x1fc58c
callq 0x5540
movq -0x78(%rbp), %rdi
movl 0x78(%rdi), %esi
movl 0x7c(%rdi), %edx
movl 0x80(%rdi), %ecx
callq 0xf2ef0
leaq -0x28(%rbp), %rdi
xorps %xmm2, %xmm2
movaps %xmm2, %xmm0
movaps %xmm2, %xmm1
callq 0xea8e0
movq -0x78(%rbp), %rax
movq -0x28(%rbp), %rcx
movq %rcx, (%rax)
movq -0x20(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x18(%rbp), %rcx
movq %rcx, 0x10(%rax)
movq -0x10(%rbp), %rcx
movq 0x38(%rcx), %rdx
movq %rdx, 0x18(%rax)
movq 0x40(%rcx), %rdx
movq %rdx, 0x20(%rax)
movq 0x48(%rcx), %rcx
movq %rcx, 0x28(%rax)
movq -0x10(%rbp), %rcx
movq 0x50(%rcx), %rdx
movq %rdx, 0x30(%rax)
movq 0x58(%rcx), %rdx
movq %rdx, 0x38(%rax)
movq 0x60(%rcx), %rcx
movq %rcx, 0x40(%rax)
movq -0x10(%rbp), %rcx
movq 0x68(%rcx), %rdx
movq %rdx, 0x48(%rax)
movq 0x70(%rcx), %rdx
movq %rdx, 0x50(%rax)
movq 0x78(%rcx), %rcx
movq %rcx, 0x58(%rax)
movq %rax, %rsi
addq $0x18, %rsi
cvtsi2sdl 0x78(%rax), %xmm1
movsd 0xff265(%rip), %xmm0    # 0x1f2050
subsd %xmm0, %xmm1
movsd 0xff259(%rip), %xmm0    # 0x1f2050
divsd %xmm1, %xmm0
leaq -0x40(%rbp), %rdi
callq 0xea9f0
movq -0x78(%rbp), %rax
movq -0x40(%rbp), %rcx
movq %rcx, 0x18(%rax)
movq -0x38(%rbp), %rcx
movq %rcx, 0x20(%rax)
movq -0x30(%rbp), %rcx
movq %rcx, 0x28(%rax)
movq %rax, %rsi
addq $0x30, %rsi
cvtsi2sdl 0x7c(%rax), %xmm1
movsd 0xff21c(%rip), %xmm0    # 0x1f2050
subsd %xmm0, %xmm1
movsd 0xff210(%rip), %xmm0    # 0x1f2050
divsd %xmm1, %xmm0
leaq -0x58(%rbp), %rdi
callq 0xea9f0
movq -0x78(%rbp), %rax
movq -0x58(%rbp), %rcx
movq %rcx, 0x30(%rax)
movq -0x50(%rbp), %rcx
movq %rcx, 0x38(%rax)
movq -0x48(%rbp), %rcx
movq %rcx, 0x40(%rax)
movq %rax, %rsi
addq $0x48, %rsi
cvtsi2sdl 0x80(%rax), %xmm1
movsd 0xff1d0(%rip), %xmm0    # 0x1f2050
subsd %xmm0, %xmm1
movsd 0xff1c4(%rip), %xmm0    # 0x1f2050
divsd %xmm1, %xmm0
leaq -0x70(%rbp), %rdi
callq 0xea9f0
movq -0x78(%rbp), %rax
movq -0x70(%rbp), %rcx
movq %rcx, 0x48(%rax)
movq -0x68(%rbp), %rcx
movq %rcx, 0x50(%rax)
movq -0x60(%rbp), %rcx
movq %rcx, 0x58(%rax)
addq $0x80, %rsp
popq %rbp
retq
nop