// File: /workspace/github_c_makefile_star2_O3/haxlang[P]hax/haxHistory.c
// Function: GetWords
static char *
GetWords(
    Interp *iPtr,		/* Hax interpreter in which to place
				 * an error message if needed. */
    char *command,		/* Command string. */
    char *words			/* Description of which words to extract
				 * from the command.  Either num[-num] or
				 * a pattern. */)
{
    Hax_Memoryp *memoryp = iPtr->memoryp;
    char *result;
    char *start, *end, *dst;
    char *next;
    int first;			/* First word desired. -1 means last word
				 * only. */
    int last;			/* Last word desired.  -1 means use everything
				 * up to the end. */
    int index;			/* Index of current word. */
    char *pattern;

    /*
     * Figure out whether we're looking for a numerical range or for
     * a pattern.
     */

    pattern = NULL;
    first = 0;
    last = -1;
    if (*words == '$') {
	if (words[1] != '\0') {
	    goto error;
	}
	first = -1;
    } else if (isdigit(*words)) {
	first = Strtoul(NULL, words, &start, 0);
	if (*start == 0) {
	    last = first;
	} else if (*start == '-') {
	    start++;
	    if (*start == '$') {
		start++;
	    } else if (isdigit(*start)) {
		last = Strtoul(NULL, start, &start, 0);
	    } else {
		goto error;
	    }
	    if (*start != 0) {
		goto error;
	    }
	}
	if ((first > last) && (last != -1)) {
	    goto error;
	}
    } else {
	pattern = words;
    }

    /*
     * Scan through the words one at a time, copying those that are
     * relevant into the result string.  Allocate a result area large
     * enough to hold all the words if necessary.
     */

    result = (char *) ckalloc(memoryp, (unsigned) (strlen(command) + 1));
    dst = result;
    for (next = command; isspace(*next); next++) {
	/* Empty loop body:  just find start of first word. */
    }
    for (index = 0; *next != 0; index++) {
	start = next;
	end = HaxWordEnd(next, 0);
	if (*end != 0) {
	    end++;
	    for (next = end; isspace(*next); next++) {
		/* Empty loop body:  just find start of next word. */
	    }
	}
	if ((first > index) || ((first == -1) && (*next != 0))) {
	    continue;
	}
	if ((last != -1) && (last < index)) {
	    continue;
	}
	if (pattern != NULL) {
	    int match;
	    char savedChar = *end;

	    *end = 0;
	    match = Hax_StringMatch(start, pattern);
	    *end = savedChar;
	    if (!match) {
		continue;
	    }
	}
	if (dst != result) {
	    *dst = ' ';
	    dst++;
	}
	strncpy(dst, start, (end-start));
	dst += end-start;
    }
    *dst = 0;

    /*
     * Check for an out-of-range argument index.
     */

    if ((last >= index) || (first >= index)) {
	ckfree(memoryp, result);
	Hax_AppendResult((Hax_Interp *) iPtr, "word selector \"", words,
		"\" specified non-existent words", (char *) NULL);
	return NULL;
    }
    return result;

    error:
    Hax_AppendResult((Hax_Interp *) iPtr, "bad word selector \"", words,
	    "\":  should be num-num or pattern", (char *) NULL);
    return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdx, %r12
movq %rsi, %rbx
movq %rdi, %rbp
movq 0x280(%rdi), %rax
movq %rax, 0x28(%rsp)
movsbq (%rdx), %r15
cmpq $0x24, %r15
jne 0xece7
cmpb $0x0, 0x1(%r12)
je 0xed5a
leaq 0x70c7(%rip), %rsi      # 0x15d9a
leaq 0x70d4(%rip), %rcx      # 0x15dae
xorl %ebx, %ebx
movq %rbp, %rdi
movq %r12, %rdx
jmp 0xef27
callq 0x4650
movq %rax, %r14
movq (%rax), %rax
xorl %r13d, %r13d
testb $0x8, 0x1(%rax,%r15,2)
jne 0xed04
movq %r12, 0x10(%rsp)
jmp 0xed69
leaq 0x8(%rsp), %r15
xorl %edi, %edi
movq %r12, %rsi
movq %r15, %rdx
xorl %ecx, %ecx
callq 0x4360
movq %rax, %r13
movq (%r15), %rdx
movzbl (%rdx), %ecx
testl %ecx, %ecx
je 0xef43
cmpl $0x2d, %ecx
jne 0xed60
leaq 0x1(%rdx), %rsi
movq %rsi, 0x8(%rsp)
movsbq 0x1(%rdx), %rcx
cmpq $0x24, %rcx
jne 0xef54
addq $0x2, %rdx
movq %rdx, 0x8(%rsp)
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
jmp 0xef79
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
movq $0x0, 0x10(%rsp)
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movq %rbx, %rdi
callq 0x41d0
leal 0x1(%rax), %esi
leaq 0x6e1b(%rip), %rdx      # 0x15b9c
movq 0x28(%rsp), %rdi
movl $0x41c, %ecx            # imm = 0x41C
callq 0x44d0
movq %rax, 0x18(%rsp)
callq 0x4650
movq %rax, %r15
movq (%rax), %rax
decq %rbx
movsbq 0x1(%rbx), %rcx
incq %rbx
testb $0x20, 0x1(%rax,%rcx,2)
jne 0xeda3
movq %rbp, 0x38(%rsp)
movq %r12, 0x40(%rsp)
xorl %ebp, %ebp
testb %cl, %cl
je 0xeec9
movq 0x18(%rsp), %rax
movq %rax, 0x20(%rsp)
movq %r15, 0x30(%rsp)
movq %rbx, 0x8(%rsp)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x41b0
movq %rax, %r12
cmpb $0x0, (%rax)
je 0xee0b
movq %r12, %rax
incq %rax
movq (%r15), %rcx
movsbq 0x1(%r12), %rdx
incq %r12
testb $0x20, 0x1(%rcx,%rdx,2)
jne 0xedf5
movq %r12, %rbx
movq %rax, %r12
cmpl %ebp, %r13d
jg 0xeebb
cmpl $-0x1, %r13d
je 0xee30
cmpl $-0x1, %r14d
setne %al
cmpl %ebp, %r14d
setl %cl
testb %cl, %al
je 0xee47
jmp 0xeebb
cmpl $-0x1, %r14d
setne %cl
movb (%rbx), %al
cmpl %ebp, %r14d
setl %dl
testb %al, %al
jne 0xeebd
andb %dl, %cl
jne 0xeebd
movq %r13, %r15
movq %r14, %r13
movq 0x10(%rsp), %rsi
testq %rsi, %rsi
je 0xee72
movb (%r12), %r14b
movb $0x0, (%r12)
movq 0x8(%rsp), %rdi
callq 0x4470
movb %r14b, (%r12)
testl %eax, %eax
je 0xeeb0
movq 0x18(%rsp), %rax
movq %rax, %r14
movq 0x20(%rsp), %rcx
cmpq %rax, %rcx
je 0xee90
movq %rcx, %rax
movb $0x20, (%rcx)
incq %rax
movq %rax, %r14
movq 0x8(%rsp), %rsi
movq %r12, %rdx
subq %rsi, %rdx
movq %r14, %rdi
callq 0x40a0
subq 0x8(%rsp), %r12
addq %r14, %r12
movq %r12, 0x20(%rsp)
movq %r13, %r14
movq %r15, %r13
movq 0x30(%rsp), %r15
movb (%rbx), %al
incl %ebp
testb %al, %al
jne 0xedd5
jmp 0xeed3
movq 0x18(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x20(%rsp), %rax
movb $0x0, (%rax)
cmpl %ebp, %r14d
setl %al
cmpl %ebp, %r13d
setl %cl
testb %cl, %al
je 0xeef2
movq 0x18(%rsp), %rbx
jmp 0xef31
leaq 0x6ca3(%rip), %rdx      # 0x15b9c
movq 0x28(%rsp), %rdi
movq 0x18(%rsp), %rsi
movl $0x449, %ecx            # imm = 0x449
callq 0x4280
leaq 0x6e8a(%rip), %rsi      # 0x15d9e
leaq 0x6e60(%rip), %rcx      # 0x15d7b
xorl %ebx, %ebx
movq 0x38(%rsp), %rdi
movq 0x40(%rsp), %rdx
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x4510
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq $0x0, 0x10(%rsp)
movl %r13d, %r14d
jmp 0xed6f
movq (%r14), %rax
testb $0x8, 0x1(%rax,%rcx,2)
je 0xeccc
leaq 0x8(%rsp), %r14
xorl %edi, %edi
movq %r14, %rdx
xorl %ecx, %ecx
callq 0x4360
movq (%r14), %rdx
movq %rax, %r14
cmpb $0x0, (%rdx)
jne 0xeccc
cmpl %r13d, %r14d
setl %al
cmpl $-0x1, %r14d
setne %cl
testb %cl, %al
jne 0xeccc
movq $0x0, 0x10(%rsp)
jmp 0xed6f