// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc28, %rsp            # imm = 0xC28
movl %esi, %ebp
movq %rdi, %r15
callq 0x722d
testq %rax, %rax
je 0x71a9
movq %rax, %rbx
movb (%rax), %cl
xorl %r14d, %r14d
testb %cl, %cl
je 0x7218
movq %r15, (%rsp)
andq $0x0, 0x8(%rsp)
movb $0x3d, %r12b
leaq 0x820(%rsp), %r13
leaq 0x420(%rsp), %rdi
movq %r13, %rax
negq %rax
movq %rax, 0x18(%rsp)
xorl %eax, %eax
movq %r13, %r15
movl %ebp, 0x14(%rsp)
leaq 0x1(%rbx), %rdx
cmpl $0x2, %r14d
je 0x702c
cmpl $0x1, %r14d
je 0x705b
testl %r14d, %r14d
jne 0x7092
testl %ebp, %ebp
setne %sil
cmpq %r13, %r15
sete %r9b
testb %al, %al
sete %r8b
andb %sil, %r8b
andb %r9b, %r8b
cmpb $0x22, %cl
sete %sil
testb %sil, %r8b
je 0x7078
movq %rdx, %rbx
movb $0x1, %al
jmp 0x71a2
movb $0x20, %r12b
movq %rdx, %rbx
movq %r13, %r15
pushq $0x2
popq %rdx
movl %edx, %r14d
cmpb $0x3d, %cl
je 0x71a2
jmp 0x71ae
cmpb $0x22, %cl
sete %sil
testb %al, %al
setne %r8b
testb %sil, %r8b
je 0x70b0
movq %rdx, %rbx
jmp 0x7119
cmpb $0x20, %cl
je 0x7111
movzbl %cl, %ecx
testl %ecx, %ecx
je 0x71d6
xorl %r14d, %r14d
movb $0x3d, %r12b
movq %r13, %r15
jmp 0x71a2
testb %al, %al
setne %sil
cmpb %r12b, %cl
setne %r9b
testb %cl, %cl
setne %r8b
andb %r9b, %r8b
orb %sil, %r8b
cmpb $0x1, %r8b
jne 0x7119
movl %ecx, %esi
xorb $0x20, %sil
orb %al, %sil
je 0x71f1
testb %cl, %cl
setne %sil
testb %al, %al
sete %r8b
orb %sil, %r8b
je 0x71fa
movb %cl, (%r15)
movq 0x18(%rsp), %rcx
addq %r15, %rcx
incq %rcx
cmpq $0x401, %rcx            # imm = 0x401
jae 0x7203
incq %r15
movq %rdx, %rbx
jmp 0x71a2
movb $0x0, (%r15)
movl $0x400, %esi            # imm = 0x400
testl %r14d, %r14d
je 0x7180
movq %r13, %rdx
movq %rdi, %r13
callq 0x7259
testl %ebp, %ebp
jne 0x7150
leaq 0x20(%rsp), %rdi
callq 0x729c
testl %eax, %eax
jne 0x71b7
movq %r13, %rdi
callq 0x729c
testl %eax, %eax
jne 0x71b7
movq %r13, %rdi
callq 0x5ede
leaq 0x20(%rsp), %rdi
movq %rax, %rsi
callq 0x6e9f
movq 0x8(%rsp), %rcx
movq %rcx, (%rax)
movq %rax, 0x8(%rsp)
leaq 0x820(%rsp), %r13
movl 0x14(%rsp), %ebp
jmp 0x7194
leaq 0x20(%rsp), %rdi
movq %r13, %rdx
callq 0x7259
cmpb $0x0, 0x20(%rsp)
je 0x71e8
orl $0x1, %r14d
xorl %eax, %eax
leaq 0x420(%rsp), %rdi
movb (%rbx), %cl
jmp 0x7017
xorl %r14d, %r14d
jmp 0x7218
leaq 0x101a0(%rip), %rdi     # 0x17355
jmp 0x720a
leaq 0x1013b(%rip), %rdi     # 0x172f9
leaq 0x20(%rsp), %rsi
leaq 0x420(%rsp), %rdx
movq (%rsp), %rcx
xorl %eax, %eax
callq 0xa3aa
leaq 0x8(%rsp), %rbx
movq %rbx, %rdi
callq 0x613f
movq (%rbx), %r14
jmp 0x7218
leaq 0x100d4(%rip), %rdi     # 0x172c3
jmp 0x720a
leaq 0x10032(%rip), %rdi     # 0x1722a
jmp 0x720a
leaq 0x1005b(%rip), %rdi     # 0x1725c
jmp 0x720a
leaq 0x10081(%rip), %rdi     # 0x1728b
xorl %r14d, %r14d
movq (%rsp), %rsi
xorl %eax, %eax
callq 0xa3aa
movq %r14, %rax
addq $0xc28, %rsp            # imm = 0xC28
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq