// File: /workspace/github_cpp_makefile_star2_O1/Luthaf[P]zeopp/networkio.cc
// Function: writeToCIF(char*, ATOM_NETWORK*)
bool writeToCIF(char *filename,  ATOM_NETWORK *cell){
  fstream output;
  output.open(filename, fstream::out);
  if(!output.is_open()){
    cerr << "Error: Failed to open .cif output file " << filename << endl;
	//cerr << "Exiting ..." << "\n";
    //exit(1);
    return false;
  }
  else{
    cout   << "Writing atom network information to " << filename << "\n";
    //output << "data_" << origname << endl; //we need this data_(name) line otherwise the cif file will not be considered valid in some software packages
    //Instead of supplying argument to write data_..., using timestamp with number of atoms in the structure
    string formula = get_formula(cell);
    string time_stamp = get_timestamp();
    output << "data_" << formula << "_" << time_stamp << endl;
    output << "#******************************************" << endl;
    output << "#" << endl;
    output << "# CIF file created by Zeo++" << endl;
    output << "# Zeo++ is an open source package to" << endl;
    output << "# analyze microporous materials" << endl;
    output << "#" << endl;
    output << "#*******************************************" << "\n\n";
    output << "_cell_length_a\t\t" << cell->a << "   " << endl;     //  removed (0)
    output << "_cell_length_b\t\t" << cell->b << "   " << endl;
    output << "_cell_length_c\t\t" << cell->c << "   " << endl;
    output << "_cell_angle_alpha\t\t" << cell->alpha << "   " << endl;
    output << "_cell_angle_beta\t\t" << cell->beta << "   " << endl;
    output << "_cell_angle_gamma\t\t" << cell->gamma << "   \n\n";
    output << "_symmetry_space_group_name_H-M\t\t" << "'P1'" << endl;
    output << "_symmetry_Int_Tables_number\t\t" << "1" << endl;
    output << "_symmetry_cell_setting\t\t";

    //Determine the Crystal System
    if (cell->alpha == 90 && cell->beta == 90 && cell->gamma == 90){
      if (cell->a == cell->b || cell->b == cell->c || cell->a == cell->c){
	      if (cell->a == cell->b && cell->b == cell->c){
	        output << "Isometric\n" << endl;
	      }
	      else {
	        output << "Tetragonal\n" << endl;
        }
      }
      else{
      	output << "Orthorhombic\n" << endl;
      }
    }
    else if(cell->alpha == cell->beta || cell->beta == cell->gamma || cell->alpha == cell->gamma){
      output << "Monoclinic\n" << endl;
    }
    else{
      output << "Triclinic\n" << endl;
    }

    output << "loop_" << endl;
    output << "_symmetry_equiv_pos_as_xyz" << endl;
    output << "'+x,+y,+z'\n" << endl;
    output << "loop_" << endl;
    output << "_atom_site_label" << endl;
    output << "_atom_site_type_symbol" << endl;
    output << "_atom_site_fract_x" << endl;
    output << "_atom_site_fract_y" << endl;
    output << "_atom_site_fract_z" << endl;
    for (unsigned int i=0; i<cell->atoms.size(); i++){
      ATOM *temp=&(cell->atoms.at(i));
      output << temp->specialID << "\t" << temp->type << "\t" << trans_to_origuc(temp->a_coord) << "\t" << trans_to_origuc(temp->b_coord) << "\t" << trans_to_origuc(temp->c_coord) << endl;
    }
    output.close();
    return true;
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x268, %rsp            # imm = 0x268
movq %rsi, %r14
movq %rdi, %r15
leaq 0x58(%rsp), %rbx
movq %rbx, %rdi
callq 0x4520
movq %rbx, %rdi
movq %r15, %rsi
movl $0x10, %edx
callq 0x43d0
leaq 0xd8(%rsp), %rdi
callq 0x4120
movl %eax, %ebx
testb %al, %al
je 0x2b9bf
movq 0x16b636(%rip), %r12    # 0x196fc0
leaq 0x1249c9(%rip), %rsi    # 0x15035a
movl $0x24, %edx
movq %r12, %rdi
callq 0x44e0
testq %r15, %r15
je 0x2ba02
movq %r15, %rdi
callq 0x41e0
movq 0x16b60e(%rip), %rdi    # 0x196fc0
movq %r15, %rsi
movq %rax, %rdx
callq 0x44e0
jmp 0x2ba1b
movq 0x16b62a(%rip), %r14    # 0x196ff0
leaq 0x1249f8(%rip), %rsi    # 0x1503c5
movl $0x27, %edx
movq %r14, %rdi
callq 0x44e0
testq %r15, %r15
je 0x2bfc3
movq %r15, %rdi
callq 0x41e0
movq 0x16b5fe(%rip), %rdi    # 0x196ff0
movq %r15, %rsi
movq %rax, %rdx
callq 0x44e0
jmp 0x2bfdb
movq (%r12), %rax
movq -0x18(%rax), %rax
leaq (%r12,%rax), %rdi
movl 0x20(%r12,%rax), %esi
orl $0x1, %esi
callq 0x4710
movq 0x16b59e(%rip), %rdi    # 0x196fc0
leaq 0x129b05(%rip), %rsi    # 0x15552e
movl $0x1, %edx
callq 0x44e0
leaq 0x38(%rsp), %rdi
movq %r14, %rsi
callq 0x2b6a3
leaq 0x18(%rsp), %rdi
callq 0x2b8d4
leaq 0x68(%rsp), %r13
leaq 0x12413b(%rip), %rsi    # 0x14fb91
movl $0x5, %edx
movq %r13, %rdi
callq 0x44e0
movq 0x38(%rsp), %rsi
movq 0x40(%rsp), %rdx
movq %r13, %rdi
callq 0x44e0
movq %rax, %r12
leaq 0x124116(%rip), %rsi    # 0x14fb95
movl $0x1, %edx
movq %rax, %rdi
callq 0x44e0
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
movq %r12, %rdi
callq 0x44e0
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x4420
movsbl %al, %esi
movq %r12, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x42c0
leaq 0x12491e(%rip), %rsi    # 0x1503ed
movl $0x2b, %edx
movq %r13, %rdi
callq 0x44e0
movq 0x68(%rsp), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x4420
movsbl %al, %esi
movq %r13, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x42c0
leaq 0x1278f2(%rip), %rsi    # 0x1533fe
movl $0x1, %edx
movq %r13, %rdi
callq 0x44e0
movq 0x68(%rsp), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x4420
movsbl %al, %esi
movq %r13, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x42c0
leaq 0x1248d0(%rip), %rsi    # 0x150419
movl $0x1b, %edx
movq %r13, %rdi
callq 0x44e0
movq 0x68(%rsp), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x4420
movsbl %al, %esi
movq %r13, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x42c0
leaq 0x1248af(%rip), %rsi    # 0x150435
movl $0x24, %edx
movq %r13, %rdi
callq 0x44e0
movq 0x68(%rsp), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x4420
movsbl %al, %esi
movq %r13, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x42c0
leaq 0x124897(%rip), %rsi    # 0x15045a
movl $0x1f, %edx
movq %r13, %rdi
callq 0x44e0
movq 0x68(%rsp), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x4420
movsbl %al, %esi
movq %r13, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x42c0
leaq 0x1277fe(%rip), %rsi    # 0x1533fe
movl $0x1, %edx
movq %r13, %rdi
callq 0x44e0
movq 0x68(%rsp), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x4420
movsbl %al, %esi
movq %r13, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x42c0
leaq 0x12483d(%rip), %rsi    # 0x15047a
movl $0x2c, %edx
movq %r13, %rdi
callq 0x44e0
leaq 0x12b2c5(%rip), %rsi    # 0x156f16
movl $0x2, %edx
movq %r13, %rdi
callq 0x44e0
leaq 0x124842(%rip), %rsi    # 0x1504a7
movl $0x10, %edx
movq %r13, %rdi
callq 0x44e0
movsd 0x8(%r14), %xmm0
movq %r13, %rdi
callq 0x46b0
movq %rax, %r12
leaq 0x123804(%rip), %rsi    # 0x14f48e
movl $0x3, %edx
movq %rax, %rdi
callq 0x44e0
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x4420
movsbl %al, %esi
movq %r12, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x42c0
leaq 0x1247f2(%rip), %rsi    # 0x1504b8
movl $0x10, %edx
movq %r13, %rdi
callq 0x44e0
movsd 0x10(%r14), %xmm0
movq %r13, %rdi
callq 0x46b0
movq %rax, %r12
leaq 0x1237a3(%rip), %rsi    # 0x14f48e
movl $0x3, %edx
movq %rax, %rdi
callq 0x44e0
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x4420
movsbl %al, %esi
movq %r12, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x42c0
leaq 0x1247a2(%rip), %rsi    # 0x1504c9
movl $0x10, %edx
movq %r13, %rdi
callq 0x44e0
movsd 0x18(%r14), %xmm0
movq %r13, %rdi
callq 0x46b0
movq %rax, %r12
leaq 0x123742(%rip), %rsi    # 0x14f48e
movl $0x3, %edx
movq %rax, %rdi
callq 0x44e0
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x4420
movsbl %al, %esi
movq %r12, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x42c0
leaq 0x124752(%rip), %rsi    # 0x1504da
movl $0x13, %edx
movq %r13, %rdi
callq 0x44e0
movsd 0x20(%r14), %xmm0
movq %r13, %rdi
callq 0x46b0
movq %rax, %r12
leaq 0x1236e1(%rip), %rsi    # 0x14f48e
movl $0x3, %edx
movq %rax, %rdi
callq 0x44e0
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x4420
movsbl %al, %esi
movq %r12, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x42c0
leaq 0x124705(%rip), %rsi    # 0x1504ee
movl $0x12, %edx
movq %r13, %rdi
callq 0x44e0
movsd 0x28(%r14), %xmm0
movq %r13, %rdi
callq 0x46b0
movq %rax, %r12
leaq 0x123680(%rip), %rsi    # 0x14f48e
movl $0x3, %edx
movq %rax, %rdi
callq 0x44e0
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x4420
movsbl %al, %esi
movq %r12, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x42c0
leaq 0x1246b7(%rip), %rsi    # 0x150501
movl $0x13, %edx
movq %r13, %rdi
callq 0x44e0
movsd 0x30(%r14), %xmm0
movq %r13, %rdi
callq 0x46b0
leaq 0x1246a9(%rip), %rsi    # 0x150515
movl $0x5, %edx
movq %rax, %rdi
callq 0x44e0
leaq 0x12469b(%rip), %rsi    # 0x15051b
movl $0x20, %edx
movq %r13, %rdi
callq 0x44e0
leaq 0x1246a8(%rip), %rsi    # 0x15053c
movl $0x4, %edx
movq %r13, %rdi
callq 0x44e0
movq 0x68(%rsp), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x4420
movsbl %al, %esi
movq %r13, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x42c0
leaq 0x124670(%rip), %rsi    # 0x150541
movl $0x1d, %edx
movq %r13, %rdi
callq 0x44e0
leaq 0x1244b7(%rip), %rsi    # 0x15039c
movl $0x1, %edx
movq %r13, %rdi
callq 0x44e0
movq 0x68(%rsp), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x4420
movsbl %al, %esi
movq %r13, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x42c0
leaq 0x12463d(%rip), %rsi    # 0x15055f
movl $0x18, %edx
movq %r13, %rdi
callq 0x44e0
movsd 0x20(%r14), %xmm0
ucomisd 0x123b93(%rip), %xmm0   # 0x14fad0
jne 0x2bfa4
jp 0x2bfa4
movsd 0x28(%r14), %xmm1
ucomisd 0x123b81(%rip), %xmm1   # 0x14fad0
jne 0x2bfa4
jp 0x2bfa4
movsd 0x30(%r14), %xmm1
ucomisd 0x123b6f(%rip), %xmm1   # 0x14fad0
jne 0x2bfa4
jp 0x2bfa4
movsd 0x8(%r14), %xmm1
movsd 0x10(%r14), %xmm0
ucomisd %xmm0, %xmm1
movsd 0x18(%r14), %xmm2
jne 0x2c042
jp 0x2c042
ucomisd %xmm2, %xmm0
jne 0x2bf93
jnp 0x2c076
movl $0xb, %edx
leaq 0x1245e4(%rip), %rsi    # 0x150583
jmp 0x2c082
movsd 0x28(%r14), %xmm1
ucomisd %xmm1, %xmm0
jne 0x2c00b
jp 0x2c00b
movl $0xb, %edx
leaq 0x1245df(%rip), %rsi    # 0x15059d
jmp 0x2c082
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 0x16aff7(%rip), %rdi    # 0x196ff0
callq 0x4040
movq %rax, %rdi
callq 0x42c0
jmp 0x2c45b
movsd 0x30(%r14), %xmm2
cmpeqpd %xmm2, %xmm0
cmpeqpd %xmm2, %xmm1
orpd %xmm0, %xmm1
movq %xmm1, %rax
leaq 0x124572(%rip), %rcx    # 0x15059d
leaq 0x124577(%rip), %rsi    # 0x1505a9
testb $0x1, %al
cmovneq %rcx, %rsi
movl $0xa, %edx
subq %rax, %rdx
jmp 0x2c082
cmpneqpd %xmm2, %xmm1
cmpneqpd %xmm2, %xmm0
andpd %xmm1, %xmm0
movq %xmm0, %rax
leaq 0x124533(%rip), %rcx    # 0x15058f
leaq 0x124520(%rip), %rsi    # 0x150583
testb $0x1, %al
cmovneq %rcx, %rsi
andl $0x1, %eax
leaq 0xb(,%rax,2), %rdx
jmp 0x2c082
movl $0xa, %edx
leaq 0x1244f6(%rip), %rsi    # 0x150578
movq %r13, %rdi
callq 0x44e0
movq 0x68(%rsp), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x4420
movsbl %al, %esi
movq %r13, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x42c0
leaq 0x123b3f(%rip), %rsi    # 0x14fbf9
movl $0x5, %edx
movq %r13, %rdi
callq 0x44e0
movq 0x68(%rsp), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x4420
movsbl %al, %esi
movq %r13, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x42c0
leaq 0x123b08(%rip), %rsi    # 0x14fbff
movl $0x1a, %edx
movq %r13, %rdi
callq 0x44e0
movq 0x68(%rsp), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x4420
movsbl %al, %esi
movq %r13, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x42c0
leaq 0x124480(%rip), %rsi    # 0x1505b4
movl $0xb, %edx
movq %r13, %rdi
callq 0x44e0
movq 0x68(%rsp), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x4420
movsbl %al, %esi
movq %r13, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x42c0
leaq 0x123a88(%rip), %rsi    # 0x14fbf9
movl $0x5, %edx
movq %r13, %rdi
callq 0x44e0
movq 0x68(%rsp), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x4420
movsbl %al, %esi
movq %r13, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x42c0
leaq 0x123a8d(%rip), %rsi    # 0x14fc3b
movl $0x10, %edx
movq %r13, %rdi
callq 0x44e0
movq 0x68(%rsp), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x4420
movsbl %al, %esi
movq %r13, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x42c0
leaq 0x123a61(%rip), %rsi    # 0x14fc4c
movl $0x16, %edx
movq %r13, %rdi
callq 0x44e0
movq 0x68(%rsp), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x4420
movsbl %al, %esi
movq %r13, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x42c0
leaq 0x123a3b(%rip), %rsi    # 0x14fc63
movl $0x12, %edx
movq %r13, %rdi
callq 0x44e0
movq 0x68(%rsp), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x4420
movsbl %al, %esi
movq %r13, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x42c0
leaq 0x123a11(%rip), %rsi    # 0x14fc76
movl $0x12, %edx
movq %r13, %rdi
callq 0x44e0
movq 0x68(%rsp), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x4420
movsbl %al, %esi
movq %r13, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x42c0
leaq 0x1239e7(%rip), %rsi    # 0x14fc89
movl $0x12, %edx
movq %r13, %rdi
callq 0x44e0
movq 0x68(%rsp), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x4420
movsbl %al, %esi
movq %r13, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x42c0
movb %bl, 0xf(%rsp)
movq 0x2f0(%r14), %r15
movq %r14, 0x10(%rsp)
cmpq %r15, 0x2f8(%r14)
je 0x2c417
movl $0x1, %ebp
xorl %eax, %eax
leaq 0x12407f(%rip), %r12    # 0x150382
imulq $0x98, %rax, %r14
movl 0x80(%r15,%r14), %esi
movq %r13, %rbx
movq %r13, %rdi
callq 0x4750
movq %rax, %r13
movl $0x1, %edx
movq %rax, %rdi
movq %r12, %rsi
callq 0x44e0
addq %r14, %r15
movq 0x40(%r15), %rsi
movq 0x48(%r15), %rdx
movq %r13, %rdi
callq 0x44e0
movq %rax, %r13
movl $0x1, %edx
movq %rax, %rdi
movq %r12, %rsi
callq 0x44e0
movsd 0x18(%r15), %xmm0
callq 0x84e6b
movq %r13, %rdi
callq 0x46b0
movq %rax, %r13
movl $0x1, %edx
movq %rax, %rdi
movq %r12, %rsi
callq 0x44e0
movsd 0x20(%r15), %xmm0
callq 0x84e6b
movq %r13, %rdi
callq 0x46b0
movq %rax, %r13
movl $0x1, %edx
movq %rax, %rdi
movq %r12, %rsi
callq 0x44e0
movsd 0x28(%r15), %xmm0
callq 0x84e6b
movq %r13, %rdi
callq 0x46b0
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x4420
movsbl %al, %esi
movq %r13, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x42c0
movl %ebp, %eax
movq 0x10(%rsp), %rcx
movq 0x2f0(%rcx), %r15
movq 0x2f8(%rcx), %rcx
subq %r15, %rcx
sarq $0x3, %rcx
movabsq $-0x79435e50d79435e5, %rdx # imm = 0x86BCA1AF286BCA1B
imulq %rdx, %rcx
incl %ebp
cmpq %rax, %rcx
movq %rbx, %r13
ja 0x2c303
leaq 0x58(%rsp), %rdi
callq 0x4090
movb 0xf(%rsp), %bl
leaq 0x28(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2c440
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x4470
leaq 0x48(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2c45b
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x4470
leaq 0x58(%rsp), %rdi
callq 0x4110
movl %ebx, %eax
addq $0x268, %rsp            # imm = 0x268
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x2c4a5
jmp 0x2c480
movq %rax, %rbx
jmp 0x2c4c0
jmp 0x2c487
movq %rax, %rbx
leaq 0x28(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2c4a5
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x4470
leaq 0x48(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2c4c0
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x4470
leaq 0x58(%rsp), %rdi
callq 0x4110
movq %rbx, %rdi
callq 0x4780