// File: /workspace/github_cpp_makefile_star2_O3/Luthaf[P]zeopp/networkstorage.cc
// Function: parse_edge(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>*, int, ATOM_NETWORK*, int, bool)
void parse_edge(vector<string> *token, int first_index, ATOM_NETWORK *cell, int atom_index, bool uses_node) {
  bool verbose = false;
  if(!uses_node) {
    printf("NET ERROR: parsed unexpected \"edge\" field, when edges where expected to be provided with atoms\n");
    exit(EXIT_FAILURE);
  }
  XYZ start(convertToDouble(token->at(first_index+0)), convertToDouble(token->at(first_index+1)), convertToDouble(token->at(first_index+2)));
  XYZ start_xyz = cell->abc_to_xyz_returning_XYZ(start);
  XYZ end(convertToDouble(token->at(first_index+3)), convertToDouble(token->at(first_index+4)), convertToDouble(token->at(first_index+5)));
  XYZ end_xyz = cell->abc_to_xyz_returning_XYZ(end);
  //1) detect which vertex it starts at
  int v_index = -1;
  for(int i=0; i<atom_index && v_index==-1; i++) {
    if((start_xyz-cell->abc_to_xyz_returning_XYZ(cell->vertices.at(i).abc)).magnitude()<DISTANCE_TOLERANCE) { //match to parsed vertex
      v_index = i;
    }
  }
  if(v_index==-1) {
    printf("NET ERROR: could not match this edge start position to a previously parsed vertex\n");
    exit(EXIT_FAILURE);
  }
  //2) update the cell accordingly
  cell->vertices.at(v_index).edges.push_back(end);
  if(verbose) printf("parsed edge assigned to vertex %d at %.3f %.3f %.3f\n", v_index+1, end.x, end.y, end.z);
  //3) detect which vertex it ends at
  v_index = -1;
  for(int i=0; i<atom_index && v_index==-1; i++) {
    if((end_xyz-cell->abc_to_xyz_returning_XYZ(cell->vertices.at(i).abc)).magnitude()<DISTANCE_TOLERANCE) { //match to parsed vertex
      v_index = i;
    }
  }
  if(v_index==-1) {
/*
    printf("ERROR: could not match this edge end position to a previously parsed vertex\n");
    exit(EXIT_FAILURE);
*/
    if(verbose) printf("DEBUG: could not match this edge end position to a previously parsed vertex - creating an orphan edge to temporarily store this start/end until its true position by symmetry is known\n");
    //this is a specific scenario - the cgd file contains a definition of an edge, for which the end point is not a basic vertex - normally this is the default case, but for this cgd format the edges are not given exhaustively and so we need to know of each edge in both directions in order to construct the complete net including symmetry operations upon these edges
    //accordingly, we need to store this orphan edge, by saving its start and end in the cell as an orphan - this vertex is the symmetry image of some basic vertex, and we will assign this orphaned edge to that vertex when we know it
    cell->orphan_edge_starts.push_back(end);
    cell->orphan_edge_ends.push_back(start);
  } else {
    //4) update the cell accordingly
    cell->vertices.at(v_index).edges.push_back(start);
    if(verbose) printf("parsed edge assigned to vertex %d at %.3f %.3f %.3f\n", v_index+1, start.x, start.y, start.z);
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
testl %r8d, %r8d
je 0x62366
movq %rdx, %rbx
movl %esi, %r15d
movq %rdi, %r14
movslq %esi, %r12
movq (%rdi), %rdi
movq 0x8(%r14), %rdx
subq %rdi, %rdx
sarq $0x5, %rdx
cmpq %r12, %rdx
jbe 0x62337
movl %ecx, %ebp
movq %r12, %rax
shlq $0x5, %rax
addq %rax, %rdi
callq 0x4a5c7
movsd %xmm0, 0x8(%rsp)
incl %r12d
movslq %r12d, %rsi
movq (%r14), %rdi
movq 0x8(%r14), %rdx
subq %rdi, %rdx
sarq $0x5, %rdx
cmpq %rsi, %rdx
jbe 0x62354
shlq $0x5, %rsi
addq %rsi, %rdi
callq 0x4a5c7
movsd %xmm0, 0x10(%rsp)
leal 0x2(%r15), %eax
movslq %eax, %rsi
movq (%r14), %rdi
movq 0x8(%r14), %rdx
subq %rdi, %rdx
sarq $0x5, %rdx
cmpq %rsi, %rdx
jbe 0x62354
shlq $0x5, %rsi
addq %rsi, %rdi
callq 0x4a5c7
movapd %xmm0, %xmm2
leaq 0x30(%rsp), %r12
movq %r12, %rdi
movsd 0x8(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
callq 0x84364
movsd (%r12), %xmm0
movsd 0x8(%r12), %xmm1
movsd 0x10(%r12), %xmm2
leaq 0x90(%rsp), %rdi
movq %rbx, %rsi
callq 0x52dd8
leal 0x3(%r15), %eax
movslq %eax, %rsi
movq (%r14), %rdi
movq 0x8(%r14), %rdx
subq %rdi, %rdx
sarq $0x5, %rdx
cmpq %rsi, %rdx
jbe 0x62354
shlq $0x5, %rsi
addq %rsi, %rdi
callq 0x4a5c7
movsd %xmm0, 0x8(%rsp)
leal 0x4(%r15), %eax
movslq %eax, %rsi
movq (%r14), %rdi
movq 0x8(%r14), %rdx
subq %rdi, %rdx
sarq $0x5, %rdx
cmpq %rsi, %rdx
jbe 0x62354
shlq $0x5, %rsi
addq %rsi, %rdi
callq 0x4a5c7
movsd %xmm0, 0x10(%rsp)
addl $0x5, %r15d
movslq %r15d, %rsi
movq (%r14), %rdi
movq 0x8(%r14), %rdx
subq %rdi, %rdx
sarq $0x5, %rdx
cmpq %rsi, %rdx
jbe 0x62354
shlq $0x5, %rsi
addq %rsi, %rdi
callq 0x4a5c7
movapd %xmm0, %xmm2
leaq 0x18(%rsp), %r14
movq %r14, %rdi
movsd 0x8(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
callq 0x84364
movsd (%r14), %xmm0
movsd 0x8(%r14), %xmm1
movsd 0x10(%r14), %xmm2
leaq 0x78(%rsp), %rdi
movq %rbx, %rsi
callq 0x52dd8
testl %ebp, %ebp
jle 0x6235d
movabsq $-0x100000000, %r15     # imm = 0xFFFFFFFF00000000
movl %ebp, 0x10(%rsp)
movl %ebp, %eax
movq %rax, 0x8(%rsp)
movl $0x10, %r13d
xorl %r12d, %r12d
movq 0x3c0(%rbx), %rax
movq 0x3c8(%rbx), %rdx
subq %rax, %rdx
sarq $0x4, %rdx
movabsq $0x6db6db6db6db6db7, %rcx # imm = 0x6DB6DB6DB6DB6DB7
imulq %rcx, %rdx
cmpq %r12, %rdx
jbe 0x62337
movsd -0x10(%rax,%r13), %xmm0
movsd -0x8(%rax,%r13), %xmm1
movsd (%rax,%r13), %xmm2
leaq 0x48(%rsp), %rbp
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x52dd8
movq %rbx, %r14
leaq 0x60(%rsp), %rbx
movq %rbx, %rdi
leaq 0x90(%rsp), %rsi
movq %rbp, %rdx
callq 0x8461e
movq %rbx, %rdi
movq %r14, %rbx
callq 0x8398c
movabsq $0x100000000, %rax      # imm = 0x100000000
addq %rax, %r15
movsd 0xf0670(%rip), %xmm1    # 0x152758
ucomisd %xmm0, %xmm1
ja 0x62100
incq %r12
addq $0x70, %r13
cmpq 0x8(%rsp), %r12
jb 0x6205d
movsd 0xf0650(%rip), %xmm1    # 0x152758
ucomisd %xmm0, %xmm1
movl 0x10(%rsp), %ebp
jbe 0x6235d
sarq $0x20, %r15
movq 0x3c0(%rbx), %rax
movq 0x3c8(%rbx), %rdx
subq %rax, %rdx
sarq $0x4, %rdx
movabsq $0x6db6db6db6db6db7, %rcx # imm = 0x6DB6DB6DB6DB6DB7
imulq %rcx, %rdx
cmpq %r15, %rdx
jbe 0x62343
imulq $0x70, %r15, %rcx
leaq (%rax,%rcx), %rdi
addq $0x20, %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x62176
movq 0x28(%rsp), %rax
movq %rax, 0x10(%rsi)
movupd 0x18(%rsp), %xmm0
movupd %xmm0, (%rsi)
addq $0x18, 0x8(%rdi)
jmp 0x62180
leaq 0x18(%rsp), %rdx
callq 0x69b82
movabsq $-0x100000000, %r14     # imm = 0xFFFFFFFF00000000
testl %ebp, %ebp
jle 0x6223f
movl $0x10, %ebp
xorl %r15d, %r15d
leaq 0x48(%rsp), %r12
leaq 0x60(%rsp), %r13
movq 0x3c0(%rbx), %rax
movq 0x3c8(%rbx), %rdx
subq %rax, %rdx
sarq $0x4, %rdx
movabsq $0x6db6db6db6db6db7, %rcx # imm = 0x6DB6DB6DB6DB6DB7
imulq %rcx, %rdx
cmpq %r15, %rdx
jbe 0x62343
movsd -0x10(%rax,%rbp), %xmm0
movsd -0x8(%rax,%rbp), %xmm1
movsd (%rax,%rbp), %xmm2
movq %r12, %rdi
movq %rbx, %rsi
callq 0x52dd8
movq %r13, %rdi
leaq 0x78(%rsp), %rsi
movq %r12, %rdx
callq 0x8461e
movq %r13, %rdi
callq 0x8398c
movabsq $0x100000000, %rax      # imm = 0x100000000
addq %rax, %r14
movsd 0xf053f(%rip), %xmm1    # 0x152758
ucomisd %xmm0, %xmm1
ja 0x62231
incq %r15
addq $0x70, %rbp
cmpq 0x8(%rsp), %r15
jb 0x621a4
movsd 0xf051f(%rip), %xmm1    # 0x152758
ucomisd %xmm0, %xmm1
ja 0x6226c
movq 0x3e0(%rbx), %rsi
cmpq 0x3e8(%rbx), %rsi
je 0x622cc
movq 0x28(%rsp), %rax
movq %rax, 0x10(%rsi)
movupd 0x18(%rsp), %xmm0
movupd %xmm0, (%rsi)
addq $0x18, 0x3e0(%rbx)
jmp 0x622dd
sarq $0x20, %r14
movq 0x3c0(%rbx), %rax
movq 0x3c8(%rbx), %rdx
subq %rax, %rdx
sarq $0x4, %rdx
movabsq $0x6db6db6db6db6db7, %rcx # imm = 0x6DB6DB6DB6DB6DB7
imulq %rcx, %rdx
cmpq %r14, %rdx
jbe 0x6237c
imulq $0x70, %r14, %rcx
leaq (%rax,%rcx), %rdi
addq $0x20, %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x6231b
movq 0x40(%rsp), %rax
movq %rax, 0x10(%rsi)
movupd 0x30(%rsp), %xmm0
movupd %xmm0, (%rsi)
addq $0x18, 0x8(%rdi)
jmp 0x62325
leaq 0x3d8(%rbx), %rdi
leaq 0x18(%rsp), %rdx
callq 0x69b82
movq 0x3f8(%rbx), %rsi
cmpq 0x400(%rbx), %rsi
je 0x6230a
movq 0x40(%rsp), %rax
movq %rax, 0x10(%rsi)
movupd 0x30(%rsp), %xmm0
movupd %xmm0, (%rsi)
addq $0x18, 0x3f8(%rbx)
jmp 0x62325
addq $0x3f0, %rbx            # imm = 0x3F0
leaq 0x30(%rsp), %rdx
movq %rbx, %rdi
jmp 0x62320
leaq 0x30(%rsp), %rdx
callq 0x69b82
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xeb3b7(%rip), %rdi     # 0x14d6f5
movq %r12, %rsi
jmp 0x6234d
leaq 0xeb3ab(%rip), %rdi     # 0x14d6f5
movq %r15, %rsi
xorl %eax, %eax
callq 0x4630
leaq 0xeb39a(%rip), %rdi     # 0x14d6f5
jmp 0x6234d
leaq 0xf1eab(%rip), %rdi     # 0x15420f
jmp 0x6236d
leaq 0xf1e43(%rip), %rdi     # 0x1541b0
callq 0x4660
movl $0x1, %edi
callq 0x72bc
leaq 0xeb372(%rip), %rdi     # 0x14d6f5
movq %r14, %rsi
jmp 0x6234d