// File: /workspace/github_c_makefile_star2_O0/JimKent[P]linearSat/lib/common.c
// Function: slPairListFromString
struct slPair *slPairListFromString(char *str,boolean respectQuotes)
// Return slPair list parsed from list in string like:  [name1=val1 name2=val2 ...]
// if respectQuotes then string can have double quotes: [name1="val 1" "name 2"=val2 ...]
//    resulting pair strips quotes: {name1}={val 1},{name 2}={val2}
// Returns NULL if parse error.  Free this up with slPairFreeValsAndList.
{
char *s = skipLeadingSpaces(str);  // Would like to remove this and tighten up the standard someday.
if (isEmpty(s))
    return NULL;

struct slPair *list = NULL;
char name[1024];
char val[1024];
char buf[1024];
bool inQuote = FALSE;
char *b = buf;
char sep = '=';
char c = ' ';
int mode = 0;
while(1)
    {
    c = *s++;
    if (mode == 0 || mode == 2) // reading name or val
	{
	boolean term = FALSE;
	if (respectQuotes && b == buf && !inQuote && c == '"')
	    inQuote = TRUE;
	else if (inQuote && c == '"')
	    term = TRUE;
	else if ((c == sep || c == 0) && !inQuote)
	    {
	    term = TRUE;
	    --s;  // rewind
	    }
	else if (c == ' ' && !inQuote)
	    {
	    warn("slPairListFromString: Unexpected whitespace in %s", str);
	    return NULL;
	    }
	else if (c == 0 && inQuote)
	    {
	    warn("slPairListFromString: Unterminated quote in %s", str);
	    return NULL;
	    }
	else
	    {
	    *b++ = c;
	    if ((b - buf) > sizeof buf)
		{
		warn("slPairListFromString: pair name or value too long in %s", str);
		return NULL;
		}
	    }
	if (term)
	    {
	    inQuote = FALSE;
	    *b = 0;
	    if (mode == 0)
		{
		safecpy(name, sizeof name, buf);
		if (strlen(name)<1)
		    {
		    warn("slPairListFromString: Pair name cannot be empty in %s", str);
		    return NULL;
		    }
		// Shall we check for name being alphanumeric, at least for the respectQuotes=FALSE case?
		}
	    else // mode == 2
                {
		safecpy(val, sizeof val, buf);
		if (!respectQuotes && (hasWhiteSpace(name) || hasWhiteSpace(val))) // should never happen
		    {
		    warn("slPairListFromString() Unexpected white space in name=value pair: [%s]=[%s] in string=[%s]\n", name, val, str);
		    break;
		    }
		slPairAdd(&list, name, cloneString(val));
		}
	    ++mode;
	    }
	}
    else if (mode == 1) // read required "=" sign
	{
	if (c != '=')
	    {
	    warn("slPairListFromString: Expected character = after name in %s", str);
	    return NULL;
            }
	++mode;
	sep = ' ';
	b = buf;
	}
    else // (mode == 3) reading optional separating space
	{
	if (c == 0)
	    break;
	if (c != ' ')
	    {
	    mode = 0;
	    --s;
	    b = buf;
	    sep = '=';
	    }
	}
    }
slReverse(&list);
return list;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc60, %rsp            # imm = 0xC60
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq -0x10(%rbp), %rdi
callq 0x9bb0
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x97e2
movq -0x20(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0x97ef
movq $0x0, -0x8(%rbp)
jmp 0x9b9c
movq $0x0, -0x28(%rbp)
movb $0x0, -0xc31(%rbp)
leaq -0xc30(%rbp), %rax
movq %rax, -0xc40(%rbp)
movb $0x3d, -0xc41(%rbp)
movb $0x20, -0xc42(%rbp)
movl $0x0, -0xc48(%rbp)
movq -0x20(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x20(%rbp)
movb (%rax), %al
movb %al, -0xc42(%rbp)
cmpl $0x0, -0xc48(%rbp)
je 0x9851
cmpl $0x2, -0xc48(%rbp)
jne 0x9ae3
movl $0x0, -0xc4c(%rbp)
cmpl $0x0, -0x14(%rbp)
je 0x9895
movq -0xc40(%rbp), %rax
leaq -0xc30(%rbp), %rcx
cmpq %rcx, %rax
jne 0x9895
cmpb $0x0, -0xc31(%rbp)
jne 0x9895
movsbl -0xc42(%rbp), %eax
cmpl $0x22, %eax
jne 0x9895
movb $0x1, -0xc31(%rbp)
jmp 0x99c8
movsbl -0xc31(%rbp), %eax
cmpl $0x0, %eax
je 0x98bc
movsbl -0xc42(%rbp), %eax
cmpl $0x22, %eax
jne 0x98bc
movl $0x1, -0xc4c(%rbp)
jmp 0x99c6
movsbl -0xc42(%rbp), %eax
movsbl -0xc41(%rbp), %ecx
cmpl %ecx, %eax
je 0x98da
movsbl -0xc42(%rbp), %eax
cmpl $0x0, %eax
jne 0x98fe
cmpb $0x0, -0xc31(%rbp)
jne 0x98fe
movl $0x1, -0xc4c(%rbp)
movq -0x20(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x99c4
movsbl -0xc42(%rbp), %eax
cmpl $0x20, %eax
jne 0x9932
cmpb $0x0, -0xc31(%rbp)
jne 0x9932
movq -0x10(%rbp), %rsi
leaq 0x1a8fc(%rip), %rdi     # 0x2421a
movb $0x0, %al
callq 0xf8f0
movq $0x0, -0x8(%rbp)
jmp 0x9b9c
movsbl -0xc42(%rbp), %eax
cmpl $0x0, %eax
jne 0x9969
movsbl -0xc31(%rbp), %eax
cmpl $0x0, %eax
je 0x9969
movq -0x10(%rbp), %rsi
leaq 0x1a8f7(%rip), %rdi     # 0x2424c
movb $0x0, %al
callq 0xf8f0
movq $0x0, -0x8(%rbp)
jmp 0x9b9c
movb -0xc42(%rbp), %cl
movq -0xc40(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0xc40(%rbp)
movb %cl, (%rax)
movq -0xc40(%rbp), %rax
leaq -0xc30(%rbp), %rcx
subq %rcx, %rax
cmpq $0x400, %rax            # imm = 0x400
jbe 0x99be
movq -0x10(%rbp), %rsi
leaq 0x1a8d1(%rip), %rdi     # 0x2427b
movb $0x0, %al
callq 0xf8f0
movq $0x0, -0x8(%rbp)
jmp 0x9b9c
jmp 0x99c0
jmp 0x99c2
jmp 0x99c4
jmp 0x99c6
jmp 0x99c8
cmpl $0x0, -0xc4c(%rbp)
je 0x9ade
movb $0x0, -0xc31(%rbp)
movq -0xc40(%rbp), %rax
movb $0x0, (%rax)
cmpl $0x0, -0xc48(%rbp)
jne 0x9a3d
leaq -0x430(%rbp), %rdi
leaq -0xc30(%rbp), %rdx
movl $0x400, %esi            # imm = 0x400
callq 0x9c20
leaq -0x430(%rbp), %rdi
callq 0x31f0
cmpq $0x1, %rax
jae 0x9a38
movq -0x10(%rbp), %rsi
leaq 0x1a88f(%rip), %rdi     # 0x242b3
movb $0x0, %al
callq 0xf8f0
movq $0x0, -0x8(%rbp)
jmp 0x9b9c
jmp 0x9acf
leaq -0x830(%rbp), %rdi
leaq -0xc30(%rbp), %rdx
movl $0x400, %esi            # imm = 0x400
callq 0x9c20
cmpl $0x0, -0x14(%rbp)
jne 0x9aa2
leaq -0x430(%rbp), %rdi
callq 0x9c80
cmpl $0x0, %eax
jne 0x9a7d
leaq -0x830(%rbp), %rdi
callq 0x9c80
cmpl $0x0, %eax
je 0x9aa2
leaq -0x430(%rbp), %rsi
leaq -0x830(%rbp), %rdx
movq -0x10(%rbp), %rcx
leaq 0x1a853(%rip), %rdi     # 0x242e9
movb $0x0, %al
callq 0xf8f0
jmp 0x9b8b
leaq -0x430(%rbp), %rax
movq %rax, -0xc58(%rbp)
leaq -0x830(%rbp), %rdi
callq 0x7530
movq -0xc58(%rbp), %rsi
movq %rax, %rdx
leaq -0x28(%rbp), %rdi
callq 0x95d0
movl -0xc48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc48(%rbp)
jmp 0x9b86
cmpl $0x1, -0xc48(%rbp)
jne 0x9b3d
movsbl -0xc42(%rbp), %eax
cmpl $0x3d, %eax
je 0x9b17
movq -0x10(%rbp), %rsi
leaq 0x1a842(%rip), %rdi     # 0x24345
movb $0x0, %al
callq 0xf8f0
movq $0x0, -0x8(%rbp)
jmp 0x9b9c
movl -0xc48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc48(%rbp)
movb $0x20, -0xc41(%rbp)
leaq -0xc30(%rbp), %rax
movq %rax, -0xc40(%rbp)
jmp 0x9b84
movsbl -0xc42(%rbp), %eax
cmpl $0x0, %eax
jne 0x9b4b
jmp 0x9b8b
movsbl -0xc42(%rbp), %eax
cmpl $0x20, %eax
je 0x9b82
movl $0x0, -0xc48(%rbp)
movq -0x20(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x20(%rbp)
leaq -0xc30(%rbp), %rax
movq %rax, -0xc40(%rbp)
movb $0x3d, -0xc41(%rbp)
jmp 0x9b84
jmp 0x9b86
jmp 0x9824
leaq -0x28(%rbp), %rdi
callq 0x7bb0
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xc60, %rsp            # imm = 0xC60
popq %rbp
retq
nopl (%rax)