// File: /workspace/github_c_makefile_star2_O0/haxlang[P]hax/haxCmdMZ.c
// Function: Hax_RegsubCmd
int
Hax_RegsubCmd(
    ClientData dummy,			/* Not used. */
    Hax_Interp *interp,			/* Current interpreter. */
    int argc,				/* Number of arguments. */
    char **argv				/* Argument strings. */)
{
    Interp *iPtr = (Interp *) interp;
    Hax_Memoryp *memoryp = iPtr->memoryp;
    int noCase = 0, all = 0;
    regexp *regexpPtr;
    char *string, *p, *firstChar, *newValue, **argPtr;
    int match, result, flags;
    char *src, c;

    if (argc < 5) {
	wrongNumArgs:
	Hax_AppendResult(interp, "wrong # args: should be \"", argv[0],
		" ?-nocase? ?-all? exp string subSpec varName\"", (char *) NULL);
	return HAX_ERROR;
    }
    argPtr = argv+1;
    argc--;
    while (argPtr[0][0] == '-') {
	if (strcmp(argPtr[0], "-nocase") == 0) {
	    argPtr++;
	    argc--;
	    noCase = 1;
	} else if (strcmp(argPtr[0], "-all") == 0) {
	    argPtr++;
	    argc--;
	    all = 1;
	} else {
	    break;
	}
    }
    if (argc != 4) {
	goto wrongNumArgs;
    }
    regexpPtr = HaxCompileRegexp(interp, argPtr[0]);
    if (regexpPtr == NULL) {
	return HAX_ERROR;
    }

    /*
     * Convert the string to lower case, if desired.
     */

    if (noCase) {
	char *dst;

	string = (char *) ckalloc(memoryp, (unsigned) (strlen(argPtr[1]) + 1));
	for (src = argPtr[1], dst = string; *src != 0; src++, dst++) {
	    if (isupper(*src)) {
		*dst = tolower(*src);
	    } else {
		*dst = *src;
	    }
	}
	*dst = 0;
    } else {
	string = argPtr[1];
    }

    /*
     * The following loop is to handle multiple matches within the
     * same source string;  each iteration handles one match and its
     * corresponding substitution.  If "-all" hasn't been specified
     * then the loop body only gets executed once.
     */

    flags = 0;
    for (p = string; *p != 0; ) {
	iPtr->haxRegexpError = NULL;
	match = RegExec(interp, regexpPtr, p);
	if (iPtr->haxRegexpError != NULL) {
	    Hax_AppendResult(interp, "error while matching pattern: ",
		    iPtr->haxRegexpError, (char *) NULL);
	    result = HAX_ERROR;
	    goto done;
	}
	if (!match) {
	    break;
	}

	/*
	 * Copy the portion of the source string before the match to the
	 * result variable.
	 */

	src = argPtr[1] + (regexpPtr->startp[0] - string);
	c = *src;
	*src = 0;
	newValue = Hax_SetVar(interp, argPtr[3], argPtr[1] + (p - string),
		flags);
	*src = c;
	flags = HAX_APPEND_VALUE;
	if (newValue == NULL) {
	    cantSet:
	    Hax_AppendResult(interp, "couldn't set variable \"",
		    argPtr[3], "\"", (char *) NULL);
	    result = HAX_ERROR;
	    goto done;
	}

	/*
	 * Append the subSpec argument to the variable, making appropriate
	 * substitutions.  This code is a bit hairy because of the backslash
	 * conventions and because the code saves up ranges of characters in
	 * subSpec to reduce the number of calls to Hax_SetVar.
	 */

	for (src = firstChar = argPtr[2], c = *src; c != 0; src++, c = *src) {
	    int index;

	    if (c == '&') {
		index = 0;
	    } else if (c == '\\') {
		c = src[1];
		if ((c >= '0') && (c <= '9')) {
		    index = c - '0';
		} else if ((c == '\\') || (c == '&')) {
		    *src = c;
		    src[1] = 0;
		    newValue = Hax_SetVar(interp, argPtr[3], firstChar,
			    HAX_APPEND_VALUE);
		    *src = '\\';
		    src[1] = c;
		    if (newValue == NULL) {
			goto cantSet;
		    }
		    firstChar = src+2;
		    src++;
		    continue;
		} else {
		    continue;
		}
	    } else {
		continue;
	    }
	    if (firstChar != src) {
		c = *src;
		*src = 0;
		newValue = Hax_SetVar(interp, argPtr[3], firstChar,
			HAX_APPEND_VALUE);
		*src = c;
		if (newValue == NULL) {
		    goto cantSet;
		}
	    }
	    if ((index < NSUBEXP) && (regexpPtr->startp[index] != NULL)
		    && (regexpPtr->endp[index] != NULL)) {
		char *first, *last, saved;

		first = argPtr[1] + (regexpPtr->startp[index] - string);
		last = argPtr[1] + (regexpPtr->endp[index] - string);
		saved = *last;
		*last = 0;
		newValue = Hax_SetVar(interp, argPtr[3], first,
			HAX_APPEND_VALUE);
		*last = saved;
		if (newValue == NULL) {
		    goto cantSet;
		}
	    }
	    if (*src == '\\') {
		src++;
	    }
	    firstChar = src+1;
	}
	if (firstChar != src) {
	    if (Hax_SetVar(interp, argPtr[3], firstChar,
		    HAX_APPEND_VALUE) == NULL) {
		goto cantSet;
	    }
	}
	p = regexpPtr->endp[0];
	if (!all) {
	    break;
	}
    }

    /*
     * If there were no matches at all, then return a "0" result.
     */

    if (p == string) {
	interp->result = (char *) "0";
	result = HAX_OK;
	goto done;
    }

    /*
     * Copy the portion of the source string after the last match to the
     * result variable.
     */

    if (*p != 0) {
	if (Hax_SetVar(interp, argPtr[3], p, HAX_APPEND_VALUE) == NULL) {
	    goto cantSet;
	}
    }
    interp->result = (char *) "1";
    result = HAX_OK;

    done:
    if (string != argPtr[1]) {
	ckfree(memoryp, string);
    }
    return result;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq 0x280(%rax), %rax
movq %rax, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
cmpl $0x5, -0x1c(%rbp)
jge 0xcf08
jmp 0xced7
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rax
movq (%rax), %rdx
leaq 0x10a8b(%rip), %rsi     # 0x1d974
leaq 0x113ff(%rip), %rcx     # 0x1e2ef
xorl %eax, %eax
movl %eax, %r8d
movb $0x0, %al
callq 0x4500
movl $0x1, -0x4(%rbp)
jmp 0xd5da
movq -0x28(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x70(%rbp)
movl -0x1c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x1c(%rbp)
movq -0x70(%rbp), %rax
movq (%rax), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
jne 0xcfa1
movq -0x70(%rbp), %rax
movq (%rax), %rdi
leaq 0x11340(%rip), %rsi     # 0x1e27a
callq 0x4300
cmpl $0x0, %eax
jne 0xcf62
movq -0x70(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x70(%rbp)
movl -0x1c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x1c(%rbp)
movl $0x1, -0x3c(%rbp)
jmp 0xcf9c
movq -0x70(%rbp), %rax
movq (%rax), %rdi
leaq 0x113ad(%rip), %rsi     # 0x1e31d
callq 0x4300
cmpl $0x0, %eax
jne 0xcf98
movq -0x70(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x70(%rbp)
movl -0x1c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x1c(%rbp)
movl $0x1, -0x40(%rbp)
jmp 0xcf9a
jmp 0xcfa1
jmp 0xcf9c
jmp 0xcf1d
cmpl $0x4, -0x1c(%rbp)
je 0xcfac
jmp 0xced7
movq -0x18(%rbp), %rdi
movq -0x70(%rbp), %rax
movq (%rax), %rsi
callq 0x4090
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0xcfd3
movl $0x1, -0x4(%rbp)
jmp 0xd5da
cmpl $0x0, -0x3c(%rbp)
je 0xd0ca
movq -0x38(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0x70(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x41b0
movq -0xc0(%rbp), %rdi
addq $0x1, %rax
movl %eax, %eax
movl %eax, %esi
leaq 0x11277(%rip), %rdx     # 0x1e282
movl $0x104, %ecx            # imm = 0x104
callq 0x44c0
movq %rax, -0x50(%rbp)
movq -0x70(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x88(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x88(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0xd0be
callq 0x4630
movq (%rax), %rax
movq -0x88(%rbp), %rcx
movsbl (%rcx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x100, %eax            # imm = 0x100
cmpl $0x0, %eax
je 0xd081
movq -0x88(%rbp), %rax
movsbl (%rax), %edi
callq 0x4400
movb %al, %cl
movq -0x98(%rbp), %rax
movb %cl, (%rax)
jmp 0xd093
movq -0x88(%rbp), %rax
movb (%rax), %cl
movq -0x98(%rbp), %rax
movb %cl, (%rax)
jmp 0xd095
movq -0x88(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x88(%rbp)
movq -0x98(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x98(%rbp)
jmp 0xd033
movq -0x98(%rbp), %rax
movb $0x0, (%rax)
jmp 0xd0d6
movq -0x70(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x50(%rbp)
movl $0x0, -0x7c(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0xd544
movq -0x30(%rbp), %rax
movq $0x0, 0x290(%rax)
movq -0x18(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0x58(%rbp), %rdx
callq 0x4570
movl %eax, -0x74(%rbp)
movq -0x30(%rbp), %rax
cmpq $0x0, 0x290(%rax)
je 0xd153
movq -0x18(%rbp), %rdi
movq -0x30(%rbp), %rax
movq 0x290(%rax), %rdx
leaq 0x11151(%rip), %rsi     # 0x1e28d
xorl %eax, %eax
movl %eax, %ecx
movb $0x0, %al
callq 0x4500
movl $0x1, -0x78(%rbp)
jmp 0xd5ad
cmpl $0x0, -0x74(%rbp)
jne 0xd15e
jmp 0xd544
movq -0x70(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x48(%rbp), %rcx
movq (%rcx), %rcx
movq -0x50(%rbp), %rdx
subq %rdx, %rcx
addq %rcx, %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rax
movb (%rax), %al
movb %al, -0x89(%rbp)
movq -0x88(%rbp), %rax
movb $0x0, (%rax)
movq -0x18(%rbp), %rdi
movq -0x70(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x70(%rbp), %rax
movq 0x8(%rax), %rdx
movq -0x58(%rbp), %rax
movq -0x50(%rbp), %rcx
subq %rcx, %rax
addq %rax, %rdx
movl -0x7c(%rbp), %ecx
callq 0x4450
movq %rax, -0x68(%rbp)
movb -0x89(%rbp), %cl
movq -0x88(%rbp), %rax
movb %cl, (%rax)
movl $0x2, -0x7c(%rbp)
cmpq $0x0, -0x68(%rbp)
jne 0xd216
jmp 0xd1e4
movq -0x18(%rbp), %rdi
movq -0x70(%rbp), %rax
movq 0x18(%rax), %rdx
leaq 0x110e0(%rip), %rsi     # 0x1e2d7
leaq 0x10072(%rip), %rcx     # 0x1d270
xorl %eax, %eax
movl %eax, %r8d
movb $0x0, %al
callq 0x4500
movl $0x1, -0x78(%rbp)
jmp 0xd5ad
movq -0x70(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x60(%rbp)
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rax
movb (%rax), %al
movb %al, -0x89(%rbp)
movsbl -0x89(%rbp), %eax
cmpl $0x0, %eax
je 0xd4f7
movsbl -0x89(%rbp), %eax
cmpl $0x26, %eax
jne 0xd263
movl $0x0, -0x9c(%rbp)
jmp 0xd35e
movsbl -0x89(%rbp), %eax
cmpl $0x5c, %eax
jne 0xd357
movq -0x88(%rbp), %rax
movb 0x1(%rax), %al
movb %al, -0x89(%rbp)
movsbl -0x89(%rbp), %eax
cmpl $0x30, %eax
jl 0xd2b0
movsbl -0x89(%rbp), %eax
cmpl $0x39, %eax
jg 0xd2b0
movsbl -0x89(%rbp), %eax
subl $0x30, %eax
movl %eax, -0x9c(%rbp)
jmp 0xd355
movsbl -0x89(%rbp), %eax
cmpl $0x5c, %eax
je 0xd2cc
movsbl -0x89(%rbp), %eax
cmpl $0x26, %eax
jne 0xd350
movb -0x89(%rbp), %cl
movq -0x88(%rbp), %rax
movb %cl, (%rax)
movq -0x88(%rbp), %rax
movb $0x0, 0x1(%rax)
movq -0x18(%rbp), %rdi
movq -0x70(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x60(%rbp), %rdx
movl $0x2, %ecx
callq 0x4450
movq %rax, -0x68(%rbp)
movq -0x88(%rbp), %rax
movb $0x5c, (%rax)
movb -0x89(%rbp), %cl
movq -0x88(%rbp), %rax
movb %cl, 0x1(%rax)
cmpq $0x0, -0x68(%rbp)
jne 0xd32a
jmp 0xd1e4
movq -0x88(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x60(%rbp)
movq -0x88(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x88(%rbp)
jmp 0xd4d1
jmp 0xd4d1
jmp 0xd35c
jmp 0xd4d1
jmp 0xd35e
movq -0x60(%rbp), %rax
cmpq -0x88(%rbp), %rax
je 0xd3bf
movq -0x88(%rbp), %rax
movb (%rax), %al
movb %al, -0x89(%rbp)
movq -0x88(%rbp), %rax
movb $0x0, (%rax)
movq -0x18(%rbp), %rdi
movq -0x70(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x60(%rbp), %rdx
movl $0x2, %ecx
callq 0x4450
movq %rax, -0x68(%rbp)
movb -0x89(%rbp), %cl
movq -0x88(%rbp), %rax
movb %cl, (%rax)
cmpq $0x0, -0x68(%rbp)
jne 0xd3bd
jmp 0xd1e4
jmp 0xd3bf
cmpl $0xa, -0x9c(%rbp)
jge 0xd4a1
movq -0x48(%rbp), %rax
movslq -0x9c(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
je 0xd4a1
movq -0x48(%rbp), %rax
movslq -0x9c(%rbp), %rcx
cmpq $0x0, 0x50(%rax,%rcx,8)
je 0xd4a1
movq -0x70(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x48(%rbp), %rcx
movslq -0x9c(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movq -0x50(%rbp), %rdx
subq %rdx, %rcx
addq %rcx, %rax
movq %rax, -0xa8(%rbp)
movq -0x70(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x48(%rbp), %rcx
movslq -0x9c(%rbp), %rdx
movq 0x50(%rcx,%rdx,8), %rcx
movq -0x50(%rbp), %rdx
subq %rdx, %rcx
addq %rcx, %rax
movq %rax, -0xb0(%rbp)
movq -0xb0(%rbp), %rax
movb (%rax), %al
movb %al, -0xb1(%rbp)
movq -0xb0(%rbp), %rax
movb $0x0, (%rax)
movq -0x18(%rbp), %rdi
movq -0x70(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0xa8(%rbp), %rdx
movl $0x2, %ecx
callq 0x4450
movq %rax, -0x68(%rbp)
movb -0xb1(%rbp), %cl
movq -0xb0(%rbp), %rax
movb %cl, (%rax)
cmpq $0x0, -0x68(%rbp)
jne 0xd49f
jmp 0xd1e4
jmp 0xd4a1
movq -0x88(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x5c, %eax
jne 0xd4c2
movq -0x88(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
movq -0x88(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rax
movb (%rax), %al
movb %al, -0x89(%rbp)
jmp 0xd238
movq -0x60(%rbp), %rax
cmpq -0x88(%rbp), %rax
je 0xd52b
movq -0x18(%rbp), %rdi
movq -0x70(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x60(%rbp), %rdx
movl $0x2, %ecx
callq 0x4450
cmpq $0x0, %rax
jne 0xd529
jmp 0xd1e4
jmp 0xd52b
movq -0x48(%rbp), %rax
movq 0x50(%rax), %rax
movq %rax, -0x58(%rbp)
cmpl $0x0, -0x40(%rbp)
jne 0xd53f
jmp 0xd544
jmp 0xd0e5
movq -0x58(%rbp), %rax
cmpq -0x50(%rbp), %rax
jne 0xd565
movq -0x18(%rbp), %rax
leaq 0x1094a(%rip), %rcx     # 0x1dea3
movq %rcx, (%rax)
movl $0x0, -0x78(%rbp)
jmp 0xd5ad
movq -0x58(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0xd598
movq -0x18(%rbp), %rdi
movq -0x70(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x58(%rbp), %rdx
movl $0x2, %ecx
callq 0x4450
cmpq $0x0, %rax
jne 0xd596
jmp 0xd1e4
jmp 0xd598
movq -0x18(%rbp), %rax
leaq 0x10d2a(%rip), %rcx     # 0x1e2cd
movq %rcx, (%rax)
movl $0x0, -0x78(%rbp)
movq -0x50(%rbp), %rax
movq -0x70(%rbp), %rcx
cmpq 0x8(%rcx), %rax
je 0xd5d4
movq -0x38(%rbp), %rdi
movq -0x50(%rbp), %rsi
leaq 0x10cb8(%rip), %rdx     # 0x1e282
movl $0x1a0, %ecx            # imm = 0x1A0
callq 0x4260
movl -0x78(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xc0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)