// File: /workspace/github_cpp_makefile_star2_O3/Luthaf[P]zeopp/feature.cc
// Function: FEATURE::merge_segments()
void FEATURE::merge_segments()
{
	int i;
	int current_segment;
	SEGCONN featcon;
	segment_merge_list.resize(nsegments,-1);

	nfeatures=0;


	/* loop over all segment connections and mark ones to be merge
	* Merging criteria - restriction is smaller than % of average max radii for each segment
	* */
	for(i=0;i<(int)segment_conn.size();i++)
	{
		if(segment_conn.at(i).max_radius>FEAT_NODE_R_EDGE_R_RATIO*0.5*(segment_max_r[(segment_conn.at(i).from_seg)]+segment_max_r[(segment_conn.at(i).to_seg)]))
			segment_conn.at(i).merged=1;
	/* new function to merge short edges: */

	//   if(segment_conn.at(i).length<max(segment_max_r[(segment_conn.at(i).from_seg)],segment_max_r[(segment_conn.at(i).to_seg)]))
	//       segment_conn.at(i).merged=1;

	};

	/* after connections of to-be-merged segments have been identified, we build
	* features, this includes 'flood fill' of segments */ 

	do{
		//find first segment not assigned to feature 
		current_segment=merge_findNotAssignedFragment();  
		//creature new feature
		features.push_back(nfeatures); // number of segments after merging 
		//grow
		//  cout << current_segment << "\n";
		merge_newSegmentGrow(current_segment);
		//increase counter (number of segments)
		nfeatures++;
	}while(merge_findNotAssignedFragment()!=-1);

	// update feature radii vector
	feature_max_r.resize(nfeatures,0);
	for(i=0;i<(int)segment_merge_list.size();i++)
	{
		if(feature_max_r[segment_merge_list[i]]<segment_max_r[i]) feature_max_r[segment_merge_list[i]]=segment_max_r[i]; 
	};
	// update feature information on all nodes in a channel
	for(i=0;i<(int)nodes.size();i++)
	{
		feature_node_mapping.push_back(segment_merge_list[segments[i]]);
	};

	/* having identified features we need to convert segments connectivity info
	* into feature connectivity */

	for(i=0;i<(int)segment_conn.size();i++)
	{
		if(segment_conn.at(i).merged!=1)
		{
			featcon.from_seg=segment_merge_list[segment_conn.at(i).from_seg];
			featcon.to_seg=segment_merge_list[segment_conn.at(i).to_seg];
			featcon.max_radius=segment_conn.at(i).max_radius;
			feature_conn.push_back(featcon);
		};
	};

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %rbx
leaq 0x8(%rsp), %rdi
callq 0x50e90
leaq 0x208(%rbx), %rdi
movslq 0x138(%rbx), %rsi
movq %rsp, %rdx
movl $0xffffffff, (%rdx)     # imm = 0xFFFFFFFF
callq 0x48a3e
movl $0x0, 0x1b8(%rbx)
movq 0x158(%rbx), %rax
movq 0x160(%rbx), %rdx
subq %rax, %rdx
sarq $0x4, %rdx
movabsq $-0x5555555555555555, %r13 # imm = 0xAAAAAAAAAAAAAAAB
imulq %r13, %rdx
testl %edx, %edx
jle 0x7c673
movq 0x238(%rbx), %rcx
movl %edx, %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
addq $0x8, %rax
xorl %edi, %edi
movsd 0xd0a2b(%rip), %xmm0    # 0x14d060
cmpq %rdi, %rdx
je 0x7c8ba
movslq (%rax), %r8
movsd (%rcx,%r8,8), %xmm1
movslq 0x4(%rax), %r8
addsd (%rcx,%r8,8), %xmm1
movsd 0x8(%rax), %xmm2
mulsd %xmm0, %xmm1
ucomisd %xmm1, %xmm2
jbe 0x7c667
movl $0x1, 0x18(%rax)
incq %rdi
addq $0x30, %rax
cmpq %rdi, %rsi
jne 0x7c635
leaq 0x1b8(%rbx), %r14
leaq 0x1c0(%rbx), %r15
movq %rbx, %rdi
callq 0x7c8d8
movl %eax, %ebp
movq 0x1c8(%rbx), %rsi
cmpq 0x1d0(%rbx), %rsi
je 0x7c6b0
movl 0x1b8(%rbx), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x1c8(%rbx)
jmp 0x7c6bb
movq %r15, %rdi
movq %r14, %rdx
callq 0xf864
movq %rbx, %rdi
movl %ebp, %esi
callq 0x7c924
incl 0x1b8(%rbx)
movq %rbx, %rdi
callq 0x7c8d8
cmpl $-0x1, %eax
jne 0x7c681
leaq 0x250(%rbx), %rdi
movslq 0x1b8(%rbx), %rsi
movq %rsp, %rdx
movq $0x0, (%rdx)
callq 0x48ca6
movq 0x208(%rbx), %rax
movq 0x210(%rbx), %rcx
subq %rax, %rcx
shrq $0x2, %rcx
testl %ecx, %ecx
jle 0x7c743
movq 0x238(%rbx), %rdx
movq 0x250(%rbx), %rsi
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
xorl %edi, %edi
movslq (%rax,%rdi,4), %r8
movsd (%rdx,%rdi,8), %xmm0
ucomisd (%rsi,%r8,8), %xmm0
jbe 0x7c73b
movsd %xmm0, (%rsi,%r8,8)
incq %rdi
cmpq %rdi, %rcx
jne 0x7c724
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 0x7c7cb
leaq 0x1d8(%rbx), %r14
xorl %r15d, %r15d
movq 0x140(%rbx), %rdx
movq 0x1e0(%rbx), %rsi
movslq (%rdx,%r15,4), %rdx
shlq $0x2, %rdx
addq 0x208(%rbx), %rdx
cmpq 0x1e8(%rbx), %rsi
je 0x7c7a0
movl (%rdx), %edx
movl %edx, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x1e0(%rbx)
jmp 0x7c7b0
movq %r14, %rdi
callq 0xf864
movq 0x60(%rbx), %rax
movq 0x68(%rbx), %rcx
incq %r15
movq %rcx, %rdx
subq %rax, %rdx
shrq $0x3, %rdx
imull $0x38e38e39, %edx, %edx # imm = 0x38E38E39
movslq %edx, %rdx
cmpq %rdx, %r15
jl 0x7c769
movq 0x158(%rbx), %rax
movq 0x160(%rbx), %rdx
subq %rax, %rdx
sarq $0x4, %rdx
imulq %r13, %rdx
testl %edx, %edx
jle 0x7c8ab
leaq 0x1f0(%rbx), %r15
movl $0x8, %ebp
xorl %r14d, %r14d
leaq 0x8(%rsp), %r12
cmpq %r14, %rdx
jbe 0x7c8c6
cmpl $0x1, 0x18(%rax,%rbp)
je 0x7c87f
movslq (%rax,%rbp), %rcx
movq 0x208(%rbx), %rdx
movl (%rdx,%rcx,4), %ecx
movl %ecx, 0x10(%rsp)
movslq 0x4(%rax,%rbp), %rcx
movl (%rdx,%rcx,4), %ecx
movl %ecx, 0x14(%rsp)
movsd 0x8(%rax,%rbp), %xmm0
movsd %xmm0, 0x18(%rsp)
movq 0x1f8(%rbx), %rsi
cmpq 0x200(%rbx), %rsi
je 0x7c874
movupd 0x8(%rsp), %xmm0
movupd 0x18(%rsp), %xmm1
movupd 0x28(%rsp), %xmm2
movupd %xmm2, 0x20(%rsi)
movupd %xmm1, 0x10(%rsi)
movupd %xmm0, (%rsi)
addq $0x30, 0x1f8(%rbx)
jmp 0x7c87f
movq %r15, %rdi
movq %r12, %rdx
callq 0x7f3b8
incq %r14
movq 0x158(%rbx), %rax
movq 0x160(%rbx), %rdx
subq %rax, %rdx
sarq $0x4, %rdx
imulq %r13, %rdx
movslq %edx, %rcx
addq $0x30, %rbp
cmpq %rcx, %r14
jl 0x7c800
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xd0e34(%rip), %rdi     # 0x14d6f5
movq %rdx, %rsi
jmp 0x7c8d0
leaq 0xd0e28(%rip), %rdi     # 0x14d6f5
movq %r14, %rsi
xorl %eax, %eax
callq 0x4630
nop