// File: /workspace/github_c_makefile_star2_O2/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, 0x10(%rsp)
movl %edx, (%rsp)
movl %esi, %r13d
movq %rdi, %r15
movl 0x10(%rdi), %eax
decl %eax
cmpl %esi, %eax
jne 0x2922
movslq %r13d, %r14
leaq 0x18(%r15), %rbx
pushq $0x1
popq %rbp
movq 0x88(%r15), %rax
movslq (%rax,%r14,4), %rcx
testq %rcx, %rcx
je 0x2b03
movq 0x80(%r15), %rdx
movq (%rdx,%r14,8), %rdx
leaq -0x1(%rcx), %rsi
movl %esi, (%rax,%r14,4)
movl -0x4(%rdx,%rcx,4), %r12d
cmpb $0x1, 0x1(%r15)
jne 0x28e0
movq 0x98(%r15), %rax
movsd (%rax,%r14,8), %xmm0
callq 0x6ec0
testb %al, %al
je 0x2897
movq 0x90(%r15), %rdi
movl %r12d, %esi
movl %r13d, %edx
callq 0x3d48
movq %rax, %r12
movl %r13d, %edi
callq 0x3e00
movq %rbx, %rdi
movl (%rsp), %esi
movq %r12, %rdx
movl %eax, %ecx
callq 0x4064
movq %rbx, %rdi
movl %eax, %esi
movl %ebp, %edx
callq 0x4058
incl 0x14(%r15)
jmp 0x2897
movq 0x80(%r15), %rdx
movq 0x88(%r15), %rax
movslq %r13d, %rbx
xorl %esi, %esi
movslq (%rax,%rbx,4), %rcx
cmpq %rcx, %rsi
jge 0x2952
movq (%rdx,%rbx,8), %rcx
movq 0x8(%rdx,%rbx,8), %rdi
movl (%rcx,%rsi,4), %ecx
movl %ecx, (%rdi,%rsi,4)
incq %rsi
jmp 0x2935
leal 0x1(%r13), %edx
movl %edx, 0x8(%rsp)
movslq %edx, %rdx
movq %rdx, 0x18(%rsp)
leaq 0x18(%r15), %rdx
movq %rdx, 0x28(%rsp)
testl %r13d, %r13d
movl $0x0, %ebp
cmovgl %r13d, %ebp
movl (%rsp), %edx
movl %edx, 0x4(%rsp)
movq %r13, 0x20(%rsp)
movq %rbx, 0x30(%rsp)
testl %ecx, %ecx
je 0x2b03
movq 0x80(%r15), %rdx
movq (%rdx,%rbx,8), %rsi
leal -0x1(%rcx), %edx
movl %edx, (%rax,%rbx,4)
movslq %ecx, %rcx
movl -0x4(%rsi,%rcx,4), %r14d
cmpb $0x1, 0x1(%r15)
jne 0x29d3
movq 0x98(%r15), %rax
movsd (%rax,%rbx,8), %xmm0
callq 0x6ec0
testb %al, %al
je 0x2af4
movq 0x88(%r15), %rax
movl (%rax,%rbx,4), %edx
movq 0x18(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movq 0x90(%r15), %rax
movl %r14d, (%rax,%rbx,4)
movq 0x8(%r15), %rdi
movq (%rdi), %rax
movl %r14d, %esi
callq *0xa8(%rax)
movq %rax, %r13
movq 0x8(%r15), %rdi
movq (%rdi), %rax
movl %r14d, 0xc(%rsp)
movl %r14d, %esi
callq *0x68(%rax)
movl %eax, %ebx
testl %eax, %eax
movl $0x0, %eax
cmovlel %eax, %ebx
xorl %r14d, %r14d
cmpq %rbx, %r14
je 0x2a97
movl (%r13,%r14,4), %eax
movq 0x90(%r15), %rcx
cmpl (%rcx), %eax
jle 0x2a92
xorl %r12d, %r12d
cmpq %r12, %rbp
je 0x2a5e
movl (%r13,%r14,4), %esi
movq 0x90(%r15), %rax
movl (%rax,%r12,4), %edx
cmpl %edx, %esi
je 0x2a61
movq 0x8(%r15), %rdi
movq (%rdi), %rax
callq *0x50(%rax)
testb %al, %al
jne 0x2a61
incq %r12
jmp 0x2a32
movl %ebp, %r12d
cmpl 0x20(%rsp), %r12d
jne 0x2a92
movl (%r13,%r14,4), %eax
movq 0x80(%r15), %rcx
movq 0x88(%r15), %rdx
movq 0x18(%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 %r14
jmp 0x2a1a
movq 0x20(%rsp), %r13
testl %r13d, %r13d
jle 0x2ada
movq 0x90(%r15), %rdi
movl 0xc(%rsp), %esi
movl %r13d, %edx
callq 0x3d48
movq %rax, %rbx
movl %r13d, %edi
callq 0x3e00
movq 0x28(%rsp), %rdi
movl (%rsp), %esi
movq %rbx, 0x10(%rsp)
movq %rbx, %rdx
movl %eax, %ecx
callq 0x4064
movl %eax, 0x4(%rsp)
movq %r15, %rdi
movl 0x8(%rsp), %esi
movl 0x4(%rsp), %edx
movq 0x10(%rsp), %rcx
callq 0x2864
movq 0x30(%rsp), %rbx
movq 0x88(%r15), %rax
movl (%rax,%rbx,4), %ecx
jmp 0x2988
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq