// File: /workspace/github_cpp_makefile_star2_O1/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 0x7bdab
movq %rdi, %rbx
leaq 0x140(%rdi), %r14
leaq 0x238(%rdi), %rax
movq %rax, 0x20(%rsp)
movsd 0xd3554(%rip), %xmm0    # 0x14f020
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 0x7bafd
movq %rax, 0x148(%rbx)
movq 0x238(%rbx), %rax
cmpq %rax, 0x240(%rbx)
je 0x7bb14
movq %rax, 0x240(%rbx)
movq 0x68(%rbx), %rax
subq 0x60(%rbx), %rax
shrq $0x3, %rax
imull $0x38e38e39, %eax, %eax # imm = 0x38E38E39
testl %eax, %eax
jle 0x7bb7a
xorl %ebp, %ebp
movl $0xffffffff, 0x4(%rsp)  # imm = 0xFFFFFFFF
movq 0x148(%rbx), %rsi
cmpq 0x150(%rbx), %rsi
je 0x7bb57
movl $0xffffffff, (%rsi)     # imm = 0xFFFFFFFF
addq $0x4, %rsi
movq %rsi, 0x148(%rbx)
jmp 0x7bb62
movq %r14, %rdi
movq %r15, %rdx
callq 0x1422c
movq 0x68(%rbx), %rax
subq 0x60(%rbx), %rax
incl %ebp
shrq $0x3, %rax
imull $0x38e38e39, %eax, %eax # imm = 0x38E38E39
cmpl %eax, %ebp
jl 0x7bb2c
movl $0x0, 0x138(%rbx)
movsd 0x8(%rsp), %xmm0
addsd 0xdafe6(%rip), %xmm0    # 0x156b78
movsd %xmm0, 0x8(%rsp)
ucomisd 0xd3498(%rip), %xmm0    # 0x14f038
jne 0x7bba8
jnp 0x7bd84
movq %rbx, %rdi
callq 0x7ba10
movq %rbx, %rdi
testl %eax, %eax
js 0x7bd04
callq 0x7ba10
movslq %eax, %r13
movq 0x60(%rbx), %rax
movq 0x68(%rbx), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
imulq %r12, %rdx
cmpq %r13, %rdx
jbe 0x7bd67
leaq (,%r13,8), %r14
addq %r13, %r14
movsd 0x38(%rax,%r14,8), %xmm0
movl 0x138(%rbx), %ecx
movq 0x140(%rbx), %rdx
movl %ecx, (%rdx,%r13,4)
movq 0x240(%rbx), %rsi
cmpq 0x248(%rbx), %rsi
je 0x7bc23
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x240(%rbx)
jmp 0x7bc41
leaq (%rax,%r14,8), %rdx
addq $0x38, %rdx
movq 0x20(%rsp), %rdi
movsd %xmm0, 0x10(%rsp)
callq 0x148c4
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 0x7bcf9
mulsd 0x8(%rsp), %xmm0
movl $0x6, %r15d
xorl %ebp, %ebp
movsd %xmm0, 0x10(%rsp)
cmpq %r13, %rdx
jbe 0x7bd67
cmpq %rbp, %rdx
jbe 0x7bd73
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 0x5394a
movsd 0x10(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x7bcd3
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 0x7bc70
incl 0x138(%rbx)
jmp 0x7bba8
callq 0x7c36a
testl %eax, %eax
movq 0x18(%rsp), %r14
leaq 0x4(%rsp), %r15
je 0x7bae6
movq 0x11b29e(%rip), %r14    # 0x196fc0
leaq 0xdafe4(%rip), %rsi     # 0x156d0d
movl $0x32, %edx
movq %r14, %rdi
callq 0x44e0
movl 0x138(%rbx), %esi
movq %r14, %rdi
callq 0x4750
leaq 0xd97e3(%rip), %rsi     # 0x15552e
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 0xd3937(%rip), %rdi     # 0x14f6a5
movq %r13, %rsi
jmp 0x7bd7d
leaq 0xd392b(%rip), %rdi     # 0x14f6a5
movq %rbp, %rsi
xorl %eax, %eax
callq 0x4630
movq 0x11b265(%rip), %rdi    # 0x196ff0
leaq 0xdaf5d(%rip), %rsi     # 0x156cef
callq 0x4440
leaq 0xd9790(%rip), %rsi     # 0x15552e
movq %rax, %rdi
callq 0x4440
callq 0x4260
movq 0x11b20e(%rip), %rdi    # 0x196fc0
leaq 0xdaf1e(%rip), %rsi     # 0x156cd7
jmp 0x7bda1
nop