// File: 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
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x14ec74(%rip), %rsi    # 0x1faa26
movb $0x0, %al
callq 0x5750
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movsd 0x8(%rax), %xmm0
leaq 0x14ed0d(%rip), %rsi    # 0x1faada
movb $0x1, %al
callq 0x5750
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movsd 0x10(%rax), %xmm0
leaq 0x14ed0b(%rip), %rsi    # 0x1faaf3
movb $0x1, %al
callq 0x5750
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movsd 0x18(%rax), %xmm0
leaq 0x14ed09(%rip), %rsi    # 0x1fab0c
movb $0x1, %al
callq 0x5750
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movsd 0x20(%rax), %xmm0
leaq 0x14ed07(%rip), %rsi    # 0x1fab25
movb $0x1, %al
callq 0x5750
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movsd 0x28(%rax), %xmm0
leaq 0x14ed08(%rip), %rsi    # 0x1fab41
movb $0x1, %al
callq 0x5750
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movsd 0x30(%rax), %xmm0
leaq 0x14ed08(%rip), %rsi    # 0x1fab5c
movb $0x1, %al
callq 0x5750
movq -0x8(%rbp), %rdi
leaq 0x14ed12(%rip), %rsi    # 0x1fab78
movb $0x0, %al
callq 0x5750
movq -0x8(%rbp), %rdi
leaq 0x14ed25(%rip), %rsi    # 0x1fab9d
movb $0x0, %al
callq 0x5750
movq -0x8(%rbp), %rdi
leaq 0x14791e(%rip), %rsi    # 0x1f37a8
movb $0x0, %al
callq 0x5750
movq -0x10(%rbp), %rax
movsd 0x20(%rax), %xmm0
movsd 0x146c16(%rip), %xmm1   # 0x1f2ab8
ucomisd %xmm1, %xmm0
jne 0xabfa2
jp 0xabfa2
movq -0x10(%rbp), %rax
movsd 0x28(%rax), %xmm0
movsd 0x146bf5(%rip), %xmm1   # 0x1f2ab8
ucomisd %xmm1, %xmm0
jne 0xabfa2
jp 0xabfa2
movq -0x10(%rbp), %rax
movsd 0x30(%rax), %xmm0
movsd 0x146bd4(%rip), %xmm1   # 0x1f2ab8
ucomisd %xmm1, %xmm0
jne 0xabfa2
jp 0xabfa2
movq -0x10(%rbp), %rax
movsd 0x8(%rax), %xmm0
movq -0x10(%rbp), %rax
ucomisd 0x10(%rax), %xmm0
jne 0xabf0c
jp 0xabf0c
jmp 0xabf3a
movq -0x10(%rbp), %rax
movsd 0x10(%rax), %xmm0
movq -0x10(%rbp), %rax
ucomisd 0x18(%rax), %xmm0
jne 0xabf24
jp 0xabf24
jmp 0xabf3a
movq -0x10(%rbp), %rax
movsd 0x8(%rax), %xmm0
movq -0x10(%rbp), %rax
ucomisd 0x18(%rax), %xmm0
jne 0xabf8e
jp 0xabf8e
movq -0x10(%rbp), %rax
movsd 0x8(%rax), %xmm0
movq -0x10(%rbp), %rax
ucomisd 0x10(%rax), %xmm0
jne 0xabf7a
jp 0xabf7a
movq -0x10(%rbp), %rax
movsd 0x10(%rax), %xmm0
movq -0x10(%rbp), %rax
ucomisd 0x18(%rax), %xmm0
jne 0xabf7a
jp 0xabf7a
movq -0x8(%rbp), %rdi
leaq 0x14ec4c(%rip), %rsi    # 0x1fabbd
movb $0x0, %al
callq 0x5750
jmp 0xabf8c
movq -0x8(%rbp), %rdi
leaq 0x14ec44(%rip), %rsi    # 0x1fabc9
movb $0x0, %al
callq 0x5750
jmp 0xabfa0
movq -0x8(%rbp), %rdi
leaq 0x14ec3d(%rip), %rsi    # 0x1fabd6
movb $0x0, %al
callq 0x5750
jmp 0xac010
movq -0x10(%rbp), %rax
movsd 0x20(%rax), %xmm0
movq -0x10(%rbp), %rax
ucomisd 0x28(%rax), %xmm0
jne 0xabfba
jp 0xabfba
jmp 0xabfe8
movq -0x10(%rbp), %rax
movsd 0x28(%rax), %xmm0
movq -0x10(%rbp), %rax
ucomisd 0x30(%rax), %xmm0
jne 0xabfd2
jp 0xabfd2
jmp 0xabfe8
movq -0x10(%rbp), %rax
movsd 0x20(%rax), %xmm0
movq -0x10(%rbp), %rax
ucomisd 0x30(%rax), %xmm0
jne 0xabffc
jp 0xabffc
movq -0x8(%rbp), %rdi
leaq 0x14ebf2(%rip), %rsi    # 0x1fabe5
movb $0x0, %al
callq 0x5750
jmp 0xac00e
movq -0x8(%rbp), %rdi
leaq 0x14ebeb(%rip), %rsi    # 0x1fabf2
movb $0x0, %al
callq 0x5750
jmp 0xac010
movq -0x8(%rbp), %rdi
leaq 0x14ebe3(%rip), %rsi    # 0x1fabfe
movb $0x0, %al
callq 0x5750
movq -0x8(%rbp), %rdi
leaq 0x14ebd8(%rip), %rsi    # 0x1fac05
movb $0x0, %al
callq 0x5750
movq -0x8(%rbp), %rdi
leaq 0x14ebe2(%rip), %rsi    # 0x1fac21
movb $0x0, %al
callq 0x5750
movq -0x8(%rbp), %rdi
leaq 0x14ebad(%rip), %rsi    # 0x1fabfe
movb $0x0, %al
callq 0x5750
movq -0x8(%rbp), %rdi
leaq 0x14ebcb(%rip), %rsi    # 0x1fac2e
movb $0x0, %al
callq 0x5750
movq -0x8(%rbp), %rdi
leaq 0x14ebcb(%rip), %rsi    # 0x1fac40
movb $0x0, %al
callq 0x5750
movq -0x8(%rbp), %rdi
leaq 0x14ebd1(%rip), %rsi    # 0x1fac58
movb $0x0, %al
callq 0x5750
movq -0x8(%rbp), %rdi
leaq 0x14ebd3(%rip), %rsi    # 0x1fac6c
movb $0x0, %al
callq 0x5750
movq -0x8(%rbp), %rdi
leaq 0x14ebd5(%rip), %rsi    # 0x1fac80
movb $0x0, %al
callq 0x5750
movq -0x10(%rbp), %rdi
addq $0x3c0, %rdi            # imm = 0x3C0
callq 0xae470
movl %eax, -0x1c(%rbp)
movl $0x1, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0xac295
movq -0x10(%rbp), %rdi
addq $0x3c0, %rdi            # imm = 0x3C0
movslq -0x24(%rbp), %rsi
callq 0xae4a0
movq %rax, %rsi
leaq -0x98(%rbp), %rdi
callq 0xae4e0
leaq -0x98(%rbp), %rdi
addq $0x20, %rdi
callq 0xae590
movl %eax, -0x9c(%rbp)
cmpl $0x2, -0x9c(%rbp)
jle 0xac27b
movq -0x8(%rbp), %rdi
movsd -0x98(%rbp), %xmm0
movsd -0x90(%rbp), %xmm1
movsd -0x88(%rbp), %xmm2
leaq 0x14eb4c(%rip), %rsi    # 0x1fac94
leaq 0x153387(%rip), %rcx    # 0x1ff4d6
movq %rcx, %rdx
movb $0x3, %al
callq 0x5750
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
movl $0x0, -0xa0(%rbp)
movl -0xa0(%rbp), %eax
cmpl -0x9c(%rbp), %eax
jge 0xac279
leaq -0x78(%rbp), %rdi
movslq -0xa0(%rbp), %rsi
callq 0xae5c0
movq %rax, -0x120(%rbp)
jmp 0xac197
movq -0x120(%rbp), %rax
movq 0x10(%rax), %rcx
movq %rcx, -0xb0(%rbp)
movups (%rax), %xmm0
movaps %xmm0, -0xc0(%rbp)
leaq -0x118(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
leaq -0x98(%rbp), %rdx
callq 0xeadf0
jmp 0xac1cf
leaq -0x100(%rbp), %rdi
leaq -0x118(%rbp), %rsi
movsd 0x14b6d3(%rip), %xmm0   # 0x1f78b8
callq 0xea9f0
jmp 0xac1ec
leaq -0xe8(%rbp), %rdi
leaq -0x100(%rbp), %rsi
leaq -0x98(%rbp), %rdx
callq 0xeae50
jmp 0xac208
movq -0x8(%rbp), %rdi
movsd -0xe8(%rbp), %xmm0
movsd -0xe0(%rbp), %xmm1
movsd -0xd8(%rbp), %xmm2
leaq 0x14ea69(%rip), %rsi    # 0x1fac94
leaq 0x152e8a(%rip), %rcx    # 0x1ff0bc
movq %rcx, %rdx
movb $0x3, %al
callq 0x5750
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
movl -0xa0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa0(%rbp)
jmp 0xac16c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc8(%rbp)
movl %eax, -0xcc(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x12650
jmp 0xac29e
jmp 0xac27b
leaq -0x98(%rbp), %rdi
callq 0x12650
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0xac0d3
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
movq -0xc8(%rbp), %rdi
callq 0x58f0
nopw (%rax,%rax)