// File: /workspace/github_c_makefile_star2_O3/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 $0x48, %rsp
movl %r9d, %r12d
movl %r8d, %r13d
movq %rcx, %rbp
movq %rdx, %r15
movq %rsi, 0x20(%rsp)
movq %rdi, %rbx
movq 0x80(%rsp), %rax
movq %rax, 0x10(%rsp)
movq (%rdi), %rax
movslq (%rdx), %rdx
movq %rdx, %rcx
shlq $0x6, %rcx
movl (%rax,%rcx), %r14d
testl %r8d, %r8d
je 0x4d80
movl %edx, 0x8(%rsp)
jmp 0x4e71
cmpl $-0x3, %r14d
jbe 0x4db4
movq %rdx, 0x18(%rsp)
movl (%rbp), %esi
movl 0x4(%rbp), %edx
movq %rbx, %rdi
callq 0x21d0
movslq (%rbp), %rax
cmpl 0x4(%rbp), %eax
jle 0x5082
movq 0x18(%rsp), %rdx
movl %edx, 0x8(%rsp)
jmp 0x4f1d
movl %r12d, 0xc(%rsp)
movq %rbx, %rdi
movq 0x20(%rsp), %r12
movq %r12, %rsi
movq 0x10(%rsp), %rcx
callq 0x2140
movq (%rbx), %rax
movslq (%r12), %rcx
shlq $0x6, %rcx
movl $0xffffffff, -0x80(%rax,%rcx) # imm = 0xFFFFFFFF
movl (%r12), %eax
movl %eax, 0x8(%rsp)
movq %rbx, %rdi
movq %r12, %rsi
movl $0xfffffffe, %edx       # imm = 0xFFFFFFFE
movq 0x10(%rsp), %rcx
xorl %r8d, %r8d
callq 0x20b0
movl (%r12), %edx
leal -0x3(%rdx), %esi
addl $-0x2, %edx
movq %rbx, %rdi
callq 0x21d0
movl (%r12), %edx
leal -0x3(%rdx), %esi
decl %edx
movq %rbx, %rdi
callq 0x21d0
movl (%r12), %edx
leal -0x2(%rdx), %esi
decl %edx
movq %rbx, %rdi
callq 0x21d0
movslq (%r15), %rax
movl (%r12), %ecx
cmpl %ecx, %eax
jge 0x4e5b
movq 0x10(%rsp), %rcx
movq (%rcx), %rdx
movl $0x0, (%rdx,%rax,4)
incq %rax
movslq (%r12), %rcx
cmpq %rcx, %rax
jl 0x4e48
addl $-0x2, 0x8(%rsp)
decl %ecx
movl %ecx, (%r15)
movl (%r12), %edx
addl $-0x2, %edx
movl 0xc(%rsp), %r12d
cmpl $0x2, %r13d
jl 0x4f1d
movq %rdx, 0x18(%rsp)
movl %r14d, 0x2c(%rsp)
movl %r12d, 0xc(%rsp)
movq %rbp, 0x30(%rsp)
movq %rbx, %rbp
movq %r15, %rbx
movq 0x20(%rsp), %r14
movq %r13, 0x38(%rsp)
leal -0x1(%r13), %r15d
movq %rbx, %r13
movl (%rbx), %esi
leal 0x1(%rsi), %edx
movq %rbp, %r12
movq %rbp, %rdi
callq 0x21d0
cmpl $-0x2, 0x2c(%rsp)
jne 0x4ed7
movq %r12, %rdi
movq %r14, %rsi
movq %r13, %rdx
movq 0x30(%rsp), %rcx
movq 0x10(%rsp), %r8
callq 0x2310
jmp 0x4ef9
movq %r12, %rdi
movq %r14, %rsi
movq 0x18(%rsp), %rdx
movq 0x10(%rsp), %rcx
callq 0x2140
movl (%r14), %eax
decl %eax
movl %eax, 0x8(%rsp)
movl %eax, (%r13)
decl %r15d
jne 0x4ea3
movq %rbx, %r15
movq %rbp, %rbx
movq 0x38(%rsp), %r13
movq 0x30(%rsp), %rbp
movl 0xc(%rsp), %r12d
movl 0x2c(%rsp), %r14d
movq 0x18(%rsp), %rdx
cmpl %r13d, %r12d
je 0x5062
cmpl $-0x1, %r12d
je 0x5071
movq %rdx, 0x18(%rsp)
cmpl $0x1, %r13d
sbbl $0x0, %r12d
cmpl %r13d, %r12d
jle 0x5018
movq %r15, 0x40(%rsp)
movl %r12d, 0xc(%rsp)
movl (%r15), %esi
leal 0x1(%rsi), %edx
movq %rbx, %rdi
callq 0x21d0
movq %rbx, %rdi
cmpl $-0x2, %r14d
jne 0x4fb4
movq 0x20(%rsp), %rsi
movq %r15, %rdx
movq %rbp, %rcx
movq 0x10(%rsp), %r8
callq 0x2310
movl (%rbp), %esi
movl 0x4(%rbp), %edx
movq %rbx, %rdi
callq 0x21d0
movslq (%rbp), %rax
cmpl 0x4(%rbp), %eax
jg 0x500c
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 0x4f9e
jmp 0x500c
movl %r14d, %eax
movq 0x20(%rsp), %r14
movq %r14, %rsi
movq 0x18(%rsp), %rdx
movl %eax, %r15d
movq 0x10(%rsp), %r12
movq %r12, %rcx
callq 0x2140
movl (%r14), %edx
decl %edx
movq %rbx, %rdi
movl 0x8(%rsp), %esi
callq 0x21d0
movslq (%r14), %rax
movq (%r12), %rcx
movl 0xc(%rsp), %r12d
movl %r15d, %edx
movq 0x40(%rsp), %r15
movl $0x0, -0x4(%rcx,%rax,4)
movl (%r14), %eax
movl %edx, %r14d
decl %eax
movl %eax, (%r15)
incl %r13d
cmpl %r12d, %r13d
jne 0x4f50
cmpl $-0x2, %r14d
je 0x5062
movl (%r15), %esi
movq 0x20(%rsp), %r14
movl (%r14), %edx
movq %rbx, %rdi
callq 0x21d0
movq %rbx, %rdi
movq %r14, %rsi
movl $0xfffffffe, %edx       # imm = 0xFFFFFFFE
movq 0x10(%rsp), %rcx
xorl %r8d, %r8d
callq 0x20b0
movl (%r14), %edx
decl %edx
movq %rbx, %rdi
movl 0x8(%rsp), %esi
callq 0x21d0
movl (%r14), %eax
decl %eax
movl %eax, (%r15)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $-0x2, %r14d
jne 0x50ab
movl (%rbp), %edx
movl 0x4(%rbp), %esi
movq %rbx, %rdi
jmp 0x50c0
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 0x508d
movq 0x18(%rsp), %rdx
jmp 0x4d77
movl (%r15), %esi
testl %r13d, %r13d
je 0x50ba
movq %rbx, %rdi
movl %esi, %edx
jmp 0x50c0
leal -0x1(%rsi), %edx
movq %rbx, %rdi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x21d0