// File: /workspace/github_cpp_makefile_star2_O2/Luthaf[P]zeopp/networkaccessibility.cc
// Function: AccessibilityClassNINF::segmentPoresBasedOnFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
bool AccessibilityClassNINF::segmentPoresBasedOnFile(string filename){

  fstream input;
  input.open(filename.c_str());

  int linecount=0;
  int maxid=-1;

  if(!input.is_open()){
    cout << "\n" << "Failed to open segment file  " << filename << "\n";
    cout << "Exiting function ..." << "\n";
    return false;
  }
  else{
    cout << "Reading segment file " << filename << "\n";

    segmentMapping.resize(vornet.nodes.size(), -1);

    // Read and store information about sphere defining segments 
    while(!input.eof()){
      double a,b,c, r;
      int id;

      input >> a >> b >> c >> id >> r;

      if(input.eof()) 
        break;

      r = r*0.5;
      if(id>maxid) maxid = id;

      for(unsigned int i=0; i< vornet.nodes.size(); i++)
         {
         if(vornet.nodes.at(i).active == true)
           {
           if(orgAtomNet->calcDistanceXYZABC(vornet.nodes.at(i).x, vornet.nodes.at(i).y ,vornet.nodes.at(i).z, a,b,c) <= r) 
             {
             // node is within segment sphere
             if(segmentMapping[i] != -1 && segmentMapping[i] != id)
               {
               cerr << "Voronoi node has been assigned to more than one segment. This is wrong.\n";
               abort();

               }else{
               segmentMapping[i] = id;
               };
             };
           };
         };

      linecount++;

    }
    input.close();
  }
  cout << "Segment file: " << linecount << " lines read.";
  cout << "Max segment ID = " << maxid << "\n";

  n_segments = maxid+1; // this assumes that the segmentation file has correct IDs (from 0 to maxid)

  return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x258, %rsp            # imm = 0x258
movq %rsi, %rbx
movq %rdi, %r14
leaq 0x48(%rsp), %r15
movq %r15, %rdi
callq 0x4540
movq (%rbx), %rsi
pushq $0x18
popq %rdx
movq %r15, %rdi
callq 0x4410
leaq 0xc8(%rsp), %rdi
callq 0x4130
movb %al, 0xf(%rsp)
testb %al, %al
je 0x702bd
movq 0xdfeb4(%rip), %rdi     # 0x14ffc0
leaq 0x94f98(%rip), %rsi     # 0x1050ab
callq 0x4480
movq %rax, %rdi
movq %rbx, %rsi
callq 0x43f0
leaq 0x92454(%rip), %rsi     # 0x10257e
movq %rax, %rdi
callq 0x4480
leaq 0x198(%r14), %r12
movq 0x68(%r14), %rsi
subq 0x60(%r14), %rsi
sarq $0x6, %rsi
leaq 0x20(%rsp), %rdx
orl $-0x1, (%rdx)
movq %r12, %rdi
callq 0x36f18
leaq 0x60(%r14), %r13
pushq $-0x1
popq %rbp
movl $0x0, 0x10(%rsp)
movq 0x48(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x2, 0x68(%rsp,%rax)
jne 0x7031d
leaq 0x48(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x42d0
movq %rax, %rdi
leaq 0x40(%rsp), %rsi
callq 0x42d0
movq %rax, %rdi
leaq 0x38(%rsp), %rsi
callq 0x42d0
movq %rax, %rdi
leaq 0x14(%rsp), %rsi
callq 0x42a0
movq %rax, %rdi
leaq 0x18(%rsp), %rsi
callq 0x42d0
movq 0x48(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x2, 0x68(%rsp,%rax)
jne 0x7031d
movsd 0x18(%rsp), %xmm0
mulsd 0x8be5b(%rip), %xmm0    # 0xfc038
movsd %xmm0, 0x18(%rsp)
movl 0x14(%rsp), %eax
cmpl %ebp, %eax
cmovgl %eax, %ebp
xorl %ebx, %ebx
movl %ebx, %ebx
movq 0x68(%r14), %rax
subq 0x60(%r14), %rax
sarq $0x6, %rax
cmpq %rbx, %rax
jbe 0x702b4
movq %r13, %rdi
movq %rbx, %rsi
callq 0xa848
cmpb $0x1, 0x38(%rax)
jne 0x702ad
movq (%r14), %r15
movq %r13, %rdi
movq %rbx, %rsi
callq 0xa848
movsd (%rax), %xmm0
movsd %xmm0, 0x30(%rsp)
movq %r13, %rdi
movq %rbx, %rsi
callq 0xa848
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0x28(%rsp)
movq %r13, %rdi
movq %rbx, %rsi
callq 0xa848
movsd 0x10(%rax), %xmm2
movsd 0x20(%rsp), %xmm3
movsd 0x40(%rsp), %xmm4
movsd 0x38(%rsp), %xmm5
movq %r15, %rdi
movsd 0x30(%rsp), %xmm0
movsd 0x28(%rsp), %xmm1
callq 0x3f56c
movsd 0x18(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jb 0x702ad
movq (%r12), %rax
movl (%rax,%rbx,4), %edx
cmpl $-0x1, %edx
sete %sil
movl 0x14(%rsp), %ecx
cmpl %ecx, %edx
sete %dl
orb %sil, %dl
je 0x703aa
movl %ecx, (%rax,%rbx,4)
incl %ebx
jmp 0x701ee
incl 0x10(%rsp)
jmp 0x70164
movq 0xdfcfc(%rip), %rdi     # 0x14ffc0
leaq 0x922b3(%rip), %rsi     # 0x10257e
callq 0x4480
leaq 0x94da1(%rip), %rsi     # 0x105078
movq %rax, %rdi
callq 0x4480
movq %rax, %rdi
movq %rbx, %rsi
callq 0x43f0
leaq 0x9228d(%rip), %rsi     # 0x10257e
movq %rax, %rdi
callq 0x4480
movq 0xdfcc0(%rip), %rdi     # 0x14ffc0
leaq 0x94d8f(%rip), %rsi     # 0x105096
callq 0x4480
leaq 0x9226b(%rip), %rsi     # 0x10257e
movq %rax, %rdi
callq 0x4480
jmp 0x7038a
leaq 0x48(%rsp), %rdi
callq 0x4080
movq 0xdfc92(%rip), %rdi     # 0x14ffc0
leaq 0x94dd5(%rip), %rsi     # 0x10510a
callq 0x4480
movq %rax, %rdi
movl 0x10(%rsp), %esi
callq 0x4760
leaq 0x94562(%rip), %rsi     # 0x1048af
movq %rax, %rdi
callq 0x4480
movq 0xdfc64(%rip), %rdi     # 0x14ffc0
leaq 0x94db6(%rip), %rsi     # 0x105119
callq 0x4480
movq %rax, %rdi
movl %ebp, %esi
callq 0x4760
leaq 0x92205(%rip), %rsi     # 0x10257e
movq %rax, %rdi
callq 0x4480
incl %ebp
movl %ebp, 0x190(%r14)
leaq 0x48(%rsp), %rdi
callq 0x4120
movb 0xf(%rsp), %al
addq $0x258, %rsp            # imm = 0x258
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xdfc3f(%rip), %rdi     # 0x14fff0
leaq 0x94d09(%rip), %rsi     # 0x1050c1
callq 0x4480
callq 0x4290
jmp 0x703cc
jmp 0x703cc
jmp 0x703cc
jmp 0x703cc
jmp 0x703cc
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x4120
movq %rbx, %rdi
callq 0x4780
nop