// File: /workspace/github_c_makefile_star2_O3/haxlang[P]hax/haxHistory.c
// Function: SubsAndEval
static int
SubsAndEval(
    Interp *iPtr,		/* Interpreter in which to execute
				 * new command. */
    char *cmd,			/* Command in which to substitute. */
    char *oldStr,		/* String to search for in command. */
    char *newStr		/* Replacement string for "old". */)
{
    Hax_Memoryp *memoryp = iPtr->memoryp;
    char *src, *dst, *newCmd;
    int count, oldLength, newLength, length, result;

    /*
     * Figure out how much space it will take to hold the
     * substituted command (and complain if the old string
     * doesn't appear in the original command).
     */

    oldLength = strlen(oldStr);
    newLength = strlen(newStr);
    src = cmd;
    count = 0;
    while (1) {
	src = strstr(src, oldStr);
	if (src == NULL) {
	    break;
	}
	src += oldLength;
	count++;
    }
    if (count == 0) {
	Hax_AppendResult((Hax_Interp *) iPtr, "\"", oldStr,
		"\" doesn't appear in event", (char *) NULL);
	return HAX_ERROR;
    }
    length = strlen(cmd) + count*(newLength - oldLength);

    /*
     * Generate a substituted command.
     */

    newCmd = (char *) ckalloc(memoryp, (unsigned) (length + 1));
    dst = newCmd;
    while (1) {
	src = strstr(cmd, oldStr);
	if (src == NULL) {
	    strcpy(dst, cmd);
	    break;
	}
	strncpy(dst, cmd, src-cmd);
	dst += src-cmd;
	strcpy(dst, newStr);
	dst += newLength;
	cmd = src + oldLength;
    }

    RevCommand(iPtr, newCmd);
    result = Hax_Eval((Hax_Interp *) iPtr, NULL, newCmd, 0, (char **) NULL);
    ckfree(memoryp, newCmd);
    return result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rcx, %r13
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, %r12
movq 0x280(%rdi), %rax
movq %rax, 0x10(%rsp)
movq %rdx, %rdi
callq 0x41d0
movq %rax, %rbx
movq %r13, %rdi
callq 0x41d0
movq %rax, %rbp
movq %r14, %rdi
movq %r15, %rsi
callq 0x4620
testq %rax, %rax
je 0xec0d
movq %r13, 0x18(%rsp)
movq %r12, 0x28(%rsp)
movslq %ebx, %r12
movq %rbp, 0x8(%rsp)
subl %ebx, %ebp
movl $0x1, %r13d
addl %ebp, %r13d
addq %r12, %rax
movq %rax, %rdi
movq %r15, %rsi
callq 0x4620
testq %rax, %rax
jne 0xeb56
movq %r14, %rdi
callq 0x41d0
addl %eax, %r13d
leaq 0x701e(%rip), %rdx      # 0x15b9c
movq 0x10(%rsp), %rdi
movq %r13, %rsi
movl $0x3b3, %ecx            # imm = 0x3B3
callq 0x44d0
movq %rax, %rbp
movq %r14, %rdi
movq %r15, %rsi
callq 0x4620
testq %rax, %rax
movq %rbp, 0x20(%rsp)
je 0xec32
movq %rax, %r13
movslq 0x8(%rsp), %rax
movq %rax, 0x8(%rsp)
movslq %ebx, %rax
movq %rax, 0x30(%rsp)
movq 0x18(%rsp), %r12
movq %r13, %rbx
subq %r14, %rbx
movq %rbp, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x40a0
addq %rbp, %rbx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x40f0
addq 0x8(%rsp), %rbx
movq %r13, %r14
addq 0x30(%rsp), %r14
movq %r14, %rdi
movq %r15, %rsi
callq 0x4620
movq %rax, %r13
movq %rbx, %rbp
testq %rax, %rax
jne 0xebc6
jmp 0xec35
leaq 0x569b(%rip), %rsi      # 0x142af
leaq 0x7146(%rip), %rcx      # 0x15d61
movq %r12, %rdi
movq %r15, %rdx
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x4510
movl $0x1, %eax
jmp 0xec84
movq %rbp, %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x40f0
movq 0x28(%rsp), %rbx
movq %rbx, %rdi
movq 0x20(%rsp), %r14
movq %r14, %rsi
callq 0xea3b
movq %rbx, %rdi
xorl %esi, %esi
movq %r14, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x45c0
movl %eax, %ebx
leaq 0x6f2c(%rip), %rdx      # 0x15b9c
movq 0x10(%rsp), %rdi
movq %r14, %rsi
movl $0x3c4, %ecx            # imm = 0x3C4
callq 0x4280
movl %ebx, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq