// File: /workspace/github_c_makefile_star2_O2/ComplexNetworks-DCC-FCUP[P]gtrieScanner/GTrie.cpp
// Function: GTrieNode::readFromFile(_IO_FILE*)
void GTrieNode::readFromFile(FILE *f) {
  int nchilds, i, j, pos, bits, ncond;
  iPair p;
  char aux, buf[MAX_BUF];
  GTrieNode *c;

  if (fgets(buf, MAX_BUF, f)) {
    aux = buf[0]-BASE_FIRST;
    if (BIT_VALUE(aux, 0)) is_graph=true;
    else                   is_graph=false;
    int nbytes = aux>>1;

    pos = 1;

    for (i=0, j=1, nchilds=0; i<nbytes; i++, j*=BASE_FORMAT) {
      aux = buf[pos++]-BASE_FIRST;
      nchilds += int(aux)*j;
    }

    // Connections: outgoing
    aux = buf[pos++]-BASE_FIRST;
    for (i=0, bits=0; i<depth; i++, bits++) {
      if (bits==BASE_BITS) {
	aux = buf[pos++]-BASE_FIRST;
	bits=0;
      }
      if (BIT_VALUE(aux, bits)) out[i] = true;
      else                      out[i] = false;
    }

    // Connections: ingoing
    aux = buf[pos++]-BASE_FIRST;
    for (i=0, bits=0; i<depth; i++, bits++) {
      if (bits==BASE_BITS) {
	aux = buf[pos++]-BASE_FIRST;
	bits=0;
      }
      if (BIT_VALUE(aux, bits)) in[i] = true;
      else                      in[i] = false;
    }

    // Previous Conditions
    aux = buf[pos++]-BASE_FIRST;
    if (aux==0) cond_ok = true;
    else        cond_ok = false;

    if (aux>0) {
      ncond = aux;
      for (i=0; i<ncond; i++) {
	list<iPair> newcond;
	while(1) {
	  aux = buf[pos++]-BASE_FIRST-1;
	  if (aux<0) break;
	  p.first = aux;
	  aux = buf[pos++]-BASE_FIRST-1;
	  p.second = aux;
	  newcond.push_back(p);
	}
	cond.push_back(newcond);
      }
    }
    
    if (buf[pos]!='\n') {
      fprintf(stderr, "ERROR: [%s] !%d!%c!\n", buf, pos, buf[pos]);
      fprintf(stderr,"[%d](%s) |", depth, is_graph?"X":" ");
      for (i=0, bits=0; i<depth; i++, bits++)
	fprintf(stderr,"%s", out[i]?"1":"0");
      fprintf(stderr,"|\n");
    }

    // Conn and nconn variables (was missing)
    for (i=0; i<depth; i++)
      if (out[i] || in[i]) 
      conn[(nconn)++] = i;
    
    
    for (i=0; i<nchilds; i++) {
      c = new GTrieNode(depth+1);
      c->readFromFile(f);
      child.push_back(c);
    }

  }

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x448, %rsp            # imm = 0x448
movq %rsi, %rbx
movq %rdi, %r14
andq $0x0, 0x8(%rsp)
leaq 0x40(%rsp), %r15
movq %r15, %rdi
movl $0x400, %esi            # imm = 0x400
movq %rbx, %rdx
callq 0x2360
testq %rax, %rax
je 0x93c1
movb 0x40(%rsp), %cl
leal -0x20(%rcx), %eax
andb $0x1, %cl
sarb %al
movzbl %al, %edx
xorl %eax, %eax
testb %dl, %dl
cmovlel %eax, %edx
movb %cl, 0x50(%r14)
movzbl %dl, %ecx
pushq $0x1
popq %rdx
xorl %r10d, %r10d
cmpq %rax, %rcx
je 0x91cc
movb 0x41(%rsp,%rax), %sil
addb $-0x20, %sil
movsbl %sil, %esi
imull %edx, %esi
addl %esi, %r10d
imull $0x5f, %edx, %edx
incq %rax
jmp 0x91ac
movl %ecx, %eax
addl $0x2, %ecx
movb 0x1(%rax,%r15), %sil
addb $-0x20, %sil
movl 0x4c(%r14), %eax
movq 0x60(%r14), %rdx
xorl %edi, %edi
testl %eax, %eax
cmovlel %edi, %eax
xorl %r8d, %r8d
movslq %ecx, %r9
cmpq %rdi, %rax
je 0x921e
cmpl $0x6, %r8d
jne 0x920a
leal 0x1(%r9), %ecx
movb 0x40(%rsp,%r9), %sil
addb $-0x20, %sil
xorl %r8d, %r8d
movsbl %sil, %r9d
btl %r8d, %r9d
setb (%rdx,%rdi)
incq %rdi
incl %r8d
jmp 0x91ec
leal 0x1(%r9), %ecx
movb 0x40(%rsp,%r9), %dil
addb $-0x20, %dil
movq 0x58(%r14), %rdx
xorl %esi, %esi
xorl %r8d, %r8d
movslq %ecx, %r9
cmpq %rsi, %rax
je 0x9266
cmpl $0x6, %r8d
jne 0x9252
leal 0x1(%r9), %ecx
movb 0x40(%rsp,%r9), %dil
addb $-0x20, %dil
xorl %r8d, %r8d
movsbl %dil, %r9d
btl %r8d, %r9d
setb (%rdx,%rsi)
incq %rsi
incl %r8d
jmp 0x9234
leal 0x1(%r9), %r15d
movb 0x40(%rsp,%r9), %al
addb $-0x20, %al
testb %al, %al
movq %rbx, 0x10(%rsp)
je 0x9323
movb $0x0, 0x48(%r14)
jle 0x9328
movl %r10d, (%rsp)
movsbl %al, %eax
movl %eax, 0x4(%rsp)
leaq 0x18(%r14), %rax
movq %rax, 0x18(%rsp)
xorl %r12d, %r12d
leaq 0x28(%rsp), %r13
leaq 0x8(%rsp), %rbp
cmpl 0x4(%rsp), %r12d
je 0x931d
movq %r13, 0x30(%rsp)
movq %r13, 0x28(%rsp)
andq $0x0, 0x38(%rsp)
movslq %r15d, %r15
leaq 0x41(%rsp), %rax
leaq (%rax,%r15), %rbx
incl %r15d
movb -0x1(%rbx), %al
addb $-0x21, %al
js 0x92fe
movzbl %al, %eax
movl %eax, 0x8(%rsp)
movb (%rbx), %al
addb $-0x21, %al
movsbl %al, %eax
movl %eax, 0xc(%rsp)
addq $0x2, %rbx
addl $0x2, %r15d
movq %r13, %rdi
movq %rbp, %rsi
callq 0x6666
jmp 0x92d0
movq 0x18(%rsp), %rdi
movq %r13, %rsi
callq 0xa3fc
movq %r13, %rdi
callq 0x67ea
incl %r12d
movq 0x10(%rsp), %rbx
jmp 0x92aa
movl (%rsp), %r10d
jmp 0x9328
movb $0x1, 0x48(%r14)
movslq %r15d, %rax
movsbl 0x40(%rsp,%rax), %r8d
cmpl $0xa, %r8d
jne 0x93d3
movq 0x58(%r14), %rax
movq 0x60(%r14), %rcx
movq 0x78(%r14), %rdx
xorl %esi, %esi
movslq 0x4c(%r14), %rdi
cmpq %rdi, %rsi
jge 0x9372
cmpb $0x0, (%rcx,%rsi)
jne 0x935e
cmpb $0x1, (%rax,%rsi)
jne 0x936d
movslq 0x74(%r14), %rdi
leal 0x1(%rdi), %r8d
movl %r8d, 0x74(%r14)
movl %esi, (%rdx,%rdi,4)
incq %rsi
jmp 0x9349
leaq 0x30(%r14), %r15
xorl %ebp, %ebp
testl %r10d, %r10d
cmovgl %r10d, %ebp
leaq 0x20(%rsp), %r12
subl $0x1, %ebp
jb 0x93c1
movl $0x80, %edi
callq 0x2200
movq %rax, %r13
movl 0x4c(%r14), %esi
incl %esi
movq %rax, %rdi
callq 0x7d48
movq %r13, 0x20(%rsp)
movq %r13, %rdi
movq %rbx, %rsi
callq 0x914e
movq %r15, %rdi
movq %r12, %rsi
callq 0xa32c
jmp 0x9384
addq $0x448, %rsp            # imm = 0x448
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %r10d, %ebp
movq 0xebfb(%rip), %r12      # 0x17fd8
movq (%r12), %rdi
leaq 0x78fe(%rip), %rsi      # 0x10ce6
xorl %r13d, %r13d
leaq 0x40(%rsp), %rdx
movl %r15d, %ecx
xorl %eax, %eax
callq 0x2310
movq (%r12), %rdi
movl 0x4c(%r14), %edx
leaq 0x78fd(%rip), %rax      # 0x10d06
leaq 0x803d(%rip), %rcx      # 0x1144d
cmpb $0x0, 0x50(%r14)
cmovneq %rax, %rcx
leaq 0x78db(%rip), %rsi      # 0x10cfb
xorl %eax, %eax
callq 0x2310
leaq 0x75d6(%rip), %rbx      # 0x10a04
leaq 0x7893(%rip), %r15      # 0x10cc8
movslq 0x4c(%r14), %rax
movq (%r12), %rcx
cmpq %rax, %r13
jge 0x945f
movq 0x60(%r14), %rax
cmpb $0x0, (%rax,%r13)
movq %r15, %rdi
cmovneq %rbx, %rdi
movq %rcx, %rsi
callq 0x2240
incq %r13
jmp 0x9435
leaq 0x78a2(%rip), %rdi      # 0x10d08
pushq $0x2
popq %rsi
pushq $0x1
popq %rdx
callq 0x2420
movq 0x10(%rsp), %rbx
movl %ebp, %r10d
jmp 0x933b
jmp 0x9492
movq %rax, %rbx
movl $0x80, %esi
movq %r13, %rdi
callq 0x2210
jmp 0x949f
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x67ea
movq %rbx, %rdi
callq 0x23b0
nop