// File: /workspace/github_c_makefile_star2_O0/jondurbin[P]dre2/src/dre2_parse.c
// Function: dre2_range
struct dre2_range_return dre2_range( unsigned char *re, int length, int pos )
{
  unsigned char *min_buffer, *max_buffer;
  min_buffer = ( unsigned char * )calloc( 5, sizeof( unsigned char ) );
  max_buffer = ( unsigned char * )calloc( 5, sizeof( unsigned char ) );

  pos++;

  int t = pos;

  // Is this modifier valid?
  int valid = true;
  // Are we still working on the first part of the range?
  int w_min = true;
  // Number of characters in the min string.
  int cmin = 0;
  // Number of characters in the max string.
  int cmax = 0;

  unsigned char c;
  while ( pos < length )
  {
    c = re[pos];
    if ( c == ',' )
    {
      if ( t == pos )
      {
        valid = false;
        break;
      }
      if ( !w_min )
      {
        valid = false;
        break;
      }
      w_min = false;
    } else if ( c == '}' )
    {
      break;
    } else if ( c < '0' || c > '9' )
    {
      valid = false;
      break;
    } else
    {
      int j;
      if ( w_min )
      {
        cmin++;
        min_buffer[cmin - 1] = c;
      } else
      {
        cmax++;
        max_buffer[cmax - 1] = c;
      }
    }
    pos++;
  }
  if ( !w_min )
  {
    // See if it's unbounded on the right, e.g. {1,}
    if ( cmax == false )
    {
      max_buffer[0] = '+';
    }
  } else
  {
    // See if it's an exact size, e.g. {3}
    strcat( max_buffer, min_buffer );
  }

  // Setup the return structure.
  struct dre2_range_return ret;
  ret.min = DRE2_INFINITE;
  ret.max = DRE2_INFINITE;
  ret.pos = DRE2_INFINITE;
  ret.valid = false;

  // Make sure it's valid.
  if ( !valid )
  {
    printf( "Invalid range {}\n" );
    return ret;
  }

  // Convert strings to integers.
  int min = string_to_int( min_buffer );
  int max = string_to_int( max_buffer );

  // Make sure it's a valid size range.
  if ( min > max && max != DRE2_INFINITE )
  {
    printf("Invalid range, min is greater than max!\n");
    return ret;
  }
  if ( min > 100 || max > 100 )
  {
    printf( "Way too high of a range, use + or *.\n" );
    return ret;
  }

  // Free buffers.
  free( min_buffer );
  free( max_buffer );
  min_buffer = NULL;
  max_buffer = NULL;

  // Setup the return structure and return it.
  ret.min = min;
  ret.max = max;
  ret.pos = pos;
  ret.valid = true;
  return ret;
}

// Assembly:
subq $0x58, %rsp
movq %rdi, 0x40(%rsp)
movl %esi, 0x3c(%rsp)
movl %edx, 0x38(%rsp)
movl $0x5, %edi
movl $0x1, %esi
callq 0x21d0
movq %rax, 0x30(%rsp)
movl $0x5, %edi
movl $0x1, %esi
callq 0x21d0
movq %rax, 0x28(%rsp)
movl 0x38(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x38(%rsp)
movl 0x38(%rsp), %eax
movl %eax, 0x24(%rsp)
movl $0x1, 0x20(%rsp)
movl $0x1, 0x1c(%rsp)
movl $0x0, 0x18(%rsp)
movl $0x0, 0x14(%rsp)
movl 0x38(%rsp), %eax
cmpl 0x3c(%rsp), %eax
jge 0x2f85
movq 0x40(%rsp), %rax
movslq 0x38(%rsp), %rcx
movb (%rax,%rcx), %al
movb %al, 0x13(%rsp)
movzbl 0x13(%rsp), %eax
cmpl $0x2c, %eax
jne 0x2efa
movl 0x24(%rsp), %eax
cmpl 0x38(%rsp), %eax
jne 0x2edc
movl $0x0, 0x20(%rsp)
jmp 0x2f85
cmpl $0x0, 0x1c(%rsp)
jne 0x2ef0
movl $0x0, 0x20(%rsp)
jmp 0x2f85
movl $0x0, 0x1c(%rsp)
jmp 0x2f75
movzbl 0x13(%rsp), %eax
cmpl $0x7d, %eax
jne 0x2f06
jmp 0x2f85
movzbl 0x13(%rsp), %eax
cmpl $0x30, %eax
jl 0x2f1a
movzbl 0x13(%rsp), %eax
cmpl $0x39, %eax
jle 0x2f24
movl $0x0, 0x20(%rsp)
jmp 0x2f85
cmpl $0x0, 0x1c(%rsp)
je 0x2f4e
movl 0x18(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x18(%rsp)
movb 0x13(%rsp), %dl
movq 0x30(%rsp), %rax
movl 0x18(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
jmp 0x2f6f
movl 0x14(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x14(%rsp)
movb 0x13(%rsp), %dl
movq 0x28(%rsp), %rax
movl 0x14(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
jmp 0x2f71
jmp 0x2f73
jmp 0x2f75
movl 0x38(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x38(%rsp)
jmp 0x2e9c
cmpl $0x0, 0x1c(%rsp)
jne 0x2f9d
cmpl $0x0, 0x14(%rsp)
jne 0x2f9b
movq 0x28(%rsp), %rax
movb $0x2b, (%rax)
jmp 0x2fac
movq 0x28(%rsp), %rdi
movq 0x30(%rsp), %rsi
callq 0x2320
movl $0xffffffff, 0x48(%rsp) # imm = 0xFFFFFFFF
movl $0xffffffff, 0x4c(%rsp) # imm = 0xFFFFFFFF
movl $0xffffffff, 0x54(%rsp) # imm = 0xFFFFFFFF
movl $0x0, 0x50(%rsp)
cmpl $0x0, 0x20(%rsp)
jne 0x2fe6
leaq 0xd44a(%rip), %rdi      # 0x10424
movb $0x0, %al
callq 0x2130
jmp 0x3087
movq 0x30(%rsp), %rdi
callq 0x21e0
movl %eax, 0x8(%rsp)
movq 0x28(%rsp), %rdi
callq 0x21e0
movl %eax, 0x4(%rsp)
movl 0x8(%rsp), %eax
cmpl 0x4(%rsp), %eax
jle 0x3023
cmpl $-0x1, 0x4(%rsp)
je 0x3023
leaq 0xd41c(%rip), %rdi      # 0x10436
movb $0x0, %al
callq 0x2130
jmp 0x3087
cmpl $0x64, 0x8(%rsp)
jg 0x3031
cmpl $0x64, 0x4(%rsp)
jle 0x3041
leaq 0xd427(%rip), %rdi      # 0x1045f
movb $0x0, %al
callq 0x2130
jmp 0x3087
movq 0x30(%rsp), %rdi
callq 0x2070
movq 0x28(%rsp), %rdi
callq 0x2070
movq $0x0, 0x30(%rsp)
movq $0x0, 0x28(%rsp)
movl 0x8(%rsp), %eax
movl %eax, 0x48(%rsp)
movl 0x4(%rsp), %eax
movl %eax, 0x4c(%rsp)
movl 0x38(%rsp), %eax
movl %eax, 0x54(%rsp)
movl $0x1, 0x50(%rsp)
movq 0x48(%rsp), %rax
movq 0x50(%rsp), %rdx
addq $0x58, %rsp
retq
nopw %cs:(%rax,%rax)