// File: /workspace/github_cpp_makefile_star2_O3/Luthaf[P]zeopp/feature.cc
// Function: FEATURE::segment_distBasedSegmentation(ATOM_NETWORK*)
void FEATURE::segment_distBasedSegmentation(ATOM_NETWORK *uc)
{
UnitCellPtr=uc;

int cur_maxId; // id of current max node
double cur_r;
int i;

double scale_factor=1.1;

if(UnitCellPtr==NULL) {cout<< "no distance pointer set";abort();};


do{
/* clear variable */
segments.clear();
segment_max_r.clear();
for(i=0;i<(int)nodes.size();i++)
   {
   segments.push_back(-1);
   };
nsegments=0;

/* adjust scale factor */
scale_factor-=0.05;

if(scale_factor==0.5)
    {
    cerr << "Segmentation failed. Aborting" << "\n";
    abort();
    };

/* perform segmentation */
while(segment_findMaxNode()>-1)
  {
  cur_maxId=segment_findMaxNode();
  cur_r=nodes.at(cur_maxId).max_radius;
  segments[cur_maxId]=nsegments; // assign new segment number to a nw segment
  segment_max_r.push_back(nodes.at(cur_maxId).max_radius); //store maximum r in a segment

  // now assign all nodes with close distance to the current node
  for(i=0;i<(int)nodes.size();i++)
     {
     if(UnitCellPtr->calcDistanceXYZ(nodes.at(cur_maxId).x,nodes.at(cur_maxId).y,nodes.at(cur_maxId).z,nodes.at(i).x,nodes.at(i).y,nodes.at(i).z)<scale_factor*cur_r)
        {
        segments[i]=nsegments;
        };
     };

  nsegments++;
  };

}while(validateSegmentation()==0);
//}while(scale_factor>0.5);

cout << " no segments after segment_distBasedSegmentation: " << nsegments << "\n"; 

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, 0x130(%rdi)
testq %rsi, %rsi
je 0x7ac95
movq %rdi, %rbx
leaq 0x140(%rdi), %r14
leaq 0x238(%rdi), %rax
movq %rax, 0x20(%rsp)
movsd 0xd2676(%rip), %xmm0    # 0x14d020
movsd %xmm0, 0x8(%rsp)
leaq 0x4(%rsp), %r15
movabsq $-0x71c71c71c71c71c7, %r12 # imm = 0x8E38E38E38E38E39
movq %r14, 0x18(%rsp)
movq 0x140(%rbx), %rax
cmpq %rax, 0x148(%rbx)
je 0x7a9db
movq %rax, 0x148(%rbx)
movq 0x238(%rbx), %rax
cmpq %rax, 0x240(%rbx)
je 0x7a9f2
movq %rax, 0x240(%rbx)
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 0x7aa64
xorl %ebp, %ebp
movl $0xffffffff, 0x4(%rsp)  # imm = 0xFFFFFFFF
movq 0x148(%rbx), %rsi
cmpq 0x150(%rbx), %rsi
je 0x7aa3b
movl $0xffffffff, (%rsi)     # imm = 0xFFFFFFFF
addq $0x4, %rsi
movq %rsi, 0x148(%rbx)
jmp 0x7aa4e
movq %r14, %rdi
movq %r15, %rdx
callq 0x14198
movq 0x60(%rbx), %rax
movq 0x68(%rbx), %rcx
incl %ebp
movq %rcx, %rdx
subq %rax, %rdx
shrq $0x3, %rdx
imull $0x38e38e39, %edx, %edx # imm = 0x38E38E39
cmpl %edx, %ebp
jl 0x7aa10
movl $0x0, 0x138(%rbx)
movsd 0x8(%rsp), %xmm0
addsd 0xda214(%rip), %xmm0    # 0x154c90
movsd %xmm0, 0x8(%rsp)
ucomisd 0xd25ae(%rip), %xmm0    # 0x14d038
jne 0x7aa92
jnp 0x7ac6e
movq %rbx, %rdi
callq 0x7a8ee
movq %rbx, %rdi
testl %eax, %eax
js 0x7abee
callq 0x7a8ee
movslq %eax, %r13
movq 0x60(%rbx), %rax
movq 0x68(%rbx), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
imulq %r12, %rdx
cmpq %r13, %rdx
jbe 0x7ac51
leaq (,%r13,8), %r14
addq %r13, %r14
movsd 0x38(%rax,%r14,8), %xmm0
movl 0x138(%rbx), %ecx
movq 0x140(%rbx), %rsi
movl %ecx, (%rsi,%r13,4)
movq 0x240(%rbx), %rsi
cmpq 0x248(%rbx), %rsi
je 0x7ab0d
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x240(%rbx)
jmp 0x7ab3e
leaq (%rax,%r14,8), %rdx
addq $0x38, %rdx
movq 0x20(%rsp), %rdi
movsd %xmm0, 0x10(%rsp)
callq 0x1481e
movsd 0x10(%rsp), %xmm0
movq 0x60(%rbx), %rax
movq 0x68(%rbx), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
imulq %r12, %rdx
testl %edx, %edx
jle 0x7abe3
mulsd 0x8(%rsp), %xmm0
movl $0x6, %r15d
xorl %ebp, %ebp
movsd %xmm0, 0x10(%rsp)
cmpq %r13, %rdx
jbe 0x7ac51
cmpq %rbp, %rdx
jbe 0x7ac5d
movq 0x130(%rbx), %rdi
movsd 0x18(%rax,%r14,8), %xmm2
movsd 0x8(%rax,%r14,8), %xmm0
movsd 0x10(%rax,%r14,8), %xmm1
movsd -0x10(%rax,%r15,4), %xmm3
movsd -0x8(%rax,%r15,4), %xmm4
movsd (%rax,%r15,4), %xmm5
callq 0x5364c
movsd 0x10(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x7abbd
movl 0x138(%rbx), %eax
movq 0x140(%rbx), %rcx
movl %eax, (%rcx,%rbp,4)
incq %rbp
movq 0x60(%rbx), %rax
movq 0x68(%rbx), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
imulq %r12, %rdx
movslq %edx, %rcx
addq $0x12, %r15
cmpq %rcx, %rbp
jl 0x7ab5a
incl 0x138(%rbx)
jmp 0x7aa92
callq 0x7b26c
testl %eax, %eax
movq 0x18(%rsp), %r14
leaq 0x4(%rsp), %r15
je 0x7a9c4
movq 0x11a3b4(%rip), %r14    # 0x194fc0
leaq 0xda212(%rip), %rsi     # 0x154e25
movl $0x32, %edx
movq %r14, %rdi
callq 0x44e0
movl 0x138(%rbx), %esi
movq %r14, %rdi
callq 0x4750
leaq 0xd89e9(%rip), %rsi     # 0x15361e
movl $0x1, %edx
movq %rax, %rdi
callq 0x44e0
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xd2a9d(%rip), %rdi     # 0x14d6f5
movq %r13, %rsi
jmp 0x7ac67
leaq 0xd2a91(%rip), %rdi     # 0x14d6f5
movq %rbp, %rsi
xorl %eax, %eax
callq 0x4630
movq 0x11a37b(%rip), %rdi    # 0x194ff0
leaq 0xda18b(%rip), %rsi     # 0x154e07
callq 0x4440
leaq 0xd8996(%rip), %rsi     # 0x15361e
movq %rax, %rdi
callq 0x4440
callq 0x4260
movq 0x11a324(%rip), %rdi    # 0x194fc0
leaq 0xda14c(%rip), %rsi     # 0x154def
jmp 0x7ac8b
nop