// File: /workspace/github_cpp_makefile_star2_O1/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 0x51234
leaq 0x208(%rbx), %rdi
movslq 0x138(%rbx), %rsi
movq %rsp, %rdx
movl $0xffffffff, (%rdx)     # imm = 0xFFFFFFFF
callq 0x49326
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 0x7d751
movq 0x238(%rbx), %rcx
movl %edx, %edi
andl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
addq $0x8, %rax
xorl %esi, %esi
movsd 0xd194d(%rip), %xmm0    # 0x14f060
cmpq %rsi, %rdx
je 0x7d98b
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 0x7d745
movl $0x1, 0x18(%rax)
incq %rsi
addq $0x30, %rax
cmpq %rsi, %rdi
jne 0x7d713
leaq 0x1b8(%rbx), %r14
leaq 0x1c0(%rbx), %r15
movq %rbx, %rdi
callq 0x7d9a6
movl %eax, %ebp
movq 0x1c8(%rbx), %rsi
cmpq 0x1d0(%rbx), %rsi
je 0x7d78e
movl 0x1b8(%rbx), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x1c8(%rbx)
jmp 0x7d799
movq %r15, %rdi
movq %r14, %rdx
callq 0xf7b4
movq %rbx, %rdi
movl %ebp, %esi
callq 0x7d9f2
incl 0x1b8(%rbx)
movq %rbx, %rdi
callq 0x7d9a6
cmpl $-0x1, %eax
jne 0x7d75f
leaq 0x250(%rbx), %rdi
movslq 0x1b8(%rbx), %rsi
movq %rsp, %rdx
movq $0x0, (%rdx)
callq 0x49580
movq 0x208(%rbx), %rax
movq 0x210(%rbx), %rcx
subq %rax, %rcx
shrq $0x2, %rcx
testl %ecx, %ecx
jle 0x7d821
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 0x7d819
movsd %xmm0, (%rsi,%r8,8)
incq %rdi
cmpq %rdi, %rcx
jne 0x7d802
movq 0x68(%rbx), %rax
subq 0x60(%rbx), %rax
shrq $0x3, %rax
imull $0x38e38e39, %eax, %eax # imm = 0x38E38E39
testl %eax, %eax
jle 0x7d89c
leaq 0x1d8(%rbx), %r14
xorl %r15d, %r15d
movq 0x140(%rbx), %rax
movq 0x1e0(%rbx), %rsi
movslq (%rax,%r15,4), %rdx
shlq $0x2, %rdx
addq 0x208(%rbx), %rdx
cmpq 0x1e8(%rbx), %rsi
je 0x7d878
movl (%rdx), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x1e0(%rbx)
jmp 0x7d880
movq %r14, %rdi
callq 0xf7b4
incq %r15
movq 0x68(%rbx), %rax
subq 0x60(%rbx), %rax
shrq $0x3, %rax
imull $0x38e38e39, %eax, %eax # imm = 0x38E38E39
cltq
cmpq %rax, %r15
jl 0x7d841
movq 0x158(%rbx), %rax
movq 0x160(%rbx), %rdx
subq %rax, %rdx
sarq $0x4, %rdx
imulq %r13, %rdx
testl %edx, %edx
jle 0x7d97c
leaq 0x1f0(%rbx), %r15
movl $0x8, %ebp
xorl %r14d, %r14d
leaq 0x8(%rsp), %r12
cmpq %r14, %rdx
jbe 0x7d994
cmpl $0x1, 0x18(%rax,%rbp)
je 0x7d950
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 0x7d945
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 0x7d950
movq %r15, %rdi
movq %r12, %rdx
callq 0x8061a
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 0x7d8d1
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xd1d13(%rip), %rdi     # 0x14f6a5
jmp 0x7d99e
leaq 0xd1d0a(%rip), %rdi     # 0x14f6a5
movq %r14, %rsi
xorl %eax, %eax
callq 0x4630
nop