// File: /workspace/github_cpp_makefile_star2_O3/Luthaf[P]zeopp/networkio.cc
// Function: writeToMOPAC(char*, ATOM_NETWORK*, bool)
bool writeToMOPAC(char *filename, ATOM_NETWORK *cell, bool is_supercell){
  int num_cells = SUPERCELL_SIZE; //defined in networkio.h
  if(!is_supercell) num_cells = 1;
  fstream output;
  output.open(filename, fstream::out);
  if(!output.is_open()){
    cout << "Error: Failed to open .mop output file " << filename << endl;
    //cout << "Exiting ..." << "\n";
    //exit(1);
    return false;
  }
  else{
    cout << "Writing atom network information to " << filename << "\n";

    //Write two empty lines by default
    output << "\n" << "\n";

/*
    // Write information about the atoms
    vector<ATOM>::iterator atomIter = cell->atoms.begin();
    while(atomIter != cell->atoms.end()){
      output << atomIter->type << "  " << atomIter->x << " +1 "
             << atomIter->y << " +1 " << atomIter->z << " +1\n";
      atomIter++;
    }
*/
    for(int i=0; i<cell->numAtoms; i++) {
      //first, determine all the supercell images of this atom as required
      for(int a=0; a<num_cells; a++) {
        for(int b=0; b<num_cells; b++) {
          for(int c=0; c<num_cells; c++) {
            ATOM atom = cell->atoms.at(i);
            atom.a_coord = trans_to_origuc(atom.a_coord)+a;
            atom.b_coord = trans_to_origuc(atom.b_coord)+b;
            atom.c_coord = trans_to_origuc(atom.c_coord)+c;
            Point p = cell->abc_to_xyz(atom.a_coord, atom.b_coord, atom.c_coord);
            output << atom.type << "  " << p[0] << " +1 "
             << p[1] << " +1 " << p[2] << " +1\n";
          }
        }
      }
    }

    //Write unit cell box information
    output << "Tv " << cell->v_a.x*num_cells << " +1 ";
    if(cell->v_a.y==0.0) { output << " 0.0 0 "; } else { output << cell->v_a.y*num_cells << " +1 ";};
    if(cell->v_a.z==0.0) { output << " 0.0 0 \n"; } else { output << cell->v_a.z*num_cells << " +1 \n";};

    output << "Tv ";
    if(cell->v_b.x==0.0) { output << " 0.0 0 "; } else { output << cell->v_b.x*num_cells << " +1 ";};
    output << cell->v_b.y*num_cells << " +1 ";
    if(cell->v_b.z==0.0) { output << " 0.0 0 \n"; } else { output << cell->v_b.z*num_cells << " +1 \n";};

    output << "Tv ";
    if(cell->v_c.x==0.0) { output << " 0.0 0 "; } else { output << cell->v_c.x*num_cells << " +1 ";};
    if(cell->v_c.y==0.0) { output << " 0.0 0 "; } else { output << cell->v_c.y*num_cells << " +1 ";};
    output << cell->v_c.z*num_cells << " +1 \n\n";

  }
  output.close();
  return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2f8, %rsp            # imm = 0x2F8
movl %edx, 0x8(%rsp)
movq %rsi, 0x10(%rsp)
movq %rdi, %rbx
leaq 0xd0(%rsp), %r15
movq %r15, %rdi
callq 0x4520
movq %r15, %rdi
movq %rbx, %rsi
movl $0x10, %edx
callq 0x43d0
leaq 0x150(%rsp), %rdi
callq 0x4120
movl %eax, %ebp
testb %al, %al
je 0x2ec2b
movq 0x1663ca(%rip), %r15    # 0x194fc0
leaq 0x11f7cd(%rip), %rsi    # 0x14e3ca
movl $0x24, %edx
movq %r15, %rdi
callq 0x44e0
testq %rbx, %rbx
je 0x2ec6e
movq %rbx, %rdi
callq 0x41e0
movq 0x1663a2(%rip), %rdi    # 0x194fc0
movq %rbx, %rsi
movq %rax, %rdx
callq 0x44e0
jmp 0x2ec86
movq 0x16638e(%rip), %r14    # 0x194fc0
leaq 0x11fbee(%rip), %rsi    # 0x14e827
movl $0x27, %edx
movq %r14, %rdi
callq 0x44e0
testq %rbx, %rbx
je 0x2f027
movq %rbx, %rdi
callq 0x41e0
movq 0x166362(%rip), %rdi    # 0x194fc0
movq %rbx, %rsi
movq %rax, %rdx
callq 0x44e0
jmp 0x2f03f
movq (%r15), %rax
movq -0x18(%rax), %rax
leaq (%r15,%rax), %rdi
movl 0x20(%r15,%rax), %esi
orl $0x1, %esi
callq 0x4710
movq 0x166333(%rip), %rdi    # 0x194fc0
leaq 0x12498a(%rip), %rsi    # 0x15361e
movl $0x1, %edx
callq 0x44e0
leaq 0xe0(%rsp), %rdi
leaq 0x124971(%rip), %rsi    # 0x15361e
movl $0x1, %edx
callq 0x44e0
leaq 0x124960(%rip), %rsi    # 0x15361e
movl $0x1, %edx
leaq 0xe0(%rsp), %rdi
callq 0x44e0
movb %bpl, 0x7(%rsp)
incl 0x8(%rsp)
movq 0x10(%rsp), %rax
cmpl $0x0, 0x110(%rax)
jle 0x2ef9f
leaq 0x70(%rsp), %r13
xorl %ecx, %ecx
leaq 0x2e0(%rsp), %r15
imulq $0x98, %rcx, %r12
xorl %eax, %eax
movl %eax, 0x18(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x20(%rsp)
xorl %eax, %eax
movl %eax, 0x1c(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x28(%rsp)
xorl %ebx, %ebx
movq 0x10(%rsp), %rax
movq 0x2f0(%rax), %rbp
movq 0x2f8(%rax), %rdx
subq %rbp, %rdx
sarq $0x3, %rdx
movabsq $-0x79435e50d79435e5, %rax # imm = 0x86BCA1AF286BCA1B
imulq %rax, %rdx
movq %rcx, %r14
cmpq %rcx, %rdx
jbe 0x2f2f2
movupd (%rbp,%r12), %xmm0
movupd 0x10(%rbp,%r12), %xmm1
movupd 0x20(%rbp,%r12), %xmm2
movups 0x30(%rbp,%r12), %xmm3
movaps %xmm3, 0x60(%rsp)
movapd %xmm2, 0x50(%rsp)
movapd %xmm1, 0x40(%rsp)
movapd %xmm0, 0x30(%rsp)
leaq 0x80(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0x40(%rbp,%r12), %rsi
movq 0x48(%rbp,%r12), %rdx
addq %rsi, %rdx
movq %r13, %rdi
callq 0xf3ce
addq %r12, %rbp
leaq 0xa0(%rsp), %rax
movq %rax, 0x90(%rsp)
movq 0x60(%rbp), %rsi
movq 0x68(%rbp), %rdx
addq %rsi, %rdx
leaq 0x90(%rsp), %rdi
callq 0xf3ce
movb 0x90(%rbp), %al
movb %al, 0x50(%r13)
movups 0x80(%rbp), %xmm0
movups %xmm0, 0x40(%r13)
movsd 0x48(%rsp), %xmm0
callq 0x839b6
addsd 0x20(%rsp), %xmm0
movsd %xmm0, 0x48(%rsp)
movsd 0x50(%rsp), %xmm0
callq 0x839b6
addsd 0x28(%rsp), %xmm0
movsd %xmm0, 0x50(%rsp)
movsd 0x58(%rsp), %xmm0
callq 0x839b6
movapd %xmm0, %xmm2
xorps %xmm0, %xmm0
cvtsi2sd %ebx, %xmm0
addsd %xmm0, %xmm2
movsd %xmm2, 0x58(%rsp)
movsd 0x48(%rsp), %xmm0
movsd 0x50(%rsp), %xmm1
movq %r15, %rdi
movq 0x10(%rsp), %rsi
callq 0x52d94
movq 0x70(%rsp), %rsi
movq 0x78(%rsp), %rdx
leaq 0xe0(%rsp), %rdi
callq 0x44e0
movq %rax, %rbp
movl $0x2, %edx
movq %rax, %rdi
leaq 0x11e65d(%rip), %rsi    # 0x14d4df
callq 0x44e0
movq %r15, %rdi
xorl %esi, %esi
callq 0x83f9a
movsd (%rax), %xmm0
movq %rbp, %rdi
callq 0x46b0
movq %rax, %rbp
movl $0x4, %edx
movq %rax, %rdi
leaq 0x11f9a0(%rip), %rsi    # 0x14e84f
callq 0x44e0
movq %r15, %rdi
movl $0x1, %esi
callq 0x83f9a
movsd (%rax), %xmm0
movq %rbp, %rdi
callq 0x46b0
movq %rax, %rbp
movl $0x4, %edx
movq %rax, %rdi
leaq 0x11f970(%rip), %rsi    # 0x14e84f
callq 0x44e0
movq %r15, %rdi
movl $0x2, %esi
callq 0x83f9a
movsd (%rax), %xmm0
movq %rbp, %rdi
callq 0x46b0
movl $0x4, %edx
movq %rax, %rdi
leaq 0x11f948(%rip), %rsi    # 0x14e854
callq 0x44e0
movq 0x90(%rsp), %rdi
leaq 0xa0(%rsp), %rax
cmpq %rax, %rdi
je 0x2ef36
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x4470
movq 0x70(%rsp), %rdi
leaq 0x80(%rsp), %rax
cmpq %rax, %rdi
je 0x2ef58
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x4470
incl %ebx
cmpl %ebx, 0x8(%rsp)
movq %r14, %rcx
jne 0x2ed29
movl 0x1c(%rsp), %eax
incl %eax
cmpl 0x8(%rsp), %eax
jne 0x2ed16
movl 0x18(%rsp), %eax
incl %eax
cmpl 0x8(%rsp), %eax
jne 0x2ed03
incq %rcx
movq 0x10(%rsp), %rax
movslq 0x110(%rax), %rax
cmpq %rax, %rcx
jl 0x2ecfa
leaq 0x11f8b3(%rip), %rsi    # 0x14e859
movl $0x3, %edx
leaq 0xe0(%rsp), %rdi
callq 0x44e0
movb 0x7(%rsp), %bpl
cvtsi2sdl 0x8(%rsp), %xmm1
movq 0x10(%rsp), %rax
movsd 0x38(%rax), %xmm0
movsd %xmm1, 0x8(%rsp)
mulsd %xmm1, %xmm0
leaq 0xe0(%rsp), %rdi
callq 0x46b0
leaq 0x11f864(%rip), %rbx    # 0x14e84f
movl $0x4, %edx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x44e0
movq 0x10(%rsp), %rax
movsd 0x40(%rax), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x2f06f
jp 0x2f06f
movl $0x7, %edx
leaq 0x11f840(%rip), %rbx    # 0x14e85d
leaq 0xe0(%rsp), %rdi
jmp 0x2f08a
movq (%r14), %rax
movq -0x18(%rax), %rax
leaq (%r14,%rax), %rdi
movl 0x20(%r14,%rax), %esi
orl $0x1, %esi
callq 0x4710
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x4420
movsbl %al, %esi
movq 0x165f63(%rip), %rdi    # 0x194fc0
callq 0x4040
movq %rax, %rdi
callq 0x42c0
jmp 0x2f2d1
mulsd 0x8(%rsp), %xmm0
leaq 0xe0(%rsp), %rdi
callq 0x46b0
movq %rax, %rdi
movl $0x4, %edx
movq %rbx, %rsi
callq 0x44e0
movq 0x10(%rsp), %rax
movsd 0x48(%rax), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x2f0be
jp 0x2f0be
movl $0x8, %edx
leaq 0x11f7b1(%rip), %rsi    # 0x14e865
leaq 0xe0(%rsp), %rdi
jmp 0x2f0e0
mulsd 0x8(%rsp), %xmm0
leaq 0xe0(%rsp), %rdi
callq 0x46b0
movq %rax, %rdi
movl $0x5, %edx
leaq 0x11f78e(%rip), %rsi    # 0x14e86e
callq 0x44e0
leaq 0x11f76d(%rip), %rsi    # 0x14e859
movl $0x3, %edx
leaq 0xe0(%rsp), %rdi
callq 0x44e0
movq 0x10(%rsp), %rax
movsd 0x50(%rax), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x2f12a
jp 0x2f12a
movl $0x7, %edx
leaq 0x11f73d(%rip), %rsi    # 0x14e85d
leaq 0xe0(%rsp), %rdi
jmp 0x2f14c
mulsd 0x8(%rsp), %xmm0
leaq 0xe0(%rsp), %rdi
callq 0x46b0
movq %rax, %rdi
movl $0x4, %edx
leaq 0x11f703(%rip), %rsi    # 0x14e84f
callq 0x44e0
movq 0x10(%rsp), %rax
movsd 0x58(%rax), %xmm0
mulsd 0x8(%rsp), %xmm0
leaq 0xe0(%rsp), %rdi
callq 0x46b0
leaq 0x11f6da(%rip), %rbx    # 0x14e84f
movl $0x4, %edx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x44e0
movq 0x10(%rsp), %rax
movsd 0x60(%rax), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x2f1b1
jp 0x2f1b1
movl $0x8, %edx
leaq 0x11f6be(%rip), %rsi    # 0x14e865
leaq 0xe0(%rsp), %rdi
jmp 0x2f1d3
mulsd 0x8(%rsp), %xmm0
leaq 0xe0(%rsp), %rdi
callq 0x46b0
movq %rax, %rdi
movl $0x5, %edx
leaq 0x11f69b(%rip), %rsi    # 0x14e86e
callq 0x44e0
leaq 0x11f67a(%rip), %rsi    # 0x14e859
movl $0x3, %edx
leaq 0xe0(%rsp), %rdi
callq 0x44e0
movq 0x10(%rsp), %rax
movsd 0x68(%rax), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x2f21d
jp 0x2f21d
movl $0x7, %edx
leaq 0x11f64a(%rip), %rbx    # 0x14e85d
leaq 0xe0(%rsp), %rdi
jmp 0x2f238
mulsd 0x8(%rsp), %xmm0
leaq 0xe0(%rsp), %rdi
callq 0x46b0
movq %rax, %rdi
movl $0x4, %edx
movq %rbx, %rsi
callq 0x44e0
movq 0x10(%rsp), %rax
movsd 0x70(%rax), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x2f26c
jp 0x2f26c
movl $0x7, %edx
leaq 0x11f5fb(%rip), %rsi    # 0x14e85d
leaq 0xe0(%rsp), %rdi
jmp 0x2f28e
mulsd 0x8(%rsp), %xmm0
leaq 0xe0(%rsp), %rdi
callq 0x46b0
movq %rax, %rdi
movl $0x4, %edx
leaq 0x11f5c1(%rip), %rsi    # 0x14e84f
callq 0x44e0
movsd 0x8(%rsp), %xmm0
movq 0x10(%rsp), %rax
mulsd 0x78(%rax), %xmm0
leaq 0xe0(%rsp), %rdi
callq 0x46b0
leaq 0x11f5bd(%rip), %rsi    # 0x14e874
movl $0x6, %edx
movq %rax, %rdi
callq 0x44e0
leaq 0xd0(%rsp), %rdi
callq 0x4090
leaq 0xd0(%rsp), %rdi
callq 0x4110
movl %ebp, %eax
addq $0x2f8, %rsp            # imm = 0x2F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x11e3fc(%rip), %rdi    # 0x14d6f5
movq %r14, %rsi
xorl %eax, %eax
callq 0x4630
jmp 0x2f307
jmp 0x2f307
movq %rax, %rbx
jmp 0x2f35d
movq %rax, %rbx
jmp 0x2f33b
jmp 0x2f313
movq %rax, %rbx
movq 0x90(%rsp), %rdi
leaq 0xa0(%rsp), %rax
cmpq %rax, %rdi
je 0x2f33b
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x4470
movq 0x70(%rsp), %rdi
leaq 0x80(%rsp), %rax
cmpq %rax, %rdi
je 0x2f35d
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x4470
leaq 0xd0(%rsp), %rdi
callq 0x4110
movq %rbx, %rdi
callq 0x4780