// File: 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
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movb %cl, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
andb $0x1, %al
movb %al, -0x19(%rbp)
movsd %xmm0, -0x28(%rbp)
movsd %xmm1, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x88(%rbp)
movsd -0x30(%rbp), %xmm0
movsd %xmm0, 0x9e8(%rax)
movb -0x19(%rbp), %cl
andb $0x1, %cl
movb %cl, 0x8c0(%rax)
testb $0x1, -0x19(%rbp)
je 0xfd27b
movq -0x88(%rbp), %rsi
movq -0x10(%rbp), %rdi
addq $0x460, %rsi            # imm = 0x460
callq 0x96980
movq -0x88(%rbp), %rsi
movq -0x18(%rbp), %rdi
callq 0x96980
jmp 0xfd2a2
movq -0x88(%rbp), %rsi
movq -0x18(%rbp), %rdi
addq $0x460, %rsi            # imm = 0x460
callq 0x96980
movq -0x88(%rbp), %rsi
movq -0x18(%rbp), %rdi
callq 0x96980
movl $0x0, -0x34(%rbp)
movq -0x88(%rbp), %rdi
movl -0x34(%rbp), %eax
movq %rax, -0x90(%rbp)
addq $0x2f0, %rdi            # imm = 0x2F0
callq 0xf060
movq %rax, %rcx
movq -0x90(%rbp), %rax
cmpq %rcx, %rax
jae 0xfd31a
movq -0x88(%rbp), %rdi
movsd 0x9e8(%rdi), %xmm0
movsd %xmm0, -0x98(%rbp)
addq $0x2f0, %rdi            # imm = 0x2F0
movl -0x34(%rbp), %eax
movl %eax, %esi
callq 0xfcc0
movsd -0x98(%rbp), %xmm0
addsd 0x30(%rax), %xmm0
movsd %xmm0, 0x30(%rax)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0xfd2a9
movl $0x0, -0x38(%rbp)
movq -0x88(%rbp), %rdi
movl -0x38(%rbp), %eax
movq %rax, -0xa0(%rbp)
addq $0x460, %rdi            # imm = 0x460
addq $0x2f0, %rdi            # imm = 0x2F0
callq 0xf060
movq %rax, %rcx
movq -0xa0(%rbp), %rax
cmpq %rcx, %rax
jae 0xfd3a0
movq -0x88(%rbp), %rdi
movsd 0x9e8(%rdi), %xmm0
movsd %xmm0, -0xa8(%rbp)
addq $0x460, %rdi            # imm = 0x460
addq $0x2f0, %rdi            # imm = 0x2F0
movl -0x38(%rbp), %eax
movl %eax, %esi
callq 0xfcc0
movsd -0xa8(%rbp), %xmm0
addsd 0x30(%rax), %xmm0
movsd %xmm0, 0x30(%rax)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0xfd321
movq -0x88(%rbp), %r9
movq %r9, %rsi
addq $0x460, %rsi            # imm = 0x460
movq %r9, %rdx
addq $0x8c8, %rdx            # imm = 0x8C8
movq %r9, %rcx
addq $0x958, %rcx            # imm = 0x958
addq $0x940, %r9             # imm = 0x940
movl $0x1, %edi
xorl %r8d, %r8d
callq 0x6950
movq %rax, %rcx
movq -0x88(%rbp), %rax
movq %rcx, 0x9f0(%rax)
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
movq -0x88(%rbp), %rdi
movl -0x40(%rbp), %eax
movq %rax, -0xb0(%rbp)
addq $0x8c8, %rdi            # imm = 0x8C8
addq $0x48, %rdi
callq 0xf270
movq %rax, %rcx
movq -0xb0(%rbp), %rax
cmpq %rcx, %rax
jae 0xfd468
movq -0x88(%rbp), %rdi
addq $0x8c8, %rdi            # imm = 0x8C8
addq $0x48, %rdi
movl -0x40(%rbp), %eax
movl %eax, %esi
callq 0xf390
movsd 0x18(%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0xfd45b
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0xfd45d
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0xfd3f8
movq 0x175b51(%rip), %rdi    # 0x272fc0
leaq 0xff6e2(%rip), %rsi     # 0x1fcb58
callq 0x5540
movq -0x88(%rbp), %rdi
movq %rax, -0xd0(%rbp)
addq $0x8c8, %rdi            # imm = 0x8C8
addq $0x48, %rdi
callq 0xf270
movq -0xd0(%rbp), %rdi
movq %rax, %rsi
callq 0x5160
movq %rax, %rdi
leaq 0xf75ed(%rip), %rsi     # 0x1f4a9f
callq 0x5540
movq %rax, %rdi
movl -0x3c(%rbp), %esi
callq 0x58d0
movq %rax, %rdi
leaq 0xff6a2(%rip), %rsi     # 0x1fcb6e
callq 0x5540
movq %rax, %rdi
movq 0x175abd(%rip), %rsi    # 0x272f98
callq 0x55b0
movq -0x88(%rbp), %rax
movq %rax, %rcx
addq $0x8c8, %rcx            # imm = 0x8C8
movq %rcx, -0xc8(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x28(%rbp), %xmm0
subsd 0x9e8(%rax), %xmm0
movsd %xmm0, -0x50(%rbp)
leaq -0x48(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x64c70
movq -0xc8(%rbp), %rdi
movq -0x88(%rbp), %rdx
movsd (%rax), %xmm0
movq %rdx, %rsi
addq $0x990, %rsi            # imm = 0x990
addq $0x970, %rdx            # imm = 0x970
callq 0xc6740
movq -0x88(%rbp), %rdi
movq %rdi, %rax
addq $0x9b8, %rax            # imm = 0x9B8
movq %rax, -0xc0(%rbp)
addq $0x990, %rdi            # imm = 0x990
callq 0x27d50
movq -0xc0(%rbp), %rdi
movq %rax, %rsi
movl $0xffffffff, -0x54(%rbp) # imm = 0xFFFFFFFF
leaq -0x54(%rbp), %rdx
callq 0x84b00
movq -0x88(%rbp), %rdi
movq %rdi, %rax
addq $0x9d0, %rax            # imm = 0x9D0
movq %rax, -0xb8(%rbp)
addq $0x990, %rdi            # imm = 0x990
callq 0x27d50
movq -0xb8(%rbp), %rdi
movq %rax, %rsi
movl $0xffffffff, -0x58(%rbp) # imm = 0xFFFFFFFF
leaq -0x58(%rbp), %rdx
callq 0x84b00
movq -0x88(%rbp), %rax
movl $0x0, 0x988(%rax)
movl $0x0, 0x98c(%rax)
movl $0x0, -0x5c(%rbp)
movq -0x88(%rbp), %rdi
movl -0x5c(%rbp), %eax
movq %rax, -0xd8(%rbp)
addq $0x970, %rdi            # imm = 0x970
callq 0x10230
movq %rax, %rcx
movq -0xd8(%rbp), %rax
cmpq %rcx, %rax
jae 0xfd7fb
movq -0x88(%rbp), %rdi
addq $0x970, %rdi            # imm = 0x970
movl -0x5c(%rbp), %eax
movl %eax, %esi
callq 0x10260
cmpl $0x0, 0x108(%rax)
jle 0xfd714
movl $0x0, -0x60(%rbp)
movq -0x88(%rbp), %rdi
movl -0x60(%rbp), %eax
movq %rax, -0xe0(%rbp)
addq $0x970, %rdi            # imm = 0x970
movl -0x5c(%rbp), %eax
movl %eax, %esi
callq 0x10260
movq %rax, %rdi
addq $0x60, %rdi
callq 0x10100
movq %rax, %rcx
movq -0xe0(%rbp), %rax
cmpq %rcx, %rax
jae 0xfd6f9
movq -0x88(%rbp), %rdi
movl 0x988(%rdi), %eax
movl %eax, -0xe4(%rbp)
movq %rdi, %rax
addq $0x9b8, %rax            # imm = 0x9B8
movq %rax, -0xf0(%rbp)
addq $0x970, %rdi            # imm = 0x970
movl -0x5c(%rbp), %eax
movl %eax, %esi
callq 0x10260
movq %rax, %rdi
addq $0x30, %rdi
movl -0x60(%rbp), %eax
movl %eax, -0x6c(%rbp)
leaq -0x6c(%rbp), %rsi
callq 0x102e0
movq %rax, -0x68(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x10350
movq -0xf0(%rbp), %rdi
movslq 0x4(%rax), %rsi
callq 0xed60
movl -0xe4(%rbp), %ecx
movl %ecx, (%rax)
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
jmp 0xfd63f
movq -0x88(%rbp), %rax
movl 0x988(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x988(%rax)
jmp 0xfd7eb
movl $0x0, -0x70(%rbp)
movq -0x88(%rbp), %rdi
movl -0x70(%rbp), %eax
movq %rax, -0xf8(%rbp)
addq $0x970, %rdi            # imm = 0x970
movl -0x5c(%rbp), %eax
movl %eax, %esi
callq 0x10260
movq %rax, %rdi
addq $0x60, %rdi
callq 0x10100
movq %rax, %rcx
movq -0xf8(%rbp), %rax
cmpq %rcx, %rax
jae 0xfd7d5
movq -0x88(%rbp), %rdi
movl 0x98c(%rdi), %eax
movl %eax, -0xfc(%rbp)
movq %rdi, %rax
addq $0x9d0, %rax            # imm = 0x9D0
movq %rax, -0x108(%rbp)
addq $0x970, %rdi            # imm = 0x970
movl -0x5c(%rbp), %eax
movl %eax, %esi
callq 0x10260
movq %rax, %rdi
addq $0x30, %rdi
movl -0x70(%rbp), %eax
movl %eax, -0x7c(%rbp)
leaq -0x7c(%rbp), %rsi
callq 0x102e0
movq %rax, -0x78(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x10350
movq -0x108(%rbp), %rdi
movslq 0x4(%rax), %rsi
callq 0xed60
movl -0xfc(%rbp), %ecx
movl %ecx, (%rax)
movl -0x70(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x70(%rbp)
jmp 0xfd71b
movq -0x88(%rbp), %rax
movl 0x98c(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x98c(%rax)
jmp 0xfd7ed
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0xfd5e3
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
nopw %cs:(%rax,%rax)