// File: Luthaf[P]zeopp/networkstorage.cc
// Function: ATOM_NETWORK::randomlyAdjustCoordsAndCell()
void ATOM_NETWORK::randomlyAdjustCoordsAndCell() {
  double shiftMagnitude = TOLERANCE;
  printf("NOTICE: attempting random vector shift of all atom coordinates by %e (and unit cell parameters by up to this amount) to overcome Voronoi volume check failure (this option can be disabled by not using the -allowAdjustCoordsAndCell flag)\n", shiftMagnitude);
  printf("NOTICE: original cell dimensions and angles: %e %e %e; %e %e %e\n", a, b, c, alpha, beta, gamma);
  make(
(((rand()*1.0/RAND_MAX)-0.5)*2.0*shiftMagnitude)+a,
(((rand()*1.0/RAND_MAX)-0.5)*2.0*shiftMagnitude)+b,
(((rand()*1.0/RAND_MAX)-0.5)*2.0*shiftMagnitude)+c,
(((rand()*1.0/RAND_MAX)-0.5)*2.0*shiftMagnitude)+alpha,
(((rand()*1.0/RAND_MAX)-0.5)*2.0*shiftMagnitude)+beta,
(((rand()*1.0/RAND_MAX)-0.5)*2.0*shiftMagnitude)+gamma
);
  printf("NOTICE: randomly adjusted cell dimensions and angles: %e %e %e; %e %e %e\n", a, b, c, alpha, beta, gamma);
  for(int at=0; at<numAtoms; at++) {
    //shift each Cartesian coord in some direction, by distance TOLERANCE
    Point smallShift = genRandomVec().scale(shiftMagnitude);
    Point resultOfShiftInABCNoPBC = xyz_to_abc(Point(
      atoms.at(at).x+smallShift[0],
      atoms.at(at).y+smallShift[1],
      atoms.at(at).z+smallShift[2]
    ));
//    Point resultOfShiftInABC = Point(trans_to_origuc(resultOfShiftInABCNoPBC[0]),trans_to_origuc(resultOfShiftInABCNoPBC[1]),trans_to_origuc(resultOfShiftInABCNoPBC[2]));
    Point resultOfShiftInABC = resultOfShiftInABCNoPBC;
    Point resultOfShiftInXYZ = abc_to_xyz(resultOfShiftInABC);
    //now write the new coords to the atmnet
//printf("DEBUG: atom %d was at %e %e %e, now at %e %e %e\n", at, atoms.at(at).x, atoms.at(at).y, atoms.at(at).z, resultOfShiftInXYZ[0], resultOfShiftInXYZ[1], resultOfShiftInXYZ[2]);
    atoms.at(at).x = resultOfShiftInXYZ[0];
    atoms.at(at).y = resultOfShiftInXYZ[1];
    atoms.at(at).z = resultOfShiftInXYZ[2];
    atoms.at(at).a_coord = resultOfShiftInABC[0];
    atoms.at(at).b_coord = resultOfShiftInABC[1];
    atoms.at(at).c_coord = resultOfShiftInABC[2];
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x160, %rsp            # imm = 0x160
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xc8(%rbp)
movsd 0x161dae(%rip), %xmm0   # 0x1f7860
movsd %xmm0, -0x10(%rbp)
movsd -0x10(%rbp), %xmm0
leaq 0x161e35(%rip), %rdi    # 0x1f78f8
movb $0x1, %al
callq 0x5070
movq -0xc8(%rbp), %rax
movsd 0x8(%rax), %xmm0
movsd 0x10(%rax), %xmm1
movsd 0x18(%rax), %xmm2
movsd 0x20(%rax), %xmm3
movsd 0x28(%rax), %xmm4
movsd 0x30(%rax), %xmm5
leaq 0x161eef(%rip), %rdi    # 0x1f79e5
movb $0x6, %al
callq 0x5070
callq 0x5190
movl %eax, %ecx
movq -0xc8(%rbp), %rax
cvtsi2sd %ecx, %xmm0
movsd 0x15c539(%rip), %xmm1   # 0x1f2050
mulsd %xmm1, %xmm0
movsd 0x160ae5(%rip), %xmm1   # 0x1f6608
divsd %xmm1, %xmm0
movsd 0x15c549(%rip), %xmm1   # 0x1f2078
subsd %xmm1, %xmm0
movsd 0x15c50d(%rip), %xmm1   # 0x1f2048
mulsd %xmm1, %xmm0
movsd -0x10(%rbp), %xmm2
movsd 0x8(%rax), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0xf0(%rbp)
callq 0x5190
movl %eax, %ecx
movq -0xc8(%rbp), %rax
cvtsi2sd %ecx, %xmm0
movsd 0x15c4dd(%rip), %xmm1   # 0x1f2050
mulsd %xmm1, %xmm0
movsd 0x160a89(%rip), %xmm1   # 0x1f6608
divsd %xmm1, %xmm0
movsd 0x15c4ed(%rip), %xmm1   # 0x1f2078
subsd %xmm1, %xmm0
movsd 0x15c4b1(%rip), %xmm1   # 0x1f2048
mulsd %xmm1, %xmm0
movsd -0x10(%rbp), %xmm2
movsd 0x10(%rax), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0xe8(%rbp)
callq 0x5190
movl %eax, %ecx
movq -0xc8(%rbp), %rax
cvtsi2sd %ecx, %xmm0
movsd 0x15c481(%rip), %xmm1   # 0x1f2050
mulsd %xmm1, %xmm0
movsd 0x160a2d(%rip), %xmm1   # 0x1f6608
divsd %xmm1, %xmm0
movsd 0x15c491(%rip), %xmm1   # 0x1f2078
subsd %xmm1, %xmm0
movsd 0x15c455(%rip), %xmm1   # 0x1f2048
mulsd %xmm1, %xmm0
movsd -0x10(%rbp), %xmm2
movsd 0x18(%rax), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0xe0(%rbp)
callq 0x5190
movl %eax, %ecx
movq -0xc8(%rbp), %rax
cvtsi2sd %ecx, %xmm0
movsd 0x15c425(%rip), %xmm1   # 0x1f2050
mulsd %xmm1, %xmm0
movsd 0x1609d1(%rip), %xmm1   # 0x1f6608
divsd %xmm1, %xmm0
movsd 0x15c435(%rip), %xmm1   # 0x1f2078
subsd %xmm1, %xmm0
movsd 0x15c3f9(%rip), %xmm1   # 0x1f2048
mulsd %xmm1, %xmm0
movsd -0x10(%rbp), %xmm2
movsd 0x20(%rax), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0xd8(%rbp)
callq 0x5190
movl %eax, %ecx
movq -0xc8(%rbp), %rax
cvtsi2sd %ecx, %xmm0
movsd 0x15c3c9(%rip), %xmm1   # 0x1f2050
mulsd %xmm1, %xmm0
movsd 0x160975(%rip), %xmm1   # 0x1f6608
divsd %xmm1, %xmm0
movsd 0x15c3d9(%rip), %xmm1   # 0x1f2078
subsd %xmm1, %xmm0
movsd 0x15c39d(%rip), %xmm1   # 0x1f2048
mulsd %xmm1, %xmm0
movsd -0x10(%rbp), %xmm2
movsd 0x28(%rax), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0xd0(%rbp)
callq 0x5190
movsd -0xf0(%rbp), %xmm0
movsd -0xe8(%rbp), %xmm1
movsd -0xe0(%rbp), %xmm2
movsd -0xd8(%rbp), %xmm3
movsd -0xd0(%rbp), %xmm4
movq -0xc8(%rbp), %rdi
cvtsi2sd %eax, %xmm5
movsd 0x15c347(%rip), %xmm6   # 0x1f2050
mulsd %xmm6, %xmm5
movsd 0x1608f3(%rip), %xmm6   # 0x1f6608
divsd %xmm6, %xmm5
movsd 0x15c357(%rip), %xmm6   # 0x1f2078
subsd %xmm6, %xmm5
movsd 0x15c31b(%rip), %xmm6   # 0x1f2048
mulsd %xmm6, %xmm5
movsd -0x10(%rbp), %xmm7
movsd 0x30(%rdi), %xmm6
mulsd %xmm7, %xmm5
addsd %xmm6, %xmm5
callq 0x960d0
movq -0xc8(%rbp), %rax
movsd 0x8(%rax), %xmm0
movsd 0x10(%rax), %xmm1
movsd 0x18(%rax), %xmm2
movsd 0x20(%rax), %xmm3
movsd 0x28(%rax), %xmm4
movsd 0x30(%rax), %xmm5
leaq 0x161cb2(%rip), %rdi    # 0x1f7a26
movb $0x6, %al
callq 0x5070
movl $0x0, -0x14(%rbp)
movq -0xc8(%rbp), %rcx
movl -0x14(%rbp), %eax
cmpl 0x110(%rcx), %eax
jge 0x960c4
leaq -0x48(%rbp), %rdi
callq 0x8d7c0
movsd -0x10(%rbp), %xmm0
leaq -0x30(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0xea000
movq -0xc8(%rbp), %rdi
addq $0x2f0, %rdi            # imm = 0x2F0
movslq -0x14(%rbp), %rsi
callq 0xf090
movsd (%rax), %xmm0
movsd %xmm0, -0x148(%rbp)
leaq -0x30(%rbp), %rdi
xorl %esi, %esi
callq 0xe9d70
movsd -0x148(%rbp), %xmm0
movq -0xc8(%rbp), %rdi
addsd (%rax), %xmm0
movsd %xmm0, -0x130(%rbp)
addq $0x2f0, %rdi            # imm = 0x2F0
movslq -0x14(%rbp), %rsi
callq 0xf090
movsd 0x8(%rax), %xmm0
movsd %xmm0, -0x140(%rbp)
leaq -0x30(%rbp), %rdi
movl $0x1, %esi
callq 0xe9d70
movsd -0x140(%rbp), %xmm0
movq -0xc8(%rbp), %rdi
addsd (%rax), %xmm0
movsd %xmm0, -0x128(%rbp)
addq $0x2f0, %rdi            # imm = 0x2F0
movslq -0x14(%rbp), %rsi
callq 0xf090
movsd 0x10(%rax), %xmm0
movsd %xmm0, -0x138(%rbp)
leaq -0x30(%rbp), %rdi
movl $0x2, %esi
callq 0xe9d70
movsd -0x138(%rbp), %xmm2
movsd -0x130(%rbp), %xmm0
movsd -0x128(%rbp), %xmm1
addsd (%rax), %xmm2
leaq -0x78(%rbp), %rdi
callq 0xe9c70
movq -0xc8(%rbp), %rsi
leaq -0x60(%rbp), %rdi
leaq -0x78(%rbp), %rax
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x10(%rsp)
callq 0x96150
movq -0xc8(%rbp), %rsi
movq -0x60(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x90(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0x88(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0x80(%rbp), %rax
movq %rax, -0xb0(%rbp)
leaq -0xa8(%rbp), %rdi
leaq -0xc0(%rbp), %rax
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x10(%rsp)
callq 0x961d0
leaq -0xa8(%rbp), %rdi
xorl %esi, %esi
callq 0xe9d70
movq -0xc8(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0x120(%rbp)
addq $0x2f0, %rdi            # imm = 0x2F0
movslq -0x14(%rbp), %rsi
callq 0xf090
movsd -0x120(%rbp), %xmm0
movsd %xmm0, (%rax)
leaq -0xa8(%rbp), %rdi
movl $0x1, %esi
callq 0xe9d70
movq -0xc8(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0x118(%rbp)
addq $0x2f0, %rdi            # imm = 0x2F0
movslq -0x14(%rbp), %rsi
callq 0xf090
movsd -0x118(%rbp), %xmm0
movsd %xmm0, 0x8(%rax)
leaq -0xa8(%rbp), %rdi
movl $0x2, %esi
callq 0xe9d70
movq -0xc8(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0x110(%rbp)
addq $0x2f0, %rdi            # imm = 0x2F0
movslq -0x14(%rbp), %rsi
callq 0xf090
movsd -0x110(%rbp), %xmm0
movsd %xmm0, 0x10(%rax)
leaq -0x90(%rbp), %rdi
xorl %esi, %esi
callq 0xe9d70
movq -0xc8(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0x108(%rbp)
addq $0x2f0, %rdi            # imm = 0x2F0
movslq -0x14(%rbp), %rsi
callq 0xf090
movsd -0x108(%rbp), %xmm0
movsd %xmm0, 0x18(%rax)
leaq -0x90(%rbp), %rdi
movl $0x1, %esi
callq 0xe9d70
movq -0xc8(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0x100(%rbp)
addq $0x2f0, %rdi            # imm = 0x2F0
movslq -0x14(%rbp), %rsi
callq 0xf090
movsd -0x100(%rbp), %xmm0
movsd %xmm0, 0x20(%rax)
leaq -0x90(%rbp), %rdi
movl $0x2, %esi
callq 0xe9d70
movq -0xc8(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0xf8(%rbp)
addq $0x2f0, %rdi            # imm = 0x2F0
movslq -0x14(%rbp), %rsi
callq 0xf090
movsd -0xf8(%rbp), %xmm0
movsd %xmm0, 0x28(%rax)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x95d82
addq $0x160, %rsp            # imm = 0x160
popq %rbp
retq
nopl (%rax)