// File: /workspace/github_cpp_makefile_star2_O2/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 $0x48, %rsp
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r13
cmpl $0x0, 0x9c(%rdi)
movq %rsi, -0x50(%rbp)
jle 0x2b332
movq %rsp, -0x38(%rbp)
leaq 0xe8(%rbx), %r15
movq 0xf0(%rbx), %rax
subq 0xe8(%rbx), %rax
addq $0xf, %rax
andq $-0x10, %rax
movq %rsp, %r14
subq %rax, %r14
movq %r14, %rsp
xorl %eax, %eax
movl %eax, %r12d
movq 0xf0(%rbx), %rax
subq 0xe8(%rbx), %rax
sarq $0x3, %rax
cmpq %r12, %rax
jbe 0x2b313
movq %r15, %rdi
movq %r12, %rsi
callq 0xc916
movsd (%rax), %xmm0
movsd %xmm0, (%r14,%r12,8)
leal 0x1(%r12), %eax
jmp 0x2b2dd
shll $0x3, %eax
leaq -0x3c(%rbp), %rcx
movl %eax, (%rcx)
movq %r13, %rdi
movq -0x50(%rbp), %r15
movq %r15, %rsi
movq %r14, %rdx
callq 0x2bad0
movq -0x38(%rbp), %rsp
movq %r13, -0x58(%rbp)
movq 0x28(%r13), %r14
testq %r14, %r14
je 0x2b48a
movq %r14, %rdi
callq 0x1b6a8
movq %rsp, -0x48(%rbp)
movl %eax, %eax
movq %rsp, %rcx
leaq 0xf(,%rax,4), %rax
andq $-0x10, %rax
subq %rax, %rcx
movq %rcx, -0x38(%rbp)
movq %rcx, %rsp
movq %r14, %rdi
callq 0x1b6a8
movl %eax, %eax
movq %rsp, %r12
leaq 0xf(,%rax,4), %rax
andq $-0x10, %rax
subq %rax, %r12
movq %r12, %rsp
movq %r14, %rdi
callq 0x1b6a8
movl %eax, %eax
movq %rsp, %r13
leaq 0xf(,%rax,4), %rax
andq $-0x10, %rax
subq %rax, %r13
movq %r13, %rsp
xorl %r15d, %r15d
leaq -0x2c(%rbp), %rbx
movl %r15d, -0x2c(%rbp)
movq %r14, %rdi
callq 0x1b6a8
cmpl %eax, %r15d
jae 0x2b42a
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1ab66
movq %rax, %rdi
callq 0xec26
cvtsd2ss (%rax), %xmm0
movl -0x2c(%rbp), %eax
movq -0x38(%rbp), %rcx
movss %xmm0, (%rcx,%rax,4)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1ab66
movq %rax, %rdi
callq 0xec2e
cvtsd2ss (%rax), %xmm0
movl -0x2c(%rbp), %eax
movss %xmm0, (%r12,%rax,4)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1ab66
movq %rax, %rdi
callq 0xec36
cvtsd2ss (%rax), %xmm0
movl -0x2c(%rbp), %eax
movss %xmm0, (%r13,%rax,4)
leal 0x1(%rax), %r15d
jmp 0x2b3af
movq %r14, %rdi
callq 0x1b6a8
movq -0x50(%rbp), %r15
shll $0x2, %eax
leaq -0x3c(%rbp), %rbx
movl %eax, (%rbx)
movq -0x58(%rbp), %r14
movq %r14, %rdi
movq %r15, %rsi
movq -0x38(%rbp), %rdx
movq %rbx, %rcx
callq 0x2bb1a
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
movq %rbx, %rcx
callq 0x2bb1a
movq %r14, %rdi
movq %r15, %rsi
movq %r13, %rdx
movq %rbx, %rcx
callq 0x2bb1a
movq -0x48(%rbp), %rsp
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rsp, -0x48(%rbp)
leaq 0x130(%rbx), %rax
movq %rax, -0x70(%rbp)
movq 0x138(%rbx), %rax
subq 0x130(%rbx), %rax
addq $0xf, %rax
andq $-0x10, %rax
movq %rsp, %rcx
subq %rax, %rcx
movq %rcx, -0x38(%rbp)
movq %rcx, %rsp
leaq 0x148(%rbx), %rax
movq %rax, -0x68(%rbp)
movq 0x150(%rbx), %rax
subq 0x148(%rbx), %rax
addq $0xf, %rax
andq $-0x10, %rax
movq %rsp, %r12
subq %rax, %r12
movq %r12, %rsp
leaq 0x160(%rbx), %rax
movq %rax, -0x60(%rbp)
movq 0x168(%rbx), %rax
subq 0x160(%rbx), %rax
addq $0xf, %rax
andq $-0x10, %rax
movq %rsp, %r13
subq %rax, %r13
movq %r13, %rsp
xorl %eax, %eax
movl %eax, %r14d
movq 0x138(%rbx), %rax
subq 0x130(%rbx), %rax
sarq $0x2, %rax
cmpq %r14, %rax
jbe 0x2b436
movq -0x70(%rbp), %rdi
movq %r14, %rsi
callq 0x2bc2a
movss (%rax), %xmm0
movq -0x38(%rbp), %rax
movss %xmm0, (%rax,%r14,4)
movq -0x68(%rbp), %rdi
movq %r14, %rsi
callq 0x2bc2a
movss (%rax), %xmm0
movss %xmm0, (%r12,%r14,4)
movq -0x60(%rbp), %rdi
movq %r14, %rsi
callq 0x2bc2a
movss (%rax), %xmm0
movss %xmm0, (%r13,%r14,4)
leal 0x1(%r14), %eax
jmp 0x2b512
nop