// File: /workspace/github_c_makefile_star2_O3/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 0x4650
movsbq (%r14), %rcx
cmpq $0x2d, %rcx
je 0xe889
movq (%rax), %rax
movzwl (%rax,%rcx,2), %eax
andl $0x800, %eax            # imm = 0x800
jne 0xe889
movq %r14, %rdi
callq 0x41d0
movl 0xe8(%rbx), %ebp
movslq %eax, %r12
movl %ebp, %eax
leal -0x1(%rax), %ebp
testl %eax, %eax
jg 0xe83d
addl 0xd8(%rbx), %ebp
cmpl 0xe8(%rbx), %ebp
je 0xe8cc
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 0xe913
movq %r13, %rdi
movq %r14, %rsi
callq 0x4470
testl %eax, %eax
je 0xe82e
jmp 0xe913
leaq 0x4(%rsp), %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x41c0
testl %eax, %eax
je 0xe8a2
xorl %r15d, %r15d
jmp 0xe913
movl 0x4(%rsp), %eax
movl 0xec(%rbx), %edx
testl %eax, %eax
jns 0xe8b6
addl %edx, %eax
movl %eax, 0x4(%rsp)
movl %eax, %ecx
subl %edx, %ecx
jle 0xe8dc
leaq 0x7454(%rip), %rsi      # 0x15d17
leaq 0x7455(%rip), %rcx      # 0x15d1f
jmp 0xe900
leaq 0x747b(%rip), %rsi      # 0x15d4e
leaq 0x59d5(%rip), %rcx      # 0x142af
jmp 0xe900
movl 0xd8(%rbx), %esi
subl %esi, %edx
cmpl %edx, %eax
setg %dl
testl %eax, %eax
setg %al
testb %dl, %al
jne 0xe925
leaq 0x741e(%rip), %rsi      # 0x15d17
leaq 0x7435(%rip), %rcx      # 0x15d35
xorl %r15d, %r15d
movq %rbx, %rdi
movq %r14, %rdx
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x4510
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 0xe913