// File: /workspace/github_cpp_makefile_star2_O1/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 0x4520
movq %r15, %rdi
movq %rbx, %rsi
movl $0x10, %edx
callq 0x43d0
leaq 0x128(%rsp), %rdi
callq 0x4120
movl %eax, %ebp
testb %al, %al
je 0x2ab68
movq 0x16c48d(%rip), %r15    # 0x196fc0
leaq 0x125820(%rip), %rsi    # 0x15035a
movl $0x24, %edx
movq %r15, %rdi
callq 0x44e0
testq %rbx, %rbx
je 0x2abab
movq %rbx, %rdi
callq 0x41e0
movq 0x16c465(%rip), %rdi    # 0x196fc0
movq %rbx, %rsi
movq %rax, %rdx
callq 0x44e0
jmp 0x2abc3
movq 0x16c481(%rip), %r14    # 0x196ff0
leaq 0x1257bb(%rip), %rsi    # 0x150331
movl $0x28, %edx
movq %r14, %rdi
callq 0x44e0
testq %rbx, %rbx
je 0x2b022
movq %rbx, %rdi
callq 0x41e0
movq 0x16c455(%rip), %rdi    # 0x196ff0
movq %rbx, %rsi
movq %rax, %rdx
callq 0x44e0
jmp 0x2b03a
movq (%r15), %rax
movq -0x18(%rax), %rax
leaq (%r15,%rax), %rdi
movl 0x20(%r15,%rax), %esi
orl $0x1, %esi
callq 0x4710
movq 0x16c3f6(%rip), %rdi    # 0x196fc0
leaq 0x12a95d(%rip), %rsi    # 0x15552e
movl $0x1, %edx
callq 0x44e0
leaq 0xb8(%rsp), %rdi
leaq 0x125795(%rip), %rsi    # 0x15037f
movl $0x4, %edx
callq 0x44e0
movsd 0x8(%r14), %xmm0
leaq 0xb8(%rsp), %rdi
callq 0x46b0
movq %rax, %rbx
leaq 0x12487e(%rip), %rsi    # 0x14f48f
movl $0x2, %edx
movq %rax, %rdi
callq 0x44e0
movsd 0x10(%r14), %xmm0
movq %rbx, %rdi
callq 0x46b0
movq %rax, %rbx
leaq 0x124859(%rip), %rsi    # 0x14f48f
movl $0x2, %edx
movq %rax, %rdi
callq 0x44e0
movsd 0x18(%r14), %xmm0
movq %rbx, %rdi
callq 0x46b0
leaq 0x12a8d6(%rip), %rsi    # 0x15552e
movl $0x1, %edx
movq %rax, %rdi
callq 0x44e0
leaq 0x125715(%rip), %rsi    # 0x150381
movl $0x2, %edx
leaq 0xb8(%rsp), %rdi
callq 0x44e0
movsd 0x20(%r14), %xmm0
leaq 0xb8(%rsp), %rdi
callq 0x46b0
movq %rax, %rbx
leaq 0x1247f4(%rip), %rsi    # 0x14f48f
movl $0x2, %edx
movq %rax, %rdi
callq 0x44e0
movsd 0x28(%r14), %xmm0
movq %rbx, %rdi
callq 0x46b0
movq %rax, %rbx
leaq 0x1247cf(%rip), %rsi    # 0x14f48f
movl $0x2, %edx
movq %rax, %rdi
callq 0x44e0
movsd 0x30(%r14), %xmm0
movq %rbx, %rdi
callq 0x46b0
movq %rax, %rbx
leaq 0x12569f(%rip), %rsi    # 0x150384
movl $0x19, %edx
movq %rax, %rdi
callq 0x44e0
leaq 0x12a835(%rip), %rsi    # 0x15552e
movl $0x1, %edx
movq %rbx, %rdi
callq 0x44e0
movl 0x110(%r14), %esi
leaq 0xb8(%rsp), %rdi
callq 0x4750
movq %rax, %rbx
leaq 0x12567a(%rip), %rsi    # 0x15039e
movl $0x5, %edx
movq %rax, %rdi
callq 0x44e0
leaq 0x12a7f6(%rip), %rsi    # 0x15552e
movl $0x1, %edx
movq %rbx, %rdi
callq 0x44e0
leaq 0x125655(%rip), %rsi    # 0x1503a1
movl $0x2, %edx
leaq 0xb8(%rsp), %rdi
callq 0x44e0
movq 0x320(%r14), %rsi
movq 0x328(%r14), %rdx
leaq 0xb8(%rsp), %rdi
callq 0x44e0
movq %rax, %rbx
leaq 0x1255ff(%rip), %rsi    # 0x150382
movl $0x1, %edx
movq %rax, %rdi
callq 0x44e0
leaq 0x1298da(%rip), %rsi    # 0x154671
movl $0x2, %edx
movq %rbx, %rdi
callq 0x44e0
movq 0x320(%r14), %rsi
movq 0x328(%r14), %rdx
movq %rbx, %rdi
callq 0x44e0
leaq 0x12a76d(%rip), %rsi    # 0x15552e
movl $0x1, %edx
movq %rax, %rdi
callq 0x44e0
movb %bpl, 0xf(%rsp)
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 0x5162c
leaq 0x50(%rsp), %r13
movl $0x40, %ebp
xorl %r12d, %r12d
leaq 0x12c673(%rip), %rbx    # 0x157486
movslq 0x110(%r14), %rax
cmpq %rax, %r12
jge 0x2afd2
movq 0x2f0(%r14), %r15
movq 0x2f8(%r14), %rdx
subq %r15, %rdx
sarq $0x3, %rdx
movabsq $-0x79435e50d79435e5, %rax # imm = 0x86BCA1AF286BCA1B
imulq %rax, %rdx
cmpq %r12, %rdx
jbe 0x2b086
leaq (%r15,%rbp), %rsi
movups -0x40(%r15,%rbp), %xmm0
movups -0x30(%r15,%rbp), %xmm1
movups -0x20(%r15,%rbp), %xmm2
movups -0x10(%r15,%rbp), %xmm3
movaps %xmm3, 0x40(%rsp)
movaps %xmm2, 0x30(%rsp)
movaps %xmm1, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
movq %r13, %rdi
callq 0x4240
leaq (%r15,%rbp), %rsi
addq $0x20, %rsi
leaq 0x70(%rsp), %rdi
callq 0x4240
movb 0x50(%r15,%rbp), %al
movb %al, 0x50(%r13)
movups 0x40(%r15,%rbp), %xmm0
movups %xmm0, 0x40(%r13)
movl $0x1, %edx
leaq 0xb8(%rsp), %rdi
movq %rbx, %rsi
callq 0x44e0
leal 0x1(%r12), %esi
leaq 0xb8(%rsp), %rdi
callq 0x4750
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x44e0
movq 0x2f0(%r14), %rax
movq 0x2f8(%r14), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
movabsq $-0x79435e50d79435e5, %rcx # imm = 0x86BCA1AF286BCA1B
imulq %rcx, %rdx
cmpq %r12, %rdx
jbe 0x2b086
movq (%rax,%rbp), %rsi
movq 0x8(%rax,%rbp), %rdx
movq %r15, %rdi
callq 0x44e0
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x44e0
movsd 0x28(%rsp), %xmm0
movq %r15, %rdi
callq 0x46b0
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x44e0
movsd 0x30(%rsp), %xmm0
movq %r15, %rdi
callq 0x46b0
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x44e0
movsd 0x38(%rsp), %xmm0
movq %r15, %rdi
callq 0x46b0
movq %rax, %r15
movl $0x1a, %edx
movq %rax, %rdi
leaq 0x12540b(%rip), %rsi    # 0x1503a4
callq 0x44e0
movsd 0x98(%rsp), %xmm0
movq %r15, %rdi
callq 0x46b0
addq $0x98, %rbp
incq %r12
movl $0x1, %edx
movq %rax, %rdi
leaq 0x12a566(%rip), %rsi    # 0x15552e
callq 0x44e0
jmp 0x2ae13
leaq 0xa8(%rsp), %rdi
callq 0x4090
leaq 0x80(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
movb 0xf(%rsp), %bpl
je 0x2b005
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x4470
leaq 0x60(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2b065
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x4470
jmp 0x2b065
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 0x16bf98(%rip), %rdi    # 0x196ff0
callq 0x4040
movq %rax, %rdi
callq 0x42c0
leaq 0xa8(%rsp), %rdi
callq 0x4110
movl %ebp, %eax
addq $0x2b8, %rsp            # imm = 0x2B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x124618(%rip), %rdi    # 0x14f6a5
movq %r12, %rsi
xorl %eax, %eax
callq 0x4630
jmp 0x2b099
movq %rax, %rbx
jmp 0x2b0ad
jmp 0x2b0a0
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x2f814
leaq 0xa8(%rsp), %rdi
callq 0x4110
movq %rbx, %rdi
callq 0x4780