// File: /workspace/github_c_makefile_star2_O3/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 $0x48, %rsp
movq %rcx, 0x28(%rsp)
movl %edx, 0xc(%rsp)
movq %rdi, %r15
movl 0x10(%rdi), %eax
decl %eax
cmpl %esi, %eax
movq %rsi, 0x10(%rsp)
jne 0x2bba
movslq %esi, %r13
movq 0x88(%r15), %rcx
movl (%rcx,%r13,4), %eax
testl %eax, %eax
je 0x2da4
leaq (%rcx,%r13,4), %rcx
leaq 0x18(%r15), %rbx
movq 0x10(%rsp), %r14
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 0x2b60
movq 0x98(%r15), %rax
movsd (%rax,%r13,8), %xmm0
callq 0x7a3c
testb %al, %al
je 0x2ba0
movq 0x90(%r15), %rdi
movl %ebp, %esi
movl %r14d, %edx
callq 0x44b8
movq %rax, %r12
movl %r14d, %edi
callq 0x457c
movq %rbx, %rdi
movl 0xc(%rsp), %esi
movq %r12, %rdx
movl %eax, %ecx
callq 0x483a
movq %rbx, %rdi
movl %eax, %esi
movl $0x1, %edx
callq 0x482e
incl 0x14(%r15)
movq 0x88(%r15), %rax
leaq (%rax,%r13,4), %rcx
movl (%rcx), %eax
testl %eax, %eax
jne 0x2b2d
jmp 0x2da4
movq 0x88(%r15), %rax
movslq %esi, %r14
movl (%rax,%r14,4), %ecx
testl %ecx, %ecx
jle 0x2bf0
movq 0x80(%r15), %rcx
movq (%rcx,%r14,8), %rdx
movq 0x8(%rcx,%r14,8), %rsi
xorl %edi, %edi
movl (%rdx,%rdi,4), %ecx
movl %ecx, (%rsi,%rdi,4)
incq %rdi
movslq (%rax,%r14,4), %rcx
cmpq %rcx, %rdi
jl 0x2bde
testl %ecx, %ecx
je 0x2da4
movq 0x10(%rsp), %rdx
leal 0x1(%rdx), %esi
movl %esi, 0x20(%rsp)
movslq %esi, %rsi
movq %rsi, 0x30(%rsp)
leaq 0x18(%r15), %rsi
movq %rsi, 0x38(%rsp)
movl %edx, %ebx
movl 0xc(%rsp), %edx
movl %edx, 0x1c(%rsp)
movq %r14, 0x40(%rsp)
movq 0x80(%r15), %rdx
movq (%rdx,%r14,8), %rdx
leal -0x1(%rcx), %esi
movl %esi, (%rax,%r14,4)
movslq %ecx, %rcx
movl -0x4(%rdx,%rcx,4), %ebp
cmpb $0x1, 0x1(%r15)
jne 0x2c65
movq 0x98(%r15), %rax
movsd (%rax,%r14,8), %xmm0
callq 0x7a3c
testb %al, %al
je 0x2d91
movq 0x88(%r15), %rax
movl (%rax,%r14,4), %ecx
movq 0x30(%rsp), %rdx
movl %ecx, (%rax,%rdx,4)
movq 0x90(%r15), %rax
movl %ebp, (%rax,%r14,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, 0x24(%rsp)
movl %ebp, %esi
callq *0x68(%rax)
testl %eax, %eax
jle 0x2d33
movl %eax, %ebp
xorl %r14d, %r14d
movl (%r13,%r14,4), %eax
movq 0x90(%r15), %rcx
cmpl (%rcx), %eax
jle 0x2d27
movq 0x10(%rsp), %rax
xorl %r12d, %r12d
testl %eax, %eax
jle 0x2cf8
movl (%r13,%r14,4), %esi
movq 0x90(%r15), %rax
movl (%rax,%r12,4), %edx
cmpl %edx, %esi
je 0x2cf3
movq 0x8(%r15), %rdi
movq (%rdi), %rax
callq *0x50(%rax)
testb %al, %al
jne 0x2cf3
incq %r12
cmpq %r12, %rbx
jne 0x2cc7
jmp 0x2cfd
movq 0x10(%rsp), %rax
cmpl %eax, %r12d
jne 0x2d27
movl (%r13,%r14,4), %eax
movq 0x80(%r15), %rcx
movq 0x88(%r15), %rdx
movq 0x30(%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
cmpq %rbp, %r14
jne 0x2cab
movq 0x10(%rsp), %r14
testl %r14d, %r14d
jle 0x2d77
movq 0x90(%r15), %rdi
movl 0x24(%rsp), %esi
movl %r14d, %edx
callq 0x44b8
movq %rax, %r12
movl %r14d, %edi
callq 0x457c
movq 0x38(%rsp), %rdi
movl 0xc(%rsp), %esi
movq %r12, 0x28(%rsp)
movq %r12, %rdx
movl %eax, %ecx
callq 0x483a
movl %eax, 0x1c(%rsp)
movq %r15, %rdi
movl 0x20(%rsp), %esi
movl 0x1c(%rsp), %edx
movq 0x28(%rsp), %rcx
callq 0x2ade
movq 0x40(%rsp), %r14
movq 0x88(%r15), %rax
movl (%rax,%r14,4), %ecx
testl %ecx, %ecx
jne 0x2c24
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop