// File: /workspace/github_cpp_makefile_star2_O1/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 %r12
pushq %rbx
subq $0x10, %rsp
movq %rdi, %rbx
movq 0xb4e8c0(%rdi), %rax
movl 0x320c(%rax), %r14d
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpq %rcx, %r14
je 0x3b30
movsd 0x3218(%rax), %xmm0
movsd %xmm0, -0x28(%rbp)
cmpl $-0x1, 0x3208(%rax)
je 0x3964
movq 0x769d(%rip), %rdi      # 0xaff0
leaq 0x48f5(%rip), %rsi      # 0x824f
movl $0x3e, %edx
callq 0x21f0
movl %r14d, %r15d
imull %r14d, %r15d
movl %r15d, %esi
imull %r14d, %esi
movq 0xb4e8c0(%rbx), %rax
movl %esi, 0x3208(%rax)
movq %rbx, %rdi
callq 0x3230
cmpl $0x2, %r14d
movsd -0x28(%rbp), %xmm8
jl 0x3b30
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
divsd %xmm0, %xmm8
movsd 0x4664(%rip), %xmm2     # 0x8010
movapd %xmm8, %xmm0
mulsd %xmm2, %xmm0
movsd 0x4663(%rip), %xmm1     # 0x8020
mulsd %xmm8, %xmm1
mulsd 0x464e(%rip), %xmm0     # 0x8018
divsd %xmm2, %xmm1
movl %r14d, %eax
shrl $0x1f, %eax
addl %r14d, %eax
sarl %eax
movsd 0x4637(%rip), %xmm2     # 0x8018
mulsd %xmm8, %xmm2
movapd %xmm0, %xmm3
divsd 0x4636(%rip), %xmm3     # 0x8028
movl %r15d, %esi
imulq $0x10e0, %rsi, %rcx     # imm = 0x10E0
imulq $0x870, %r14, %rdx      # imm = 0x870
imulq $0x870, %rsi, %rsi      # imm = 0x870
addq $0x18, %rsi
xorl %edi, %edi
movl $0x18, %r8d
xorl %r9d, %r9d
xorps %xmm4, %xmm4
cvtsi2sd %edi, %xmm4
mulsd %xmm1, %xmm4
movq 0xb4e8b8(%rbx), %r10
addq %r8, %r10
xorl %r11d, %r11d
xorps %xmm5, %xmm5
cvtsi2sd %r11d, %xmm5
movl %r11d, %r15d
andl $0x1, %r15d
xorps %xmm6, %xmm6
cvtsi2sd %r15d, %xmm6
mulsd %xmm2, %xmm6
mulsd %xmm0, %xmm5
movq %r10, %r15
xorl %r12d, %r12d
xorps %xmm7, %xmm7
cvtsi2sd %r12d, %xmm7
mulsd %xmm8, %xmm7
addsd %xmm6, %xmm7
movsd %xmm7, -0x10(%r15)
movsd %xmm5, -0x8(%r15)
movsd %xmm4, (%r15)
incq %r12
addq $0x870, %r15            # imm = 0x870
cmpq %r12, %r14
jne 0x3a56
incq %r11
addq %rdx, %r10
cmpq %r14, %r11
jne 0x3a31
movl %edi, %r10d
orl $0x1, %r10d
xorps %xmm4, %xmm4
cvtsi2sd %r10d, %xmm4
mulsd %xmm1, %xmm4
movq 0xb4e8b8(%rbx), %r10
addq %rsi, %r10
xorl %r11d, %r11d
xorps %xmm5, %xmm5
cvtsi2sd %r11d, %xmm5
movl %r11d, %r15d
notl %r15d
andl $0x1, %r15d
xorps %xmm6, %xmm6
cvtsi2sd %r15d, %xmm6
mulsd %xmm2, %xmm6
mulsd %xmm0, %xmm5
addsd %xmm3, %xmm5
movq %r10, %r15
xorl %r12d, %r12d
xorps %xmm7, %xmm7
cvtsi2sd %r12d, %xmm7
mulsd %xmm8, %xmm7
addsd %xmm6, %xmm7
movsd %xmm7, -0x10(%r15)
movsd %xmm5, -0x8(%r15)
movsd %xmm4, (%r15)
incq %r12
addq $0x870, %r15            # imm = 0x870
cmpq %r12, %r14
jne 0x3ade
incq %r11
addq %rdx, %r10
cmpq %r14, %r11
jne 0x3ab2
addq $0x2, %rdi
incl %r9d
addq %rcx, %r8
addq %rcx, %rsi
cmpl %eax, %r9d
jne 0x3a19
movq 0xb4e8c0(%rbx), %rbx
cmpl $0x0, 0x3214(%rbx)
jns 0x3b6d
movsd 0x3218(%rbx), %xmm0
divsd 0x3250(%rbx), %xmm0
callq 0x2300
cvttsd2si %xmm0, %eax
cmpl $0x6, %eax
movl $0x5, %ecx
cmovgel %eax, %ecx
addl $-0x2, %ecx
movl %ecx, 0x3214(%rbx)
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq