// File: Luthaf[P]zeopp/network.cc
// Function: NEWcalculateFreeSphereParameters(MATERIAL*)
void NEWcalculateFreeSphereParameters(MATERIAL *Mat){

  if(Mat->doneFlatVoroFlag == false)
    {
    Mat->runVoroFlat();
    };

  vector<double> freeRadResults;
  vector<double> incRadResults;
  vector<bool> NtoN;

  DELTA_POS directions [3] = {DELTA_POS(1,0,0), DELTA_POS(0,1,0), DELTA_POS(0,0,1)};
  for(unsigned int i = 0; i < 3; i++){
    VORONOI_NETWORK newNet;
    set<int> sourceNodes;
    map<int,int> idAliases;
    extendVorNet(&(Mat->vornet), &newNet, directions[i], &idAliases, &sourceNodes);
   
    DIJKSTRA_NETWORK dnet;
    DIJKSTRA_NETWORK::buildDijkstraNetwork(&newNet,&dnet);

    TRAVERSAL_NETWORK analyzeNet = TRAVERSAL_NETWORK(directions[i].x,directions[i].y,directions[i].z, &dnet);    
    pair<bool,PATH> results = analyzeNet.findMaxFreeSphere(&idAliases, &sourceNodes);
    
    freeRadResults.push_back(2*results.second.max_radius);
    incRadResults.push_back(2*results.second.max_inc_radius);
    NtoN.push_back(results.first);
  }

  double maxd=0.0; int maxdir=0;
  for(unsigned int i = 0; i < freeRadResults.size(); i++)
     {
     if(i==0) {maxd=freeRadResults[i]; maxdir=i;}
       else
       {
       if(maxd<freeRadResults[i])
         {
         maxd=freeRadResults[i]; 
         maxdir=i;
         }
       else if(maxd==freeRadResults[i])
         {
         if(incRadResults[maxdir]<incRadResults[i]) maxdir=i;
         };
       };
     };

 Mat->directionDf = freeRadResults; Mat->directionDif = incRadResults;
 Mat->Di = 2 * findMaxIncludedSphere(&(Mat->vornet));
 Mat->Df = freeRadResults[maxdir];
 Mat->Dif = incRadResults[maxdir];

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x3a0, %rsp            # imm = 0x3A0
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movb 0xc20(%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x8b9c
movq -0x8(%rbp), %rdi
callq 0x172610
leaq -0x20(%rbp), %rdi
callq 0xf650
leaq -0x38(%rbp), %rdi
callq 0xf650
leaq -0x60(%rbp), %rdi
callq 0xf670
leaq -0x90(%rbp), %rdi
movl $0x1, %esi
xorl %ecx, %ecx
movl %ecx, %edx
callq 0x94010
jmp 0x8bce
leaq -0x84(%rbp), %rdi
movl $0x1, %edx
xorl %ecx, %ecx
movl %ecx, %esi
callq 0x94010
jmp 0x8be5
leaq -0x78(%rbp), %rdi
xorl %edx, %edx
movl $0x1, %ecx
movl %edx, %esi
callq 0x94010
jmp 0x8bf9
movl $0x0, -0xa0(%rbp)
cmpl $0x3, -0xa0(%rbp)
jae 0x8ea1
leaq -0x118(%rbp), %rdi
callq 0x99ba0
jmp 0x8c1e
leaq -0x148(%rbp), %rdi
movq %rdi, -0x368(%rbp)
callq 0xf690
leaq -0x178(%rbp), %rdi
movq %rdi, -0x370(%rbp)
callq 0xf6b0
movq -0x370(%rbp), %r8
movq -0x368(%rbp), %r9
movq -0x8(%rbp), %rdi
addq $0x8c0, %rdi            # imm = 0x8C0
movl -0xa0(%rbp), %eax
leaq (%rax,%rax,2), %rax
movl -0x88(%rbp,%rax,4), %ecx
movl %ecx, -0x180(%rbp)
movq -0x90(%rbp,%rax,4), %rax
movq %rax, -0x188(%rbp)
movl -0x180(%rbp), %eax
movl %eax, -0x190(%rbp)
movq -0x188(%rbp), %rax
movq %rax, -0x198(%rbp)
movq -0x198(%rbp), %rdx
movl -0x190(%rbp), %ecx
leaq -0x118(%rbp), %rsi
callq 0x7a80
jmp 0x8cb8
leaq -0x1f8(%rbp), %rdi
callq 0x94790
jmp 0x8cc6
leaq -0x118(%rbp), %rdi
leaq -0x1f8(%rbp), %rsi
callq 0x948c0
jmp 0x8cdb
movl -0xa0(%rbp), %eax
leaq (%rax,%rax,2), %rax
movl -0x90(%rbp,%rax,4), %esi
movl -0x8c(%rbp,%rax,4), %edx
movl -0x88(%rbp,%rax,4), %ecx
leaq -0x270(%rbp), %rdi
leaq -0x1f8(%rbp), %r8
callq 0x5d5d0
jmp 0x8d0f
leaq -0x340(%rbp), %rdi
leaq -0x270(%rbp), %rsi
leaq -0x178(%rbp), %rdx
leaq -0x148(%rbp), %rcx
callq 0x5e3a0
jmp 0x8d32
movsd -0x2d8(%rbp), %xmm0
addsd %xmm0, %xmm0
movsd %xmm0, -0x348(%rbp)
leaq -0x20(%rbp), %rdi
leaq -0x348(%rbp), %rsi
callq 0xf6d0
jmp 0x8d58
movsd -0x2d0(%rbp), %xmm0
addsd %xmm0, %xmm0
movsd %xmm0, -0x350(%rbp)
leaq -0x38(%rbp), %rdi
leaq -0x350(%rbp), %rsi
callq 0xf6d0
jmp 0x8d7e
movzbl -0x340(%rbp), %esi
andl $0x1, %esi
leaq -0x60(%rbp), %rdi
callq 0xf700
jmp 0x8d93
leaq -0x340(%rbp), %rdi
callq 0xf7d0
leaq -0x270(%rbp), %rdi
callq 0xf7f0
leaq -0x1f8(%rbp), %rdi
callq 0xf840
leaq -0x178(%rbp), %rdi
callq 0xf860
leaq -0x148(%rbp), %rdi
callq 0xf880
leaq -0x118(%rbp), %rdi
callq 0xf8a0
movl -0xa0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa0(%rbp)
jmp 0x8c03
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
jmp 0x90e3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
jmp 0x8e78
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
jmp 0x8e6c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
jmp 0x8e60
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
leaq -0x340(%rbp), %rdi
callq 0xf7d0
leaq -0x270(%rbp), %rdi
callq 0xf7f0
leaq -0x1f8(%rbp), %rdi
callq 0xf840
leaq -0x178(%rbp), %rdi
callq 0xf860
leaq -0x148(%rbp), %rdi
callq 0xf880
leaq -0x118(%rbp), %rdi
callq 0xf8a0
jmp 0x90e3
xorps %xmm0, %xmm0
movsd %xmm0, -0x358(%rbp)
movl $0x0, -0x35c(%rbp)
movl $0x0, -0x360(%rbp)
movl -0x360(%rbp), %eax
movq %rax, -0x378(%rbp)
leaq -0x20(%rbp), %rdi
callq 0xf990
movq %rax, %rcx
movq -0x378(%rbp), %rax
cmpq %rcx, %rax
jae 0x9019
cmpl $0x0, -0x360(%rbp)
jne 0x8f20
movl -0x360(%rbp), %eax
movl %eax, %esi
leaq -0x20(%rbp), %rdi
callq 0xedb0
movsd (%rax), %xmm0
movsd %xmm0, -0x358(%rbp)
movl -0x360(%rbp), %eax
movl %eax, -0x35c(%rbp)
jmp 0x9003
movsd -0x358(%rbp), %xmm0
movsd %xmm0, -0x380(%rbp)
movl -0x360(%rbp), %eax
movl %eax, %esi
leaq -0x20(%rbp), %rdi
callq 0xedb0
movsd -0x380(%rbp), %xmm1
movsd (%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x8f81
movl -0x360(%rbp), %eax
movl %eax, %esi
leaq -0x20(%rbp), %rdi
callq 0xedb0
movsd (%rax), %xmm0
movsd %xmm0, -0x358(%rbp)
movl -0x360(%rbp), %eax
movl %eax, -0x35c(%rbp)
jmp 0x9001
movsd -0x358(%rbp), %xmm0
movsd %xmm0, -0x388(%rbp)
movl -0x360(%rbp), %eax
movl %eax, %esi
leaq -0x20(%rbp), %rdi
callq 0xedb0
movsd -0x388(%rbp), %xmm0
ucomisd (%rax), %xmm0
jne 0x8fff
jp 0x8fff
movslq -0x35c(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0xedb0
movsd (%rax), %xmm0
movsd %xmm0, -0x390(%rbp)
movl -0x360(%rbp), %eax
movl %eax, %esi
leaq -0x38(%rbp), %rdi
callq 0xedb0
movsd -0x390(%rbp), %xmm1
movsd (%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x8ffd
movl -0x360(%rbp), %eax
movl %eax, -0x35c(%rbp)
jmp 0x8fff
jmp 0x9001
jmp 0x9003
jmp 0x9005
movl -0x360(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x360(%rbp)
jmp 0x8ec0
movq -0x8(%rbp), %rdi
addq $0xc40, %rdi            # imm = 0xC40
leaq -0x20(%rbp), %rsi
callq 0xfa30
jmp 0x902f
movq -0x8(%rbp), %rdi
addq $0xc58, %rdi            # imm = 0xC58
leaq -0x38(%rbp), %rsi
callq 0xfa30
jmp 0x9045
movq -0x8(%rbp), %rdi
addq $0x8c0, %rdi            # imm = 0x8C0
callq 0x5fdc0
movsd %xmm0, -0x398(%rbp)
jmp 0x905f
movsd -0x398(%rbp), %xmm1
movsd 0x1e8fd9(%rip), %xmm0   # 0x1f2048
mulsd %xmm1, %xmm0
movq -0x8(%rbp), %rax
movsd %xmm0, 0xc28(%rax)
movslq -0x35c(%rbp), %rsi
leaq -0x20(%rbp), %rdi
callq 0xedb0
movsd (%rax), %xmm0
movq -0x8(%rbp), %rax
movsd %xmm0, 0xc30(%rax)
movslq -0x35c(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0xedb0
movsd (%rax), %xmm0
movq -0x8(%rbp), %rax
movsd %xmm0, 0xc38(%rax)
leaq -0x60(%rbp), %rdi
callq 0xf9b0
leaq -0x38(%rbp), %rdi
callq 0xf9d0
leaq -0x20(%rbp), %rdi
callq 0xf9d0
addq $0x3a0, %rsp            # imm = 0x3A0
popq %rbp
retq
leaq -0x60(%rbp), %rdi
callq 0xf9b0
leaq -0x38(%rbp), %rdi
callq 0xf9d0
leaq -0x20(%rbp), %rdi
callq 0xf9d0
movq -0x98(%rbp), %rdi
callq 0x58f0
nopw (%rax,%rax)