// File: /workspace/github_cpp_makefile_star2_O3/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, %rbx
movq %rdi, %r14
leaq 0xee87e(%rip), %rdi     # 0x153a67
movl $0xb3, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x4850
movsd 0x8(%rbx), %xmm0
leaq 0xee914(%rip), %rsi     # 0x153b1b
movq %r14, %rdi
movb $0x1, %al
callq 0x45f0
movsd 0x10(%rbx), %xmm0
leaq 0xee917(%rip), %rsi     # 0x153b34
movq %r14, %rdi
movb $0x1, %al
callq 0x45f0
movsd 0x18(%rbx), %xmm0
leaq 0xee91a(%rip), %rsi     # 0x153b4d
movq %r14, %rdi
movb $0x1, %al
callq 0x45f0
movsd 0x20(%rbx), %xmm0
leaq 0xee91d(%rip), %rsi     # 0x153b66
movq %r14, %rdi
movb $0x1, %al
callq 0x45f0
movsd 0x28(%rbx), %xmm0
leaq 0xee923(%rip), %rsi     # 0x153b82
movq %r14, %rdi
movb $0x1, %al
callq 0x45f0
movsd 0x30(%rbx), %xmm0
leaq 0xee928(%rip), %rsi     # 0x153b9d
movq %r14, %rdi
movb $0x1, %al
callq 0x45f0
leaq 0xee933(%rip), %rdi     # 0x153bb9
movl $0x24, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x4850
leaq 0xee93f(%rip), %rdi     # 0x153bde
movl $0x1f, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x4850
leaq 0xe9317(%rip), %rdi     # 0x14e5cf
movl $0x18, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x4850
movsd 0x20(%rbx), %xmm0
movq %rbx, (%rsp)
movsd 0x28(%rbx), %xmm1
ucomisd 0xe8840(%rip), %xmm0    # 0x14db20
jne 0x65341
jp 0x65341
ucomisd 0xe8834(%rip), %xmm1    # 0x14db20
jne 0x65341
jp 0x65341
movq (%rsp), %rax
movsd 0x30(%rax), %xmm2
ucomisd 0xe881f(%rip), %xmm2    # 0x14db20
jne 0x65341
jp 0x65341
movq (%rsp), %rax
movsd 0x8(%rax), %xmm0
movsd 0x10(%rax), %xmm2
ucomisd %xmm2, %xmm0
movsd 0x18(%rax), %xmm1
jne 0x656fe
jp 0x656fe
ucomisd %xmm1, %xmm2
jne 0x6571f
jp 0x6571f
leaq 0xee8bf(%rip), %rdi     # 0x153bfe
jmp 0x65377
ucomisd %xmm1, %xmm0
jne 0x65357
jp 0x65357
leaq 0xee8d6(%rip), %rdi     # 0x153c26
movl $0xc, %esi
jmp 0x6537c
movq (%rsp), %rax
movsd 0x30(%rax), %xmm2
ucomisd %xmm2, %xmm1
jne 0x65368
jnp 0x65349
ucomisd %xmm2, %xmm0
jne 0x65370
jnp 0x65349
leaq 0xee8bc(%rip), %rdi     # 0x153c33
movl $0xb, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x4850
leaq 0xee8af(%rip), %rbx     # 0x153c3f
movl $0x6, %esi
movl $0x1, %edx
movq %rbx, %rdi
movq %r14, %rcx
callq 0x4850
leaq 0xee89a(%rip), %rdi     # 0x153c46
movl $0x1b, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x4850
leaq 0xee89d(%rip), %rdi     # 0x153c62
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 0xee87c(%rip), %rdi     # 0x153c6f
movl $0x11, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x4850
leaq 0xee875(%rip), %rdi     # 0x153c81
movl $0x17, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x4850
leaq 0xee874(%rip), %rdi     # 0x153c99
movl $0x13, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x4850
leaq 0xee86f(%rip), %rdi     # 0x153cad
movl $0x13, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x4850
leaq 0xee86a(%rip), %rdi     # 0x153cc1
movl $0x13, %esi
movl $0x1, %edx
movq %r14, 0x10(%rsp)
movq %r14, %rcx
callq 0x4850
movq (%rsp), %rax
movq 0x3c8(%rax), %rcx
subq 0x3c0(%rax), %rcx
sarq $0x4, %rcx
movabsq $0x6db6db6db6db6db7, %rax # imm = 0x6DB6DB6DB6DB6DB7
imulq %rax, %rcx
movq %rcx, 0x8(%rsp)
testl %ecx, %ecx
jle 0x656ec
movq 0x8(%rsp), %rax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %rax, 0x8(%rsp)
xorl %ebp, %ebp
leaq 0x20(%rsp), %rbx
leaq 0xe0(%rsp), %r14
leaq 0xf1d80(%rip), %r15     # 0x157244
movq (%rsp), %rax
movq 0x3c0(%rax), %r12
movq 0x3c8(%rax), %rdx
subq %r12, %rdx
sarq $0x4, %rdx
movabsq $0x6db6db6db6db6db7, %rax # imm = 0x6DB6DB6DB6DB6DB7
imulq %rax, %rdx
cmpq %rbp, %rdx
jbe 0x6573c
imulq $0x70, %rbp, %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 0x679ba
leaq (%r12,%r13), %rsi
addq $0x38, %rsi
leaq 0x58(%rsp), %rdi
callq 0x679ba
movq %rbp, 0x18(%rsp)
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 0xf3ce
movq 0x48(%rsp), %r13
subq 0x40(%rsp), %r13
sarq $0x3, %r13
movabsq $-0x5555555555555555, %rax # imm = 0xAAAAAAAAAAAAAAAB
imulq %rax, %r13
cmpl $0x3, %r13d
jl 0x65689
movsd 0x20(%rsp), %xmm0
movsd 0x28(%rsp), %xmm1
movsd 0x30(%rsp), %xmm2
movq 0x10(%rsp), %rdi
leaq 0xee733(%rip), %rsi     # 0x153cd5
leaq 0xf20b5(%rip), %rcx     # 0x15765e
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 0x6572b
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 0x8461e
movq %r14, %rdi
leaq 0xc8(%rsp), %rsi
movsd 0xed183(%rip), %xmm0    # 0x1527b0
callq 0x84416
leaq 0x98(%rsp), %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x84642
movsd 0x98(%rsp), %xmm0
movsd 0xa0(%rsp), %xmm1
movsd 0xa8(%rsp), %xmm2
movq 0x10(%rsp), %rdi
leaq 0xee669(%rip), %rsi     # 0x153cd5
movq %r15, %rdx
movq %r15, %rcx
movb $0x3, %al
callq 0x45f0
incq %r12
addq $0x18, %rbp
cmpq %r12, %r13
jne 0x655bf
movq 0x70(%rsp), %rdi
leaq 0x80(%rsp), %rax
cmpq %rax, %rdi
je 0x656ab
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x4470
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
movq 0x18(%rsp), %rbp
je 0x656c7
movq 0x68(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x656de
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
incq %rbp
cmpq 0x8(%rsp), %rbp
jne 0x654c4
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
ucomisd %xmm1, %xmm2
jne 0x65706
jnp 0x6571f
ucomisd %xmm1, %xmm0
jne 0x6570e
jnp 0x6571f
leaq 0xee502(%rip), %rdi     # 0x153c17
movl $0xe, %esi
jmp 0x6537c
leaq 0xee4e4(%rip), %rdi     # 0x153c0a
jmp 0x65350
leaq 0xe7fc3(%rip), %rdi     # 0x14d6f5
movq %r12, %rsi
xorl %eax, %eax
callq 0x4630
leaq 0xe7fb2(%rip), %rdi     # 0x14d6f5
movq %rbp, %rsi
xorl %eax, %eax
callq 0x4630
movq %rax, %rbx
jmp 0x6576c
movq %rax, %rbx
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x6576c
movq 0x68(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x65794
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
jmp 0x65794
jmp 0x65787
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x670a4
movq %rbx, %rdi
callq 0x4780