// File: /workspace/github_cpp_makefile_star2_O1/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 0x51234
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
movq $0x0, 0x60(%rsp)
cmpl $0x0, 0x138(%rbx)
jle 0x7d103
xorl %r13d, %r13d
leaq 0xcc(%rsp), %rbp
leaq 0x8(%rsp), %r14
leaq 0xc(%rsp), %r15
movabsq $-0x3333333333333333, %r12 # imm = 0xCCCCCCCCCCCCCCCD
movq 0x10(%rsp), %rax
cmpq %rax, 0x18(%rsp)
je 0x7cc69
movq %rax, 0x18(%rsp)
movq 0x30(%rsp), %rax
cmpq %rax, 0x38(%rsp)
je 0x7cc7a
movq %rax, 0x38(%rsp)
movl $0x0, 0x8(%rsp)
movq 0x68(%rbx), %rax
subq 0x60(%rbx), %rax
shrq $0x3, %rax
imull $0x38e38e39, %eax, %eax # imm = 0x38E38E39
testl %eax, %eax
jle 0x7ccf0
xorl %eax, %eax
movslq %eax, %rcx
movq 0x140(%rbx), %rdx
cmpl %r13d, (%rdx,%rcx,4)
jne 0x7ccd0
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x7ccc3
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x7ccd0
leaq 0x10(%rsp), %rdi
movq %r14, %rdx
callq 0xf7b4
movl 0x8(%rsp), %eax
incl %eax
movl %eax, 0x8(%rsp)
movq 0x68(%rbx), %rcx
subq 0x60(%rbx), %rcx
shrq $0x3, %rcx
imull $0x38e38e39, %ecx, %ecx # imm = 0x38E38E39
cmpl %ecx, %eax
jl 0x7cc9a
movq 0x90(%rsp), %rax
cmpq %rax, 0x98(%rsp)
je 0x7cd0a
movq %rax, 0x98(%rsp)
movq 0x70(%rsp), %rax
cmpq %rax, 0x78(%rsp)
je 0x7cd1b
movq %rax, 0x78(%rsp)
movq 0x18(%rsp), %rsi
subq 0x10(%rsp), %rsi
sarq $0x2, %rsi
movl $0x0, 0xc(%rsp)
leaq 0x90(%rsp), %rdi
movq %r15, %rdx
callq 0x49326
movq 0x18(%rsp), %rsi
subq 0x10(%rsp), %rsi
sarq $0x2, %rsi
movl $0xffffffff, 0xc(%rsp)  # imm = 0xFFFFFFFF
leaq 0x70(%rsp), %rdi
movq %r15, %rdx
callq 0x49326
movl $0x0, 0x8(%rsp)
movq 0x18(%rsp), %rax
subq 0x10(%rsp), %rax
shrq $0x2, %rax
testl %eax, %eax
jle 0x7cfff
movl 0x8(%rsp), %edi
movslq %edi, %rsi
movq 0x10(%rsp), %rcx
movslq (%rcx,%rsi,4), %r15
movq 0x60(%rbx), %rax
movq 0x68(%rbx), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
movabsq $-0x71c71c71c71c71c7, %r8 # imm = 0x8E38E38E38E38E39
imulq %r8, %rdx
cmpq %r15, %rdx
jbe 0x7d199
leaq (%r15,%r15,8), %r9
movq 0x20(%rax,%r9,8), %r8
movq 0x28(%rax,%r9,8), %r9
subq %r8, %r9
sarq $0x3, %r9
imulq %r12, %r9
testl %r9d, %r9d
jle 0x7cfe3
xorl %r14d, %r14d
xorl %r15d, %r15d
cmpq %r15, %r9
jbe 0x7d196
movslq 0x4(%r8,%r14), %r8
movq 0x140(%rbx), %rdi
cmpl %r13d, (%rdi,%r8,4)
je 0x7cf81
movq 0x90(%rsp), %r8
incl (%r8,%rsi,4)
movslq 0x8(%rsp), %rsi
movslq (%rcx,%rsi,4), %r8
cmpq %r8, %rdx
jbe 0x7d191
leaq (%r8,%r8,8), %r9
movq 0x20(%rax,%r9,8), %r8
movq 0x28(%rax,%r9,8), %r9
subq %r8, %r9
sarq $0x3, %r9
imulq %r12, %r9
cmpq %r15, %r9
jbe 0x7d196
movslq 0x4(%r8,%r14), %r8
movl (%rdi,%r8,4), %r8d
movq 0x70(%rsp), %r9
movl %r8d, (%r9,%rsi,4)
movslq 0x8(%rsp), %rsi
movl (%rcx,%rsi,4), %r8d
movl %r8d, 0xa8(%rsp)
movslq (%rcx,%rsi,4), %r8
cmpq %r8, %rdx
jbe 0x7d191
leaq (%r8,%r8,8), %r9
movq 0x20(%rax,%r9,8), %r8
movq 0x28(%rax,%r9,8), %r9
subq %r8, %r9
sarq $0x3, %r9
imulq %r12, %r9
cmpq %r15, %r9
jbe 0x7d196
movl 0x4(%r8,%r14), %r8d
movl %r8d, 0xac(%rsp)
movl %r13d, 0xb0(%rsp)
movslq (%rcx,%rsi,4), %r8
cmpq %r8, %rdx
jbe 0x7d191
leaq (%r8,%r8,8), %r9
movq 0x20(%rax,%r9,8), %r8
movq 0x28(%rax,%r9,8), %r9
subq %r8, %r9
sarq $0x3, %r9
imulq %r12, %r9
cmpq %r15, %r9
jbe 0x7d196
movslq 0x4(%r8,%r14), %r8
movl (%rdi,%r8,4), %edi
movl %edi, 0xb4(%rsp)
movslq (%rcx,%rsi,4), %rcx
cmpq %rcx, %rdx
jbe 0x7d1aa
leaq (%rcx,%rcx,8), %rdx
movq 0x20(%rax,%rdx,8), %rcx
movq 0x28(%rax,%rdx,8), %rdx
subq %rcx, %rdx
sarq $0x3, %rdx
imulq %r12, %rdx
cmpq %r15, %rdx
jbe 0x7d199
movsd 0x10(%rcx,%r14), %xmm0
movsd %xmm0, 0xb8(%rsp)
movl 0x20(%rcx,%r14), %eax
movl %eax, 0x8(%rbp)
movq 0x18(%rcx,%r14), %rax
movq %rax, (%rbp)
movq 0x38(%rsp), %rsi
cmpq 0x40(%rsp), %rsi
je 0x7cf6f
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)
jmp 0x7cf81
leaq 0x30(%rsp), %rdi
leaq 0xa8(%rsp), %rdx
callq 0x8061a
movl 0x8(%rsp), %edi
movslq %edi, %rsi
movq 0x10(%rsp), %rcx
movslq (%rcx,%rsi,4), %r8
movq 0x60(%rbx), %rax
movq 0x68(%rbx), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
movabsq $-0x71c71c71c71c71c7, %r9 # imm = 0x8E38E38E38E38E39
imulq %r9, %rdx
cmpq %r8, %rdx
jbe 0x7d191
incq %r15
leaq (%r8,%r8,8), %r9
movq 0x20(%rax,%r9,8), %r8
movq 0x28(%rax,%r9,8), %r9
subq %r8, %r9
sarq $0x3, %r9
imulq %r12, %r9
movslq %r9d, %r10
addq $0x28, %r14
cmpq %r10, %r15
jl 0x7cde0
incl %edi
movl %edi, 0x8(%rsp)
movq 0x18(%rsp), %rax
subq 0x10(%rsp), %rax
shrq $0x2, %rax
cmpl %eax, %edi
jl 0x7cd82
movq 0x38(%rsp), %rax
subq 0x30(%rsp), %rax
sarq $0x4, %rax
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rax
movl %eax, 0xc(%rsp)
movq 0x50(%rsp), %rcx
cmpq %rcx, 0x58(%rsp)
je 0x7d030
movq %rcx, 0x58(%rsp)
movslq %eax, %rsi
movl $0xffffffff, 0x6c(%rsp) # imm = 0xFFFFFFFF
leaq 0x50(%rsp), %rdi
leaq 0x6c(%rsp), %rdx
callq 0x49326
movq 0x30(%rsp), %rax
movq 0x38(%rsp), %rcx
subq %rax, %rcx
shrq $0x4, %rcx
imull $0xaaaaaaab, %ecx, %ecx # imm = 0xAAAAAAAB
testl %ecx, %ecx
jle 0x7d0e1
movl 0xc(%rsp), %edx
xorl %r15d, %r15d
movl $0x3, %ebp
xorl %r14d, %r14d
movq 0x50(%rsp), %rcx
cmpl $-0x1, (%rcx,%r15,4)
jne 0x7d0bb
movl (%rax,%rbp,4), %r9d
movl %r14d, (%rcx,%r15,4)
decl %edx
movl %edx, 0x4c(%rsp)
movq %rbx, %rdi
leaq 0x10(%rsp), %rsi
leaq 0x50(%rsp), %rdx
leaq 0xc(%rsp), %rcx
movl %r14d, %r8d
pushq %r15
leaq 0x38(%rsp), %rax
pushq %rax
callq 0x7d252
addq $0x10, %rsp
incl %r14d
movl 0x4c(%rsp), %edx
incq %r15
movq 0x30(%rsp), %rax
movq 0x38(%rsp), %rcx
subq %rax, %rcx
shrq $0x4, %rcx
imull $0xaaaaaaab, %ecx, %ecx # imm = 0xAAAAAAAB
movslq %ecx, %rcx
addq $0xc, %rbp
cmpq %rcx, %r15
jl 0x7d074
incl %r13d
cmpl 0x138(%rbx), %r13d
leaq 0xcc(%rsp), %rbp
leaq 0x8(%rsp), %r14
leaq 0xc(%rsp), %r15
jl 0x7cc58
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x7d11a
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x7d131
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x7d14b
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x7d168
movq 0xa0(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x7d17f
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 %r8, %r15
jmp 0x7d199
movq %r9, %rdx
leaq 0xd2505(%rip), %rdi     # 0x14f6a5
movq %r15, %rsi
xorl %eax, %eax
callq 0x4630
movq %rcx, %r15
jmp 0x7d199
movq %rax, %rbx
jmp 0x7d1e5
jmp 0x7d1cb
jmp 0x7d1cb
jmp 0x7d1cb
jmp 0x7d1cb
movq %rax, %rbx
movl 0x4c(%rsp), %eax
movl %eax, 0xc(%rsp)
jmp 0x7d1ce
jmp 0x7d1cb
movq %rax, %rbx
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x7d1e5
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x7d1fc
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x7d216
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x7d233
movq 0xa0(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x7d24a
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq %rbx, %rdi
callq 0x4780