// File: /workspace/github_cpp_makefile_star2_O2/Luthaf[P]zeopp/networkio.cc
// Function: writeToCSSR(char*, ATOM_NETWORK*)
bool writeToCSSR(char *filename, ATOM_NETWORK *cell){
  fstream output;
  output.open(filename, fstream::out);
  if(!output.is_open()){
    cerr << "Error: Failed to open .cssr output file " << filename << endl;
	//cerr << "Exiting ..." << "\n";
    //exit(1);
    return false;
  }
  else{
    cout   << "Writing atom network information to " << filename << "\n";

    // Write information about the unit cell
    output << "\t\t\t\t" << cell->a << "  " << cell->b << "  " << cell->c << "\n";
    output << "\t\t" << cell->alpha<<"  "<< cell->beta <<"  " << cell->gamma <<"  SPGR =  1 P 1\t\t OPT = 1" << "\n";
    output << cell->numAtoms << "   0 " << "\n";
    output << "0 " << cell->name << "\t" << ": " << cell->name << "\n";
    output.setf(ios::fixed, ios::floatfield);
    int i;
    ATOM atm;

    // Write information about each atom
    for(i = 0; i<cell->numAtoms; i++){
      atm = cell->atoms.at(i);
      output << " " << i+1 << " " << cell->atoms.at(i).type << " " << atm.a_coord << " "
	     << atm.b_coord << " " << atm.c_coord << "  0  0  0  0  0  0  0  0  " << atm.charge <<  "\n";
    }
    output.close();
    return true;
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2b8, %rsp            # imm = 0x2B8
movq %rsi, %r14
movq %rdi, %rbx
leaq 0xa8(%rsp), %r15
movq %r15, %rdi
callq 0x4540
pushq $0x10
popq %rdx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x4410
leaq 0x128(%rsp), %rdi
callq 0x4130
movb %al, 0xf(%rsp)
testb %al, %al
je 0x21c5a
movq 0x12e634(%rip), %rdi    # 0x14ffc0
leaq 0xdba37(%rip), %rsi     # 0xfd3ca
callq 0x4480
movq %rax, %rdi
movq %rbx, %rsi
callq 0x4480
leaq 0xe0bd4(%rip), %rsi     # 0x10257e
movq %rax, %rdi
callq 0x4480
leaq 0xb8(%rsp), %rdi
leaq 0xdba2e(%rip), %rsi     # 0xfd3ef
callq 0x4480
movsd 0x8(%r14), %xmm0
movq %rax, %rdi
callq 0x46c0
leaq 0xdaaf4(%rip), %rsi     # 0xfc4cf
movq %rax, %rdi
callq 0x4480
movsd 0x10(%r14), %xmm0
movq %rax, %rdi
callq 0x46c0
leaq 0xdaad7(%rip), %rsi     # 0xfc4cf
movq %rax, %rdi
callq 0x4480
movsd 0x18(%r14), %xmm0
movq %rax, %rdi
callq 0x46c0
leaq 0xe0b69(%rip), %rsi     # 0x10257e
movq %rax, %rdi
callq 0x4480
leaq 0xdb9cd(%rip), %rsi     # 0xfd3f1
leaq 0xb8(%rsp), %rdi
callq 0x4480
movsd 0x20(%r14), %xmm0
movq %rax, %rdi
callq 0x46c0
leaq 0xdaa89(%rip), %rsi     # 0xfc4cf
movq %rax, %rdi
callq 0x4480
movsd 0x28(%r14), %xmm0
movq %rax, %rdi
callq 0x46c0
leaq 0xdaa6c(%rip), %rsi     # 0xfc4cf
movq %rax, %rdi
callq 0x4480
movsd 0x30(%r14), %xmm0
movq %rax, %rdi
callq 0x46c0
leaq 0xdb974(%rip), %rsi     # 0xfd3f4
movq %rax, %rdi
callq 0x4480
leaq 0xe0aef(%rip), %rsi     # 0x10257e
movq %rax, %rdi
callq 0x4480
movl 0x110(%r14), %esi
leaq 0xb8(%rsp), %rdi
callq 0x4760
leaq 0xdb95c(%rip), %rsi     # 0xfd40e
movq %rax, %rdi
callq 0x4480
leaq 0xe0abd(%rip), %rsi     # 0x10257e
movq %rax, %rdi
callq 0x4480
leaq 0xdb941(%rip), %rsi     # 0xfd411
leaq 0xb8(%rsp), %rdi
callq 0x4480
leaq 0x320(%r14), %rbx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x43f0
leaq 0xdb8fc(%rip), %rsi     # 0xfd3f2
movq %rax, %rdi
callq 0x4480
leaq 0xdfb8c(%rip), %rsi     # 0x101691
movq %rax, %rdi
callq 0x4480
movq %rax, %rdi
movq %rbx, %rsi
callq 0x43f0
leaq 0xe0a5f(%rip), %rsi     # 0x10257e
movq %rax, %rdi
callq 0x4480
movq 0xa8(%rsp), %rax
movq -0x18(%rax), %rax
movl $0xfffffefb, %ecx       # imm = 0xFFFFFEFB
andl 0xc0(%rsp,%rax), %ecx
orl $0x4, %ecx
movl %ecx, 0xc0(%rsp,%rax)
leaq 0x10(%rsp), %rdi
callq 0x3dc5a
leaq 0x2f0(%r14), %r12
xorl %r13d, %r13d
leaq 0xe29ae(%rip), %rbx     # 0x104512
leaq 0xe0a13(%rip), %rbp     # 0x10257e
movslq 0x110(%r14), %rax
cmpq %rax, %r13
jge 0x21c82
movq %r12, %rdi
movq %r13, %rsi
callq 0xa73a
leaq 0x10(%rsp), %rdi
movq %rax, %rsi
callq 0x245be
leaq 0xb8(%rsp), %rdi
movq %rbx, %rsi
callq 0x4480
incq %r13
movq %rax, %rdi
movl %r13d, %esi
callq 0x4760
movq %rax, %rdi
movq %rbx, %rsi
callq 0x4480
movq %rax, %r15
decq %r13
movq %r12, %rdi
movq %r13, %rsi
callq 0xa73a
addq $0x40, %rax
movq %r15, %rdi
movq %rax, %rsi
callq 0x43f0
movq %rax, %rdi
movq %rbx, %rsi
callq 0x4480
movsd 0x28(%rsp), %xmm0
movq %rax, %rdi
callq 0x46c0
movq %rax, %rdi
movq %rbx, %rsi
callq 0x4480
movsd 0x30(%rsp), %xmm0
movq %rax, %rdi
callq 0x46c0
movq %rax, %rdi
movq %rbx, %rsi
callq 0x4480
movsd 0x38(%rsp), %xmm0
movq %rax, %rdi
callq 0x46c0
movq %rax, %rdi
leaq 0xdb7e3(%rip), %rsi     # 0xfd414
callq 0x4480
movsd 0x98(%rsp), %xmm0
movq %rax, %rdi
callq 0x46c0
incq %r13
movq %rax, %rdi
movq %rbp, %rsi
callq 0x4480
jmp 0x21b6b
movq 0x12e38f(%rip), %rdi    # 0x14fff0
leaq 0xdb739(%rip), %rsi     # 0xfd3a1
callq 0x4480
movq %rax, %rdi
movq %rbx, %rsi
callq 0x4480
movq %rax, %rdi
callq 0x4230
jmp 0x21c99
leaq 0xa8(%rsp), %rdi
callq 0x4080
leaq 0x10(%rsp), %rdi
callq 0xa808
leaq 0xa8(%rsp), %rdi
callq 0x4120
movb 0xf(%rsp), %al
addq $0x2b8, %rsp            # imm = 0x2B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x21cc5
jmp 0x21cc0
movq %rax, %rbx
jmp 0x21cd2
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0xa808
leaq 0xa8(%rsp), %rdi
callq 0x4120
movq %rbx, %rdi
callq 0x4780