// File: /workspace/github_c_makefile_star2_O1/ComplexNetworks-DCC-FCUP[P]fase/Fase.cpp
// Function: Fase::expandEnumeration(int, int, long long)
void Fase::expandEnumeration(int depth, int labelNode, long long int label)
{
  if (depth == K - 1)
  {
    while (vextSz[depth])
    {
      int currentVertex = vext[depth][--vextSz[depth]];

      if (!sampling || Random::testProb(sampProb[depth]))
      {
        long long int clabel = Label::updateLabel(vsub, currentVertex, depth);
        igtrie.incrementLabel(igtrie.insertLabel(labelNode, clabel, Label::repDigits(depth)), 1);

        motifCount++;
      }
    }

    return;
  }

  int i, j;
  long long int clabel = label;
  int clabelNode = labelNode;

  for (i = 0; i < vextSz[depth]; i++)
    vext[depth + 1][i] = vext[depth][i];

  while (vextSz[depth])
  {
    int currentVertex = vext[depth][--vextSz[depth]];

    if (!sampling || Random::testProb(sampProb[depth]))
    {
      vextSz[depth + 1] = vextSz[depth];
      vsub[depth] = currentVertex;

      int *eExcl = graph->arrayNeighbours(currentVertex);
      int eExclNum = graph->numNeighbours(currentVertex);
      
      for (i = 0; i < eExclNum; i++)
      {
        if (eExcl[i] <= vsub[0])
          continue;

        for (j = 0; j < depth; j++)
          if (eExcl[i] == vsub[j] || graph->isConnected(eExcl[i], vsub[j]))
            break;

        if (j == depth)
          vext[depth + 1][vextSz[depth + 1]++] = eExcl[i];
      }

      if (depth >= 1)
      {
        clabel = Label::updateLabel(vsub, currentVertex, depth);
        clabelNode = igtrie.insertLabel(labelNode, clabel, Label::repDigits(depth));
      }

      expandEnumeration(depth + 1, clabelNode, clabel);
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rcx, 0x18(%rsp)
movl %edx, (%rsp)
movl %esi, %r12d
movq %rdi, %r15
movl 0x10(%rdi), %eax
decl %eax
cmpl %esi, %eax
movq %r12, 0x8(%rsp)
jne 0x2bbf
movslq %r12d, %r13
movq 0x88(%r15), %rcx
movl (%rcx,%r13,4), %eax
testl %eax, %eax
je 0x2dac
leaq (%rcx,%r13,4), %rcx
leaq 0x18(%r15), %rbx
movq 0x80(%r15), %rdx
movq (%rdx,%r13,8), %rdx
leal -0x1(%rax), %esi
movl %esi, (%rcx)
cltq
movl -0x4(%rdx,%rax,4), %ebp
cmpb $0x1, 0x1(%r15)
jne 0x2b5f
movq 0x98(%r15), %rax
movsd (%rax,%r13,8), %xmm0
callq 0x794c
testb %al, %al
je 0x2ba5
movq 0x90(%r15), %rdi
movl %ebp, %esi
movl %r12d, %edx
callq 0x44ac
movq %rax, %r12
movq 0x8(%rsp), %rdi
callq 0x4570
movq %rbx, %rdi
movl (%rsp), %esi
movq %r12, %rdx
movq 0x8(%rsp), %r12
movl %eax, %ecx
callq 0x481e
movq %rbx, %rdi
movl %eax, %esi
movl $0x1, %edx
callq 0x4812
incl 0x14(%r15)
movq 0x88(%r15), %rax
leaq (%rax,%r13,4), %rcx
movl (%rcx), %eax
testl %eax, %eax
jne 0x2b2c
jmp 0x2dac
movq 0x88(%r15), %rax
movslq %r12d, %rbx
cmpl $0x0, (%rax,%rbx,4)
jle 0x2bf3
movq 0x80(%r15), %rdx
movq (%rdx,%rbx,8), %rcx
movq 0x8(%rdx,%rbx,8), %rdx
xorl %esi, %esi
movl (%rcx,%rsi,4), %edi
movl %edi, (%rdx,%rsi,4)
incq %rsi
movslq (%rax,%rbx,4), %rdi
cmpq %rdi, %rsi
jl 0x2be1
movq 0x88(%r15), %rcx
movl (%rcx,%rbx,4), %eax
testl %eax, %eax
je 0x2dac
movl %r12d, %r14d
leaq (%rcx,%rbx,4), %rcx
leal 0x1(%r12), %edx
movl %edx, 0x10(%rsp)
movslq %edx, %rdx
movq %rdx, 0x20(%rsp)
leaq 0x18(%r15), %rdx
movq %rdx, 0x28(%rsp)
movl (%rsp), %edx
movl %edx, 0x4(%rsp)
movq %rbx, 0x30(%rsp)
movq 0x80(%r15), %rdx
movq (%rdx,%rbx,8), %rdx
leal -0x1(%rax), %esi
movl %esi, (%rcx)
cltq
movl -0x4(%rdx,%rax,4), %ebp
cmpb $0x1, 0x1(%r15)
jne 0x2c68
movq 0x98(%r15), %rax
movsd (%rax,%rbx,8), %xmm0
callq 0x794c
testb %al, %al
je 0x2d97
movq 0x88(%r15), %rax
movl (%rax,%rbx,4), %ecx
movq 0x20(%rsp), %rdx
movl %ecx, (%rax,%rdx,4)
movq 0x90(%r15), %rax
movl %ebp, (%rax,%rbx,4)
movq 0x8(%r15), %rdi
movq (%rdi), %rax
movl %ebp, %esi
callq *0xa8(%rax)
movq %rax, %r13
movq 0x8(%r15), %rdi
movq (%rdi), %rax
movl %ebp, 0x14(%rsp)
movl %ebp, %esi
callq *0x68(%rax)
testl %eax, %eax
jle 0x2d3f
movl %eax, %ebp
xorl %ebx, %ebx
movl (%r13,%rbx,4), %eax
movq 0x90(%r15), %rcx
cmpl (%rcx), %eax
jle 0x2d33
testl %r12d, %r12d
jle 0x2cf9
xorl %r12d, %r12d
movl (%r13,%rbx,4), %esi
movq 0x90(%r15), %rax
movl (%rax,%r12,4), %edx
cmpl %edx, %esi
je 0x2cfc
movq 0x8(%r15), %rdi
movq (%rdi), %rax
callq *0x50(%rax)
testb %al, %al
jne 0x2cfc
incq %r12
cmpq %r12, %r14
jne 0x2cca
movl %r14d, %r12d
jmp 0x2cfc
xorl %r12d, %r12d
movq 0x8(%rsp), %rax
cmpl %eax, %r12d
movq %rax, %r12
jne 0x2d33
movl (%r13,%rbx,4), %eax
movq 0x80(%r15), %rcx
movq 0x88(%r15), %rdx
movq 0x20(%rsp), %r8
movq (%rcx,%r8,8), %rcx
movslq (%rdx,%r8,4), %rsi
leal 0x1(%rsi), %edi
movl %edi, (%rdx,%r8,4)
movl %eax, (%rcx,%rsi,4)
incq %rbx
cmpq %rbp, %rbx
jne 0x2cb2
testl %r12d, %r12d
jle 0x2d7d
movq 0x90(%r15), %rdi
movl 0x14(%rsp), %esi
movl %r12d, %edx
callq 0x44ac
movq %rax, %rbx
movl %r12d, %edi
callq 0x4570
movq 0x28(%rsp), %rdi
movl (%rsp), %esi
movq %rbx, 0x18(%rsp)
movq %rbx, %rdx
movl %eax, %ecx
callq 0x481e
movl %eax, 0x4(%rsp)
movq %r15, %rdi
movl 0x10(%rsp), %esi
movl 0x4(%rsp), %edx
movq 0x18(%rsp), %rcx
callq 0x2ae0
movq 0x30(%rsp), %rbx
movq 0x88(%r15), %rax
leaq (%rax,%rbx,4), %rcx
movl (%rcx), %eax
testl %eax, %eax
jne 0x2c32
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop