// File: /workspace/github_c_makefile_star2_O0/jondurbin[P]dre2/src/dre2_backtracking.c
// Function: dre2_backtrack_match
void dre2_backtrack_match( struct dre2 *graph, unsigned char *input, unsigned char ***submatches )
{
  int i, j;
  int matched, pos;
  int *state;
  int *group_open, *group_close;

  // Allocate some memory for the state table to ensure we don't ever get in an infinite loop.
  state = ( int * )calloc( graph->original->count, sizeof( int ) );

  // Allocate some memory for extracting submatches.
  if ( graph->original->group_count > 1 )
  {
    group_open = ( int * )calloc( graph->original->group_count, sizeof( int ) );
    group_close = ( int * )calloc( graph->original->group_count, sizeof( int ) );
  } else
  {
    return;
  }

  if ( ( matched = dre2_backtrack_recursive( graph->original, input, 0, 0, &state, &group_open, &group_close ) ) )
  {
    for ( i = 1; i < graph->original->group_count; i++ )
    {
      if ( group_close[i - 1] > group_open[i - 1] )
        sprintf( ( *submatches )[i - 1], "%.*s", group_close[i - 1] - group_open[i - 1], input + group_open[i - 1] );
      else
        ( *submatches )[i - 1][0] = '\0';
    }
  } else
  {
    printf( "FAIL!\n" );
  }

  // Free up memory used.
  if ( graph->original->group_count > 1 )
  {
    free( state ); state = NULL;
    free( group_open ); group_open = NULL;
    free( group_close ); group_close = NULL;
  }
}

// Assembly:
subq $0x48, %rsp
movq %rdi, 0x40(%rsp)
movq %rsi, 0x38(%rsp)
movq %rdx, 0x30(%rsp)
movq 0x40(%rsp), %rax
movq 0x458(%rax), %rax
movslq 0x8(%rax), %rdi
movl $0x4, %esi
callq 0x21d0
movq %rax, 0x18(%rsp)
movq 0x40(%rsp), %rax
movq 0x458(%rax), %rax
cmpl $0x1, 0x460(%rax)
jle 0xc17d
movq 0x40(%rsp), %rax
movq 0x458(%rax), %rax
movslq 0x460(%rax), %rdi
movl $0x4, %esi
callq 0x21d0
movq %rax, 0x10(%rsp)
movq 0x40(%rsp), %rax
movq 0x458(%rax), %rax
movslq 0x460(%rax), %rdi
movl $0x4, %esi
callq 0x21d0
movq %rax, 0x8(%rsp)
jmp 0xc182
jmp 0xc2f4
movq 0x40(%rsp), %rax
movq 0x458(%rax), %rdi
movq 0x38(%rsp), %rsi
xorl %ecx, %ecx
leaq 0x18(%rsp), %r8
leaq 0x10(%rsp), %r9
leaq 0x8(%rsp), %rax
movl %ecx, %edx
movq %rax, (%rsp)
callq 0x2080
movl %eax, 0x24(%rsp)
cmpl $0x0, %eax
je 0xc298
movl $0x1, 0x2c(%rsp)
movl 0x2c(%rsp), %eax
movq 0x40(%rsp), %rcx
movq 0x458(%rcx), %rcx
cmpl 0x460(%rcx), %eax
jge 0xc296
movq 0x8(%rsp), %rax
movl 0x2c(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movq 0x10(%rsp), %rcx
movl 0x2c(%rsp), %edx
subl $0x1, %edx
movslq %edx, %rdx
cmpl (%rcx,%rdx,4), %eax
jle 0xc26b
movq 0x30(%rsp), %rax
movq (%rax), %rax
movl 0x2c(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
movq 0x8(%rsp), %rax
movl 0x2c(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %edx
movq 0x10(%rsp), %rax
movl 0x2c(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
subl (%rax,%rcx,4), %edx
movq 0x38(%rsp), %rcx
movq 0x10(%rsp), %rax
movl 0x2c(%rsp), %esi
subl $0x1, %esi
movslq %esi, %rsi
movslq (%rax,%rsi,4), %rax
addq %rax, %rcx
leaq 0x4299(%rip), %rsi      # 0x104fb
movb $0x0, %al
callq 0x2350
jmp 0xc284
movq 0x30(%rsp), %rax
movq (%rax), %rax
movl 0x2c(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movb $0x0, (%rax)
jmp 0xc286
movl 0x2c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2c(%rsp)
jmp 0xc1c4
jmp 0xc2a6
leaq 0x4261(%rip), %rdi      # 0x10500
movb $0x0, %al
callq 0x2130
movq 0x40(%rsp), %rax
movq 0x458(%rax), %rax
cmpl $0x1, 0x460(%rax)
jle 0xc2f4
movq 0x18(%rsp), %rdi
callq 0x2070
movq $0x0, 0x18(%rsp)
movq 0x10(%rsp), %rdi
callq 0x2070
movq $0x0, 0x10(%rsp)
movq 0x8(%rsp), %rdi
callq 0x2070
movq $0x0, 0x8(%rsp)
addq $0x48, %rsp
retq