// File: /workspace/github_c_makefile_star2_O2/msteveb[P]autosetup/./jimsh0.c
// Function: Jim_RegexpCmd
int Jim_RegexpCmd(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
    int opt_indices = 0;
    int opt_all = 0;
    int opt_inline = 0;
    regex_t *regex;
    int match, i, j;
    int offset = 0;
    regmatch_t *pmatch = NULL;
    int source_len;
    int result = JIM_OK;
    const char *pattern;
    const char *source_str;
    int num_matches = 0;
    int num_vars;
    Jim_Obj *resultListObj = NULL;
    int regcomp_flags = 0;
    int eflags = 0;
    int option;
    enum {
        OPT_INDICES,  OPT_NOCASE, OPT_LINE, OPT_ALL, OPT_INLINE, OPT_START, OPT_END
    };
    static const char * const options[] = {
        "-indices", "-nocase", "-line", "-all", "-inline", "-start", "--", NULL
    };

    if (argc < 3) {
      wrongNumArgs:
        Jim_WrongNumArgs(interp, 1, argv,
            "?-switch ...? exp string ?matchVar? ?subMatchVar ...?");
        return JIM_ERR;
    }

    for (i = 1; i < argc; i++) {
        const char *opt = Jim_String(argv[i]);

        if (*opt != '-') {
            break;
        }
        if (Jim_GetEnum(interp, argv[i], options, &option, "switch", JIM_ERRMSG | JIM_ENUM_ABBREV) != JIM_OK) {
            return JIM_ERR;
        }
        if (option == OPT_END) {
            i++;
            break;
        }
        switch (option) {
            case OPT_INDICES:
                opt_indices = 1;
                break;

            case OPT_NOCASE:
                regcomp_flags |= REG_ICASE;
                break;

            case OPT_LINE:
                regcomp_flags |= REG_NEWLINE;
                break;

            case OPT_ALL:
                opt_all = 1;
                break;

            case OPT_INLINE:
                opt_inline = 1;
                break;

            case OPT_START:
                if (++i == argc) {
                    goto wrongNumArgs;
                }
                if (Jim_GetIndex(interp, argv[i], &offset) != JIM_OK) {
                    return JIM_ERR;
                }
                break;
        }
    }
    if (argc - i < 2) {
        goto wrongNumArgs;
    }

    regex = SetRegexpFromAny(interp, argv[i], regcomp_flags);
    if (!regex) {
        return JIM_ERR;
    }

    pattern = Jim_String(argv[i]);
    source_str = Jim_GetString(argv[i + 1], &source_len);

    num_vars = argc - i - 2;

    if (opt_inline) {
        if (num_vars) {
            Jim_SetResultString(interp, "regexp match variables not allowed when using -inline",
                -1);
            result = JIM_ERR;
            goto done;
        }
        num_vars = regex->re_nsub + 1;
    }

    pmatch = Jim_Alloc((num_vars + 1) * sizeof(*pmatch));

    if (offset) {
        if (offset < 0) {
            offset += source_len + 1;
        }
        if (offset > source_len) {
            source_str += source_len;
        }
        else if (offset > 0) {
            source_str += utf8_index(source_str, offset);
        }
        eflags |= REG_NOTBOL;
    }

    if (opt_inline) {
        resultListObj = Jim_NewListObj(interp, NULL, 0);
    }

  next_match:
    match = jim_regexec(regex, source_str, num_vars + 1, pmatch, eflags);
    if (match >= REG_BADPAT) {
        char buf[100];

        jim_regerror(match, regex, buf, sizeof(buf));
        Jim_SetResultFormatted(interp, "error while matching pattern: %s", buf);
        result = JIM_ERR;
        goto done;
    }

    if (match == REG_NOMATCH) {
        goto done;
    }

    num_matches++;

    if (opt_all && !opt_inline) {

        goto try_next_match;
    }


    j = 0;
    for (i += 2; opt_inline ? j < num_vars : i < argc; i++, j++) {
        Jim_Obj *resultObj;

        if (opt_indices) {
            resultObj = Jim_NewListObj(interp, NULL, 0);
        }
        else {
            resultObj = Jim_NewStringObj(interp, "", 0);
        }

        if (pmatch[j].rm_so == -1) {
            if (opt_indices) {
                Jim_ListAppendElement(interp, resultObj, Jim_NewIntObj(interp, -1));
                Jim_ListAppendElement(interp, resultObj, Jim_NewIntObj(interp, -1));
            }
        }
        else {
            if (opt_indices) {

                int so = utf8_strlen(source_str, pmatch[j].rm_so);
                int eo = utf8_strlen(source_str, pmatch[j].rm_eo);
                Jim_ListAppendElement(interp, resultObj, Jim_NewIntObj(interp, offset + so));
                Jim_ListAppendElement(interp, resultObj, Jim_NewIntObj(interp, offset + eo - 1));
            }
            else {
                Jim_AppendString(interp, resultObj, source_str + pmatch[j].rm_so, pmatch[j].rm_eo - pmatch[j].rm_so);
            }
        }

        if (opt_inline) {
            Jim_ListAppendElement(interp, resultListObj, resultObj);
        }
        else {

            result = Jim_SetVariable(interp, argv[i], resultObj);

            if (result != JIM_OK) {
                Jim_FreeObj(interp, resultObj);
                break;
            }
        }
    }

  try_next_match:
    if (opt_all && (pattern[0] != '^' || (regcomp_flags & REG_NEWLINE)) && *source_str) {
        if (pmatch[0].rm_eo) {
            offset += utf8_strlen(source_str, pmatch[0].rm_eo);
            source_str += pmatch[0].rm_eo;
        }
        else {
            source_str++;
            offset++;
        }
        if (*source_str) {
            eflags = REG_NOTBOL;
            goto next_match;
        }
    }

  done:
    if (result == JIM_OK) {
        if (opt_inline) {
            Jim_SetResult(interp, resultListObj);
        }
        else {
            Jim_SetResultInt(interp, num_matches);
        }
    }

    Jim_Free(pmatch);
    return result;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movq %rdi, %r12
andl $0x0, -0x34(%rbp)
cmpl $0x3, %esi
jl 0x766b
movl %esi, %r15d
pushq $0x1
popq %r14
movl $0x0, -0x44(%rbp)
leaq 0x1ba97(%rip), %rbx     # 0x23010
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x54(%rbp)
movl $0x0, -0x70(%rbp)
movq %r12, -0x68(%rbp)
movq %rdx, -0x60(%rbp)
cmpl %r15d, %r14d
jge 0x7660
movslq %r14d, %r12
movq (%rdx,%r12,8), %rdi
movq %rdx, %r13
callq 0x7340
cmpb $0x2d, (%rax)
jne 0x7659
movq (%r13,%r12,8), %rsi
movq -0x68(%rbp), %r12
movq %r12, %rdi
leaq 0x29736(%rip), %rdx     # 0x30d00
leaq -0x8c(%rbp), %rcx
leaq 0x1f4ea(%rip), %r8      # 0x26ac2
pushq $0x3
popq %r9
callq 0x7b44
testl %eax, %eax
jne 0x7653
movl -0x8c(%rbp), %eax
cmpq $0x6, %rax
ja 0x7622
movslq (%rbx,%rax,4), %rax
addq %rbx, %rax
movq -0x60(%rbp), %rdx
jmpq *%rax
pushq $0x1
popq %rax
movl %eax, -0x70(%rbp)
jmp 0x764b
pushq $0x1
popq %rax
movl %eax, -0x2c(%rbp)
jmp 0x764b
orl $0x1, -0x44(%rbp)
jmp 0x764b
pushq $0x1
popq %rax
movl %eax, -0x54(%rbp)
jmp 0x764b
orl $0x2, -0x44(%rbp)
jmp 0x764b
movq -0x60(%rbp), %rdx
jmp 0x764b
incl %r14d
cmpl %r15d, %r14d
je 0x766b
movslq %r14d, %rax
movq (%rdx,%rax,8), %rsi
movq %r12, %rdi
leaq -0x34(%rbp), %rdx
callq 0x7d46
movq -0x60(%rbp), %rdx
testl %eax, %eax
jne 0x7653
incl %r14d
jmp 0x7596
pushq $0x1
popq %r13
jmp 0x7681
movq -0x68(%rbp), %r12
movq %r13, %rdx
movl %r15d, %ebx
subl %r14d, %ebx
cmpl $0x2, %ebx
jge 0x7696
leaq 0x1f41a(%rip), %rcx     # 0x26a8c
pushq $0x1
popq %r13
movq %r12, %rdi
movl %r13d, %esi
callq 0x72a5
movl %r13d, %eax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r12, %rdi
movslq %r14d, %r12
movq (%rdx,%r12,8), %rsi
movl -0x44(%rbp), %edx
callq 0x7ee6
movq %rax, -0x98(%rbp)
testq %rax, %rax
pushq $0x1
popq %r13
je 0x7681
movq -0x60(%rbp), %r13
movq (%r13,%r12,8), %rdi
callq 0x7340
movq %rax, -0xb8(%rbp)
movq 0x8(%r13,%r12,8), %rdi
leaq -0x90(%rbp), %rsi
callq 0x7fc7
addl $-0x2, %ebx
cmpl $0x0, -0x2c(%rbp)
je 0x7734
testl %ebx, %ebx
movq -0x68(%rbp), %r12
je 0x773e
leaq 0x1f3d3(%rip), %rsi     # 0x26ac9
pushq $-0x1
popq %rdx
movq %r12, %rdi
callq 0x7363
movq %rax, %r14
incl 0x10(%rax)
movq (%r12), %rsi
movl 0x10(%rsi), %eax
leal -0x1(%rax), %ecx
movl %ecx, 0x10(%rsi)
cmpl $0x1, %eax
jg 0x7721
movq %r12, %rdi
callq 0x73bf
movq %r14, (%r12)
pushq $0x1
popq %rax
movq %rax, -0x50(%rbp)
xorl %r13d, %r13d
jmp 0x7b30
movq %rax, -0x40(%rbp)
movq -0x68(%rbp), %r12
jmp 0x774d
movq %rax, -0x40(%rbp)
movq -0x98(%rbp), %rax
movl (%rax), %ebx
incl %ebx
movslq %ebx, %rax
movq %rax, -0xa8(%rbp)
leaq 0x8(,%rax,8), %rsi
xorl %ebx, %ebx
xorl %edi, %edi
callq *0x2bb1f(%rip)          # 0x33288
movq %rax, %r13
movl -0x34(%rbp), %eax
testl %eax, %eax
je 0x77ad
movslq -0x90(%rbp), %rcx
jns 0x7783
addl %ecx, %eax
incl %eax
movl %eax, -0x34(%rbp)
pushq $0x10
popq %rbx
cmpl %ecx, %eax
jle 0x779e
movq -0x40(%rbp), %rax
addq %rcx, %rax
movq %rax, %rcx
jmp 0x77b1
incl %r14d
jmp 0x7660
testl %eax, %eax
jle 0x77ad
movl %eax, %eax
movq -0x40(%rbp), %rcx
addq %rax, %rcx
jmp 0x77b1
movq -0x40(%rbp), %rcx
movq $0x0, -0x50(%rbp)
cmpl $0x0, -0x2c(%rbp)
je 0x77e5
movq %r12, %rdi
xorl %esi, %esi
xorl %edx, %edx
movq %rbx, -0x88(%rbp)
movq %rcx, %rbx
callq 0x745b
movq %rbx, %rcx
movq -0x88(%rbp), %rbx
movq %rax, -0x78(%rbp)
jmp 0x77ed
movq $0x0, -0x78(%rbp)
movq -0xa8(%rbp), %rax
incq %rax
movq %rax, -0xb0(%rbp)
cmpl $0x0, -0x2c(%rbp)
setne %al
cmpl $0x0, -0x54(%rbp)
sete %dl
orb %al, %dl
movb %dl, -0x2d(%rbp)
movl %r15d, %eax
movq %rax, -0xd0(%rbp)
movl $0x0, -0x6c(%rbp)
movq %r13, -0x80(%rbp)
movq -0x98(%rbp), %rdi
movq %rcx, -0x40(%rbp)
movq %rcx, %rsi
movq -0xb0(%rbp), %rdx
movq %r13, %rcx
movl %ebx, %r8d
callq 0x7ff7
cmpl $0x2, %eax
jae 0x7ac7
cmpl $0x1, %eax
je 0x7a8c
incl -0x6c(%rbp)
cmpb $0x0, -0x2d(%rbp)
je 0x7a34
addl $0x2, %r14d
movl -0x34(%rbp), %eax
movq %rax, -0xc8(%rbp)
movslq %r14d, %rcx
movq -0x60(%rbp), %rax
movq %rcx, -0x88(%rbp)
leaq (%rax,%rcx,8), %rax
movq %rax, -0xc0(%rbp)
xorl %ebx, %ebx
movq %r14, -0xa0(%rbp)
movq -0x88(%rbp), %rax
addq %rbx, %rax
xorl %ecx, %ecx
cmpq -0xa8(%rbp), %rbx
setl %cl
xorl %edx, %edx
cmpq -0xd0(%rbp), %rax
setl %dl
cmpl $0x0, -0x2c(%rbp)
cmovnel %ecx, %edx
cmpb $0x1, %dl
jne 0x7a28
cmpl $0x0, -0x70(%rbp)
je 0x795a
movq %r12, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x745b
movq %rax, %r15
movl (%r13,%rbx,8), %r13d
cmpl $-0x1, %r13d
je 0x7994
testl %r13d, %r13d
jns 0x7900
movq -0x40(%rbp), %rdi
callq 0x6180
movq %rax, %r13
movq -0x80(%rbp), %rax
movl 0x4(%rax,%rbx,8), %r12d
testl %r12d, %r12d
jns 0x791a
movq -0x40(%rbp), %rdi
callq 0x6180
movq %rax, %r12
movq -0xc8(%rbp), %r14
addl %r14d, %r13d
movslq %r13d, %rsi
movq -0x68(%rbp), %r13
movq %r13, %rdi
callq 0x8212
movq %r13, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x74ad
leal (%r12,%r14), %eax
decl %eax
movq %r13, %r12
movslq %eax, %rsi
movq %r13, %rdi
callq 0x8212
movq %r13, %rdi
jmp 0x79bf
movq %r12, %rdi
leaq 0x21cdd(%rip), %rsi     # 0x29641
xorl %edx, %edx
callq 0x7363
movq %rax, %r15
movslq (%r13,%rbx,8), %rax
cmpq $-0x1, %rax
je 0x79d5
movq %rax, %rdx
addq -0x40(%rbp), %rdx
movl 0x4(%r13,%rbx,8), %ecx
subl %eax, %ecx
movq %r12, %rdi
movq %r15, %rsi
callq 0x823a
jmp 0x79d5
movq %r12, %rdi
pushq $-0x1
popq %r13
movq %r13, %rsi
callq 0x8212
movq %r12, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x74ad
movq %r12, %rdi
movq %r13, %rsi
callq 0x8212
movq %r12, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x74ad
movq -0x80(%rbp), %r13
movq -0xa0(%rbp), %r14
cmpl $0x0, -0x2c(%rbp)
je 0x79ec
movq %r12, %rdi
movq -0x78(%rbp), %rsi
movq %r15, %rdx
callq 0x74ad
jmp 0x7a0e
movq -0xc0(%rbp), %rax
movq (%rax,%rbx,8), %rsi
movq %r12, %rdi
movq %r15, %rdx
callq 0x8306
movq $0x0, -0x50(%rbp)
testl %eax, %eax
jne 0x7a16
incq %rbx
jmp 0x7895
movq %r12, %rdi
movq %r15, %rsi
callq 0x73bf
pushq $0x1
popq %rax
movq %rax, -0x50(%rbp)
cmpl $0x0, -0x54(%rbp)
je 0x7a8c
movl %r14d, %r14d
addq %rbx, %r14
testb $0x1, -0x44(%rbp)
sete %al
movq -0xb8(%rbp), %rcx
cmpb $0x5e, (%rcx)
sete %cl
testb %al, %cl
jne 0x7a8c
movq -0x40(%rbp), %rcx
cmpb $0x0, (%rcx)
je 0x7a8c
movslq 0x4(%r13), %rbx
testq %rbx, %rbx
je 0x7a78
movl %ebx, %eax
testl %ebx, %ebx
jns 0x7a70
movq %rcx, %rdi
callq 0x6180
movq -0x40(%rbp), %rcx
addl %eax, -0x34(%rbp)
addq %rbx, %rcx
jmp 0x7a7e
incq %rcx
incl -0x34(%rbp)
cmpb $0x0, (%rcx)
pushq $0x10
popq %rax
movl %eax, %ebx
jne 0x7826
cmpl $0x0, -0x50(%rbp)
jne 0x7b30
cmpl $0x0, -0x2c(%rbp)
je 0x7af8
movq -0x78(%rbp), %rax
incl 0x10(%rax)
movq (%r12), %rsi
movl 0x10(%rsi), %eax
leal -0x1(%rax), %ecx
movl %ecx, 0x10(%rsi)
cmpl $0x1, %eax
jg 0x7abd
movq %r12, %rdi
callq 0x73bf
movq -0x78(%rbp), %rax
movq %rax, (%r12)
jmp 0x7b28
leaq -0x140(%rbp), %r14
pushq $0x64
popq %rcx
movl %eax, %edi
movq %r14, %rdx
callq 0x81d2
leaq 0x1f01d(%rip), %rsi     # 0x26aff
movq %r12, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x68a7
pushq $0x1
popq %rax
movq %rax, -0x50(%rbp)
jmp 0x7b30
movslq -0x6c(%rbp), %rsi
movq %r12, %rdi
callq 0x8212
movq %rax, %r14
incl 0x10(%rax)
movq (%r12), %rsi
movl 0x10(%rsi), %eax
leal -0x1(%rax), %ecx
movl %ecx, 0x10(%rsi)
cmpl $0x1, %eax
jg 0x7b24
movq %r12, %rdi
callq 0x73bf
movq %r14, (%r12)
movq $0x0, -0x50(%rbp)
movq %r13, %rdi
xorl %esi, %esi
callq *0x2b74d(%rip)          # 0x33288
movq -0x50(%rbp), %r13
jmp 0x7681