// File: /workspace/github_c_makefile_star2_O1/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, %rbx
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, 0x10(%rsp)
movq 0x280(%rdi), %r13
movq %rdx, %rdi
callq 0x41d0
movq %rax, %rbp
movq %rbx, 0x28(%rsp)
movq %rbx, %rdi
callq 0x41d0
movq %rax, 0x8(%rsp)
movq %r14, %rdi
movq %r15, %rsi
callq 0x4610
testq %rax, %rax
je 0xf1b5
movslq %ebp, %r12
xorl %ebx, %ebx
addq %r12, %rax
incl %ebx
movq %rax, %rdi
movq %r15, %rsi
callq 0x4610
testq %rax, %rax
jne 0xf19e
jmp 0xf1b7
xorl %ebx, %ebx
testl %ebx, %ebx
je 0xf26d
movq %r14, %rdi
callq 0x41d0
movq 0x8(%rsp), %r12
movl %r12d, %ecx
subl %ebp, %ecx
imull %ecx, %ebx
leal (%rbx,%rax), %esi
incl %esi
leaq 0x7cb8(%rip), %rdx      # 0x16e98
movq %r13, 0x20(%rsp)
movq %r13, %rdi
movl $0x3b3, %ecx            # imm = 0x3B3
callq 0x44c0
movq %rax, %rbx
movq %r14, %rdi
movq %r15, %rsi
callq 0x4610
testq %rax, %rax
movq %rbx, 0x18(%rsp)
je 0xf294
movq %rax, %r13
movslq %r12d, %rax
movq %rax, 0x8(%rsp)
movslq %ebp, %rax
movq %rax, 0x30(%rsp)
movq 0x28(%rsp), %r12
movq %r13, %rbp
subq %r14, %rbp
movq %rbx, %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x40a0
addq %rbx, %rbp
movq %rbp, %rdi
movq %r12, %rsi
callq 0x40f0
addq 0x8(%rsp), %rbp
movq %r13, %r14
addq 0x30(%rsp), %r14
movq %r14, %rdi
movq %r15, %rsi
callq 0x4610
movq %rax, %r13
movq %rbp, %rbx
testq %rax, %rax
jne 0xf226
jmp 0xf297
leaq 0x603b(%rip), %rsi      # 0x152af
leaq 0x7de2(%rip), %rcx      # 0x1705d
movq 0x10(%rsp), %rdi
movq %r15, %rdx
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x4500
movl $0x1, %eax
jmp 0xf2e6
movq %rbx, %rbp
movq %rbp, %rdi
movq %r14, %rsi
callq 0x40f0
movq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq 0x18(%rsp), %r14
movq %r14, %rsi
callq 0xf098
movq %rbx, %rdi
xorl %esi, %esi
movq %r14, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x45b0
movl %eax, %ebx
leaq 0x7bc6(%rip), %rdx      # 0x16e98
movq 0x20(%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