// File: /workspace/github_c_makefile_star2_O0/haxlang[P]hax/haxHistory.c
// Function: DoRevs
static void
DoRevs(
    Interp *iPtr		/* Interpreter whose history is to
				 * be modified. */)
{
    Hax_Memoryp *memoryp = iPtr->memoryp;
    HistoryRev *revPtr;
    HistoryEvent *eventPtr;
    char *newCommand, *p;
    unsigned int size;
    int bytesSeen, count;

    if (iPtr->revPtr == NULL) {
	return;
    }

    /*
     * The revision is done in two passes.  The first pass computes the
     * amount of space needed for the revised event, and the second pass
     * pieces together the new event and frees up the revisions.
     */

    eventPtr = &iPtr->events[iPtr->curEvent];
    size = strlen(eventPtr->command) + 1;
    for (revPtr = iPtr->revPtr; revPtr != NULL; revPtr = revPtr->nextPtr) {
	size -= revPtr->lastIndex + 1 - revPtr->firstIndex;
	size += revPtr->newSize;
    }

    newCommand = (char *) ckalloc(memoryp, size);
    p = newCommand;
    bytesSeen = 0;
    for (revPtr = iPtr->revPtr; revPtr != NULL; ) {
	HistoryRev *nextPtr = revPtr->nextPtr;

	count = revPtr->firstIndex - bytesSeen;
	if (count > 0) {
	    strncpy(p, eventPtr->command + bytesSeen, count);
	    p += count;
	}
	strncpy(p, revPtr->newBytes, revPtr->newSize);
	p += revPtr->newSize;
	bytesSeen = revPtr->lastIndex+1;
	ckfree(memoryp, revPtr->newBytes);
	ckfree(memoryp, (char *) revPtr);
	revPtr = nextPtr;
    }
    if (&p[strlen(&eventPtr->command[bytesSeen]) + 1] >
	    &newCommand[size]) {
	printf("Assertion failed!\n");
    }
    strcpy(p, eventPtr->command + bytesSeen);

    /*
     * Replace the command in the event.
     */

    ckfree(memoryp, eventPtr->command);
    eventPtr->command = newCommand;
    eventPtr->bytesAvl = size;
    iPtr->revPtr = NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq 0x280(%rax), %rax
movq %rax, -0x10(%rbp)
movq -0x8(%rbp), %rax
cmpq $0x0, 0xf0(%rax)
jne 0x1428e
jmp 0x144b7
movq -0x8(%rbp), %rax
movq 0xe0(%rax), %rax
movq -0x8(%rbp), %rcx
movslq 0xe8(%rcx), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rdi
callq 0x41b0
addq $0x1, %rax
movl %eax, -0x34(%rbp)
movq -0x8(%rbp), %rax
movq 0xf0(%rax), %rax
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x1430b
movq -0x18(%rbp), %rax
movl 0x4(%rax), %ecx
addl $0x1, %ecx
movq -0x18(%rbp), %rax
subl (%rax), %ecx
movl -0x34(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x34(%rbp)
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
addl -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x18(%rbp)
jmp 0x142d1
movq -0x10(%rbp), %rdi
movl -0x34(%rbp), %eax
movl %eax, %esi
leaq 0xaabd(%rip), %rdx      # 0x1edd8
movl $0x302, %ecx            # imm = 0x302
callq 0x44c0
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
movl $0x0, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq 0xf0(%rax), %rax
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x1441a
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rax
movl (%rax), %eax
subl -0x38(%rbp), %eax
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
jle 0x1439c
movq -0x30(%rbp), %rdi
movq -0x20(%rbp), %rax
movq (%rax), %rsi
movslq -0x38(%rbp), %rax
addq %rax, %rsi
movslq -0x3c(%rbp), %rdx
callq 0x4080
movl -0x3c(%rbp), %ecx
movq -0x30(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x18(%rbp), %rax
movslq 0x8(%rax), %rdx
callq 0x4080
movq -0x18(%rbp), %rax
movl 0x8(%rax), %ecx
movq -0x30(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rax
movl 0x4(%rax), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rsi
leaq 0xa9ee(%rip), %rdx      # 0x1edd8
movl $0x310, %ecx            # imm = 0x310
callq 0x4260
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
leaq 0xa9d5(%rip), %rdx      # 0x1edd8
movl $0x311, %ecx            # imm = 0x311
callq 0x4260
movq -0x48(%rbp), %rax
movq %rax, -0x18(%rbp)
jmp 0x14347
movq -0x30(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rdi
movslq -0x38(%rbp), %rax
addq %rax, %rdi
callq 0x41b0
movq %rax, %rcx
movq -0x50(%rbp), %rax
addq $0x1, %rcx
addq %rcx, %rax
movq -0x28(%rbp), %rcx
movl -0x34(%rbp), %edx
addq %rdx, %rcx
cmpq %rcx, %rax
jbe 0x14460
leaq 0xaafa(%rip), %rdi      # 0x1ef53
movb $0x0, %al
callq 0x4240
movq -0x30(%rbp), %rdi
movq -0x20(%rbp), %rax
movq (%rax), %rsi
movslq -0x38(%rbp), %rax
addq %rax, %rsi
callq 0x40d0
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rax
movq (%rax), %rsi
leaq 0xa94f(%rip), %rdx      # 0x1edd8
movl $0x31e, %ecx            # imm = 0x31E
callq 0x4260
movq -0x28(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movl -0x34(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x8(%rbp), %rax
movq $0x0, 0xf0(%rax)
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)