// File: /workspace/github_cpp_makefile_star2_O3/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 0x52620
movq %r14, %rdi
movq %rbx, %rsi
callq 0x52620
movq 0x2f0(%rbx), %rax
movq 0x2f8(%rbx), %rcx
movabsq $-0x79435e50d79435e5, %r12 # imm = 0x86BCA1AF286BCA1B
subq %rax, %rcx
je 0x93bc8
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 0x93bad
movq 0x750(%rbx), %rax
movq 0x758(%rbx), %rcx
subq %rax, %rcx
je 0x93c0f
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 0x93bf4
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 0x732c
movq 0x910(%rbx), %rcx
movq 0x918(%rbx), %rdx
movq %rax, 0x9f0(%rbx)
subq %rcx, %rdx
je 0x93c85
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 0x93c67
movq 0x101334(%rip), %r15    # 0x194fc0
leaq 0xc22cd(%rip), %rsi     # 0x155f60
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 0xbbd99(%rip), %rsi     # 0x14fa5d
movl $0x8, %edx
movq %rax, %rdi
callq 0x44e0
movq %r15, %rdi
movl %ebp, %esi
callq 0x4750
movq %rax, %r15
leaq 0xc2291(%rip), %rsi     # 0x155f76
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 0x70d00
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 0x48a3e
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 0x48a3e
movq 0x970(%rbx), %rax
movq 0x978(%rbx), %rcx
movq $0x0, 0x988(%rbx)
subq %rax, %rcx
je 0x93ef1
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 0x93e7a
cmpq %r11, %r14
je 0x93e72
movq 0x40(%r9), %r11
addq $0x38, %r9
xorl %r14d, %r14d
movq %r9, %r12
testq %r11, %r11
je 0x93e5b
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 0x93e2e
movq %r9, %r12
cmpq %r9, %r15
je 0x93e5b
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 0x93e20
incl 0x988(%rbx)
jmp 0x93ee2
cmpq %r11, %r14
je 0x93edc
movq 0x40(%r9), %r11
addq $0x38, %r9
xorl %r14d, %r14d
movq %r9, %r12
testq %r11, %r11
je 0x93ec5
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 0x93e98
movq %r9, %r12
cmpq %r9, %r15
je 0x93ec5
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 0x93e8a
incl 0x98c(%rbx)
incq %rdi
movl %edi, %r9d
cmpq %r9, %rcx
ja 0x93de2
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq