// File: 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
movq %rsp, %rbp
subq $0x370, %rsp            # imm = 0x370
movq %rsi, -0x288(%rbp)
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x290(%rbp)
leaq -0x228(%rbp), %rdi
callq 0x5660
movq -0x288(%rbp), %rdi
callq 0x5200
movq %rax, -0x280(%rbp)
movl $0x8, %edi
movl $0x10, %esi
callq 0x47640
movl %eax, -0x274(%rbp)
jmp 0x10021b
movl -0x274(%rbp), %edx
movq -0x280(%rbp), %rsi
leaq -0x228(%rbp), %rdi
callq 0x54b0
jmp 0x100236
movl $0x0, -0x238(%rbp)
movl $0xffffffff, -0x23c(%rbp) # imm = 0xFFFFFFFF
leaq -0x228(%rbp), %rdi
callq 0x58b0
movb %al, -0x291(%rbp)
jmp 0x10025e
movb -0x291(%rbp), %al
testb $0x1, %al
jne 0x10033e
jmp 0x10026e
movq 0x172d4b(%rip), %rdi    # 0x272fc0
leaq 0xf93a9(%rip), %rsi     # 0x1f9625
callq 0x5540
movq %rax, -0x2a0(%rbp)
jmp 0x10028a
movq -0x2a0(%rbp), %rdi
leaq 0xfca98(%rip), %rsi     # 0x1fcd30
callq 0x5540
movq %rax, -0x2a8(%rbp)
jmp 0x1002a6
movq -0x288(%rbp), %rsi
movq -0x2a8(%rbp), %rdi
callq 0x5480
movq %rax, -0x2b0(%rbp)
jmp 0x1002c2
movq -0x2b0(%rbp), %rdi
leaq 0xf9355(%rip), %rsi     # 0x1f9625
callq 0x5540
jmp 0x1002d7
movq 0x172ce2(%rip), %rdi    # 0x272fc0
leaq 0xfca69(%rip), %rsi     # 0x1fcd4e
callq 0x5540
movq %rax, -0x2b8(%rbp)
jmp 0x1002f3
movq -0x2b8(%rbp), %rdi
leaq 0xf9324(%rip), %rsi     # 0x1f9625
callq 0x5540
jmp 0x100308
movb $0x0, -0x1(%rbp)
movl $0x1, -0x240(%rbp)
jmp 0x1007df
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x230(%rbp)
movl %eax, -0x234(%rbp)
leaq -0x228(%rbp), %rdi
callq 0x5150
jmp 0x1007f9
movq 0x172c7b(%rip), %rdi    # 0x272fc0
leaq 0xfca17(%rip), %rsi     # 0x1fcd63
callq 0x5540
movq %rax, -0x2c0(%rbp)
jmp 0x10035a
movq -0x288(%rbp), %rsi
movq -0x2c0(%rbp), %rdi
callq 0x5480
movq %rax, -0x2c8(%rbp)
jmp 0x100376
movq -0x2c8(%rbp), %rdi
leaq 0xf92a1(%rip), %rsi     # 0x1f9625
callq 0x5540
jmp 0x10038b
movq -0x290(%rbp), %rdi
movq %rdi, %rax
addq $0x198, %rax            # imm = 0x198
movq %rax, -0x2d0(%rbp)
addq $0x60, %rdi
callq 0xf270
movq -0x2d0(%rbp), %rdi
movq %rax, %rsi
movl $0xffffffff, -0x244(%rbp) # imm = 0xFFFFFFFF
leaq -0x244(%rbp), %rdx
callq 0x84b00
jmp 0x1003cd
jmp 0x1003cf
movq -0x228(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x228(%rbp,%rax), %rdi
callq 0x5960
movb %al, -0x2d1(%rbp)
jmp 0x1003ef
movb -0x2d1(%rbp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x100400
jmp 0x100713
leaq -0x228(%rbp), %rdi
leaq -0x250(%rbp), %rsi
callq 0x5420
movq %rax, -0x2e0(%rbp)
jmp 0x10041c
movq -0x2e0(%rbp), %rdi
leaq -0x258(%rbp), %rsi
callq 0x5420
movq %rax, -0x2e8(%rbp)
jmp 0x100438
movq -0x2e8(%rbp), %rdi
leaq -0x260(%rbp), %rsi
callq 0x5420
movq %rax, -0x2f0(%rbp)
jmp 0x100454
movq -0x2f0(%rbp), %rdi
leaq -0x26c(%rbp), %rsi
callq 0x52f0
movq %rax, -0x2f8(%rbp)
jmp 0x100470
movq -0x2f8(%rbp), %rdi
leaq -0x268(%rbp), %rsi
callq 0x5420
jmp 0x100485
movq -0x228(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x228(%rbp,%rax), %rdi
callq 0x5960
movb %al, -0x2f9(%rbp)
jmp 0x1004a5
movb -0x2f9(%rbp), %al
testb $0x1, %al
jne 0x1004b1
jmp 0x1004b6
jmp 0x100713
movsd 0xf1bba(%rip), %xmm0    # 0x1f2078
mulsd -0x268(%rbp), %xmm0
movsd %xmm0, -0x268(%rbp)
movl -0x26c(%rbp), %eax
cmpl -0x23c(%rbp), %eax
jle 0x1004e8
movl -0x26c(%rbp), %eax
movl %eax, -0x23c(%rbp)
movl $0x0, -0x270(%rbp)
movq -0x290(%rbp), %rdi
movl -0x270(%rbp), %eax
movq %rax, -0x308(%rbp)
addq $0x18, %rdi
addq $0x48, %rdi
callq 0xf270
movq %rax, %rcx
movq -0x308(%rbp), %rax
cmpq %rcx, %rax
jae 0x1006ff
movq -0x290(%rbp), %rdi
addq $0x60, %rdi
movl -0x270(%rbp), %eax
movl %eax, %esi
callq 0xf390
movq %rax, -0x310(%rbp)
jmp 0x100547
movq -0x310(%rbp), %rax
movb 0x38(%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0x1006e9
movq -0x290(%rbp), %rdi
movq (%rdi), %rax
movq %rax, -0x320(%rbp)
addq $0x60, %rdi
movl -0x270(%rbp), %eax
movl %eax, %esi
callq 0xf390
movq %rax, -0x318(%rbp)
jmp 0x10058a
movq -0x290(%rbp), %rdi
movq -0x318(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x330(%rbp)
addq $0x60, %rdi
movl -0x270(%rbp), %eax
movl %eax, %esi
callq 0xf390
movq %rax, -0x328(%rbp)
jmp 0x1005be
movq -0x290(%rbp), %rdi
movq -0x328(%rbp), %rax
movsd 0x8(%rax), %xmm0
movsd %xmm0, -0x340(%rbp)
addq $0x60, %rdi
movl -0x270(%rbp), %eax
movl %eax, %esi
callq 0xf390
movq %rax, -0x338(%rbp)
jmp 0x1005f3
movsd -0x340(%rbp), %xmm1
movsd -0x330(%rbp), %xmm0
movq -0x320(%rbp), %rdi
movq -0x338(%rbp), %rax
movsd 0x10(%rax), %xmm2
movsd -0x250(%rbp), %xmm3
movsd -0x258(%rbp), %xmm4
movsd -0x260(%rbp), %xmm5
callq 0x978a0
movsd %xmm0, -0x348(%rbp)
jmp 0x10063d
movsd -0x348(%rbp), %xmm1
movsd -0x268(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jb 0x1006e7
movq -0x290(%rbp), %rdi
addq $0x198, %rdi            # imm = 0x198
movl -0x270(%rbp), %eax
movl %eax, %esi
callq 0xed60
cmpl $-0x1, (%rax)
je 0x1006b6
movq -0x290(%rbp), %rdi
addq $0x198, %rdi            # imm = 0x198
movl -0x270(%rbp), %eax
movl %eax, %esi
callq 0xed60
movl (%rax), %eax
cmpl -0x26c(%rbp), %eax
je 0x1006b6
movq 0x17294d(%rip), %rdi    # 0x272ff0
leaq 0xfc6cf(%rip), %rsi     # 0x1fcd79
callq 0x5540
jmp 0x1006b1
callq 0x52b0
movq -0x290(%rbp), %rdi
movl -0x26c(%rbp), %eax
movl %eax, -0x34c(%rbp)
addq $0x198, %rdi            # imm = 0x198
movl -0x270(%rbp), %eax
movl %eax, %esi
callq 0xed60
movl -0x34c(%rbp), %ecx
movl %ecx, (%rax)
jmp 0x1006e7
jmp 0x1006e9
jmp 0x1006eb
movl -0x270(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x270(%rbp)
jmp 0x1004f2
movl -0x238(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x238(%rbp)
jmp 0x1003cf
leaq -0x228(%rbp), %rdi
callq 0x50a0
jmp 0x100721
jmp 0x100723
movq 0x172896(%rip), %rdi    # 0x272fc0
leaq 0xfc691(%rip), %rsi     # 0x1fcdc2
callq 0x5540
movq %rax, -0x358(%rbp)
jmp 0x10073f
movq -0x358(%rbp), %rdi
movl -0x238(%rbp), %esi
callq 0x58d0
movq %rax, -0x360(%rbp)
jmp 0x10075a
movq -0x360(%rbp), %rdi
leaq 0xfbea0(%rip), %rsi     # 0x1fc608
callq 0x5540
jmp 0x10076f
movq 0x17284a(%rip), %rdi    # 0x272fc0
leaq 0xfc654(%rip), %rsi     # 0x1fcdd1
callq 0x5540
movq %rax, -0x368(%rbp)
jmp 0x10078b
movq -0x368(%rbp), %rdi
movl -0x23c(%rbp), %esi
callq 0x58d0
movq %rax, -0x370(%rbp)
jmp 0x1007a6
movq -0x370(%rbp), %rdi
leaq 0xf8e71(%rip), %rsi     # 0x1f9625
callq 0x5540
jmp 0x1007bb
movq -0x290(%rbp), %rax
movl -0x23c(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, 0x190(%rax)
movb $0x1, -0x1(%rbp)
movl $0x1, -0x240(%rbp)
leaq -0x228(%rbp), %rdi
callq 0x5150
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x370, %rsp            # imm = 0x370
popq %rbp
retq
movq -0x230(%rbp), %rdi
callq 0x58f0
nopw %cs:(%rax,%rax)