// File: /workspace/github_cpp_makefile_star2_O1/atfrank[P]PCASA/lib/Trajectory.cpp
// Function: Trajectory::writeFrame(std::basic_ofstream<char, std::char_traits<char>>&, Trajectory*)
void Trajectory::writeFrame(std::ofstream &trjout, Trajectory *ftrjin){
  double *dbuffer;
  float *xbuffer;
  float *ybuffer;
  float *zbuffer;
  unsigned int i;
  int length;
  Molecule *mol;

  //crystal
  if (this->getQCrystal() > 0){
    double pbc[ftrjin->pb.size()];
    for(i=0; i< ftrjin->pb.size(); i++){
      pbc[i]=ftrjin->pb.at(i);
    }
    dbuffer=&pbc[0];
    length=sizeof(double)*ftrjin->pb.size();
    writeFortran(trjout, dbuffer, length);
  }

  if (this->getMolecule() == NULL){
    float x[ftrjin->x.size()];
    float y[ftrjin->y.size()];
    float z[ftrjin->z.size()];

    for(i=0; i< ftrjin->x.size(); i++){
      x[i]=ftrjin->x.at(i);
      y[i]=ftrjin->y.at(i);
      z[i]=ftrjin->z.at(i);
    } 

    length=sizeof(float)*ftrjin->x.size();

    xbuffer=&x[0];
    ybuffer=&y[0];
    zbuffer=&z[0];

    writeFortran(trjout, xbuffer, length);
    writeFortran(trjout, ybuffer, length);
    writeFortran(trjout, zbuffer, length);
  
  }
  else{
    mol=this->getMolecule();
    float x[mol->getNAtom()];
    float y[mol->getNAtom()];
    float z[mol->getNAtom()];

    for(i=0; i< mol->getNAtom(); i++){
      x[i]=mol->getAtom(i)->getX();
      y[i]=mol->getAtom(i)->getY();
      z[i]=mol->getAtom(i)->getZ();
    }

    length=sizeof(float)*mol->getNAtom();

    xbuffer=&x[0];
    ybuffer=&y[0];
    zbuffer=&z[0];

    writeFortran(trjout, xbuffer, length);
    writeFortran(trjout, ybuffer, length);
    writeFortran(trjout, zbuffer, length);

  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %r12
cmpl $0x0, 0x9c(%rdi)
jle 0x3970c
movq %rsp, %rbx
movq 0xf0(%r14), %rax
subq 0xe8(%r14), %rax
addq $0xf, %rax
andq $-0x10, %rax
movq %rsp, %rdx
subq %rax, %rdx
movq %rdx, %rsp
movq 0xe8(%r14), %rcx
movq 0xf0(%r14), %rsi
movq %rsi, %rax
subq %rcx, %rax
sarq $0x3, %rax
cmpq %rcx, %rsi
je 0x396f0
xorl %esi, %esi
movsd (%rcx,%rsi,8), %xmm0
movsd %xmm0, (%rdx,%rsi,8)
incq %rsi
movl %esi, %edi
cmpq %rdi, %rax
ja 0x396da
jmp 0x396f2
xorl %esi, %esi
movl %esi, -0x2c(%rbp)
shll $0x3, %eax
leaq -0x30(%rbp), %rcx
movl %eax, (%rcx)
movq %r12, %rdi
movq %r15, %rsi
callq 0x39f5e
movq %rbx, %rsp
movq %r12, -0x50(%rbp)
movq 0x28(%r12), %rbx
testq %rbx, %rbx
je 0x3983d
movq %r15, -0x48(%rbp)
movq %rbx, %rdi
callq 0x2577c
movq %rsp, -0x38(%rbp)
movl %eax, %eax
movq %rsp, %rcx
leaq 0xf(,%rax,4), %rax
andq $-0x10, %rax
subq %rax, %rcx
movq %rcx, -0x40(%rbp)
movq %rcx, %rsp
movq %rbx, %rdi
callq 0x2577c
movl %eax, %eax
movq %rsp, %r12
leaq 0xf(,%rax,4), %rax
andq $-0x10, %rax
subq %rax, %r12
movq %r12, %rsp
movq %rbx, %rdi
callq 0x2577c
movl %eax, %eax
movq %rsp, %r13
leaq 0xf(,%rax,4), %rax
andq $-0x10, %rax
subq %rax, %r13
movq %r13, %rsp
movl $0x0, -0x2c(%rbp)
movq %rbx, %rdi
callq 0x2577c
testl %eax, %eax
je 0x39828
leaq -0x2c(%rbp), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x24776
movq %rax, %rdi
callq 0x14d4e
xorps %xmm0, %xmm0
cvtsd2ss (%rax), %xmm0
movl -0x2c(%rbp), %eax
movq -0x40(%rbp), %rcx
movss %xmm0, (%rcx,%rax,4)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x24776
movq %rax, %rdi
callq 0x14d56
xorps %xmm0, %xmm0
cvtsd2ss (%rax), %xmm0
movl -0x2c(%rbp), %eax
movss %xmm0, (%r12,%rax,4)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x24776
movq %rax, %rdi
callq 0x14d5e
xorps %xmm0, %xmm0
cvtsd2ss (%rax), %xmm0
movl -0x2c(%rbp), %eax
movss %xmm0, (%r13,%rax,4)
leal 0x1(%rax), %r15d
movl %r15d, -0x2c(%rbp)
movq %rbx, %rdi
callq 0x2577c
cmpl %eax, %r15d
jb 0x397a2
movq %rbx, %rdi
callq 0x2577c
movq -0x48(%rbp), %r15
movq -0x40(%rbp), %r11
jmp 0x3990e
movq %rsp, %r10
movq 0x138(%r14), %rax
subq 0x130(%r14), %rax
addq $0xf, %rax
andq $-0x10, %rax
movq %rsp, %r11
subq %rax, %r11
movq %r11, %rsp
movq 0x148(%r14), %rdi
movq 0x150(%r14), %rdx
subq %rdi, %rdx
movq %rsp, %r12
leaq 0xf(%rdx), %rax
andq $-0x10, %rax
subq %rax, %r12
movq %r12, %rsp
movq 0x160(%r14), %r8
movq 0x168(%r14), %rcx
subq %r8, %rcx
movq %rsp, %r13
leaq 0xf(%rcx), %rax
andq $-0x10, %rax
subq %rax, %r13
movq %r13, %rsp
movq 0x130(%r14), %r9
movq 0x138(%r14), %rsi
movq %rsi, %rax
subq %r9, %rax
sarq $0x2, %rax
cmpq %r9, %rsi
je 0x39905
sarq $0x2, %rdx
sarq $0x2, %rcx
xorl %esi, %esi
movss (%r9,%rsi,4), %xmm0
movss %xmm0, (%r11,%rsi,4)
cmpq %rsi, %rdx
jbe 0x39970
movss (%rdi,%rsi,4), %xmm0
movss %xmm0, (%r12,%rsi,4)
cmpq %rsi, %rcx
jbe 0x39961
movss (%r8,%rsi,4), %xmm0
movss %xmm0, (%r13,%rsi,4)
incl %esi
cmpq %rsi, %rax
ja 0x398ca
jmp 0x39907
xorl %esi, %esi
movq %r10, -0x38(%rbp)
movl %esi, -0x2c(%rbp)
shll $0x2, %eax
leaq -0x30(%rbp), %rbx
movl %eax, (%rbx)
movq -0x50(%rbp), %r14
movq %r14, %rdi
movq %r15, %rsi
movq %r11, %rdx
movq %rbx, %rcx
callq 0x39fa0
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
movq %rbx, %rcx
callq 0x39fa0
movq %r14, %rdi
movq %r15, %rsi
movq %r13, %rdx
movq %rbx, %rcx
callq 0x39fa0
movq -0x38(%rbp), %rsp
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %esi, -0x2c(%rbp)
leaq 0x29be(%rip), %rdi      # 0x3c329
movq %rcx, %rdx
jmp 0x3997a
movl %esi, -0x2c(%rbp)
leaq 0x29af(%rip), %rdi      # 0x3c329
xorl %eax, %eax
callq 0x4440
nop