// File: /workspace/github_c_makefile_star2_O3/mattn[P]orelang/slre.c
// Function: bar
static int bar(const char *re, int re_len, const char *s, int s_len,
               struct regex_info *info, int bi) {
  /* i is offset in re, j is offset in s, bi is brackets index */
  int i, j, n, step;

  for (i = j = 0; i < re_len && j <= s_len; i += step) {

    /* Handle quantifiers. Get the length of the chunk. */
    step = re[i] == '(' ? info->brackets[bi + 1].len + 2 :
      get_op_len(re + i, re_len - i);

    DBG(("%s [%.*s] [%.*s] re_len=%d step=%d i=%d j=%d\n", __func__,
         re_len - i, re + i, s_len - j, s + j, re_len, step, i, j));

    FAIL_IF(is_quantifier(&re[i]), SLRE_UNEXPECTED_QUANTIFIER);
    FAIL_IF(step <= 0, SLRE_INVALID_CHARACTER_SET);

    if (i + step < re_len && is_quantifier(re + i + step)) {
      DBG(("QUANTIFIER: [%.*s]%c [%.*s]\n", step, re + i,
           re[i + step], s_len - j, s + j));
      if (re[i + step] == '?') {
        int result = bar(re + i, step, s + j, s_len - j, info, bi);
        j += result > 0 ? result : 0;
        i++;
      } else if (re[i + step] == '+' || re[i + step] == '*') {
        int j2 = j, nj = j, n1, n2 = -1, ni, non_greedy = 0;

        /* Points to the regexp code after the quantifier */
        ni = i + step + 1;
        if (ni < re_len && re[ni] == '?') {
          non_greedy = 1;
          ni++;
        }

        do {
          if ((n1 = bar(re + i, step, s + j2, s_len - j2, info, bi)) > 0) {
            j2 += n1;
          }
          if (re[i + step] == '+' && n1 < 0) break;

          if (ni >= re_len) {
            /* After quantifier, there is nothing */
            nj = j2;
          } else if ((n2 = bar(re + ni, re_len - ni, s + j2,
                               s_len - j2, info, bi)) >= 0) {
            /* Regex after quantifier matched */
            nj = j2 + n2;
          }
          if (nj > j && non_greedy) break;
        } while (n1 > 0);

        /*
         * Even if we found one or more pattern, this branch will be executed,
         * changing the next captures.
         */
        if (n1 < 0 && n2 < 0 && re[i + step] == '*' &&
            (n2 = bar(re + ni, re_len - ni, s + j, s_len - j, info, bi)) > 0) {
          nj = j + n2;
        }

        DBG(("STAR/PLUS END: %d %d %d %d %d\n", j, nj, re_len - ni, n1, n2));
        FAIL_IF(re[i + step] == '+' && nj == j, SLRE_NO_MATCH);

        /* If while loop body above was not executed for the * quantifier,  */
        /* make sure the rest of the regex matches                          */
        FAIL_IF(nj == j && ni < re_len && n2 < 0, SLRE_NO_MATCH);

        /* Returning here cause we've matched the rest of RE already */
        return nj;
      }
      continue;
    }

    if (re[i] == '[') {
      n = match_set(re + i + 1, re_len - (i + 2), s + j, info);
      DBG(("SET %.*s [%.*s] -> %d\n", step, re + i, s_len - j, s + j, n));
      FAIL_IF(n <= 0, SLRE_NO_MATCH);
      j += n;
    } else if (re[i] == '(') {
      n = SLRE_NO_MATCH;
      bi++;
      FAIL_IF(bi >= info->num_brackets, SLRE_INTERNAL_ERROR);
      DBG(("CAPTURING [%.*s] [%.*s] [%s]\n",
           step, re + i, s_len - j, s + j, re + i + step));

      if (re_len - (i + step) <= 0) {
        /* Nothing follows brackets */
        n = doh(s + j, s_len - j, info, bi);
      } else {
        int j2;
        for (j2 = 0; j2 <= s_len - j; j2++) {
          if ((n = doh(s + j, s_len - (j + j2), info, bi)) >= 0 &&
              bar(re + i + step, re_len - (i + step),
                  s + j + n, s_len - (j + n), info, bi) >= 0) break;
        }
      }

      DBG(("CAPTURED [%.*s] [%.*s]:%d\n", step, re + i, s_len - j, s + j, n));
      FAIL_IF(n < 0, n);
      if (info->caps != NULL && n > 0) {
        info->caps[bi - 1].ptr = s + j;
        info->caps[bi - 1].len = n;
      }
      j += n;
    } else if (re[i] == '^') {
      FAIL_IF(j != 0, SLRE_NO_MATCH);
    } else if (re[i] == '$') {
      FAIL_IF(j != s_len, SLRE_NO_MATCH);
    } else {
      FAIL_IF(j >= s_len, SLRE_NO_MATCH);
      n = match_op((unsigned char *) (re + i), (unsigned char *) (s + j), info);
      FAIL_IF(n <= 0, n);
      j += n;
    }
  }

  return j;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %r9, 0x10(%rsp)
movq %rdx, 0x28(%rsp)
movq %rdi, 0x60(%rsp)
movq %rsi, 0x38(%rsp)
testl %esi, %esi
setle %al
testl %ecx, %ecx
sets %dl
xorl %r14d, %r14d
orb %al, %dl
jne 0xc497
movq 0x38(%rsp), %rax
addl $-0x2, %eax
movl %eax, 0x58(%rsp)
leal 0x1(%rcx), %eax
movl %eax, 0x44(%rsp)
xorl %r13d, %r13d
xorl %r15d, %r15d
movq $0x0, 0x20(%rsp)
movq %r8, (%rsp)
movq %rcx, 0x30(%rsp)
movl %r15d, %esi
movq 0x60(%rsp), %r14
leaq (%r14,%rsi), %rdi
movzbl (%r14,%rsi), %ebx
cmpl $0x28, %ebx
jne 0xbe74
movq 0x10(%rsp), %rax
incl %eax
cltq
leaq (%rax,%rax,2), %rax
movq (%rsp), %rcx
movl 0x8(%rcx,%rax,8), %r8d
addl $0x2, %r8d
movq 0x20(%rsp), %rbp
jmp 0xbebf
movq %rsi, 0x18(%rsp)
movq 0x38(%rsp), %rax
movl %eax, %esi
subl %r15d, %esi
movq %rdi, %r12
callq 0xbca9
movl %eax, %r8d
cmpl $0x3f, %ebx
movq 0x20(%rsp), %rbp
ja 0xbeb7
movl %ebx, %eax
movabsq $-0x7ffff40000000000, %rcx # imm = 0x80000C0000000000
btq %rax, %rcx
movq 0x18(%rsp), %rsi
movq %r12, %rdi
jae 0xbebf
jmp 0xc2bd
movq 0x18(%rsp), %rsi
movq %r12, %rdi
testl %r8d, %r8d
jle 0xc2c8
movl %r8d, %eax
addq %rax, %rsi
cmpl %esi, 0x38(%rsp)
movq %rsi, 0x18(%rsp)
jle 0xbf12
movzbl (%rdi,%rax), %ecx
cmpq $0x3f, %rcx
ja 0xbf12
movabsq $-0x7ffff40000000000, %rdx # imm = 0x80000C0000000000
btq %rcx, %rdx
jae 0xbf12
movzbl (%r14,%rsi), %eax
cmpl $0x3f, %eax
je 0xc127
addl $-0x2a, %eax
cmpl $0x2, %eax
jae 0xc217
jmp 0xc2e6
cmpl $0x5a, %ebx
jg 0xbfdb
cmpl $0x24, %ebx
je 0xc1a5
cmpl $0x28, %ebx
jne 0xc16c
movq 0x10(%rsp), %rcx
leal 0x1(%rcx), %r15d
movq (%rsp), %rdx
cmpl 0x960(%rdx), %r15d
jge 0xc491
movq 0x38(%rsp), %rcx
subl %esi, %ecx
movl %ecx, 0x8(%rsp)
jle 0xc221
movq 0x30(%rsp), %rcx
cmpl %ebp, %ecx
jl 0xc2d3
movslq %ebp, %rdx
addq 0x28(%rsp), %rdx
addl %ecx, %r13d
addq %rax, %rdi
movq %rdi, 0x50(%rsp)
movl 0x44(%rsp), %ebx
subl %ebp, %ebx
movl %r13d, 0x48(%rsp)
movl %r13d, %ebp
movq %rdx, %rdi
movl %ebp, %esi
movq (%rsp), %r12
movq %rdx, %r13
movq %r12, %rdx
movl %r15d, %ecx
callq 0xbd1f
movl %eax, %r14d
testl %eax, %eax
js 0xbfcd
movl %r14d, %edx
addq %r13, %rdx
movl 0x48(%rsp), %ecx
subl %r14d, %ecx
movq 0x50(%rsp), %rdi
movl 0x8(%rsp), %esi
movq %r12, %r8
movl %r15d, %r9d
callq 0xbddb
testl %eax, %eax
jns 0xc24b
decl %ebp
decl %ebx
movq %r13, %rdx
jne 0xbf86
jmp 0xc23d
cmpl $0x5e, %ebx
je 0xc1c1
cmpl $0x5b, %ebx
jne 0xc16c
movb 0x1(%rdi), %dl
xorl %eax, %eax
cmpb $0x5e, %dl
sete %al
movl 0x58(%rsp), %ebp
subl %r15d, %ebp
subl %eax, %ebp
movq (%rsp), %rbx
js 0xc1e6
movb %dl, 0x50(%rsp)
movslq 0x20(%rsp), %rcx
addq 0x28(%rsp), %rcx
movq %rcx, 0x8(%rsp)
leaq (%rdi,%rax), %r14
incq %r14
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
xorl %r15d, %r15d
movslq %r15d, %rcx
movsbq (%r14,%rcx), %r13
cmpq $0x5d, %r13
je 0xc1db
testl %eax, %eax
jg 0xc1db
leaq (%r14,%rcx), %rdi
cmpb $0x2d, %r13b
jne 0xc06a
movq 0x8(%rsp), %rsi
movq %rbx, %rdx
callq 0xc4ae
movq 0x18(%rsp), %rsi
movl $0x1, %ecx
jmp 0xc0b5
movb 0x1(%r14,%rcx), %r12b
cmpb $0x2d, %r12b
jne 0xc084
movzbl 0x2(%r14,%rcx), %ebx
testl %ebx, %ebx
je 0xc084
cmpl $0x5d, %ebx
jne 0xc0c6
movq 0x8(%rsp), %rsi
movq (%rsp), %rbx
movq %rbx, %rdx
callq 0xc4ae
movl $0x1, %ecx
cmpb $0x5c, %r13b
jne 0xc0b0
xorl %ecx, %ecx
cmpb $0x78, %r12b
sete %cl
leal 0x2(,%rcx,2), %ecx
movq 0x18(%rsp), %rsi
addl %ecx, %r15d
cmpl %ebp, %r15d
jle 0xc02d
jmp 0xc1db
movq (%rsp), %rax
testb $0x1, 0xfbc(%rax)
jne 0xc0ed
movq 0x8(%rsp), %rax
movb (%rax), %al
cmpb %r13b, %al
setge %cl
cmpb %bl, %al
setle %al
andb %cl, %al
movq (%rsp), %rbx
jmp 0xc11e
callq 0x22a0
movq (%rax), %rax
movq 0x8(%rsp), %rcx
movsbq (%rcx), %rcx
movl (%rax,%rcx,4), %ecx
cmpl (%rax,%r13,4), %ecx
jge 0xc10b
xorl %eax, %eax
jmp 0xc115
movsbq %bl, %rdx
cmpl (%rax,%rdx,4), %ecx
setle %al
movq (%rsp), %rbx
movq 0x18(%rsp), %rsi
movzbl %al, %eax
addl $0x3, %r15d
jmp 0xc0b8
movslq %ebp, %rdx
addq 0x28(%rsp), %rdx
movq 0x30(%rsp), %rax
movl %eax, %ecx
subl %ebp, %ecx
movl %r8d, %esi
movq (%rsp), %rbx
movq %r8, %r12
movq %rbx, %r8
movq 0x10(%rsp), %r14
movl %r14d, %r9d
callq 0xbddb
testl %eax, %eax
movl $0x0, %ecx
cmovlel %ecx, %eax
addl %eax, %ebp
leal (%r15,%r12), %esi
incl %esi
movl %r14d, %r15d
jmp 0xc28c
cmpl %ebp, 0x30(%rsp)
movq (%rsp), %rbx
jle 0xc2d3
movslq %ebp, %rsi
addq 0x28(%rsp), %rsi
movq %rbx, %rdx
callq 0xc4ae
movl %eax, %r14d
testl %eax, %eax
jle 0xc497
addl %r14d, %ebp
movq 0x10(%rsp), %rax
movl %eax, %r15d
jmp 0xc287
movq 0x10(%rsp), %rax
movl %eax, %r15d
movq 0x30(%rsp), %rax
cmpl %ebp, %eax
movl %eax, %ebp
je 0xc28c
jmp 0xc2d3
movq 0x10(%rsp), %rax
movl %eax, %r15d
testl %ebp, %ebp
movl $0x0, %ebp
je 0xc28c
jmp 0xc2d3
testl %eax, %eax
setle %al
movb 0x50(%rsp), %dl
jmp 0xc1e8
movb $0x1, %al
cmpb $0x5e, %dl
sete %cl
andb %al, %cl
movzbl %cl, %ecx
decl %ecx
orl $0x1, %ecx
testb $0x1, %al
movl $0x1, %eax
cmovnel %ecx, %eax
cmpb $0x5e, %dl
cmovel %ecx, %eax
testl %eax, %eax
movq 0x20(%rsp), %rbp
jle 0xc2d3
addl %eax, %ebp
movq 0x10(%rsp), %rax
movl %eax, %r15d
jmp 0xc28c
movslq %ebp, %rdi
addq 0x28(%rsp), %rdi
movq 0x30(%rsp), %rax
movl %eax, %esi
subl %ebp, %esi
movl %r15d, %ecx
callq 0xbd1f
movl %eax, %r14d
testl %r14d, %r14d
movq (%rsp), %rbx
jns 0xc24e
jmp 0xc497
movq %r12, %rbx
movq 0xfb0(%rbx), %rax
testq %rax, %rax
sete %cl
testl %r14d, %r14d
sete %dl
orb %cl, %dl
movq 0x20(%rsp), %rbp
jne 0xc284
movslq %ebp, %rcx
addq 0x28(%rsp), %rcx
movslq 0x10(%rsp), %rdx
shlq $0x4, %rdx
movq %rcx, (%rax,%rdx)
movl %r14d, 0x8(%rax,%rdx)
addl %r14d, %ebp
movq 0x18(%rsp), %rsi
cmpl 0x38(%rsp), %esi
jge 0xc2de
movl %ebp, %r13d
negl %r13d
movl %r15d, %eax
movq %rax, 0x10(%rsp)
movl %esi, %r15d
movl %ebp, %r14d
movq %rbp, 0x20(%rsp)
movq 0x30(%rsp), %rcx
cmpl %ecx, %ebp
jle 0xbe3d
jmp 0xc497
movl $0xfffffffe, %r14d      # imm = 0xFFFFFFFE
jmp 0xc497
movl $0xfffffffb, %r14d      # imm = 0xFFFFFFFB
jmp 0xc497
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
jmp 0xc497
movl %ebp, %r14d
jmp 0xc497
movl %esi, %ecx
incq %rcx
movb $0x1, 0x50(%rsp)
cmpl 0x38(%rsp), %ecx
jge 0xc308
leal 0x2(%rsi), %eax
cmpb $0x3f, (%r14,%rcx)
setne 0x50(%rsp)
cmovnel %ecx, %eax
movl %eax, %ecx
movl %ecx, %eax
addq %r14, %rax
movq %rax, 0x58(%rsp)
movq 0x38(%rsp), %rax
movq %rcx, 0x8(%rsp)
subl %ecx, %eax
movl %eax, 0x44(%rsp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %rax, 0x48(%rsp)
movl %ebp, %r15d
movslq %r15d, %rax
movq 0x28(%rsp), %rcx
leaq (%rcx,%rax), %rdx
movq 0x30(%rsp), %rcx
subl %eax, %ecx
movq %rdi, %r12
movq %r8, %r13
movl %r8d, %esi
movq (%rsp), %r8
movq 0x10(%rsp), %r9
callq 0xbddb
movq 0x18(%rsp), %rsi
movl %eax, %ebx
movl $0x0, %eax
testl %ebx, %ebx
cmovgl %ebx, %eax
jns 0xc37b
movq 0x60(%rsp), %rcx
cmpb $0x2b, (%rcx,%rsi)
je 0xc457
addl %eax, %r15d
movl %r15d, %r14d
movq 0x8(%rsp), %rax
cmpl %eax, 0x38(%rsp)
jle 0xc3cc
movslq %r15d, %r14
movq 0x28(%rsp), %rax
leaq (%rax,%r14), %rdx
movq 0x30(%rsp), %rax
movl %eax, %ecx
subl %r14d, %ecx
movq 0x58(%rsp), %rdi
movl 0x44(%rsp), %esi
movq (%rsp), %r8
movq 0x10(%rsp), %r9
callq 0xbddb
movq 0x18(%rsp), %rsi
addl %eax, %r14d
movq %rax, 0x48(%rsp)
testl %eax, %eax
cmovsl %ebp, %r14d
cmpl 0x20(%rsp), %r14d
setle %al
testl %ebx, %ebx
jle 0xc3eb
movq %r12, %rdi
movq %r13, %r8
orb 0x50(%rsp), %al
movl %r14d, %ebp
jne 0xc32f
movq 0x60(%rsp), %rax
movb (%rax,%rsi), %al
testl %ebx, %ebx
jns 0xc4a9
movq 0x48(%rsp), %rdx
testl %edx, %edx
jns 0xc44d
cmpb $0x2a, %al
jne 0xc44d
movq 0x20(%rsp), %rbx
movslq %ebx, %rax
movq 0x28(%rsp), %rdx
addq %rax, %rdx
movq 0x30(%rsp), %rcx
subl %ebx, %ecx
movq 0x58(%rsp), %rdi
movq %rsi, %r15
movl 0x44(%rsp), %esi
movq (%rsp), %r8
movq 0x10(%rsp), %r9
callq 0xbddb
movl %eax, %edx
leal (%rdx,%rbx), %eax
testl %edx, %edx
cmovgl %eax, %r14d
movq 0x60(%rsp), %rax
movb (%rax,%r15), %al
movl %r14d, %ebp
movq 0x8(%rsp), %rcx
jmp 0xc463
movb $0x2b, %al
movq 0x8(%rsp), %rcx
movq 0x48(%rsp), %rdx
cmpb $0x2b, %al
jne 0xc473
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
cmpl 0x20(%rsp), %ebp
je 0xc497
testl %edx, %edx
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
cmovnsl %ebp, %r14d
cmpl %ecx, 0x38(%rsp)
cmovlel %ebp, %r14d
cmpl 0x20(%rsp), %ebp
cmovnel %ebp, %r14d
jmp 0xc497
movl $0xfffffffc, %r14d      # imm = 0xFFFFFFFC
movl %r14d, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %r14d, %ebp
jmp 0xc459