// File: Luthaf[P]zeopp/feature.cc
// Function: FEATURE::validateSegment(int)
int FEATURE::validateSegment(int segid){
int i;
int id,conn_to;
int nvisited=0;
int valid=1;
vector <int> nodelist;
vector <int> visited;

vector <int> heap;

/* count nodes and init heap */
for(i=0;i<(int)nodes.size();i++)
   {
   if(segments[i]==segid) 
      {
      nodelist.push_back(i);
//      visited.push_back(-1);
      };
   visited.push_back(-1);
   };

heap.push_back(nodelist[0]);
visited[nodelist[0]]=1;
nvisited++;

/* investigate connections by adding them to heap */
while(nvisited<(int)nodelist.size())
   {
   if(heap.size()==0)
     {
     valid=0;
     break;
     };

   id=heap.back();heap.pop_back();

   /* current node is id, investigate its connections, add to heap */

   for(i=0;i<(int)nodes.at(id).connections.size();i++)
      {
      conn_to=nodes.at(id).connections.at(i).to;

      if(segments[conn_to]==segid&&visited[conn_to]==-1) // if connected to other node within same segment and not visited, add to heap
        {
        heap.push_back(conn_to);
        nvisited++;
        visited[conn_to]=1;
        };
      };

   };


return valid;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x80(%rbp)
movl $0x0, -0x1c(%rbp)
movl $0x1, -0x20(%rbp)
leaq -0x38(%rbp), %rdi
callq 0xd0d0
leaq -0x50(%rbp), %rdi
callq 0xd0d0
leaq -0x68(%rbp), %rdi
callq 0xd0d0
movl $0x0, -0x10(%rbp)
movq -0x80(%rbp), %rdi
movl -0x10(%rbp), %eax
movl %eax, -0x84(%rbp)
addq $0x60, %rdi
callq 0x10100
movq %rax, %rcx
movl -0x84(%rbp), %eax
cmpl %ecx, %eax
jge 0xdc10b
movq -0x80(%rbp), %rdi
addq $0x140, %rdi            # imm = 0x140
movslq -0x10(%rbp), %rsi
callq 0xed60
movl (%rax), %eax
cmpl -0xc(%rbp), %eax
jne 0xdc0e5
leaq -0x38(%rbp), %rdi
leaq -0x10(%rbp), %rsi
callq 0xd1b0
jmp 0xdc0b7
jmp 0xdc0e5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x68(%rbp), %rdi
callq 0xec80
leaq -0x50(%rbp), %rdi
callq 0xec80
leaq -0x38(%rbp), %rdi
callq 0xec80
jmp 0xdc2d2
movl $0xffffffff, -0x78(%rbp) # imm = 0xFFFFFFFF
leaq -0x50(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0xffc0
jmp 0xdc0fb
jmp 0xdc0fd
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0xdc06a
xorl %eax, %eax
movl %eax, %esi
leaq -0x38(%rbp), %rdi
callq 0xed60
movq %rax, %rsi
leaq -0x68(%rbp), %rdi
callq 0xd1b0
jmp 0xdc126
leaq -0x38(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xed60
movslq (%rax), %rsi
leaq -0x50(%rbp), %rdi
callq 0xed60
movl $0x1, (%rax)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x88(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x10090
movq %rax, %rcx
movl -0x88(%rbp), %eax
cmpl %ecx, %eax
jge 0xdc29f
leaq -0x68(%rbp), %rdi
callq 0x10090
cmpq $0x0, %rax
jne 0xdc18c
movl $0x0, -0x20(%rbp)
jmp 0xdc29f
leaq -0x68(%rbp), %rdi
callq 0x29870
movl (%rax), %eax
movl %eax, -0x14(%rbp)
leaq -0x68(%rbp), %rdi
callq 0xaefa0
movl $0x0, -0x10(%rbp)
movq -0x80(%rbp), %rdi
movl -0x10(%rbp), %eax
movl %eax, -0x94(%rbp)
addq $0x60, %rdi
movslq -0x14(%rbp), %rsi
callq 0x10130
movq %rax, -0x90(%rbp)
jmp 0xdc1cd
movq -0x90(%rbp), %rdi
addq $0x20, %rdi
callq 0x2a9e0
movq %rax, %rcx
movl -0x94(%rbp), %eax
cmpl %ecx, %eax
jge 0xdc29a
movq -0x80(%rbp), %rdi
addq $0x60, %rdi
movslq -0x14(%rbp), %rsi
callq 0x10130
movq %rax, -0xa0(%rbp)
jmp 0xdc208
movq -0xa0(%rbp), %rdi
addq $0x20, %rdi
movslq -0x10(%rbp), %rsi
callq 0x64470
movq %rax, -0xa8(%rbp)
jmp 0xdc225
movq -0x80(%rbp), %rdi
movq -0xa8(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x18(%rbp)
addq $0x140, %rdi            # imm = 0x140
movslq -0x18(%rbp), %rsi
callq 0xed60
movl (%rax), %eax
cmpl -0xc(%rbp), %eax
jne 0xdc28a
movslq -0x18(%rbp), %rsi
leaq -0x50(%rbp), %rdi
callq 0xed60
cmpl $-0x1, (%rax)
jne 0xdc28a
leaq -0x68(%rbp), %rdi
leaq -0x18(%rbp), %rsi
callq 0xd1b0
jmp 0xdc26e
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
movslq -0x18(%rbp), %rsi
leaq -0x50(%rbp), %rdi
callq 0xed60
movl $0x1, (%rax)
jmp 0xdc28c
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0xdc1aa
jmp 0xdc14e
movl -0x20(%rbp), %eax
movl %eax, -0xac(%rbp)
leaq -0x68(%rbp), %rdi
callq 0xec80
leaq -0x50(%rbp), %rdi
callq 0xec80
leaq -0x38(%rbp), %rdi
callq 0xec80
movl -0xac(%rbp), %eax
addq $0xb0, %rsp
popq %rbp
retq
movq -0x70(%rbp), %rdi
callq 0x58f0
nopl (%rax,%rax)