// File: /workspace/github_cpp_makefile_star2_O1/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 0x62b97
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 0x62ba0
movl %ecx, %ebp
movq %r12, %rax
shlq $0x5, %rax
addq %rax, %rdi
callq 0x4a8cf
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 0x62b8e
shlq $0x5, %rsi
addq %rsi, %rdi
callq 0x4a8cf
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 0x62b8e
shlq $0x5, %rsi
addq %rsi, %rdi
callq 0x4a8cf
movapd %xmm0, %xmm2
leaq 0x30(%rsp), %r12
movq %r12, %rdi
movsd 0x8(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
callq 0x85982
movsd (%r12), %xmm0
movsd 0x8(%r12), %xmm1
movsd 0x10(%r12), %xmm2
leaq 0x90(%rsp), %rdi
movq %rbx, %rsi
callq 0x530d6
leal 0x3(%r15), %eax
movslq %eax, %rsi
movq (%r14), %rdi
movq 0x8(%r14), %rdx
subq %rdi, %rdx
sarq $0x5, %rdx
cmpq %rsi, %rdx
jbe 0x62b8e
shlq $0x5, %rsi
addq %rsi, %rdi
callq 0x4a8cf
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 0x62b8e
shlq $0x5, %rsi
addq %rsi, %rdi
callq 0x4a8cf
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 0x62b8e
movabsq $-0x100000000, %r15     # imm = 0xFFFFFFFF00000000
shlq $0x5, %rsi
addq %rsi, %rdi
callq 0x4a8cf
movapd %xmm0, %xmm2
leaq 0x18(%rsp), %r14
movq %r14, %rdi
movsd 0x8(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
callq 0x85982
movsd (%r14), %xmm0
movsd 0x8(%r14), %xmm1
movsd 0x10(%r14), %xmm2
leaq 0x78(%rsp), %rdi
movq %rbx, %rsi
callq 0x530d6
movl %ebp, %eax
movq %rax, 0x8(%rsp)
testl %ebp, %ebp
jle 0x62930
movl %ebp, 0x10(%rsp)
movl $0x10, %r13d
xorl %r14d, %r14d
movq %r15, %rbp
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 0x62b7d
movsd -0x10(%rax,%r13), %xmm0
movsd -0x8(%rax,%r13), %xmm1
movsd (%rax,%r13), %xmm2
leaq 0x48(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
callq 0x530d6
movq %rbx, %r15
leaq 0x60(%rsp), %rbx
movq %rbx, %rdi
leaq 0x90(%rsp), %rsi
movq %r12, %rdx
callq 0x85da6
movq %rbx, %rdi
movq %r15, %rbx
callq 0x84e36
movabsq $0x100000000, %rax      # imm = 0x100000000
addq %rax, %rbp
movsd 0xf1dbc(%rip), %xmm1    # 0x1546b0
ucomisd %xmm0, %xmm1
setbe %al
ja 0x6290f
incq %r14
addq $0x70, %r13
cmpq 0x8(%rsp), %r14
jb 0x62869
sarq $0x20, %rbp
movsd 0xf1d95(%rip), %xmm1    # 0x1546b0
ucomisd %xmm0, %xmm1
movq $-0x1, %rsi
cmovaq %rbp, %rsi
movl 0x10(%rsp), %ebp
jmp 0x62939
movb $0x1, %al
movq $-0x1, %rsi
testb %al, %al
jne 0x62bac
movq 0x3c0(%rbx), %rax
movq 0x3c8(%rbx), %rdx
subq %rax, %rdx
sarq $0x4, %rdx
movabsq $0x6db6db6db6db6db7, %rcx # imm = 0x6DB6DB6DB6DB6DB7
imulq %rcx, %rdx
cmpq %rsi, %rdx
jbe 0x62b8e
imulq $0x70, %rsi, %rcx
leaq (%rax,%rcx), %rdi
addq $0x20, %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
movabsq $-0x100000000, %r15     # imm = 0xFFFFFFFF00000000
je 0x629a7
movq 0x28(%rsp), %rax
movq %rax, 0x10(%rsi)
movupd 0x18(%rsp), %xmm0
movupd %xmm0, (%rsi)
addq $0x18, 0x8(%rdi)
jmp 0x629b1
leaq 0x18(%rsp), %rdx
callq 0x6a5be
testl %ebp, %ebp
jle 0x62a7c
movl $0x10, %r13d
xorl %r14d, %r14d
leaq 0x48(%rsp), %rbp
leaq 0x60(%rsp), %r12
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 0x62b7d
movsd -0x10(%rax,%r13), %xmm0
movsd -0x8(%rax,%r13), %xmm1
movsd (%rax,%r13), %xmm2
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x530d6
movq %r12, %rdi
leaq 0x78(%rsp), %rsi
movq %rbp, %rdx
callq 0x85da6
movq %r12, %rdi
callq 0x84e36
movabsq $0x100000000, %rax      # imm = 0x100000000
addq %rax, %r15
movsd 0xf1c6c(%rip), %xmm1    # 0x1546b0
ucomisd %xmm0, %xmm1
setbe %al
ja 0x62a5f
incq %r14
addq $0x70, %r13
cmpq 0x8(%rsp), %r14
jb 0x629cc
sarq $0x20, %r15
movsd 0xf1c45(%rip), %xmm1    # 0x1546b0
ucomisd %xmm0, %xmm1
movq $-0x1, %rsi
cmovaq %r15, %rsi
jmp 0x62a85
movb $0x1, %al
movq $-0x1, %rsi
testb %al, %al
je 0x62ab6
movq 0x3e0(%rbx), %rsi
cmpq 0x3e8(%rbx), %rsi
je 0x62b12
movq 0x28(%rsp), %rax
movq %rax, 0x10(%rsi)
movupd 0x18(%rsp), %xmm0
movupd %xmm0, (%rsi)
addq $0x18, 0x3e0(%rbx)
jmp 0x62b23
movq 0x3c0(%rbx), %rax
movq 0x3c8(%rbx), %rdx
subq %rax, %rdx
sarq $0x4, %rdx
movabsq $0x6db6db6db6db6db7, %rcx # imm = 0x6DB6DB6DB6DB6DB7
imulq %rcx, %rdx
cmpq %rsi, %rdx
jbe 0x62b8e
imulq $0x70, %rsi, %rcx
leaq (%rax,%rcx), %rdi
addq $0x20, %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x62b61
movq 0x40(%rsp), %rax
movq %rax, 0x10(%rsi)
movupd 0x30(%rsp), %xmm0
movupd %xmm0, (%rsi)
addq $0x18, 0x8(%rdi)
jmp 0x62b6b
leaq 0x3d8(%rbx), %rdi
leaq 0x18(%rsp), %rdx
callq 0x6a5be
movq 0x3f8(%rbx), %rsi
cmpq 0x400(%rbx), %rsi
je 0x62b50
movq 0x40(%rsp), %rax
movq %rax, 0x10(%rsi)
movupd 0x30(%rsp), %xmm0
movupd %xmm0, (%rsi)
addq $0x18, 0x3f8(%rbx)
jmp 0x62b6b
addq $0x3f0, %rbx            # imm = 0x3F0
leaq 0x30(%rsp), %rdx
movq %rbx, %rdi
jmp 0x62b66
leaq 0x30(%rsp), %rdx
callq 0x6a5be
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xecb21(%rip), %rdi     # 0x14f6a5
movq %r14, %rsi
xorl %eax, %eax
callq 0x4630
leaq 0xecb10(%rip), %rdi     # 0x14f6a5
jmp 0x62b87
leaq 0xf3522(%rip), %rdi     # 0x1560c0
jmp 0x62bb3
leaq 0xecafe(%rip), %rdi     # 0x14f6a5
movq %r12, %rsi
jmp 0x62b87
leaq 0xf356c(%rip), %rdi     # 0x15611f
callq 0x4660
movl $0x1, %edi
callq 0x710c