// File: /workspace/github_c_makefile_star2_O2/haxlang[P]hax/haxHistory.c
// Function: GetEvent
static HistoryEvent *
GetEvent(
    Interp *iPtr,		/* Interpreter in which to look. */
    char *string		/* Description of event. */)
{
    int eventNum, index;
    HistoryEvent *eventPtr;
    int length;

    /*
     * First check for a numeric specification of an event.
     */

    if (isdigit(*string) || (*string == '-')) {
	if (Hax_GetInt((Hax_Interp *) iPtr, string, &eventNum) != HAX_OK) {
	    return NULL;
	}
	if (eventNum < 0) {
	    eventNum += iPtr->curEventNum;
        }
	if (eventNum > iPtr->curEventNum) {
	    Hax_AppendResult((Hax_Interp *) iPtr, "event \"", string,
		    "\" hasn't occurred yet", (char *) NULL);
	    return NULL;
	}
	if ((eventNum <= iPtr->curEventNum-iPtr->numEvents)
		|| (eventNum <= 0)) {
	    Hax_AppendResult((Hax_Interp *) iPtr, "event \"", string,
		    "\" is too far in the past", (char *) NULL);
	    return NULL;
	}
	index = iPtr->curEvent + (eventNum - iPtr->curEventNum);
	if (index < 0) {
	    index += iPtr->numEvents;
	}
	return &iPtr->events[index];
    }

    /*
     * Next, check for an event that contains the string as a prefix or
     * that matches the string in the sense of Hax_StringMatch.
     */

    length = strlen(string);
    for (index = iPtr->curEvent - 1; ; index--) {
	if (index < 0) {
	    index += iPtr->numEvents;
	}
	if (index == iPtr->curEvent) {
	    break;
	}
	eventPtr = &iPtr->events[index];
	if ((strncmp(eventPtr->command, string, length) == 0)
		|| Hax_StringMatch(eventPtr->command, string)) {
	    return eventPtr;
	}
    }

    Hax_AppendResult((Hax_Interp *) iPtr, "no event matches \"", string,
	    "\"", (char *) NULL);
    return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %rbx
callq 0x4660
movsbq (%r14), %rcx
cmpq $0x2d, %rcx
je 0xe07b
movq (%rax), %rax
movzwl (%rax,%rcx,2), %eax
andl $0x800, %eax            # imm = 0x800
jne 0xe07b
movq %r14, %rdi
callq 0x41d0
movl 0xe8(%rbx), %ebp
movslq %eax, %r12
movl %ebp, %eax
leal -0x1(%rax), %ebp
testl %eax, %eax
jg 0xe02f
addl 0xd8(%rbx), %ebp
cmpl 0xe8(%rbx), %ebp
je 0xe0be
movq 0xe0(%rbx), %rax
movslq %ebp, %rcx
shlq $0x4, %rcx
leaq (%rax,%rcx), %r15
movq (%rax,%rcx), %r13
movq %r13, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x40c0
testl %eax, %eax
je 0xe105
movq %r13, %rdi
movq %r14, %rsi
callq 0x4480
testl %eax, %eax
je 0xe020
jmp 0xe105
leaq 0x4(%rsp), %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x41c0
testl %eax, %eax
je 0xe094
xorl %r15d, %r15d
jmp 0xe105
movl 0x4(%rsp), %eax
movl 0xec(%rbx), %edx
testl %eax, %eax
jns 0xe0a8
addl %edx, %eax
movl %eax, 0x4(%rsp)
movl %eax, %ecx
subl %edx, %ecx
jle 0xe0ce
leaq 0x6c32(%rip), %rsi      # 0x14ce7
leaq 0x6c33(%rip), %rcx      # 0x14cef
jmp 0xe0f2
leaq 0x6c59(%rip), %rsi      # 0x14d1e
leaq 0x51e3(%rip), %rcx      # 0x132af
jmp 0xe0f2
movl 0xd8(%rbx), %esi
subl %esi, %edx
cmpl %edx, %eax
setg %dl
testl %eax, %eax
setg %al
testb %dl, %al
jne 0xe117
leaq 0x6bfc(%rip), %rsi      # 0x14ce7
leaq 0x6c13(%rip), %rcx      # 0x14d05
xorl %r15d, %r15d
movq %rbx, %rdi
movq %r14, %rdx
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x4520
movq %r15, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
addl 0xe8(%rbx), %ecx
movl %ecx, %eax
sarl $0x1f, %eax
andl %esi, %eax
addl %ecx, %eax
movslq %eax, %r15
shlq $0x4, %r15
addq 0xe0(%rbx), %r15
jmp 0xe105