// File: /workspace/github_cpp_makefile_star2_O2/WolfgangLechner[P]StructureAnalysis/molecular_system.cpp
// Function: CMolecularSystem::createHCP()
void CMolecularSystem::createHCP()
{
  double a,c,h;
  int bu,t;
  bu = this->parameter->baseunit;

  a = this->parameter->boxx/(double(bu));
  c = a*sqrt(3.0)/2.0;
  h = a*sqrt(2.0)/sqrt(3.0);
  if (bu != -1)
  {
    if (parameter->nop != -1) {cerr << "how comes that numberofparticles is already set in createHCP?\n";}
    this->parameter->nop = bu*bu*bu;
    this->initializeMolecules(bu*bu*bu);


    int jz = 0;
    for (int tz=0; tz < bu/2 ; tz++)
    {
      for (int jy=0; jy < bu ; jy++)
      {
        for (int jx=0; jx < bu ; jx++)
        {
          t  = bu*bu*jz + bu*jy + jx;
          this->molecules[t].posx = double(jx)*a + a/2.0*(jy % 2);
          this->molecules[t].posy = double(jy)*c;
          this->molecules[t].posz = double(jz)*h;
        }
      }
      jz += 1;

      for (int jy=0; jy < bu ; jy++)
      {
        for (int jx=0; jx < bu ; jx++)
        {
          t  = bu*bu*jz + bu*jy + jx;
          this->molecules[t].posx = double(jx)*a + a/2.0*((jy+1) % 2);
          this->molecules[t].posy = double(jy)*c + c/3.0;;
          this->molecules[t].posz = double(jz)*h;
        }
      }
      jz += 1;
    }
  }
  setNumberOfCells();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
movq 0xb4e8c0(%rdi), %rax
movslq 0x320c(%rax), %r15
cmpq $-0x1, %r15
je 0x3822
movl %r15d, %r14d
movsd 0x3218(%rax), %xmm1
cvtsi2sd %r15d, %xmm0
divsd %xmm0, %xmm1
movsd 0x39e4(%rip), %xmm2     # 0x7010
movapd %xmm1, %xmm0
mulsd %xmm2, %xmm0
mulsd 0x39dc(%rip), %xmm0     # 0x7018
movsd %xmm0, -0x38(%rbp)
movsd 0x39d7(%rip), %xmm0     # 0x7020
movsd %xmm1, -0x40(%rbp)
mulsd %xmm1, %xmm0
cmpl $-0x1, 0x3208(%rax)
je 0x3687
movq 0x698e(%rip), %rdi      # 0x9ff0
leaq 0x3be6(%rip), %rsi      # 0x724f
movsd %xmm0, -0x30(%rbp)
callq 0x21b0
movsd 0x3995(%rip), %xmm2     # 0x7010
movsd -0x30(%rbp), %xmm0
movq 0xb4e8c0(%rbx), %rax
divsd %xmm2, %xmm0
movsd %xmm0, -0x30(%rbp)
movl %r14d, %r12d
imull %r12d, %r12d
movl %r12d, %esi
imull %r15d, %esi
movl %esi, 0x3208(%rax)
movq %rbx, %rdi
callq 0x2faa
pushq $0x2
popq %rcx
movl %r14d, %eax
cltd
idivl %ecx
movsd 0x395b(%rip), %xmm0     # 0x7018
movsd -0x38(%rbp), %xmm7
movapd %xmm7, %xmm1
divsd 0x395a(%rip), %xmm1     # 0x7028
movsd -0x40(%rbp), %xmm6
mulsd %xmm6, %xmm0
xorl %ecx, %ecx
testl %r15d, %r15d
movl $0x0, %edx
cmovgl %r15d, %edx
testl %eax, %eax
cmovlel %ecx, %eax
imulq $0x10e0, %r12, %rsi     # imm = 0x10E0
imulq $0x870, %r15, %rdi      # imm = 0x870
imulq $0x870, %r12, %r8       # imm = 0x870
addq $0x18, %r8
pushq $0x18
popq %r9
xorl %r10d, %r10d
movsd -0x30(%rbp), %xmm8
cmpl %eax, %r10d
je 0x3822
cvtsi2sd %ecx, %xmm2
mulsd %xmm8, %xmm2
movq %r9, %r11
xorl %r15d, %r15d
cmpq %rdx, %r15
je 0x378d
cvtsi2sd %r15d, %xmm3
movl %r15d, %r12d
andl $0x1, %r12d
cvtsi2sd %r12d, %xmm4
mulsd %xmm0, %xmm4
mulsd %xmm7, %xmm3
movq 0xb4e8b8(%rbx), %r12
addq %r11, %r12
xorl %r13d, %r13d
cmpq %r13, %r14
je 0x3785
cvtsi2sd %r13d, %xmm5
mulsd %xmm6, %xmm5
addsd %xmm4, %xmm5
movsd %xmm5, -0x10(%r12)
movsd %xmm3, -0x8(%r12)
movsd %xmm2, (%r12)
incq %r13
addq $0x870, %r12            # imm = 0x870
jmp 0x3753
incq %r15
addq %rdi, %r11
jmp 0x3728
movl %ecx, %r11d
orl $0x1, %r11d
cvtsi2sd %r11d, %xmm2
mulsd %xmm8, %xmm2
movq %r8, %r11
xorl %r15d, %r15d
cmpq %rdx, %r15
je 0x3810
cvtsi2sd %r15d, %xmm3
movl %r15d, %r12d
notl %r12d
andl $0x1, %r12d
cvtsi2sd %r12d, %xmm4
mulsd %xmm0, %xmm4
mulsd %xmm7, %xmm3
addsd %xmm1, %xmm3
movq 0xb4e8b8(%rbx), %r12
addq %r11, %r12
xorl %r13d, %r13d
cmpq %r13, %r14
je 0x3808
cvtsi2sd %r13d, %xmm5
mulsd %xmm6, %xmm5
addsd %xmm4, %xmm5
movsd %xmm5, -0x10(%r12)
movsd %xmm3, -0x8(%r12)
movsd %xmm2, (%r12)
incq %r13
addq $0x870, %r12            # imm = 0x870
jmp 0x37d6
incq %r15
addq %rdi, %r11
jmp 0x37a4
addq $0x2, %rcx
incl %r10d
addq %rsi, %r9
addq %rsi, %r8
jmp 0x3710
movq %rbx, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3b2a