// File: /workspace/github_cpp_makefile_star2_O1/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 $0x248, %rsp            # imm = 0x248
movq %rsi, %rbx
movq %rdi, %r14
leaq 0x38(%rsp), %r15
movq %r15, %rdi
callq 0x4520
movq (%rbx), %rsi
movq %r15, %rdi
movl $0x18, %edx
callq 0x43d0
leaq 0xb8(%rsp), %rdi
callq 0x4120
movl %eax, %r15d
testb %al, %al
je 0x982bc
movq 0xfef4f(%rip), %rdi     # 0x196fc0
leaq 0xbff93(%rip), %rsi     # 0x15800b
movl $0x15, %edx
callq 0x44e0
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq 0xfef30(%rip), %rdi     # 0x196fc0
callq 0x44e0
leaq 0xbd492(%rip), %rsi     # 0x15552e
movl $0x1, %edx
movq %rax, %rdi
callq 0x44e0
movb %r15b, 0xf(%rsp)
movq 0x68(%r14), %rsi
subq 0x60(%r14), %rsi
leaq 0x198(%r14), %r12
sarq $0x6, %rsi
leaq 0x20(%rsp), %rdx
movl $0xffffffff, (%rdx)     # imm = 0xFFFFFFFF
movq %r12, %rdi
callq 0x49326
movl $0xffffffff, 0x10(%rsp) # imm = 0xFFFFFFFF
xorl %ebx, %ebx
leaq 0x38(%rsp), %r15
leaq 0x20(%rsp), %rbp
movq 0x38(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x2, 0x58(%rsp,%rax)
jne 0x98227
movq %r15, %rdi
movq %rbp, %rsi
callq 0x42a0
movq %rax, %rdi
leaq 0x30(%rsp), %rsi
callq 0x42a0
movq %rax, %rdi
leaq 0x28(%rsp), %rsi
callq 0x42a0
movq %rax, %rdi
leaq 0x14(%rsp), %rsi
callq 0x4270
movq %rax, %rdi
leaq 0x18(%rsp), %rsi
callq 0x42a0
movq 0x38(%rsp), %rax
movq -0x18(%rax), %rax
movl 0x58(%rsp,%rax), %r13d
testb $0x2, %r13b
jne 0x9821d
movq %rbx, %rbp
movsd 0x18(%rsp), %xmm0
mulsd 0xb6ed4(%rip), %xmm0    # 0x14f038
movl 0x14(%rsp), %eax
movl 0x10(%rsp), %ecx
cmpl %ecx, %eax
cmovgl %eax, %ecx
movl %ecx, 0x10(%rsp)
movsd %xmm0, 0x18(%rsp)
movq 0x60(%r14), %rax
cmpq %rax, 0x68(%r14)
je 0x9820e
movl $0x1, %ebx
xorl %r15d, %r15d
movq %r15, %rcx
shlq $0x6, %rcx
cmpb $0x1, 0x38(%rax,%rcx)
jne 0x981f5
addq %rcx, %rax
movq (%r14), %rdi
movsd (%rax), %xmm0
movsd 0x8(%rax), %xmm1
movsd 0x10(%rax), %xmm2
movsd 0x20(%rsp), %xmm3
movsd 0x30(%rsp), %xmm4
movsd 0x28(%rsp), %xmm5
callq 0x53836
movsd 0x18(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jb 0x981f5
movq (%r12), %rax
movl (%rax,%r15,4), %ecx
cmpl $-0x1, %ecx
je 0x981ed
cmpl 0x14(%rsp), %ecx
jne 0x98362
movl 0x14(%rsp), %ecx
movl %ecx, (%rax,%r15,4)
movl %ebx, %r15d
movq 0x60(%r14), %rax
movq 0x68(%r14), %rcx
subq %rax, %rcx
sarq $0x6, %rcx
incl %ebx
cmpq %r15, %rcx
ja 0x98191
movq %rbp, %rbx
incl %ebx
leaq 0x38(%rsp), %r15
leaq 0x20(%rsp), %rbp
testb $0x2, %r13b
je 0x980e8
leaq 0x38(%rsp), %rdi
callq 0x4090
movb 0xf(%rsp), %r15b
movl 0x10(%rsp), %ebp
movq 0xfed7f(%rip), %rdi     # 0x196fc0
leaq 0xbfe22(%rip), %rsi     # 0x15806a
movl $0xe, %edx
callq 0x44e0
movq 0xfed67(%rip), %rdi     # 0x196fc0
movl %ebx, %esi
callq 0x4750
leaq 0xbf5a8(%rip), %rsi     # 0x15780f
movl $0xc, %edx
movq %rax, %rdi
callq 0x44e0
movq 0xfed45(%rip), %rdi     # 0x196fc0
leaq 0xbfdf7(%rip), %rsi     # 0x158079
movl $0x11, %edx
callq 0x44e0
movq 0xfed2d(%rip), %rdi     # 0x196fc0
movl %ebp, %esi
callq 0x4750
leaq 0xbd28d(%rip), %rsi     # 0x15552e
movl $0x1, %edx
movq %rax, %rdi
callq 0x44e0
incl %ebp
movl %ebp, 0x190(%r14)
jmp 0x98343
movq 0xfecfd(%rip), %rdi     # 0x196fc0
leaq 0xbd264(%rip), %rsi     # 0x15552e
movl $0x1, %edx
callq 0x44e0
movq 0xfece5(%rip), %rdi     # 0x196fc0
leaq 0xbfcf6(%rip), %rsi     # 0x157fd8
movl $0x1d, %edx
callq 0x44e0
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq 0xfecc6(%rip), %rdi     # 0x196fc0
callq 0x44e0
leaq 0xbd228(%rip), %rsi     # 0x15552e
movl $0x1, %edx
movq %rax, %rdi
callq 0x44e0
movq 0xfeca6(%rip), %rdi     # 0x196fc0
leaq 0xbfcd5(%rip), %rsi     # 0x157ff6
movl $0x14, %edx
callq 0x44e0
movq 0xfec8e(%rip), %rdi     # 0x196fc0
leaq 0xbd1f5(%rip), %rsi     # 0x15552e
movl $0x1, %edx
callq 0x44e0
leaq 0x38(%rsp), %rdi
callq 0x4110
movl %r15d, %eax
addq $0x248, %rsp            # imm = 0x248
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xfec87(%rip), %rdi     # 0x196ff0
leaq 0xbfcb1(%rip), %rsi     # 0x158021
callq 0x4440
callq 0x4260
jmp 0x98384
jmp 0x98384
jmp 0x98384
jmp 0x98384
jmp 0x98384
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x4110
movq %rbx, %rdi
callq 0x4780
nop