// File: /workspace/github_cpp_makefile_star2_O1/Luthaf[P]zeopp/networkstorage.cc
// Function: write_abstract_cif(_IO_FILE*, ATOM_NETWORK*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void write_abstract_cif(FILE *cif, ATOM_NETWORK *cell, string name) {
  //this function writes out a cif file with abstracted cell information
  //the basic vertices and edges are written, i.e. before symmetry operations, and the symmetry group is written to the file
  //edges are written as vertices - they are shortened to 1/4 length, so that they do not overlap with real vertices, and so that their direction can be preserved
  fprintf(cif, "#******************************************\n#\n# CIF file created by Richard L. Martin, Lawrence Berkeley National Laboratory, 2013\n#\n#*******************************************\n\n");
  fprintf(cif, "_cell_length_a\t\t%.3f(0)\n", cell->a);
  fprintf(cif, "_cell_length_b\t\t%.3f(0)\n", cell->b);
  fprintf(cif, "_cell_length_c\t\t%.3f(0)\n", cell->c);
  fprintf(cif, "_cell_angle_alpha\t\t%.3f(0)\n", cell->alpha);
  fprintf(cif, "_cell_angle_beta\t\t%.3f(0)\n", cell->beta);
  fprintf(cif, "_cell_angle_gamma\t\t%.3f(0)\n", cell->gamma);
//  fprintf(cif, "_symmetry_space_group_name_H-M\t\t%s\n", cell->sym_name.c_str());
fprintf(cif, "_symmetry_space_group_name_H-M\t\tP-1\n");
//  fprintf(cif, "_symmetry_Int_Tables_number\t\t%d\n", cell->sym_ID);
  fprintf(cif, "_symmetry_Int_Tables_number\t\t1\n");
  fprintf(cif, "_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){
        fprintf(cif, "Isometric\n\n");
      }
      else {
        fprintf(cif, "Tetragonal\n\n");
      }
    }
    else{
    	fprintf(cif, "Orthorhombic\n\n");
    }
  }
  else if(cell->alpha == cell->beta || cell->beta == cell->gamma || cell->alpha == cell->gamma){
    fprintf(cif, "Monoclinic\n\n");
  }
  else{
    fprintf(cif, "Triclinic\n\n");
  }
  
  fprintf(cif, "loop_\n");
  fprintf(cif, "_symmetry_equiv_pos_as_xyz\n");
fprintf(cif, "'+x,+y,+z'\n\n"); //can we do something smarter here?
  fprintf(cif, "loop_\n");
  fprintf(cif, "_atom_site_label\n");
  fprintf(cif, "_atom_site_type_symbol\n");
  fprintf(cif, "_atom_site_fract_x\n");
  fprintf(cif, "_atom_site_fract_y\n");
  fprintf(cif, "_atom_site_fract_z\n");
  int num_vertices = cell->vertices.size();
  int count = 1;
  for (int i=0; i<num_vertices; i++){
    VERTEX v = cell->vertices.at(i);
    int num_edges = v.edges.size();
    if(num_edges>2) { //don't write out augmented, 2-c vertices...
//      fprintf(cif, "%d\t%d\t%.6f\t%.6f\t%.6f\n", count, count, v.abc.x, v.abc.y, v.abc.z);
      fprintf(cif, "%s\t%s\t%.6f\t%.6f\t%.6f\n", "C", "C", v.abc.x, v.abc.y, v.abc.z);
      count++;
      for (int j=0; j<num_edges; j++) { //... or dummy edges...
        XYZ edge = v.edges.at(j);
        XYZ quarter_edge = ((edge-v.abc).scale(1.0/4.0))+v.abc;
//        fprintf(cif, "%d\t%d\t%.6f\t%.6f\t%.6f\n", count, count, quarter_edge.x, quarter_edge.y, quarter_edge.z);
        fprintf(cif, "%s\t%s\t%.6f\t%.6f\t%.6f\n", "H", "H", quarter_edge.x, quarter_edge.y, quarter_edge.z);
        count++;        
      }
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movq %rsi, %rbp
movq %rdi, %r14
leaq 0xefe12(%rip), %rdi     # 0x155977
movl $0xb3, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x4850
movsd 0x8(%rbp), %xmm0
leaq 0xefea8(%rip), %rsi     # 0x155a2b
movq %r14, %rdi
movb $0x1, %al
callq 0x45f0
movsd 0x10(%rbp), %xmm0
leaq 0xefeab(%rip), %rsi     # 0x155a44
movq %r14, %rdi
movb $0x1, %al
callq 0x45f0
movsd 0x18(%rbp), %xmm0
leaq 0xefeae(%rip), %rsi     # 0x155a5d
movq %r14, %rdi
movb $0x1, %al
callq 0x45f0
movsd 0x20(%rbp), %xmm0
leaq 0xefeb1(%rip), %rsi     # 0x155a76
movq %r14, %rdi
movb $0x1, %al
callq 0x45f0
movsd 0x28(%rbp), %xmm0
leaq 0xefeb7(%rip), %rsi     # 0x155a92
movq %r14, %rdi
movb $0x1, %al
callq 0x45f0
movsd 0x30(%rbp), %xmm0
leaq 0xefebc(%rip), %rsi     # 0x155aad
movq %r14, %rdi
movb $0x1, %al
callq 0x45f0
leaq 0xefec7(%rip), %rdi     # 0x155ac9
movl $0x24, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x4850
leaq 0xefed3(%rip), %rdi     # 0x155aee
movl $0x1f, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x4850
leaq 0xea92b(%rip), %rdi     # 0x15055f
movl $0x18, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x4850
movsd 0x20(%rbp), %xmm0
ucomisd 0xe9e7d(%rip), %xmm0    # 0x14fad0
jne 0x65cad
jp 0x65cad
movsd 0x28(%rbp), %xmm1
ucomisd 0xe9e6c(%rip), %xmm1    # 0x14fad0
jne 0x65cad
jp 0x65cad
movsd 0x30(%rbp), %xmm1
ucomisd 0xe9e5b(%rip), %xmm1    # 0x14fad0
jne 0x65cad
jp 0x65cad
movsd 0x8(%rbp), %xmm1
movsd 0x10(%rbp), %xmm0
ucomisd %xmm0, %xmm1
jne 0x66069
jp 0x66069
ucomisd 0x18(%rbp), %xmm0
jne 0x6609b
jp 0x6609b
leaq 0xefe63(%rip), %rdi     # 0x155b0e
jmp 0x65ce4
movsd 0x28(%rbp), %xmm1
ucomisd %xmm1, %xmm0
jne 0x65cc8
jp 0x65cc8
leaq 0xefe75(%rip), %rdi     # 0x155b36
movl $0xc, %esi
jmp 0x65ce9
movsd 0x30(%rbp), %xmm2
ucomisd %xmm2, %xmm1
jne 0x65cd5
jnp 0x65cba
ucomisd %xmm2, %xmm0
jne 0x65cdd
jnp 0x65cba
leaq 0xefe5f(%rip), %rdi     # 0x155b43
movl $0xb, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x4850
leaq 0xefe52(%rip), %rbx     # 0x155b4f
movl $0x6, %esi
movl $0x1, %edx
movq %rbx, %rdi
movq %r14, %rcx
callq 0x4850
leaq 0xefe3d(%rip), %rdi     # 0x155b56
movl $0x1b, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x4850
leaq 0xefe40(%rip), %rdi     # 0x155b72
movl $0xc, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x4850
movl $0x6, %esi
movl $0x1, %edx
movq %rbx, %rdi
movq %r14, %rcx
callq 0x4850
leaq 0xefe1f(%rip), %rdi     # 0x155b7f
movl $0x11, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x4850
leaq 0xefe18(%rip), %rdi     # 0x155b91
movl $0x17, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x4850
leaq 0xefe17(%rip), %rdi     # 0x155ba9
movl $0x13, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x4850
leaq 0xefe12(%rip), %rdi     # 0x155bbd
movl $0x13, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x4850
leaq 0xefe0d(%rip), %rdi     # 0x155bd1
movl $0x13, %esi
movl $0x1, %edx
movq %r14, 0x8(%rsp)
movq %r14, %rcx
callq 0x4850
movq 0x3c8(%rbp), %rax
subq 0x3c0(%rbp), %rax
sarq $0x4, %rax
movabsq $0x6db6db6db6db6db7, %rcx # imm = 0x6DB6DB6DB6DB6DB7
imulq %rcx, %rax
movq %rax, (%rsp)
testl %eax, %eax
jle 0x66057
movq (%rsp), %rax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %rax, (%rsp)
xorl %esi, %esi
leaq 0x20(%rsp), %rbx
leaq 0xe0(%rsp), %r14
leaq 0xf325a(%rip), %r15     # 0x159084
movq %rbp, 0x10(%rsp)
movq 0x3c0(%rbp), %r12
movq 0x3c8(%rbp), %rdx
subq %r12, %rdx
sarq $0x4, %rdx
movabsq $0x6db6db6db6db6db7, %rax # imm = 0x6DB6DB6DB6DB6DB7
imulq %rax, %rdx
cmpq %rsi, %rdx
jbe 0x660b8
movq %rsi, 0x18(%rsp)
imulq $0x70, %rsi, %r13
leaq (%r12,%r13), %rsi
addq $0x20, %rsi
movupd -0x20(%rsi), %xmm0
movupd -0x14(%rsi), %xmm1
movupd %xmm1, 0x2c(%rsp)
movapd %xmm0, 0x20(%rsp)
leaq 0x40(%rsp), %rdi
callq 0x682e6
leaq (%r12,%r13), %rsi
addq $0x38, %rsi
leaq 0x58(%rsp), %rdi
callq 0x682e6
addq %r13, %r12
leaq 0x80(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0x50(%r12), %rsi
movq 0x58(%r12), %rdx
addq %rsi, %rdx
leaq 0x70(%rsp), %rdi
callq 0xf32a
movq 0x48(%rsp), %r13
subq 0x40(%rsp), %r13
sarq $0x3, %r13
movabsq $-0x5555555555555555, %rax # imm = 0xAAAAAAAAAAAAAAAB
imulq %rax, %r13
cmpl $0x3, %r13d
jl 0x65ff0
movsd 0x20(%rsp), %xmm0
movsd 0x28(%rsp), %xmm1
movsd 0x30(%rsp), %xmm2
movq 0x8(%rsp), %rdi
leaq 0xefcdc(%rip), %rsi     # 0x155be5
leaq 0xf358e(%rip), %rcx     # 0x15949e
movq %rcx, %rdx
movb $0x3, %al
callq 0x45f0
andl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
xorl %ebp, %ebp
xorl %r12d, %r12d
movq 0x40(%rsp), %rax
movq 0x48(%rsp), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rdx
cmpq %r12, %rdx
jbe 0x660a7
movq 0x10(%rax,%rbp), %rcx
movq %rcx, 0xc0(%rsp)
movupd (%rax,%rbp), %xmm0
movapd %xmm0, 0xb0(%rsp)
leaq 0xc8(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
movq %rbx, %rdx
callq 0x85da6
movq %r14, %rdi
leaq 0xc8(%rsp), %rsi
movsd 0xee774(%rip), %xmm0    # 0x154708
callq 0x85a34
leaq 0x98(%rsp), %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x85dd4
movsd 0x98(%rsp), %xmm0
movsd 0xa0(%rsp), %xmm1
movsd 0xa8(%rsp), %xmm2
movq 0x8(%rsp), %rdi
leaq 0xefc12(%rip), %rsi     # 0x155be5
movq %r15, %rdx
movq %r15, %rcx
movb $0x3, %al
callq 0x45f0
incq %r12
addq $0x18, %rbp
cmpq %r12, %r13
jne 0x65f26
movq 0x70(%rsp), %rdi
leaq 0x80(%rsp), %rax
cmpq %rax, %rdi
je 0x66012
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x4470
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
movq 0x10(%rsp), %rbp
je 0x6602e
movq 0x68(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x66045
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x18(%rsp), %rsi
incq %rsi
cmpq (%rsp), %rsi
jne 0x65e2f
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movsd 0x18(%rbp), %xmm2
ucomisd %xmm2, %xmm0
jne 0x66076
jnp 0x6608f
ucomisd %xmm2, %xmm1
jne 0x6607e
jnp 0x6608f
leaq 0xefaa2(%rip), %rdi     # 0x155b27
movl $0xe, %esi
jmp 0x65ce9
ucomisd %xmm0, %xmm1
jne 0x6609b
jnp 0x65c93
leaq 0xefa78(%rip), %rdi     # 0x155b1a
jmp 0x65cc1
leaq 0xe95f7(%rip), %rdi     # 0x14f6a5
movq %r12, %rsi
xorl %eax, %eax
callq 0x4630
leaq 0xe95e6(%rip), %rdi     # 0x14f6a5
xorl %eax, %eax
callq 0x4630
movq %rax, %rbx
jmp 0x660e5
movq %rax, %rbx
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x660e5
movq 0x68(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x6610d
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
jmp 0x6610d
jmp 0x66100
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x679f6
movq %rbx, %rdi
callq 0x4780