// File: /workspace/github_c_makefile_star2_O2/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 $0x78, %rsp
movl %ecx, 0x4(%rsp)
movq %rdx, 0x18(%rsp)
movq %rdi, %r13
movq %rsi, 0x40(%rsp)
leal -0x2(%rsi), %eax
movl %eax, 0x24(%rsp)
xorl %r10d, %r10d
xorl %r12d, %r12d
movq %rdi, 0x38(%rsp)
movq %r8, 0x10(%rsp)
movq %r9, 0x60(%rsp)
leal 0x1(%r9), %eax
movl %eax, 0x30(%rsp)
cltq
imulq $0x18, %rax, %rax
addq %r8, %rax
addq $0x8, %rax
movq %rax, 0x50(%rsp)
movq %r10, 0x8(%rsp)
movq 0x40(%rsp), %rax
movl %eax, %esi
subl %r12d, %esi
jle 0x9f11
movl 0x4(%rsp), %ebx
subl %r10d, %ebx
jl 0x9f11
movl %r12d, %r14d
movl %r12d, %r12d
leaq (%r12,%r13), %rdi
movzbl (%r13,%r12), %r13d
cmpl $0x28, %r13d
jne 0x99e1
movq 0x50(%rsp), %rax
movl (%rax), %r15d
addl $0x2, %r15d
jmp 0x9a1a
movq %rdi, %rbp
callq 0x981e
movl %eax, %r15d
cmpl $0x3f, %r13d
ja 0x9a12
movl %r13d, %eax
movabsq $-0x7ffff40000000000, %rcx # imm = 0x80000C0000000000
btq %rax, %rcx
movq 0x8(%rsp), %r10
movq %rbp, %rdi
jae 0x9a1a
jmp 0x9f0d
movq 0x8(%rsp), %r10
movq %rbp, %rdi
testl %r15d, %r15d
jle 0x9f16
movl %r15d, %eax
addq %rax, %r12
movslq %r10d, %r8
cmpl %r12d, 0x40(%rsp)
jle 0x9aac
movzbl (%rdi,%rax), %ecx
cmpq $0x3f, %rcx
ja 0x9aac
movabsq $-0x7ffff40000000000, %rdx # imm = 0x80000C0000000000
btq %rcx, %rdx
jae 0x9aac
movq 0x38(%rsp), %r13
movzbl (%r13,%r12), %eax
leal -0x2a(%rax), %ecx
cmpl $0x2, %ecx
jb 0x9dae
cmpl $0x3f, %eax
jne 0x99a0
addq 0x18(%rsp), %r8
movl 0x4(%rsp), %ecx
subl %r10d, %ecx
movl %r15d, %esi
movq %r8, %rdx
movq 0x10(%rsp), %r8
movq 0x60(%rsp), %r9
callq 0x9946
movq 0x8(%rsp), %r10
testl %eax, %eax
movl $0x0, %ecx
cmovlel %ecx, %eax
addl %eax, %r10d
leal (%r14,%r15), %r12d
incl %r12d
jmp 0x999b
cmpl $0x24, %r13d
je 0x9c4f
cmpl $0x5b, %r13d
je 0x9b0a
cmpl $0x5e, %r13d
je 0x9c5b
cmpl $0x28, %r13d
je 0x9c74
cmpl %r10d, 0x4(%rsp)
jle 0x9f30
addq 0x18(%rsp), %r8
movq %r8, %rsi
movq 0x10(%rsp), %rdx
callq 0x9f6f
movl %eax, %r15d
testl %eax, %eax
jle 0x9f54
movq 0x8(%rsp), %r10
addl %r15d, %r10d
movq 0x38(%rsp), %r13
jmp 0x999b
addq 0x18(%rsp), %r8
movb 0x1(%rdi), %cl
xorl %eax, %eax
movb %cl, 0x48(%rsp)
cmpb $0x5e, %cl
sete %al
movl 0x24(%rsp), %ebp
subl %r14d, %ebp
subl %eax, %ebp
leaq (%rdi,%rax), %r14
incq %r14
xorl %r13d, %r13d
pushq $-0x1
popq %rax
movq %r8, 0x28(%rsp)
cmpl %ebp, %r13d
jg 0x9c10
movslq %r13d, %rbx
movsbq (%r14,%rbx), %r15
cmpq $0x5d, %r15
je 0x9c10
testl %eax, %eax
jg 0x9c10
cmpb $0x2d, %r15b
je 0x9b79
cmpb $0x2d, 0x1(%r14,%rbx)
jne 0x9b79
movzbl 0x2(%r14,%rbx), %edx
testl %edx, %edx
je 0x9b79
cmpl $0x5d, %edx
jne 0x9bb4
addq %r14, %rbx
movq %rbx, %rdi
movq %r8, %rsi
movq 0x10(%rsp), %rdx
callq 0x9f6f
pushq $0x1
popq %rcx
cmpb $0x5c, %r15b
jne 0x9ba5
xorl %ecx, %ecx
cmpb $0x78, 0x1(%rbx)
sete %cl
leal 0x2(,%rcx,2), %ecx
addl %ecx, %r13d
movq 0x8(%rsp), %r10
movq 0x28(%rsp), %r8
jmp 0x9b39
movq 0x10(%rsp), %rax
testb $0x1, 0xfbc(%rax)
jne 0x9bd4
movb (%r8), %al
cmpb %r15b, %al
setge %cl
cmpb %dl, %al
setle %al
andb %cl, %al
jmp 0x9c04
movq %rdx, %rbx
callq 0x22a0
movq 0x28(%rsp), %r8
movq (%rax), %rax
movsbq (%r8), %rcx
movl (%rax,%rcx,4), %ecx
cmpl (%rax,%r15,4), %ecx
jge 0x9bf5
xorl %eax, %eax
jmp 0x9bff
movsbq %bl, %rdx
cmpl (%rax,%rdx,4), %ecx
setle %al
movq 0x8(%rsp), %r10
movzbl %al, %eax
addl $0x3, %r13d
jmp 0x9b39
movb 0x48(%rsp), %sil
cmpb $0x5e, %sil
sete %cl
testl %eax, %eax
setle %dl
andb %cl, %dl
movzbl %dl, %ecx
decl %ecx
orl $0x1, %ecx
testl %eax, %eax
pushq $0x1
popq %rax
cmovlel %ecx, %eax
cmpb $0x5e, %sil
cmovel %ecx, %eax
testl %eax, %eax
jle 0x9f30
addl %eax, %r10d
movq 0x38(%rsp), %r13
jmp 0x999b
movl 0x4(%rsp), %eax
cmpl %r10d, %eax
movl %eax, %r10d
jmp 0x9c64
testl %r10d, %r10d
movl $0x0, %r10d
movq 0x38(%rsp), %r13
je 0x999b
jmp 0x9f30
movq %r8, 0x28(%rsp)
movq 0x10(%rsp), %rdx
movl 0x30(%rsp), %r8d
cmpl 0x960(%rdx), %r8d
jge 0x9f6b
movq 0x40(%rsp), %rcx
subl %r12d, %ecx
movl %ecx, 0x74(%rsp)
movq 0x38(%rsp), %r13
jle 0x9d36
movq 0x18(%rsp), %rcx
movq 0x28(%rsp), %rdx
addq %rdx, %rcx
addq %rax, %rdi
xorl %eax, %eax
movl %ebx, %esi
pushq $-0x1
popq %r15
movq %rdi, 0x68(%rsp)
movq %rcx, 0x58(%rsp)
cmpl %ebx, %eax
jg 0x9d56
movl %eax, 0x50(%rsp)
movq %rcx, %rdi
movl %esi, 0x48(%rsp)
movq 0x10(%rsp), %r14
movq %r14, %rdx
movl 0x30(%rsp), %ebp
movl %ebp, %ecx
callq 0x988b
movl %eax, %r15d
testl %eax, %eax
js 0x9d23
movl %r15d, %edx
addq 0x58(%rsp), %rdx
movl %r15d, %eax
addl 0x8(%rsp), %eax
movl 0x4(%rsp), %ecx
subl %eax, %ecx
movq 0x68(%rsp), %rdi
movl 0x74(%rsp), %esi
movq %r14, %r8
movl %ebp, %r9d
callq 0x9946
testl %eax, %eax
jns 0x9d5f
movl 0x50(%rsp), %eax
incl %eax
movl 0x48(%rsp), %esi
decl %esi
movq 0x58(%rsp), %rcx
jmp 0x9cc9
movq 0x18(%rsp), %rax
movq 0x28(%rsp), %rcx
leaq (%rax,%rcx), %rdi
movl 0x4(%rsp), %esi
subl %r10d, %esi
movl %r8d, %ecx
callq 0x988b
movl %eax, %r15d
testl %r15d, %r15d
js 0x9f54
movq 0x10(%rsp), %r8
movq 0xfb0(%r8), %rax
testq %rax, %rax
sete %cl
testl %r15d, %r15d
sete %dl
orb %cl, %dl
movq 0x8(%rsp), %r10
movq 0x60(%rsp), %rcx
movl 0x30(%rsp), %edx
jne 0x9da3
movq 0x28(%rsp), %rsi
addq 0x18(%rsp), %rsi
movslq %ecx, %rcx
shlq $0x4, %rcx
movq %rsi, (%rax,%rcx)
movl %r15d, 0x8(%rax,%rcx)
addl %r15d, %r10d
movl %edx, %r9d
jmp 0x997c
movl %r12d, %ecx
incq %rcx
movb $0x1, 0x24(%rsp)
cmpl 0x40(%rsp), %ecx
movq %r8, 0x28(%rsp)
jge 0x9dd9
leal 0x2(%r12), %eax
cmpb $0x3f, (%r13,%rcx)
setne 0x24(%rsp)
cmovnel %ecx, %eax
movl %eax, %ecx
movl %ecx, %eax
addq %r13, %rax
movq %rax, 0x48(%rsp)
movq 0x40(%rsp), %rax
movq %rcx, 0x50(%rsp)
subl %ecx, %eax
movl %eax, 0x58(%rsp)
pushq $-0x1
popq %rax
movq %rax, 0x30(%rsp)
movl %r10d, %r13d
movl %r10d, %r14d
movq %rdi, 0x68(%rsp)
movslq %r13d, %rax
movq 0x18(%rsp), %rcx
leaq (%rcx,%rax), %rdx
movl 0x4(%rsp), %ecx
subl %eax, %ecx
movl %r15d, %esi
movq 0x10(%rsp), %r8
movq 0x60(%rsp), %r9
callq 0x9946
movl %eax, %ebx
movl $0x0, %eax
testl %ebx, %ebx
cmovgl %ebx, %eax
jns 0x9e48
movq 0x38(%rsp), %rcx
cmpb $0x2b, (%rcx,%r12)
je 0x9f1a
addl %eax, %r13d
movl %r13d, %ebp
movq 0x50(%rsp), %rax
cmpl %eax, 0x40(%rsp)
jle 0x9e90
movslq %r13d, %rbp
movq 0x18(%rsp), %rax
leaq (%rax,%rbp), %rdx
movl 0x4(%rsp), %ecx
subl %ebp, %ecx
movq 0x48(%rsp), %rdi
movl 0x58(%rsp), %esi
movq 0x10(%rsp), %r8
movq 0x60(%rsp), %r9
callq 0x9946
addl %eax, %ebp
movq %rax, 0x30(%rsp)
testl %eax, %eax
cmovsl %r14d, %ebp
movq 0x8(%rsp), %rsi
cmpl %esi, %ebp
setle %al
testl %ebx, %ebx
movq 0x68(%rsp), %rdi
jle 0x9eb0
orb 0x24(%rsp), %al
movl %ebp, %r14d
jne 0x9e06
movq 0x38(%rsp), %r14
movb (%r14,%r12), %cl
testl %ebx, %ebx
jns 0x9f66
movq 0x30(%rsp), %rax
testl %eax, %eax
jns 0x9f08
cmpb $0x2a, %cl
jne 0x9f08
movq 0x18(%rsp), %rdx
addq 0x28(%rsp), %rdx
movl 0x4(%rsp), %ecx
subl %esi, %ecx
movq 0x48(%rsp), %rdi
movl 0x58(%rsp), %esi
movq 0x10(%rsp), %r8
movq 0x60(%rsp), %r9
callq 0x9946
movq 0x8(%rsp), %rsi
leal (%rax,%rsi), %ecx
testl %eax, %eax
cmovgl %ecx, %ebp
movb (%r14,%r12), %cl
movl %ebp, %r14d
jmp 0x9f26
pushq $-0x2
jmp 0x9f32
movl %r10d, %r15d
jmp 0x9f54
pushq $-0x5
jmp 0x9f32
movb $0x2b, %cl
movq 0x8(%rsp), %rsi
movq 0x30(%rsp), %rax
cmpb $0x2b, %cl
jne 0x9f36
cmpl %esi, %r14d
jne 0x9f36
pushq $-0x1
popq %r15
jmp 0x9f54
testl %eax, %eax
pushq $-0x1
popq %r15
cmovnsl %r14d, %r15d
movq 0x50(%rsp), %rax
cmpl %eax, 0x40(%rsp)
cmovlel %r14d, %r15d
cmpl %esi, %r14d
cmovnel %r14d, %r15d
movl %r15d, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %ebp, %r14d
jmp 0x9f21
pushq $-0x4
jmp 0x9f32