// File: /workspace/github_c_makefile_star2_O0/haxlang[P]hax/haxUtil.c
// Function: Hax_ScanElement
int
Hax_ScanElement(
    char *string,		/* String to convert to Hax list element. */
    int *flagPtr		/* Where to store information to guide
				 * Hax_ConvertElement. */)
{
    int flags, nestingLevel;
    char *p;

    /*
     * This procedure and Hax_ConvertElement together do two things:
     *
     * 1. They produce a proper list, one that will yield back the
     * argument strings when evaluated or when disassembled with
     * Hax_SplitList.  This is the most important thing.
     *
     * 2. They try to produce legible output, which means minimizing the
     * use of backslashes (using braces instead).  However, there are
     * some situations where backslashes must be used (e.g. an element
     * like "{abc": the leading brace will have to be backslashed.  For
     * each element, one of three things must be done:
     *
     * (a) Use the element as-is (it doesn't contain anything special
     * characters).  This is the most desirable option.
     *
     * (b) Enclose the element in braces, but leave the contents alone.
     * This happens if the element contains embedded space, or if it
     * contains characters with special interpretation ($, [, ;, or \),
     * or if it starts with a brace or double-quote, or if there are
     * no characters in the element.
     *
     * (c) Don't enclose the element in braces, but add backslashes to
     * prevent special interpretation of special characters.  This is a
     * last resort used when the argument would normally fall under case
     * (b) but contains unmatched braces.  It also occurs if the last
     * character of the argument is a backslash or if the element contains
     * a backslash followed by newline.
     *
     * The procedure figures out how many bytes will be needed to store
     * the result (actually, it overestimates).  It also collects information
     * about the element in the form of a flags word.
     */

    nestingLevel = 0;
    flags = 0;
    if (string == NULL) {
	string = (char *) "";
    }
    p = string;
    if ((*p == '{') || (*p == '"') || (*p == 0)) {
	flags |= USE_BRACES;
    }
    for ( ; *p != 0; p++) {
	switch (*p) {
	    case '{':
		nestingLevel++;
		break;
	    case '}':
		nestingLevel--;
		if (nestingLevel < 0) {
		    flags |= HAX_DONT_USE_BRACES|BRACES_UNMATCHED;
		}
		break;
	    case '[':
	    case '$':
	    case ';':
	    case ' ':
	    case '\f':
	    case '\n':
	    case '\r':
	    case '\t':
	    case '\v':
		flags |= USE_BRACES;
		break;
	    case '\\':
		if ((p[1] == 0) || (p[1] == '\n')) {
		    flags = HAX_DONT_USE_BRACES;
		} else {
		    int size;

		    (void) Hax_Backslash(p, &size);
		    p += size-1;
		    flags |= USE_BRACES;
		}
		break;
	}
    }
    if (nestingLevel != 0) {
	flags = HAX_DONT_USE_BRACES | BRACES_UNMATCHED;
    }
    *flagPtr = flags;

    /*
     * Allow enough space to backslash every character plus leave
     * two spaces for braces.
     */

    return 2*(p-string) + 2;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x18(%rbp)
movl $0x0, -0x14(%rbp)
cmpq $0x0, -0x8(%rbp)
jne 0x18060
leaq 0x6e17(%rip), %rax      # 0x1ee73
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x7b, %eax
je 0x1808c
movq -0x20(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x22, %eax
je 0x1808c
movq -0x20(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0x18095
movl -0x14(%rbp), %eax
orl $0x2, %eax
movl %eax, -0x14(%rbp)
jmp 0x18097
movq -0x20(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x18166
movq -0x20(%rbp), %rax
movsbl (%rax), %eax
addl $-0x9, %eax
movl %eax, %ecx
movq %rcx, -0x30(%rbp)
subl $0x74, %eax
ja 0x18153
movq -0x30(%rbp), %rax
leaq 0x7315(%rip), %rcx      # 0x1f3e0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x18153
movl -0x18(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
jge 0x180f7
movl -0x14(%rbp), %eax
orl $0x5, %eax
movl %eax, -0x14(%rbp)
jmp 0x18153
movl -0x14(%rbp), %eax
orl $0x2, %eax
movl %eax, -0x14(%rbp)
jmp 0x18153
movq -0x20(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x0, %eax
je 0x1811e
movq -0x20(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0xa, %eax
jne 0x18127
movl $0x1, -0x14(%rbp)
jmp 0x18151
movq -0x20(%rbp), %rdi
leaq -0x24(%rbp), %rsi
callq 0x42a0
movl -0x24(%rbp), %ecx
subl $0x1, %ecx
movq -0x20(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movl -0x14(%rbp), %eax
orl $0x2, %eax
movl %eax, -0x14(%rbp)
jmp 0x18153
jmp 0x18155
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x18097
cmpl $0x0, -0x18(%rbp)
je 0x18173
movl $0x5, -0x14(%rbp)
movl -0x14(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, (%rax)
movq -0x20(%rbp), %rax
movq -0x8(%rbp), %rcx
subq %rcx, %rax
shlq %rax
addq $0x2, %rax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)