// File: /workspace/github_c_makefile_star2_O1/jondurbin[P]dre2/src/dre2_parse.c
// Function: dre2_make_range
void dre2_make_range( struct dre2_node **v, int *node_count, int *last_node, struct dre2_parse_return *res, int min, int max, int **minimal )
{
  int i, j;
  int group;
  struct dre2_node *node;
  int original;
  int node_opener;

  if ( ( *v )[*last_node].c == DRE2_GROUP_CLOSE )
  {
    group = true;
  } else
  {
    node_opener = *last_node;
    original = *last_node;
    group = false;
  }

  if ( min == 0 )
  {
    if ( ( *v )[*last_node].c != DRE2_GROUP_OPEN && ( *v )[*last_node].c != DRE2_GROUP_CLOSE )
    {
      // Duplicate the node.
      dre2_duplicate_node( v, node_count, original, minimal );
      // Set node that was duplicated to be group open.
      ( *v )[*node_count - 2].c = DRE2_GROUP_OPEN;
      node_opener = *node_count - 2;
      // Add the group close node.
      dre2_add_node( v, node_count, DRE2_GROUP_CLOSE, minimal, false );
      // Add link from group open node to actual node.
      dre2_add_neighbor( v, *node_count - 3, *node_count - 2 );
      // Add link from group open node to group close node.
      dre2_add_neighbor( v, *node_count - 3, *node_count - 1 );
      // Add link from actual node to group close node.
      dre2_add_neighbor( v, *node_count - 2, *node_count - 1 );

      for ( i = *last_node; i < *node_count; i++ )
        dre2_remove_minimal( minimal, i );
      *last_node = *node_count - 1;
      original = *node_count - 2;
    } else
    {
      dre2_add_neighbor( v, res->open, res->close );
      for ( i = res->open; i <= res->close; i++ )
        dre2_remove_minimal( minimal, i );
    }
  }

  // Make the required minimum range first.
  for ( i = 0; i < min - 1; i++ )
  {
    dre2_add_neighbor( v, *last_node, *last_node + 1 );
    if ( group )
    {
      dre2_duplicate_group( v, node_count, last_node, res, minimal );
    } else
    {
      dre2_duplicate_node( v, node_count, original, minimal );
      *last_node = *node_count - 1;
      node_opener = *last_node;
    }
  }

  // If max is min, we're done.
  if ( max == min )
    return;

  if ( max == DRE2_INFINITE )
  {
    if ( group )
    {
      dre2_add_neighbor( v, res->close, res->open );
    } else
    {
      if ( min == 0 )
        dre2_add_neighbor( v, *last_node, *last_node - 1 );
      else
        dre2_add_neighbor( v, *last_node, *last_node );
    }
  } else
  {
    if ( min == 0 )
      max--;
    for ( i = min; i < max; i++ )
    {
      dre2_add_neighbor( v, *last_node, *last_node + 1 );
      if ( group )
      {
        dre2_duplicate_group( v, node_count, last_node, res, minimal );
        dre2_add_neighbor( v, res->open, res->close );
        for ( j = res->open; j <= res->close; j++ )
          dre2_remove_minimal( minimal, j );
      } else
      {
        // Duplicate the node.
        dre2_duplicate_node( v, node_count, original, minimal );
        // Add a link from the last required to here.
        dre2_add_neighbor( v, node_opener, *node_count - 1 );
        // Mark it as not minimal.
        dre2_remove_minimal( minimal, *node_count - 1 );
        // Update last node.
        *last_node = *node_count - 1;
      }
    }
    if ( !group )
    {
      dre2_add_neighbor( v, *last_node, *node_count );
      dre2_add_node( v, node_count, DRE2_GROUP_CLOSE, minimal, false );
      dre2_add_neighbor( v, node_opener, *node_count - 1 );
      *last_node = *node_count - 1;
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %r9d, %r12d
movl %r8d, %r13d
movq %rcx, %rbp
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
movq 0x70(%rsp), %rax
movq %rax, 0x10(%rsp)
movq (%rdi), %rax
movslq (%rdx), %rdx
movq %rdx, %rcx
shlq $0x6, %rcx
movl (%rax,%rcx), %eax
testl %r8d, %r8d
movl %eax, 0x1c(%rsp)
movq %r13, 0x30(%rsp)
jne 0x4e69
cmpl $-0x3, %eax
jbe 0x5011
movq %rdx, 0x20(%rsp)
movl (%rbp), %esi
movl 0x4(%rbp), %edx
movq %rbx, %rdi
callq 0x21d0
movslq (%rbp), %rax
cmpl 0x4(%rbp), %eax
jg 0x4e64
movq 0x10(%rsp), %rcx
movq (%rcx), %rcx
decq %rax
movl $0x0, 0x4(%rcx,%rax,4)
movslq 0x4(%rbp), %rdx
incq %rax
cmpq %rdx, %rax
jl 0x4e50
movq 0x20(%rsp), %rdx
movl %edx, 0xc(%rsp)
movq %rdx, 0x20(%rsp)
cmpl $0x2, %r13d
jl 0x4ece
decl %r13d
movl (%r14), %esi
leal 0x1(%rsi), %edx
movq %rbx, %rdi
callq 0x21d0
cmpl $-0x2, 0x1c(%rsp)
jne 0x4ea8
movq %rbx, %rdi
movq %r15, %rsi
movq %r14, %rdx
movq %rbp, %rcx
movq 0x10(%rsp), %r8
callq 0x2320
jmp 0x4ec9
movq %rbx, %rdi
movq %r15, %rsi
movq 0x20(%rsp), %rdx
movq 0x10(%rsp), %rcx
callq 0x2140
movl (%r15), %eax
decl %eax
movl %eax, 0xc(%rsp)
movl %eax, (%r14)
decl %r13d
jne 0x4e7b
movq 0x30(%rsp), %r13
cmpl %r13d, %r12d
je 0x5002
cmpl $-0x1, %r12d
je 0x50c2
cmpl $0x1, %r13d
sbbl $0x0, %r12d
cmpl %r13d, %r12d
jle 0x4fbc
movl %r12d, 0x2c(%rsp)
movl (%r14), %esi
leal 0x1(%rsi), %edx
movq %rbx, %rdi
callq 0x21d0
cmpl $-0x2, 0x1c(%rsp)
jne 0x4f5f
movq %rbx, %rdi
movq %r15, %rsi
movq %r14, %rdx
movq %rbp, %rcx
movq 0x10(%rsp), %r8
callq 0x2320
movl (%rbp), %esi
movl 0x4(%rbp), %edx
movq %rbx, %rdi
callq 0x21d0
movslq (%rbp), %rax
cmpl 0x4(%rbp), %eax
jg 0x4fb0
movq 0x10(%rsp), %rcx
movq (%rcx), %rcx
decq %rax
movl $0x0, 0x4(%rcx,%rax,4)
movslq 0x4(%rbp), %rdx
incq %rax
cmpq %rdx, %rax
jl 0x4f49
jmp 0x4fb0
movq %rbx, %rdi
movq %r15, %rsi
movq 0x20(%rsp), %rdx
movq %r14, %r12
movq %r13, %r14
movq 0x10(%rsp), %r13
movq %r13, %rcx
callq 0x2140
movl (%r15), %edx
decl %edx
movq %rbx, %rdi
movl 0xc(%rsp), %esi
callq 0x21d0
movslq (%r15), %rax
movq (%r13), %rcx
movq %r14, %r13
movq %r12, %r14
movl 0x2c(%rsp), %r12d
movl $0x0, -0x4(%rcx,%rax,4)
movl (%r15), %eax
decl %eax
movl %eax, (%r14)
incl %r13d
cmpl %r12d, %r13d
jne 0x4efc
cmpl $-0x2, 0x1c(%rsp)
je 0x5002
movl (%r14), %esi
movl (%r15), %edx
movq %rbx, %rdi
callq 0x21d0
movq %rbx, %rdi
movq %r15, %rsi
movl $0xfffffffe, %edx       # imm = 0xFFFFFFFE
movq 0x10(%rsp), %rcx
xorl %r8d, %r8d
callq 0x20b0
movl (%r15), %edx
decl %edx
movq %rbx, %rdi
movl 0xc(%rsp), %esi
callq 0x21d0
movl (%r15), %eax
decl %eax
movl %eax, (%r14)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
movq %r15, %rsi
movq 0x10(%rsp), %r13
movq %r13, %rcx
callq 0x2140
movq (%rbx), %rax
movslq (%r15), %rcx
shlq $0x6, %rcx
movl $0xffffffff, -0x80(%rax,%rcx) # imm = 0xFFFFFFFF
movl (%r15), %eax
movl %eax, 0xc(%rsp)
movq %rbx, %rdi
movq %r15, %rsi
movl $0xfffffffe, %edx       # imm = 0xFFFFFFFE
movq %r13, %rcx
movq 0x30(%rsp), %r13
xorl %r8d, %r8d
callq 0x20b0
movl (%r15), %edx
leal -0x3(%rdx), %esi
addl $-0x2, %edx
movq %rbx, %rdi
callq 0x21d0
movl (%r15), %edx
leal -0x3(%rdx), %esi
decl %edx
movq %rbx, %rdi
callq 0x21d0
movl (%r15), %edx
leal -0x2(%rdx), %esi
decl %edx
movq %rbx, %rdi
callq 0x21d0
movslq (%r14), %rax
movl (%r15), %ecx
cmpl %ecx, %eax
jge 0x50ad
movq 0x10(%rsp), %rcx
movq (%rcx), %rdx
movl $0x0, (%rdx,%rax,4)
incq %rax
movslq (%r15), %rcx
cmpq %rcx, %rax
jl 0x509b
addl $-0x2, 0xc(%rsp)
decl %ecx
movl %ecx, (%r14)
movl (%r15), %edx
addl $-0x2, %edx
jmp 0x4e6d
cmpl $-0x2, 0x1c(%rsp)
jne 0x50d4
movl (%rbp), %edx
movl 0x4(%rbp), %esi
movq %rbx, %rdi
jmp 0x50e9
movl (%r14), %esi
testl %r13d, %r13d
je 0x50e3
movq %rbx, %rdi
movl %esi, %edx
jmp 0x50e9
leal -0x1(%rsi), %edx
movq %rbx, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x21d0