// File: /workspace/github_cpp_makefile_star2_O3/Luthaf[P]zeopp/feature.cc
// Function: FEATURE::segment_identify_connections()
void FEATURE::segment_identify_connections(){
int i,j,k;
int nfaces;
vector <int> segfaces;
vector <double> segfaces_max_r;

vector <int> nodes_in_segment; // list IDs of nodes assigned to segment
vector <int> face_nodes_in_segment; // list IDs of nodes assigned to segment and located on segment's "face", that is
                                    // nodes with connections to other segments
vector <int>  connected_segment_for_face_nodes_in_segment; // for each node, if it is a face node, store segment id to which it is connected
vector <SEGCONN> edges_from_segment; // list of edges that connect the current segment to other segments
SEGCONN segc; // inter-segment connection
vector <int> edges_in_face; // for each edge connecting to other semgent assign to a face, this svector stores face id for each edge

/* loop over all segments and identify all connections to other segments */

for(i=0;i<nsegments;i++)
   {
   nodes_in_segment.clear();
   edges_from_segment.clear();
   for(j=0;j<(int)nodes.size();j++)
      {
      if(segments[j]==i) nodes_in_segment.push_back(j);
      };
   face_nodes_in_segment.clear();
   connected_segment_for_face_nodes_in_segment.clear();
   face_nodes_in_segment.resize(nodes_in_segment.size(),0);
   connected_segment_for_face_nodes_in_segment.resize(nodes_in_segment.size(),-1);
   for(j=0;j<(int)nodes_in_segment.size();j++)
      {
      for(k=0;k<(int)nodes.at(nodes_in_segment[j]).connections.size();k++)
         {
         if(segments[nodes.at(nodes_in_segment[j]).connections.at(k).to]!=i) 
             {
             face_nodes_in_segment[j]++; 
             connected_segment_for_face_nodes_in_segment[j]=segments[nodes.at(nodes_in_segment[j]).connections.at(k).to];
        
             segc.from=nodes_in_segment[j]; // this is ID id in channel)
             segc.to=nodes.at(nodes_in_segment[j]).connections.at(k).to; // node id in channel
             segc.from_seg=i; 
             segc.to_seg=segments[nodes.at(nodes_in_segment[j]).connections.at(k).to];
             segc.max_radius=nodes.at(nodes_in_segment[j]).connections.at(k).max_radius;
             segc.deltaPos=nodes.at(nodes_in_segment[j]).connections.at(k).deltaPos;
             edges_from_segment.push_back(segc);
             };
         };
      };

// now connected_segment_for_face_nodes_in_segment has a list of segments each node in the current segment is conneed to (-1 if not) 
// we need now to find "clusters" of these nodes that will correspond to different connections;
// edges_from_segment stores all edges going out from a segment to other segments

   int nedges_tobe_assigned=edges_from_segment.size();
   edges_in_face.clear();
   edges_in_face.resize(nedges_tobe_assigned,-1);

   nfaces=0;
   int neigh_seg; // id of neighboring segment
//   while(nedges_tobe_assigned>-1)
     {
     for(k=0;k<(int)edges_from_segment.size();k++)
        {
        if(edges_in_face[k]==-1) // find first edge not assigned to face
          {
          neigh_seg=edges_from_segment[k].to_seg;
          edges_in_face[k]=nfaces;
          nedges_tobe_assigned--;
          segment_identify_connections_recurr(&nodes_in_segment,&edges_in_face,&nedges_tobe_assigned,nfaces,neigh_seg,&edges_from_segment,k);
          nfaces++;
          };
//        nfaces++;
        };
     };

/*
   cout << "Segment " << i <<": " << nodes_in_segment.size() << " nodes, " << edges_in_face.size() << " edges, " << nfaces << " faces, nodes-to-go " << nedges_tobe_assigned << "\n";
   for(k=0;k<(int)edges_from_segment.size();k++)
      {
      cout << "Edge " << edges_from_segment[k].from << "  " << edges_from_segment[k].to << "  Segments:" << edges_from_segment[k].from_seg << "  " << edges_from_segment[k].to_seg << "    "; edges_from_segment[k].deltaPos.print();
      };
*/


   }; // end of loop over all segments

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movq %rdi, %rbx
xorl %eax, %eax
movq %rax, 0x20(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq %rax, 0xa0(%rsp)
movaps %xmm0, 0x90(%rsp)
movq %rax, 0x80(%rsp)
movaps %xmm0, 0x70(%rsp)
movq %rax, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
leaq 0xa8(%rsp), %rdi
callq 0x50e90
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
movq $0x0, 0x60(%rsp)
cmpl $0x0, 0x138(%rbx)
jle 0x7c03c
xorl %eax, %eax
leaq 0x4(%rsp), %r15
movabsq $-0x3333333333333333, %rbp # imm = 0xCCCCCCCCCCCCCCCD
xorl %edi, %edi
movl $0x0, 0x8(%rsp)
movq 0x10(%rsp), %rcx
cmpq %rcx, 0x18(%rsp)
je 0x7bb37
movq %rcx, 0x18(%rsp)
cmpq %rdi, %rax
je 0x7bb41
movq %rdi, 0x38(%rsp)
movl $0x0, 0x4(%rsp)
movq 0x60(%rbx), %rax
movq 0x68(%rbx), %rcx
movq %rcx, %rdx
subq %rax, %rdx
shrq $0x3, %rdx
imull $0x38e38e39, %edx, %edx # imm = 0x38E38E39
testl %edx, %edx
jle 0x7bbc8
xorl %edx, %edx
movslq %edx, %rsi
movq 0x140(%rbx), %rdi
movl 0x8(%rsp), %r8d
cmpl %r8d, (%rdi,%rsi,4)
jne 0x7bbaa
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x7bb95
movl %edx, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x7bbaa
leaq 0x10(%rsp), %rdi
movq %r15, %rdx
callq 0xf864
movq 0x60(%rbx), %rax
movq 0x68(%rbx), %rcx
movl 0x4(%rsp), %edx
incl %edx
movl %edx, 0x4(%rsp)
movq %rcx, %rsi
subq %rax, %rsi
shrq $0x3, %rsi
imull $0x38e38e39, %esi, %esi # imm = 0x38E38E39
cmpl %esi, %edx
jl 0x7bb67
movq 0x90(%rsp), %rax
cmpq %rax, 0x98(%rsp)
je 0x7bbe2
movq %rax, 0x98(%rsp)
movq 0x70(%rsp), %rax
cmpq %rax, 0x78(%rsp)
leaq 0xc(%rsp), %r14
je 0x7bbf8
movq %rax, 0x78(%rsp)
movq 0x18(%rsp), %rsi
subq 0x10(%rsp), %rsi
sarq $0x2, %rsi
movl $0x0, 0xc(%rsp)
leaq 0x90(%rsp), %rdi
movq %r14, %rdx
callq 0x48a3e
movq 0x18(%rsp), %rsi
subq 0x10(%rsp), %rsi
sarq $0x2, %rsi
movl $0xffffffff, 0xc(%rsp)  # imm = 0xFFFFFFFF
leaq 0x70(%rsp), %rdi
movq %r14, %rdx
callq 0x48a3e
movl $0x0, 0x4(%rsp)
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rax
subq %rdi, %rax
shrq $0x2, %rax
testl %eax, %eax
jle 0x7bf11
movq 0x60(%rbx), %rcx
movq 0x68(%rbx), %r14
xorl %eax, %eax
movq %rdi, %r10
movslq %eax, %r9
movslq (%r10,%r9,4), %r15
movq %r14, %r8
subq %rcx, %r8
sarq $0x3, %r8
movabsq $-0x71c71c71c71c71c7, %rdx # imm = 0x8E38E38E38E38E39
imulq %rdx, %r8
cmpq %r15, %r8
jbe 0x7c0b8
leaq (%r15,%r15,8), %rdx
movq 0x20(%rcx,%rdx,8), %r11
movq 0x28(%rcx,%rdx,8), %rdx
subq %r11, %rdx
sarq $0x3, %rdx
movq %rbp, %r12
imulq %rbp, %rdx
testl %edx, %edx
jle 0x7beee
xorl %r13d, %r13d
xorl %r15d, %r15d
movq %r10, %rsi
cmpq %r15, %rdx
jbe 0x7c0ab
movslq 0x4(%r11,%r13), %r10
movq 0x140(%rbx), %rdx
movl 0x8(%rsp), %r11d
cmpl %r11d, (%rdx,%r10,4)
jne 0x7bcef
movq %rdi, %rsi
movq %r12, %rbp
jmp 0x7be8a
movq 0x90(%rsp), %rax
incl (%rax,%r9,4)
movslq 0x4(%rsp), %rax
movslq (%rsi,%rax,4), %r9
cmpq %r9, %r8
jbe 0x7c0b5
movq %r12, %rbp
leaq (%r9,%r9,8), %r10
movq 0x20(%rcx,%r10,8), %r9
movq 0x28(%rcx,%r10,8), %r10
subq %r9, %r10
sarq $0x3, %r10
imulq %r12, %r10
cmpq %r15, %r10
jbe 0x7c0b0
movslq 0x4(%r9,%r13), %r9
movl (%rdx,%r9,4), %r9d
movq 0x70(%rsp), %r10
movl %r9d, (%r10,%rax,4)
movl 0x4(%rsp), %eax
movslq %eax, %r9
movslq (%rsi,%r9,4), %r10
movl %r10d, 0xa8(%rsp)
cmpq %r10, %r8
jbe 0x7c0a1
leaq (%r10,%r10,8), %r11
movq 0x20(%rcx,%r11,8), %r10
movq 0x28(%rcx,%r11,8), %r11
subq %r10, %r11
sarq $0x3, %r11
imulq %rbp, %r11
cmpq %r15, %r11
jbe 0x7c0a6
movl 0x4(%r10,%r13), %r10d
movl %r10d, 0xac(%rsp)
movl 0x8(%rsp), %r10d
movl %r10d, 0xb0(%rsp)
movslq (%rsi,%r9,4), %r10
cmpq %r10, %r8
jbe 0x7c0a1
leaq (%r10,%r10,8), %r11
movq 0x20(%rcx,%r11,8), %r10
movq 0x28(%rcx,%r11,8), %r11
subq %r10, %r11
sarq $0x3, %r11
imulq %rbp, %r11
cmpq %r15, %r11
jbe 0x7c0a6
movslq 0x4(%r10,%r13), %r10
movl (%rdx,%r10,4), %edx
movl %edx, 0xb4(%rsp)
movslq (%rsi,%r9,4), %rdx
cmpq %rdx, %r8
jbe 0x7c09c
leaq (%rdx,%rdx,8), %rsi
movq 0x20(%rcx,%rsi,8), %rdx
movq 0x28(%rcx,%rsi,8), %r8
subq %rdx, %r8
sarq $0x3, %r8
imulq %rbp, %r8
cmpq %r15, %r8
jbe 0x7c0b8
movsd 0x10(%rdx,%r13), %xmm0
movsd %xmm0, 0xb8(%rsp)
movl 0x20(%rdx,%r13), %ecx
leaq 0xcc(%rsp), %rsi
movl %ecx, 0x8(%rsi)
movq 0x18(%rdx,%r13), %rcx
movq %rcx, (%rsi)
movq 0x38(%rsp), %rsi
cmpq 0x40(%rsp), %rsi
je 0x7be6f
movups 0xa8(%rsp), %xmm0
movups 0xb8(%rsp), %xmm1
movups 0xc8(%rsp), %xmm2
movups %xmm2, 0x20(%rsi)
movups %xmm1, 0x10(%rsi)
movups %xmm0, (%rsi)
addq $0x30, %rsi
movq %rsi, 0x38(%rsp)
movq %rdi, %rsi
jmp 0x7be8a
leaq 0x30(%rsp), %rdi
leaq 0xa8(%rsp), %rdx
callq 0x7f3b8
movl 0x4(%rsp), %eax
movq 0x10(%rsp), %rsi
movslq %eax, %r9
movslq (%rsi,%r9,4), %rdx
movq 0x60(%rbx), %rcx
movq 0x68(%rbx), %r14
movq %r14, %r8
subq %rcx, %r8
sarq $0x3, %r8
movabsq $-0x71c71c71c71c71c7, %rdi # imm = 0x8E38E38E38E38E39
imulq %rdi, %r8
cmpq %rdx, %r8
jbe 0x7c09c
incq %r15
leaq (%rdx,%rdx,8), %rdx
movq 0x20(%rcx,%rdx,8), %r11
movq 0x28(%rcx,%rdx,8), %rdx
subq %r11, %rdx
sarq $0x3, %rdx
imulq %rbp, %rdx
movslq %edx, %rbp
addq $0x28, %r13
movq %rsi, %rdi
movq %rsi, %r10
cmpq %rbp, %r15
jl 0x7bcc4
jmp 0x7bef1
movq %rdi, %rsi
incl %eax
movl %eax, 0x4(%rsp)
movq 0x18(%rsp), %rdx
subq %r10, %rdx
shrq $0x2, %rdx
movq %rsi, %rdi
cmpl %edx, %eax
movq %r12, %rbp
jl 0x7bc6f
movq 0x38(%rsp), %r12
subq 0x30(%rsp), %r12
sarq $0x4, %r12
movabsq $-0x5555555555555555, %rax # imm = 0xAAAAAAAAAAAAAAAB
imulq %rax, %r12
movl %r12d, 0xc(%rsp)
movq 0x50(%rsp), %rax
cmpq %rax, 0x58(%rsp)
je 0x7bf43
movq %rax, 0x58(%rsp)
movslq %r12d, %rsi
movl $0xffffffff, 0x6c(%rsp) # imm = 0xFFFFFFFF
leaq 0x50(%rsp), %rdi
leaq 0x6c(%rsp), %rdx
callq 0x48a3e
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %rax
movq %rax, %rcx
subq %rdi, %rcx
shrq $0x4, %rcx
imull $0xaaaaaaab, %ecx, %ecx # imm = 0xAAAAAAAB
testl %ecx, %ecx
jle 0x7bff0
xorl %r13d, %r13d
movl $0x3, %r15d
xorl %r14d, %r14d
movq 0x50(%rsp), %rcx
cmpl $-0x1, (%rcx,%r13,4)
jne 0x7bfd1
movl (%rdi,%r15,4), %r9d
movl %r14d, (%rcx,%r13,4)
movq %rbx, %rdi
leaq 0x10(%rsp), %rsi
leaq 0x50(%rsp), %rdx
leaq 0xc(%rsp), %rcx
movl %r14d, %r8d
pushq %r13
leaq 0x38(%rsp), %rax
pushq %rax
callq 0x7c164
addq $0x10, %rsp
decl %r12d
incl %r14d
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %rax
incq %r13
movq %rax, %rcx
subq %rdi, %rcx
shrq $0x4, %rcx
imull $0xaaaaaaab, %ecx, %ecx # imm = 0xAAAAAAAB
movslq %ecx, %rcx
addq $0xc, %r15
cmpq %rcx, %r13
jl 0x7bf87
movl 0x8(%rsp), %ecx
incl %ecx
movl %ecx, 0x8(%rsp)
cmpl 0x138(%rbx), %ecx
leaq 0x4(%rsp), %r15
jl 0x7bb26
movq 0x50(%rsp), %rax
testq %rax, %rax
je 0x7c02a
movq 0x60(%rsp), %rsi
subq %rax, %rsi
movq %rax, %rdi
callq 0x4470
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x7c03c
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x7c056
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x7c073
movq 0xa0(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x7c08a
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rdx, %r15
jmp 0x7c0b8
movq %r10, %r15
jmp 0x7c0b8
movq %r11, %r8
jmp 0x7c0b8
movq %rdx, %r8
jmp 0x7c0b8
movq %r10, %r8
jmp 0x7c0b8
movq %r9, %r15
leaq 0xd1636(%rip), %rdi     # 0x14d6f5
movq %r15, %rsi
movq %r8, %rdx
xorl %eax, %eax
callq 0x4630
movq %rax, %rbx
jmp 0x7c10e
jmp 0x7c0dd
jmp 0x7c0dd
jmp 0x7c0dd
jmp 0x7c0dd
jmp 0x7c0dd
jmp 0x7c0dd
movq %rax, %rbx
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x7c0f7
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x7c10e
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x7c128
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x7c145
movq 0xa0(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x7c15c
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq %rbx, %rdi
callq 0x4780