// File: /workspace/github_c_makefile_star2_O0/haxlang[P]hax/haxUtil.c
// Function: HaxFindElement
int
HaxFindElement(
    Hax_Interp *interp,		/* Interpreter to use for error reporting. */
    char *list,			/* String containing Hax list with zero
				 * or more elements (possibly in braces). */
    char **elementPtr,		/* Fill in with location of first significant
				 * character in first element of list. */
    char **nextPtr,		/* Fill in with location of character just
				 * after all white space following end of
				 * argument (i.e. next argument or end of
				 * list). */
    long int *sizePtr,		/* If non-zero, fill in with size of
				 * element. */
    int *bracePtr		/* If non-zero fill in with non-zero/zero
				 * to indicate that arg was/wasn't
				 * in braces. */)
{
    char *p;
    int openBraces = 0;
    int inQuotes = 0;
    long int size;

    /*
     * Skim off leading white space and check for an opening brace or
     * quote.   Note:  use of "isascii" below and elsewhere in this
     * procedure is a temporary hack (7/27/90) because Mx uses characters
     * with the high-order bit set for some things.  This should probably
     * be changed back eventually, or all of Hax should call isascii.
     */

    while (isascii(*list) && isspace(*list)) {
	list++;
    }
    if (*list == '{') {
	openBraces = 1;
	list++;
    } else if (*list == '"') {
	inQuotes = 1;
	list++;
    }
    if (bracePtr != 0) {
	*bracePtr = openBraces;
    }
    p = list;

    /*
     * Find the end of the element (either a space or a close brace or
     * the end of the string).
     */

    while (1) {
	switch (*p) {

	    /*
	     * Open brace: don't treat specially unless the element is
	     * in braces.  In this case, keep a nesting count.
	     */

	    case '{':
		if (openBraces != 0) {
		    openBraces++;
		}
		break;

	    /*
	     * Close brace: if element is in braces, keep nesting
	     * count and quit when the last close brace is seen.
	     */

	    case '}':
		if (openBraces == 1) {
		    char *p2;

		    size = p - list;
		    p++;
		    if ((isascii(*p) && isspace(*p)) || (*p == 0)) {
			goto done;
		    }
		    for (p2 = p; (*p2 != 0) && (!isspace(*p2)) && (p2 < p+20);
			    p2++) {
			/* null body */
		    }
		    Hax_ResetResult(interp);
		    sprintf(interp->result,
			    "list element in braces followed by \"%.*s\" instead of space",
			    (int)(p2-p), p);
		    return HAX_ERROR;
		} else if (openBraces != 0) {
		    openBraces--;
		}
		break;

	    /*
	     * Backslash:  skip over everything up to the end of the
	     * backslash sequence.
	     */

	    case '\\': {
		int sizeb;

		(void) Hax_Backslash(p, &sizeb);
		p += sizeb - 1;
		break;
	    }

	    /*
	     * Space: ignore if element is in braces or quotes;  otherwise
	     * terminate element.
	     */

	    case ' ':
	    case '\f':
	    case '\n':
	    case '\r':
	    case '\t':
	    case '\v':
		if ((openBraces == 0) && !inQuotes) {
		    size = p - list;
		    goto done;
		}
		break;

	    /*
	     * Double-quote:  if element is in quotes then terminate it.
	     */

	    case '"':
		if (inQuotes) {
		    char *p2;

		    size = p-list;
		    p++;
		    if ((isascii(*p) && isspace(*p)) || (*p == 0)) {
			goto done;
		    }
		    for (p2 = p; (*p2 != 0) && (!isspace(*p2)) && (p2 < p+20);
			    p2++) {
			/* null body */
		    }
		    Hax_ResetResult(interp);
		    sprintf(interp->result,
			    "list element in quotes followed by \"%.*s\" %s",
			    (int)(p2-p), p, "instead of space");
		    return HAX_ERROR;
		}
		break;

	    /*
	     * End of list:  terminate element.
	     */

	    case 0:
		if (openBraces != 0) {
		    Hax_SetResult(interp,
			    (char *) "unmatched open brace in list",
			    HAX_STATIC);
		    return HAX_ERROR;
		} else if (inQuotes) {
		    Hax_SetResult(interp,
			    (char *) "unmatched open quote in list",
			    HAX_STATIC);
		    return HAX_ERROR;
		}
		size = p - list;
		goto done;

	}
	p++;
    }

    done:
    while (isascii(*p) && isspace(*p)) {
	p++;
    }
    *elementPtr = list;
    *nextPtr = p;
    if (sizePtr != 0) {
	*sizePtr = size;
    }
    return HAX_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movl $0x0, -0x44(%rbp)
movl $0x0, -0x48(%rbp)
movq -0x18(%rbp), %rax
movsbl (%rax), %ecx
andl $-0x80, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x69(%rbp)
jne 0x17689
callq 0x4630
movq (%rax), %rax
movq -0x18(%rbp), %rcx
movsbl (%rcx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x2000, %eax           # imm = 0x2000
cmpl $0x0, %eax
setne %al
movb %al, -0x69(%rbp)
movb -0x69(%rbp), %al
testb $0x1, %al
jne 0x17692
jmp 0x176a0
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0x17651
movq -0x18(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x7b, %eax
jne 0x176c1
movl $0x1, -0x44(%rbp)
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0x176e2
movq -0x18(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x22, %eax
jne 0x176e0
movl $0x1, -0x48(%rbp)
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0x176e2
cmpq $0x0, -0x38(%rbp)
je 0x176f2
movl -0x44(%rbp), %ecx
movq -0x38(%rbp), %rax
movl %ecx, (%rax)
movq -0x18(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movsbl (%rax), %eax
movl %eax, -0x70(%rbp)
testl %eax, %eax
je 0x179f8
jmp 0x1770e
movl -0x70(%rbp), %eax
addl $-0x9, %eax
subl $0x5, %eax
jb 0x178bd
jmp 0x1771f
movl -0x70(%rbp), %eax
subl $0x20, %eax
je 0x178bd
jmp 0x1772d
movl -0x70(%rbp), %eax
subl $0x22, %eax
je 0x178e2
jmp 0x1773b
movl -0x70(%rbp), %eax
subl $0x5c, %eax
je 0x17897
jmp 0x17749
movl -0x70(%rbp), %eax
subl $0x7b, %eax
je 0x17760
jmp 0x17753
movl -0x70(%rbp), %eax
subl $0x7d, %eax
je 0x17774
jmp 0x17a57
cmpl $0x0, -0x44(%rbp)
je 0x1776f
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x17a57
cmpl $0x1, -0x44(%rbp)
jne 0x17881
movq -0x40(%rbp), %rax
movq -0x18(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movsbl (%rax), %eax
andl $-0x80, %eax
cmpl $0x0, %eax
jne 0x177c8
callq 0x4630
movq (%rax), %rax
movq -0x40(%rbp), %rcx
movsbl (%rcx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x2000, %eax           # imm = 0x2000
cmpl $0x0, %eax
jne 0x177d4
movq -0x40(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0x177d9
jmp 0x17a68
movq -0x40(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x71(%rbp)
je 0x1782d
callq 0x4630
movq (%rax), %rax
movq -0x58(%rbp), %rcx
movsbl (%rcx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %ecx
andl $0x2000, %ecx           # imm = 0x2000
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x71(%rbp)
jne 0x1782d
movq -0x58(%rbp), %rax
movq -0x40(%rbp), %rcx
addq $0x14, %rcx
cmpq %rcx, %rax
setb %al
movb %al, -0x71(%rbp)
movb -0x71(%rbp), %al
testb $0x1, %al
jne 0x17836
jmp 0x17846
jmp 0x17838
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0x177e1
movq -0x10(%rbp), %rdi
callq 0x42b0
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x58(%rbp), %rax
movq -0x40(%rbp), %rcx
subq %rcx, %rax
movl %eax, %edx
movq -0x40(%rbp), %rcx
leaq 0x7f1a(%rip), %rsi      # 0x1f788
movb $0x0, %al
callq 0x45d0
movl $0x1, -0x4(%rbp)
jmp 0x17ae8
cmpl $0x0, -0x44(%rbp)
je 0x17890
movl -0x44(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x17892
jmp 0x17a57
movq -0x40(%rbp), %rdi
leaq -0x5c(%rbp), %rsi
callq 0x42a0
movl -0x5c(%rbp), %ecx
subl $0x1, %ecx
movq -0x40(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
jmp 0x17a57
cmpl $0x0, -0x44(%rbp)
jne 0x178dd
cmpl $0x0, -0x48(%rbp)
jne 0x178dd
movq -0x40(%rbp), %rax
movq -0x18(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x50(%rbp)
jmp 0x17a68
jmp 0x17a57
cmpl $0x0, -0x48(%rbp)
je 0x179f6
movq -0x40(%rbp), %rax
movq -0x18(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movsbl (%rax), %eax
andl $-0x80, %eax
cmpl $0x0, %eax
jne 0x17936
callq 0x4630
movq (%rax), %rax
movq -0x40(%rbp), %rcx
movsbl (%rcx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x2000, %eax           # imm = 0x2000
cmpl $0x0, %eax
jne 0x17942
movq -0x40(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0x17947
jmp 0x17a68
movq -0x40(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x72(%rbp)
je 0x1799b
callq 0x4630
movq (%rax), %rax
movq -0x68(%rbp), %rcx
movsbl (%rcx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %ecx
andl $0x2000, %ecx           # imm = 0x2000
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x72(%rbp)
jne 0x1799b
movq -0x68(%rbp), %rax
movq -0x40(%rbp), %rcx
addq $0x14, %rcx
cmpq %rcx, %rax
setb %al
movb %al, -0x72(%rbp)
movb -0x72(%rbp), %al
testb $0x1, %al
jne 0x179a4
jmp 0x179b4
jmp 0x179a6
movq -0x68(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x68(%rbp)
jmp 0x1794f
movq -0x10(%rbp), %rdi
callq 0x42b0
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x68(%rbp), %rax
movq -0x40(%rbp), %rcx
subq %rcx, %rax
movl %eax, %edx
movq -0x40(%rbp), %rcx
leaq 0x7de7(%rip), %rsi      # 0x1f7c3
leaq 0x7dcf(%rip), %r8       # 0x1f7b2
movb $0x0, %al
callq 0x45d0
movl $0x1, -0x4(%rbp)
jmp 0x17ae8
jmp 0x17a57
cmpl $0x0, -0x44(%rbp)
je 0x17a1e
movq -0x10(%rbp), %rdi
leaq 0x7de7(%rip), %rsi      # 0x1f7f0
xorl %eax, %eax
movl %eax, %edx
callq 0x44e0
movl $0x1, -0x4(%rbp)
jmp 0x17ae8
cmpl $0x0, -0x48(%rbp)
je 0x17a44
movq -0x10(%rbp), %rdi
leaq 0x7dde(%rip), %rsi      # 0x1f80d
xorl %eax, %eax
movl %eax, %edx
callq 0x44e0
movl $0x1, -0x4(%rbp)
jmp 0x17ae8
jmp 0x17a46
movq -0x40(%rbp), %rax
movq -0x18(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x50(%rbp)
jmp 0x17a68
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x176fa
jmp 0x17a6a
movq -0x40(%rbp), %rax
movsbl (%rax), %ecx
andl $-0x80, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x73(%rbp)
jne 0x17aa2
callq 0x4630
movq (%rax), %rax
movq -0x40(%rbp), %rcx
movsbl (%rcx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x2000, %eax           # imm = 0x2000
cmpl $0x0, %eax
setne %al
movb %al, -0x73(%rbp)
movb -0x73(%rbp), %al
testb $0x1, %al
jne 0x17aab
jmp 0x17ab9
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x17a6a
movq -0x18(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movq -0x40(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
cmpq $0x0, -0x30(%rbp)
je 0x17ae1
movq -0x50(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)