// File: /workspace/github_c_makefile_star2_O1/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 0x280(%rdi), %rax
movq %rax, 0x20(%rsp)
movsbq (%rdx), %r15
cmpq $0x24, %r15
jne 0xf343
cmpb $0x0, 0x1(%r12)
jne 0xf3fe
movq %rdi, 0x18(%rsp)
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
xorl %r14d, %r14d
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0xf420
movq %rdi, 0x18(%rsp)
callq 0x4640
movq %rax, %r14
movq (%rax), %rax
testb $0x8, 0x1(%rax,%r15,2)
jne 0xf36b
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
xorl %r13d, %r13d
movq %r12, %r14
jmp 0xf420
leaq 0x8(%rsp), %r15
xorl %edi, %edi
movq %r12, %rsi
movq %r15, %rdx
xorl %ecx, %ecx
callq 0x4350
movq %rax, %r13
movq (%r15), %rax
movzbl (%rax), %ecx
movl %r13d, %ebp
testl %ecx, %ecx
movq 0x18(%rsp), %rdi
je 0xf3ee
cmpl $0x2d, %ecx
jne 0xf3bd
leaq 0x1(%rax), %rsi
movq %rsi, 0x8(%rsp)
movsbq 0x1(%rax), %rcx
cmpq $0x24, %rcx
jne 0xf3c4
addq $0x2, %rax
movq %rax, 0x8(%rsp)
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0xf3e4
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0xf3ee
movq (%r14), %rax
testb $0x8, 0x1(%rax,%rcx,2)
je 0xf3fe
leaq 0x8(%rsp), %rdx
xorl %edi, %edi
xorl %ecx, %ecx
callq 0x4350
movq 0x18(%rsp), %rdi
movq %rax, %rbp
movq 0x8(%rsp), %rax
cmpb $0x0, (%rax)
jne 0xf3fe
cmpl %r13d, %ebp
setl %al
cmpl $-0x1, %ebp
setne %cl
testb %cl, %al
je 0xf41d
leaq 0x7c91(%rip), %rsi      # 0x17096
leaq 0x7c9e(%rip), %rcx      # 0x170aa
movq $0x0, 0x10(%rsp)
movq %r12, %rdx
jmp 0xf5bf
xorl %r14d, %r14d
movq %rbx, %rdi
callq 0x41d0
leal 0x1(%rax), %esi
leaq 0x7a66(%rip), %rdx      # 0x16e98
movq 0x20(%rsp), %rdi
movl $0x41c, %ecx            # imm = 0x41C
callq 0x44c0
movq %rax, 0x10(%rsp)
callq 0x4640
movq %rax, 0x40(%rsp)
movq (%rax), %rax
decq %rbx
movsbq 0x1(%rbx), %rcx
incq %rbx
testb $0x20, 0x1(%rax,%rcx,2)
jne 0xf456
movq %r12, 0x28(%rsp)
cmpb $0x0, (%rbx)
je 0xf568
movq %r14, 0x38(%rsp)
xorl %r14d, %r14d
movq 0x10(%rsp), %rdi
movq %r13, 0x30(%rsp)
movq %rdi, %r15
movq %rbx, 0x8(%rsp)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x41b0
movq %rax, %r12
cmpb $0x0, (%rax)
je 0xf4c3
movq %r12, %rax
incq %rax
movq 0x40(%rsp), %rcx
movq (%rcx), %rcx
movsbq 0x1(%r12), %rdx
incq %r12
testb $0x20, 0x1(%rcx,%rdx,2)
jne 0xf4ad
movq %r12, %rbx
movq %rax, %r12
movq %r15, %rdi
cmpl %r14d, %r13d
jg 0xf55a
cmpl $-0x1, %r13d
je 0xf4e7
cmpl $-0x1, %ebp
setne %al
cmpl %r14d, %ebp
setl %cl
testb %cl, %al
je 0xf4fc
jmp 0xf55a
cmpl $-0x1, %ebp
setne %al
cmpl %r14d, %ebp
setl %cl
cmpb $0x0, (%rbx)
jne 0xf55a
andb %cl, %al
jne 0xf55a
movq 0x38(%rsp), %rsi
testq %rsi, %rsi
je 0xf52f
movq %rbp, %r13
movb (%r12), %bpl
movb $0x0, (%r12)
movq 0x8(%rsp), %rdi
callq 0x4460
movq %r15, %rdi
movb %bpl, (%r12)
movq %r13, %rbp
movq 0x30(%rsp), %r13
testl %eax, %eax
je 0xf55a
cmpq 0x10(%rsp), %rdi
je 0xf53c
movb $0x20, (%rdi)
incq %rdi
movq 0x8(%rsp), %rsi
movq %r12, %rdx
subq %rsi, %rdx
movq %rdi, %r15
callq 0x40a0
movq %r15, %rdi
subq 0x8(%rsp), %r12
addq %r12, %rdi
incl %r14d
cmpb $0x0, (%rbx)
jne 0xf485
jmp 0xf570
xorl %r14d, %r14d
movq 0x10(%rsp), %rdi
movb $0x0, (%rdi)
cmpl %r14d, %ebp
setl %al
cmpl %r14d, %r13d
setl %cl
testb %cl, %al
jne 0xf5c9
leaq 0x790e(%rip), %rdx      # 0x16e98
movq 0x20(%rsp), %rdi
movq 0x10(%rsp), %rsi
movl $0x449, %ecx            # imm = 0x449
callq 0x4280
leaq 0x7af5(%rip), %rsi      # 0x1709a
leaq 0x7acb(%rip), %rcx      # 0x17077
movq $0x0, 0x10(%rsp)
movq 0x18(%rsp), %rdi
movq 0x28(%rsp), %rdx
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x4500
movq 0x10(%rsp), %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq