// File: /workspace/github_c_makefile_star2_O1/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
movq %r8, 0x18(%rsp)
movq %rdx, 0x28(%rsp)
testl %esi, %esi
setle %al
movl %ecx, 0x4(%rsp)
testl %ecx, %ecx
sets %cl
xorl %ebp, %ebp
orb %al, %cl
jne 0xc665
movl %r9d, %r14d
movl %esi, %r13d
movq %rdi, %rbx
leal -0x2(%r13), %eax
movl %eax, 0x70(%rsp)
xorl %r12d, %r12d
xorl %eax, %eax
xorl %ebp, %ebp
movq %r13, 0x58(%rsp)
movq %rdi, 0x30(%rsp)
movl %eax, %r15d
leaq (%rbx,%r15), %rdi
movzbl (%rbx,%r15), %ebx
cmpl $0x28, %ebx
movl %eax, 0x8(%rsp)
jne 0xc080
leal 0x1(%r14), %eax
cltq
leaq (%rax,%rax,2), %rax
movq 0x18(%rsp), %rcx
movl 0x8(%rcx,%rax,8), %esi
addl $0x2, %esi
jmp 0xc0ae
movl %r13d, %esi
subl %eax, %esi
movq %r15, 0x20(%rsp)
movq %r14, %r15
movq %rbp, %r14
movq %r13, %rbp
movq %rdi, %r13
callq 0xbecf
movq %r13, %rdi
movq %rbp, %r13
movq %r14, %rbp
movq %r15, %r14
movq 0x20(%rsp), %r15
movl %eax, %esi
cmpl $0x3f, %ebx
ja 0xc0c9
movl %ebx, %eax
movabsq $-0x7ffff40000000000, %rcx # imm = 0x80000C0000000000
btq %rax, %rcx
jb 0xc4c2
testl %esi, %esi
jle 0xc4cc
movl %esi, %eax
addq %rax, %r15
cmpl %r15d, %r13d
movq %r14, 0x40(%rsp)
movl %esi, 0x20(%rsp)
jle 0xc122
movzbl (%rdi,%rax), %ecx
cmpq $0x3f, %rcx
ja 0xc122
movabsq $-0x7ffff40000000000, %rdx # imm = 0x80000C0000000000
btq %rcx, %rdx
jae 0xc122
movq 0x30(%rsp), %rbx
movzbl (%rbx,%r15), %eax
cmpl $0x3f, %eax
je 0xc345
addl $-0x2a, %eax
cmpl $0x2, %eax
jae 0xc41d
jmp 0xc4d6
cmpl $0x5a, %ebx
jg 0xc20e
cmpl $0x24, %ebx
je 0xc3b0
cmpl $0x28, %ebx
jne 0xc382
leal 0x1(%r14), %ecx
movq 0x18(%rsp), %rdx
cmpl 0x960(%rdx), %ecx
jge 0xc630
movl 0x4(%rsp), %esi
subl %ebp, %esi
movl %r13d, %r8d
subl %r15d, %r8d
movl %r8d, 0x68(%rsp)
movl %ecx, 0x14(%rsp)
movq %rbp, 0x48(%rsp)
jle 0xc422
testl %esi, %esi
js 0xc438
movl %esi, 0x38(%rsp)
addq %rax, %rdi
movq %rdi, 0x60(%rsp)
movslq %ebp, %rdi
addq 0x28(%rsp), %rdi
movl %r12d, %r15d
addl 0x4(%rsp), %r15d
xorl %ebx, %ebx
movl %r15d, 0x74(%rsp)
movq %rdi, 0x50(%rsp)
movl %r15d, %esi
movq 0x18(%rsp), %r14
movq %rdi, %r12
movq %r14, %rdx
movl %ecx, %ebp
callq 0xbf45
movl %eax, %r13d
testl %eax, %eax
js 0xc1f6
movl %r13d, %edx
addq %r12, %rdx
movl 0x74(%rsp), %ecx
subl %r13d, %ecx
movq 0x60(%rsp), %rdi
movl 0x68(%rsp), %esi
movq %r14, %r8
movl %ebp, %r9d
callq 0xc001
testl %eax, %eax
jns 0xc440
cmpl 0x38(%rsp), %ebx
movl 0x14(%rsp), %ecx
jl 0xc202
jmp 0xc444
cmpl 0x38(%rsp), %ebx
movl %ebp, %ecx
jge 0xc444
incl %ebx
decl %r15d
movq 0x50(%rsp), %rdi
jmp 0xc1a2
cmpl $0x5e, %ebx
je 0xc3b9
cmpl $0x5b, %ebx
jne 0xc382
movb 0x1(%rdi), %dl
xorl %eax, %eax
cmpb $0x5e, %dl
sete %al
movl 0x70(%rsp), %r15d
subl 0x8(%rsp), %r15d
subl %eax, %r15d
js 0xc3ec
movb %dl, 0x50(%rsp)
movq %rbp, 0x48(%rsp)
movslq %ebp, %rcx
addq 0x28(%rsp), %rcx
movq %rcx, 0x38(%rsp)
leaq (%rdi,%rax), %r12
incq %r12
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
xorl %r13d, %r13d
movslq %r13d, %rbx
movsbq (%r12,%rbx), %rbp
cmpq $0x5d, %rbp
je 0xc3d7
testl %eax, %eax
jg 0xc3d7
cmpb $0x2d, %bpl
je 0xc29c
cmpb $0x2d, 0x1(%r12,%rbx)
jne 0xc29c
movzbl 0x2(%r12,%rbx), %r14d
testl %r14d, %r14d
je 0xc29c
cmpl $0x5d, %r14d
jne 0xc2e2
addq %r12, %rbx
movq %rbx, %rdi
movq 0x38(%rsp), %rsi
movq 0x18(%rsp), %rdx
callq 0xc68f
movl $0x1, %ecx
cmpb $0x5c, %bpl
jne 0xc2cc
xorl %ecx, %ecx
cmpb $0x78, 0x1(%rbx)
sete %cl
leal 0x2(,%rcx,2), %ecx
addl %ecx, %r13d
movq 0x40(%rsp), %r14
movl 0x20(%rsp), %esi
cmpl %r15d, %r13d
jle 0xc263
jmp 0xc3d7
movq 0x18(%rsp), %rax
testb $0x1, 0xfbc(%rax)
jne 0xc30c
movq 0x38(%rsp), %rax
movb (%rax), %al
cmpb %bpl, %al
setge %cl
cmpb %r14b, %al
setle %al
andb %cl, %al
movq 0x40(%rsp), %r14
jmp 0xc33c
callq 0x22a0
movq (%rax), %rax
movq 0x38(%rsp), %rcx
movsbq (%rcx), %rcx
movl (%rax,%rcx,4), %ecx
cmpl (%rax,%rbp,4), %ecx
jge 0xc329
xorl %eax, %eax
jmp 0xc333
movsbq %r14b, %rdx
cmpl (%rax,%rdx,4), %ecx
setle %al
movq 0x40(%rsp), %r14
movl 0x20(%rsp), %esi
movzbl %al, %eax
addl $0x3, %r13d
jmp 0xc2d8
movslq %ebp, %rdx
addq 0x28(%rsp), %rdx
movl 0x4(%rsp), %ecx
subl %ebp, %ecx
movl 0x20(%rsp), %esi
movq 0x18(%rsp), %r8
movl %r14d, %r9d
callq 0xc001
movl 0x20(%rsp), %esi
testl %eax, %eax
movl $0x0, %ecx
cmovlel %ecx, %eax
addl %eax, %ebp
movl 0x8(%rsp), %eax
incl %eax
movl %r14d, %ecx
jmp 0xc49f
cmpl %ebp, 0x4(%rsp)
movq 0x18(%rsp), %rdx
jle 0xc660
movslq %ebp, %rsi
addq 0x28(%rsp), %rsi
callq 0xc68f
testl %eax, %eax
jle 0xc637
addl %eax, %ebp
movl %r14d, %ecx
jmp 0xc492
movl %r14d, %ecx
cmpl %ebp, 0x4(%rsp)
jmp 0xc3c3
movl %r14d, %ecx
testl %ebp, %ebp
movl $0x0, %ebp
movq 0x30(%rsp), %rbx
movl 0x8(%rsp), %eax
je 0xc49f
jmp 0xc660
testl %eax, %eax
setle %al
movq 0x48(%rsp), %rbp
movq 0x58(%rsp), %r13
movb 0x50(%rsp), %dl
jmp 0xc3ee
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 0x30(%rsp), %rbx
jle 0xc660
addl %eax, %ebp
movl %r14d, %ecx
jmp 0xc49b
movslq %ebp, %rdi
addq 0x28(%rsp), %rdi
callq 0xbf45
movl 0x14(%rsp), %ecx
movl %eax, %r13d
jmp 0xc444
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
jmp 0xc444
movl 0x14(%rsp), %ecx
testl %r13d, %r13d
js 0xc63b
movq 0x18(%rsp), %rax
movq 0xfb0(%rax), %rax
testq %rax, %rax
sete %sil
testl %r13d, %r13d
sete %dl
orb %sil, %dl
movq 0x48(%rsp), %rbp
jne 0xc48a
movslq %ebp, %rsi
addq 0x28(%rsp), %rsi
movslq 0x40(%rsp), %rdx
shlq $0x4, %rdx
movq %rsi, (%rax,%rdx)
movl %r13d, 0x8(%rax,%rdx)
addl %r13d, %ebp
movq 0x58(%rsp), %r13
movq 0x30(%rsp), %rbx
movl 0x20(%rsp), %esi
movl 0x8(%rsp), %eax
addl %esi, %eax
cmpl %r13d, %eax
jge 0xc665
movl %ebp, %r12d
negl %r12d
movl %ecx, %r14d
cmpl 0x4(%rsp), %ebp
jle 0xc053
jmp 0xc665
movl $0xfffffffe, %ebp       # imm = 0xFFFFFFFE
jmp 0xc665
movl $0xfffffffb, %ebp       # imm = 0xFFFFFFFB
jmp 0xc665
movl %r15d, %ecx
incq %rcx
movb $0x1, 0x38(%rsp)
cmpl %r13d, %ecx
jge 0xc4f8
leal 0x2(%r15), %eax
cmpb $0x3f, (%rbx,%rcx)
setne 0x38(%rsp)
cmovnel %ecx, %eax
movl %eax, %ecx
movl %ecx, %eax
movq %rax, 0x60(%rsp)
addq %rbx, %rax
movq %rax, 0x68(%rsp)
movl %r13d, %eax
movq %rcx, 0x8(%rsp)
subl %ecx, %eax
movl %eax, 0x14(%rsp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %rax, 0x50(%rsp)
movl %ebp, %r12d
movq %rbp, 0x48(%rsp)
movslq %r12d, %rax
movq 0x28(%rsp), %rcx
leaq (%rcx,%rax), %rdx
movl 0x4(%rsp), %ecx
subl %eax, %ecx
movq %rdi, %r14
movq 0x18(%rsp), %r8
movq 0x40(%rsp), %r9
callq 0xc001
movl %eax, %ebx
movl $0x0, %eax
testl %ebx, %ebx
cmovgl %ebx, %eax
jns 0xc565
movq 0x30(%rsp), %rcx
cmpb $0x2b, (%rcx,%r15)
je 0xc5d1
addl %eax, %r12d
movl %r12d, %r13d
movq 0x8(%rsp), %rax
cmpl %eax, 0x58(%rsp)
jle 0xc5af
movslq %r12d, %r13
movq 0x28(%rsp), %rax
leaq (%rax,%r13), %rdx
movl 0x4(%rsp), %ecx
subl %r13d, %ecx
movq 0x68(%rsp), %rdi
movl 0x14(%rsp), %esi
movq 0x18(%rsp), %r8
movq 0x40(%rsp), %r9
callq 0xc001
addl %eax, %r13d
movq %rax, 0x50(%rsp)
testl %eax, %eax
cmovsl %ebp, %r13d
cmpl 0x48(%rsp), %r13d
setle %al
testl %ebx, %ebx
jle 0xc5d4
orb 0x38(%rsp), %al
movl %r13d, %ebp
movl 0x20(%rsp), %esi
movq %r14, %rdi
jne 0xc527
jmp 0xc5d4
movl %ebp, %r13d
testl %ebx, %ebx
jns 0xc640
movq 0x50(%rsp), %rdx
testl %edx, %edx
movq 0x48(%rsp), %rbx
jns 0xc629
movq 0x30(%rsp), %rax
cmpb $0x2a, (%rax,%r15)
jne 0xc629
movq 0x60(%rsp), %rdi
addq %rax, %rdi
movslq %ebx, %rax
movq 0x28(%rsp), %rdx
addq %rax, %rdx
movl 0x4(%rsp), %ecx
subl %ebx, %ecx
movl 0x14(%rsp), %esi
movq 0x18(%rsp), %r8
movq 0x40(%rsp), %r9
callq 0xc001
movl %eax, %edx
leal (%rdx,%rbx), %eax
testl %edx, %edx
cmovgl %eax, %r13d
movq 0x8(%rsp), %rcx
jmp 0xc64f
movl $0xfffffffc, %ebp       # imm = 0xFFFFFFFC
jmp 0xc665
movl %eax, %ebp
jmp 0xc665
movl %r13d, %ebp
jmp 0xc665
movq 0x48(%rsp), %rbx
movq 0x8(%rsp), %rcx
movq 0x50(%rsp), %rdx
movq 0x30(%rsp), %rax
cmpb $0x2b, (%rax,%r15)
jne 0xc676
cmpl %ebx, %r13d
jne 0xc676
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl %ebp, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl %ebx, %r13d
jne 0xc68a
cmpl %ecx, 0x58(%rsp)
jle 0xc68a
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testl %edx, %edx
js 0xc665
movl %r13d, %ebp
jmp 0xc665