// File: /workspace/github_cpp_makefile_star2_O2/Luthaf[P]zeopp/networkstorage.cc
// Function: add_2c_vertices_and_normal_edges(ATOM_NETWORK*)
void add_2c_vertices_and_normal_edges(ATOM_NETWORK *cell) { //just add the 2-c vertices and normal edges - dummy edges are handled later, once we know all the vertices by symmetry, and can make a better guess of the orthogonal direction of the 2-c vertices
  bool verbose = false;
  if(verbose) printf("augmenting underlying net with 2-c vertices\n");
  int num_v = cell->vertices.size();
  vector<XYZ> candidates;
  vector<XYZ> from_abc_vector, to_abc_vector; //, orthogonal_abc_vector;
  for(int i=0; i<num_v; i++) {
    XYZ v_abc = cell->vertices.at(i).abc;
    XYZ v_xyz = cell->abc_to_xyz_returning_XYZ(v_abc);
    int num_e = cell->vertices.at(i).edges.size();
    for(int j=0; j<num_e; j++) {
      XYZ e_abc = cell->vertices.at(i).edges.at(j);
      XYZ e_xyz = cell->abc_to_xyz_returning_XYZ(e_abc);
      XYZ this_edge_vector = get_vector_from_to(v_xyz, e_xyz);
      double this_edge_length = this_edge_vector.magnitude();
      XYZ this_candidate_abc = v_abc+(e_abc-v_abc).scale(0.5);
      XYZ this_candidate_xyz = cell->abc_to_xyz_returning_XYZ(this_candidate_abc);
      candidates.push_back(this_candidate_abc);
      from_abc_vector.push_back(v_abc);
      to_abc_vector.push_back(e_abc);
      //forget dummy edges for now - they are handled later
    }
  }
  int num_candidates = candidates.size();
  //find and remove any duplicates
  vector<bool> keep_vector;
  int num_new_vertices = 0;
  for(int i=0; i<num_candidates; i++) {
    //check against all previous candidates to see if we should reject this one
    bool keep = true;
    for(int j=0; j<i && keep; j++) {
      if(overlaps_abc(candidates.at(i),candidates.at(j),cell)) keep = false;
    }
    keep_vector.push_back(keep);
    if(keep) num_new_vertices++;
  }
  if(num_new_vertices>0) {
    //halve the edge lengths of all previous vertices to match these new short edges!
    for(int i=0; i<num_v; i++) {
      XYZ v_abc = cell->vertices.at(i).abc;
      int num_e = cell->vertices.at(i).edges.size();
      for(int j=0; j<num_e; j++) {
        XYZ e_abc = cell->vertices.at(i).edges.at(j);
        XYZ new_e_abc = v_abc+(e_abc-v_abc).scale(0.5);
        cell->vertices.at(i).edges.at(j) = new_e_abc;
      }
    }
    //set up final vertices
    for(int i=0; i<num_candidates; i++) {
      if(keep_vector.at(i)) {
        if(verbose) printf("accepted candidate ID %d: %.3f %.3f %.3f\n", i, candidates.at(i).x, candidates.at(i).y, candidates.at(i).z);
        VERTEX v(candidates.at(i).x, candidates.at(i).y, candidates.at(i).z);
        v.expected_edges = 2; //it is a 2-c vertex
        v.edges.push_back(from_abc_vector.at(i));
        v.edges.push_back(to_abc_vector.at(i));
        cell->vertices.push_back(v);
      }
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1f8, %rsp            # imm = 0x1F8
movq %rdi, %r12
leaq 0x3c0(%rdi), %r14
movq 0x3c8(%rdi), %rax
subq 0x3c0(%rdi), %rax
pushq $0x70
popq %rcx
cqto
idivq %rcx
leaq 0x70(%rsp), %rcx
andq $0x0, 0x10(%rcx)
xorps %xmm0, %xmm0
movaps %xmm0, (%rcx)
leaq 0xc0(%rsp), %rcx
movaps %xmm0, (%rcx)
andq $0x0, 0x10(%rcx)
leaq 0xa0(%rsp), %rcx
andq $0x0, 0x10(%rcx)
xorl %edx, %edx
testl %eax, %eax
cmovlel %edx, %eax
movq %rax, 0x40(%rsp)
movaps %xmm0, (%rcx)
leaq 0x1e0(%rsp), %rbx
leaq 0x1b0(%rsp), %rbp
xorl %r15d, %r15d
movq %r14, 0x38(%rsp)
cmpq 0x40(%rsp), %r15
je 0x490e1
movq %r14, %rdi
movq %r15, %rsi
callq 0x4b63c
movq 0x10(%rax), %rcx
movq %rcx, 0x130(%rsp)
movups (%rax), %xmm0
movaps %xmm0, 0x120(%rsp)
leaq 0xd8(%rsp), %rdi
movq %r12, %rsi
leaq 0x120(%rsp), %rdx
callq 0x3f1b2
movq %r14, %rdi
movq %r15, 0x30(%rsp)
movq %r15, %rsi
callq 0x4b63c
movq 0x28(%rax), %rcx
subq 0x20(%rax), %rcx
movq %rcx, %rax
cqto
pushq $0x18
popq %rcx
idivq %rcx
movq %rax, %r15
testl %r15d, %r15d
movl $0x0, %eax
cmovlel %eax, %r15d
xorl %r14d, %r14d
cmpq %r14, %r15
je 0x490cf
movq 0x38(%rsp), %rdi
movq 0x30(%rsp), %rsi
callq 0x4b63c
addq $0x20, %rax
movq %rax, %rdi
movq %r14, %rsi
callq 0x4b6d6
movq 0x10(%rax), %rcx
movq %rcx, 0x60(%rsp)
movups (%rax), %xmm0
movaps %xmm0, 0x50(%rsp)
leaq 0x88(%rsp), %rdi
movq %r12, %rsi
leaq 0x50(%rsp), %rdx
callq 0x3f1b2
movq 0x98(%rsp), %rax
movq %rax, 0x28(%rsp)
movups 0x88(%rsp), %xmm0
movups %xmm0, 0x18(%rsp)
movq 0xe8(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0xd8(%rsp), %xmm0
movups %xmm0, (%rsp)
leaq 0x1c8(%rsp), %r13
movq %r13, %rdi
callq 0x64351
movq %r13, %rdi
callq 0x63758
leaq 0x198(%rsp), %rdi
leaq 0x50(%rsp), %rsi
leaq 0x120(%rsp), %rdx
callq 0x642ae
movq %rbx, %rdi
leaq 0x198(%rsp), %rsi
movsd 0xb2fcb(%rip), %xmm0    # 0xfc038
callq 0x640ba
movq %rbp, %rdi
leaq 0x120(%rsp), %rsi
movq %rbx, %rdx
callq 0x642d2
movq %rbx, %rdi
movq %r12, %rsi
movq %rbp, %rdx
callq 0x3f1b2
leaq 0x70(%rsp), %rdi
movq %rbp, %rsi
callq 0x4beaa
leaq 0xc0(%rsp), %rdi
leaq 0x120(%rsp), %rsi
callq 0x4beaa
leaq 0xa0(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x4beaa
incq %r14
jmp 0x48fa8
movq 0x30(%rsp), %r15
incq %r15
movq 0x38(%rsp), %r14
jmp 0x48f2e
leaq 0x70(%rsp), %rbx
movq 0x8(%rbx), %rax
subq (%rbx), %rax
cqto
pushq $0x18
popq %rcx
idivq %rcx
leaq 0xd8(%rsp), %rcx
andq $0x0, (%rcx)
andl $0x0, 0x8(%rcx)
andq $0x0, 0x10(%rcx)
andl $0x0, 0x18(%rcx)
andq $0x0, 0x20(%rcx)
xorl %ecx, %ecx
testl %eax, %eax
cmovlel %ecx, %eax
movq %rax, 0x48(%rsp)
xorl %r15d, %r15d
xorl %ecx, %ecx
cmpq 0x48(%rsp), %r15
je 0x491e1
movl %ecx, 0x30(%rsp)
movb $0x1, %r14b
xorl %r13d, %r13d
movzbl %r14b, %ebp
cmpq %r15, %r13
jae 0x491b9
testb $0x1, %r14b
je 0x491b9
movq %rbx, %rdi
movq %r15, %rsi
callq 0x4b6d6
movq 0x10(%rax), %rcx
movq %rcx, 0x110(%rsp)
movups (%rax), %xmm0
movaps %xmm0, 0x100(%rsp)
movq %rbx, %rdi
movq %r13, %rsi
callq 0x4b6d6
movq 0x10(%rax), %rcx
movq %rcx, 0x28(%rsp)
movups (%rax), %xmm0
movups %xmm0, 0x18(%rsp)
movq 0x110(%rsp), %rax
movq %rax, 0x10(%rsp)
movaps 0x100(%rsp), %xmm0
movups %xmm0, (%rsp)
movq %r12, %rdi
callq 0x436e3
testb %al, %al
movl $0x0, %eax
cmovnel %eax, %ebp
incq %r13
movl %ebp, %r14d
jmp 0x49139
andl $0x1, %ebp
leaq 0xd8(%rsp), %rdi
movl %ebp, %esi
callq 0xa8f6
andb $0x1, %r14b
movzbl %r14b, %eax
movl 0x30(%rsp), %ecx
addl %eax, %ecx
incq %r15
jmp 0x49124
testl %ecx, %ecx
je 0x49403
leaq 0x1b0(%rsp), %rbx
leaq 0x120(%rsp), %r12
leaq 0x1c8(%rsp), %r13
xorl %r15d, %r15d
cmpq 0x40(%rsp), %r15
je 0x49314
movq 0x38(%rsp), %r14
movq %r14, %rdi
movq %r15, %rsi
callq 0x4b63c
movq 0x10(%rax), %rcx
movq %rcx, 0x130(%rsp)
movups (%rax), %xmm0
movaps %xmm0, 0x120(%rsp)
movq %r14, %rdi
movq %r15, %rsi
callq 0x4b63c
movq 0x28(%rax), %rcx
subq 0x20(%rax), %rcx
movq %rcx, %rax
cqto
pushq $0x18
popq %rcx
idivq %rcx
movq %rax, %r14
testl %r14d, %r14d
movl $0x0, %eax
cmovlel %eax, %r14d
xorl %ebp, %ebp
cmpq %rbp, %r14
je 0x4930c
movq 0x38(%rsp), %rdi
movq %r15, %rsi
callq 0x4b63c
addq $0x20, %rax
movq %rax, %rdi
movq %rbp, %rsi
callq 0x4b6d6
movq 0x10(%rax), %rcx
movq %rcx, 0x60(%rsp)
movups (%rax), %xmm0
movaps %xmm0, 0x50(%rsp)
movq %rbx, %rdi
leaq 0x50(%rsp), %rsi
movq %r12, %rdx
callq 0x642ae
movq %r13, %rdi
movq %rbx, %rsi
movsd 0xb2d7f(%rip), %xmm0    # 0xfc038
callq 0x640ba
leaq 0x88(%rsp), %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x642d2
movq 0x38(%rsp), %rdi
movq %r15, %rsi
callq 0x4b63c
addq $0x20, %rax
movq %rax, %rdi
movq %rbp, %rsi
callq 0x4b6d6
movq 0x98(%rsp), %rcx
movq %rcx, 0x10(%rax)
movups 0x88(%rsp), %xmm0
movups %xmm0, (%rax)
incq %rbp
jmp 0x49265
incq %r15
jmp 0x49204
leaq 0x140(%rsp), %rbx
xorl %r14d, %r14d
leaq 0xd8(%rsp), %r15
leaq 0x70(%rsp), %r12
leaq 0x120(%rsp), %r13
leaq 0xa0(%rsp), %rbp
cmpq %r14, 0x48(%rsp)
je 0x49403
movq %r15, %rdi
movq %r14, %rsi
callq 0xaba4
testq %rdx, (%rax)
je 0x493fb
movq %r12, %rdi
movq %r14, %rsi
callq 0x4b6d6
movsd (%rax), %xmm0
movsd %xmm0, 0x30(%rsp)
movq %r12, %rdi
movq %r14, %rsi
callq 0x4b6d6
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0x40(%rsp)
movq %r12, %rdi
movq %r14, %rsi
callq 0x4b6d6
movsd 0x10(%rax), %xmm2
movq %r13, %rdi
movsd 0x30(%rsp), %xmm0
movsd 0x40(%rsp), %xmm1
callq 0x75d1c
movl $0x2, 0x138(%rsp)
leaq 0xc0(%rsp), %rdi
movq %r14, %rsi
callq 0x4b6d6
movq %rbx, %rdi
movq %rax, %rsi
callq 0x4beaa
movq %rbp, %rdi
movq %r14, %rsi
callq 0x4b6d6
movq %rbx, %rdi
movq %rax, %rsi
callq 0x4beaa
movq 0x38(%rsp), %rdi
movq %r13, %rsi
callq 0x4bed0
movq %r13, %rdi
callq 0xb1ba
incq %r14
jmp 0x4933c
leaq 0xd8(%rsp), %rdi
callq 0xa976
leaq 0xa0(%rsp), %rdi
callq 0xb132
leaq 0xc0(%rsp), %rdi
callq 0xb132
leaq 0x70(%rsp), %rdi
callq 0xb132
addq $0x1f8, %rsp            # imm = 0x1F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x49476
jmp 0x49476
jmp 0x49476
jmp 0x49476
jmp 0x4948a
jmp 0x4948a
jmp 0x4948a
jmp 0x49476
movq %rax, %rbx
leaq 0x120(%rsp), %rdi
callq 0xb1ba
jmp 0x49479
jmp 0x4948a
jmp 0x4948a
jmp 0x4948a
jmp 0x49476
jmp 0x49476
jmp 0x49476
jmp 0x4948a
movq %rax, %rbx
leaq 0xd8(%rsp), %rdi
callq 0xa976
jmp 0x4948d
jmp 0x4948a
movq %rax, %rbx
leaq 0xa0(%rsp), %rdi
callq 0xb132
leaq 0xc0(%rsp), %rdi
callq 0xb132
leaq 0x70(%rsp), %rdi
callq 0xb132
movq %rbx, %rdi
callq 0x4780