// File: /workspace/github_cpp_makefile_star2_O1/Luthaf[P]zeopp/networkaccessibility.cc
// Function: AccessibilityClass::setupAndFindChannels(ATOM_NETWORK*, ATOM_NETWORK*, bool, double, double)
void AccessibilityClass::setupAndFindChannels(ATOM_NETWORK *atmnet, ATOM_NETWORK *orgatmnet, bool highAccuracy, double r_probe_chan, double r_probe_sampl){

 r_probe = r_probe_sampl;

 highAccuracyFlag = highAccuracy;

 // Create a temporary copy of the atomic network in which each atom's radius has been increased by the probe radius
 if(highAccuracy)
   {
   atmnet->copy(&analyzedAtomNet);
   orgatmnet->copy(&orgAtomNet);
   }else{
   orgatmnet->copy(&analyzedAtomNet);
   orgatmnet->copy(&orgAtomNet);
   };
 for(unsigned int i = 0; i < orgAtomNet.atoms.size(); i++){ orgAtomNet.atoms[i].radius += r_probe; }
 for(unsigned int i = 0; i < analyzedAtomNet.atoms.size(); i++){ analyzedAtomNet.atoms[i].radius += r_probe; }

 // Calculate and store the Voronoi network for this new atomic network

 new_rad_con = (container_periodic_poly *)performVoronoiDecomp(true, &analyzedAtomNet, &vornet, advCells, false, vorcells);

//  Print vornet summary
 int noAccVorNodes = 0;
 for(unsigned int i = 0; i < vornet.nodes.size(); i++)
    {
    if(vornet.nodes.at(i).rad_stat_sphere > 0) noAccVorNodes++;
    };
 cout << "Voronoi network with " << vornet.nodes.size() << " nodes. " << noAccVorNodes << " of them are accessible. " << endl;

// CHANNEL::findChannels(&vornet, max(0.0, r_probe_chan - r_probe), &accessInfo, &channels);

 PORE::findChannelsAndPockets(&vornet, max(0.0, r_probe_chan - r_probe), &accessInfo, &pores);

 channelMapping.resize(accessInfo.size(),-1);
 pocketMapping.resize(accessInfo.size(),-1);
 n_channels = 0; n_pockets = 0; // number of channels and pockets
 for(unsigned int i = 0; i < pores.size(); i++)
   {
   if(pores[i].dimensionality>0)
    { // Channels
     for(unsigned int j = 0; j < pores[i].nodes.size(); j++)
       {
       channelMapping[pores[i].reverseIDMappings.find(j)->second] = n_channels;
       };
     n_channels++;
    }else
     { // Pockets
     for(unsigned int j = 0; j < pores[i].nodes.size(); j++)
       {
       pocketMapping[pores[i].reverseIDMappings.find(j)->second] = n_pockets;
       };
     n_pockets++;
    };

   };

/* DEBUG

for(unsigned int i = 0; i < accessInfo.size(); i++)
  {
  cout << "DEBUG: NodeID, radius, channelID, pocketID = " << i << "  ,   " << vornet.nodes.at(i).rad_stat_sphere << " ,  " << channelMapping[i] << "  ,  " << pocketMapping[i] << endl;
  };

END DEBUG */

// cout << "Accessibility setup: no channels = " << n_channels << " and no pockets = " << n_pockets << "/n";

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movsd %xmm0, 0x8(%rsp)
movq %rdx, %r14
movq %rdi, %rbx
movsd %xmm1, 0x9e8(%rdi)
movb %cl, 0x8c0(%rdi)
leaq 0x460(%rdi), %r15
testl %ecx, %ecx
cmoveq %rdx, %rsi
movq %rsi, %rdi
movq %r15, %rsi
callq 0x528f4
movq %r14, %rdi
movq %rbx, %rsi
callq 0x528f4
movq 0x2f0(%rbx), %rax
movq 0x2f8(%rbx), %rcx
movabsq $-0x79435e50d79435e5, %r12 # imm = 0x86BCA1AF286BCA1B
subq %rax, %rcx
je 0x95c2c
sarq $0x3, %rcx
imulq %r12, %rcx
movsd 0x9e8(%rbx), %xmm0
addq $0x30, %rax
movl $0x1, %edx
movsd (%rax), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, (%rax)
movl %edx, %esi
addq $0x98, %rax
incl %edx
cmpq %rsi, %rcx
ja 0x95c11
movq 0x750(%rbx), %rax
movq 0x758(%rbx), %rcx
subq %rax, %rcx
je 0x95c73
sarq $0x3, %rcx
imulq %r12, %rcx
movsd 0x9e8(%rbx), %xmm0
addq $0x30, %rax
movl $0x1, %edx
movsd (%rax), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, (%rax)
movl %edx, %esi
addq $0x98, %rax
incl %edx
cmpq %rsi, %rcx
ja 0x95c58
leaq 0x8c8(%rbx), %r14
leaq 0x958(%rbx), %rcx
leaq 0x940(%rbx), %r9
movl $0x1, %r13d
xorl %ebp, %ebp
movl $0x1, %edi
movq %r15, %rsi
movq %r14, %rdx
xorl %r8d, %r8d
callq 0x717c
movq 0x910(%rbx), %rcx
movq 0x918(%rbx), %rdx
movq %rax, 0x9f0(%rbx)
subq %rcx, %rdx
je 0x95ce9
sarq $0x6, %rdx
addq $0x18, %rcx
xorl %ebp, %ebp
xorpd %xmm0, %xmm0
movsd (%rcx), %xmm1
xorl %eax, %eax
ucomisd %xmm0, %xmm1
seta %al
addl %eax, %ebp
movl %r13d, %eax
addq $0x40, %rcx
incl %r13d
cmpq %rax, %rdx
ja 0x95ccb
movq 0x1012d0(%rip), %r15    # 0x196fc0
leaq 0xc2109(%rip), %rsi     # 0x157e00
movl $0x15, %edx
movq %r15, %rdi
callq 0x44e0
movq 0x918(%rbx), %rsi
subq 0x910(%rbx), %rsi
sarq $0x6, %rsi
movq %r15, %rdi
callq 0x42b0
movq %rax, %r15
leaq 0xbbcc5(%rip), %rsi     # 0x1519ed
movl $0x8, %edx
movq %rax, %rdi
callq 0x44e0
movq %r15, %rdi
movl %ebp, %esi
callq 0x4750
movq %rax, %r15
leaq 0xc20cd(%rip), %rsi     # 0x157e16
movl $0x19, %edx
movq %rax, %rdi
callq 0x44e0
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x4420
movsbl %al, %esi
movq %r15, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x42c0
movsd 0x8(%rsp), %xmm0
subsd 0x9e8(%rbx), %xmm0
xorpd %xmm1, %xmm1
maxsd %xmm1, %xmm0
leaq 0x990(%rbx), %rsi
leaq 0x970(%rbx), %rdx
movq %r14, %rdi
callq 0x719ce
leaq 0x9b8(%rbx), %r14
movq 0x9a0(%rbx), %rax
movl 0x9a8(%rbx), %ecx
subq 0x990(%rbx), %rax
leaq (%rcx,%rax,8), %rsi
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
leaq 0x14(%rsp), %rdx
movl %ebp, (%rdx)
movq %r14, %rdi
callq 0x49326
leaq 0x9d0(%rbx), %r15
movq 0x9a0(%rbx), %rax
subq 0x990(%rbx), %rax
movl 0x9a8(%rbx), %ecx
leaq (%rcx,%rax,8), %rsi
leaq 0x10(%rsp), %rdx
movl %ebp, (%rdx)
movq %r15, %rdi
callq 0x49326
movq 0x970(%rbx), %rax
movq 0x978(%rbx), %rcx
movq $0x0, 0x988(%rbx)
subq %rax, %rcx
je 0x95f55
sarq $0x4, %rcx
imulq %r12, %rcx
movq (%r15), %rdx
movq (%r14), %rsi
xorl %edi, %edi
movabsq $-0x71c71c71c71c71c7, %r8 # imm = 0x8E38E38E38E38E39
imulq $0x130, %rdi, %r15      # imm = 0x130
leaq (%rax,%r15), %r9
movq 0x60(%rax,%r15), %r11
movq 0x68(%rax,%r15), %r14
movq %r14, %r10
subq %r11, %r10
sarq $0x3, %r10
imulq %r8, %r10
cmpl $0x0, 0x108(%rax,%r15)
jle 0x95ede
cmpq %r11, %r14
je 0x95ed6
movq 0x40(%r9), %r11
addq $0x38, %r9
xorl %r14d, %r14d
movq %r9, %r15
testq %r11, %r11
je 0x95eac
movq %r11, %r12
movq %r9, %r15
xorl %r13d, %r13d
cmpl %r14d, 0x20(%r12)
setl %r13b
cmovgeq %r12, %r15
movq 0x10(%r12,%r13,8), %r12
testq %r12, %r12
jne 0x95e92
movq %r9, %r12
cmpq %r9, %r15
je 0x95ebf
cmpl 0x20(%r15), %r14d
cmovlq %r9, %r15
movq %r15, %r12
movl 0x988(%rbx), %ebp
movslq 0x24(%r12), %r15
movl %ebp, (%rsi,%r15,4)
incl %r14d
cmpq %r14, %r10
ja 0x95e84
incl 0x988(%rbx)
jmp 0x95f46
cmpq %r11, %r14
je 0x95f40
movq 0x40(%r9), %r11
addq $0x38, %r9
xorl %r14d, %r14d
movq %r9, %r15
testq %r11, %r11
je 0x95f16
movq %r11, %r12
movq %r9, %r15
xorl %r13d, %r13d
cmpl %r14d, 0x20(%r12)
setl %r13b
cmovgeq %r12, %r15
movq 0x10(%r12,%r13,8), %r12
testq %r12, %r12
jne 0x95efc
movq %r9, %r12
cmpq %r9, %r15
je 0x95f29
cmpl 0x20(%r15), %r14d
cmovlq %r9, %r15
movq %r15, %r12
movl 0x98c(%rbx), %ebp
movslq 0x24(%r12), %r15
movl %ebp, (%rdx,%r15,4)
incl %r14d
cmpq %r14, %r10
ja 0x95eee
incl 0x98c(%rbx)
incq %rdi
movl %edi, %r9d
cmpq %r9, %rcx
ja 0x95e46
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq