// File: /workspace/github_c_makefile_star2_O1/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 $0xc38, %rsp            # imm = 0xC38
movl %esi, %r13d
movq %rdi, %r15
testq %rdi, %rdi
je 0x78be
callq 0x37a0
movq (%rax), %rax
leaq -0x1(%r15), %r12
movsbq 0x1(%r12), %rcx
incq %r12
testb $0x20, 0x1(%rax,%rcx,2)
jne 0x78ac
jmp 0x78c1
xorl %r12d, %r12d
xorl %ebx, %ebx
testq %r12, %r12
je 0x7c87
cmpb $0x0, (%r12)
je 0x7c87
movb $0x3d, %r11b
leaq 0x30(%rsp), %rdx
xorl %r9d, %r9d
xorl %edi, %edi
movq %rdx, %r14
xorl %ebp, %ebp
movl %r13d, 0xc(%rsp)
movq %r12, %rax
movb (%rax), %cl
movzbl %cl, %esi
cmpl $0x2, %ebp
je 0x7937
cmpl $0x1, %ebp
je 0x791a
testl %ebp, %ebp
je 0x7937
cmpl $0x20, %esi
je 0x7932
xorl %ebp, %ebp
movb $0x3d, %r11b
movq %rdx, %r14
testl %esi, %esi
jne 0x78f6
jmp 0x7c6b
incq %rax
movl $0x2, %ebp
movb $0x20, %r11b
movq %rdx, %r14
cmpb $0x3d, %cl
je 0x78f1
jmp 0x7c9c
incq %rax
jmp 0x78f1
leaq 0x1(%rax), %r12
cmpq %rdx, %r14
setne %sil
movb $0x1, %r10b
testl %r13d, %r13d
je 0x7961
testb %sil, %sil
jne 0x7961
testb %dil, %dil
jne 0x7961
cmpb $0x22, %cl
jne 0x7961
movb $0x1, %dil
jmp 0x79e7
testb %dil, %dil
je 0x7970
cmpb $0x22, %cl
jne 0x7970
xorl %r10d, %r10d
jmp 0x79e7
testb %dil, %dil
setne %sil
cmpb %r11b, %cl
movl %edi, %r13d
setne %dil
testb %cl, %cl
setne %r8b
andb %dil, %r8b
orb %sil, %r8b
cmpb $0x1, %r8b
jne 0x79da
movl %ecx, %eax
xorb $0x20, %al
orb %r13b, %al
je 0x7bc9
movl %r13d, %edi
testb %dil, %dil
je 0x7c01
testb %cl, %cl
jne 0x7c01
movl %edi, %r13d
leaq 0x1188e(%rip), %rdi     # 0x1924c
movq %r15, %rsi
xorl %eax, %eax
movq %r9, 0x10(%rsp)
movb %r11b, 0xb(%rsp)
callq 0xb632
movl %r13d, %edi
jmp 0x7be6
movq %rax, %r12
xorl %edi, %edi
xorl %r10d, %r10d
movl 0xc(%rsp), %r13d
xorl %eax, %eax
testb %r10b, %r10b
jne 0x7bbc
movb %r11b, 0xb(%rsp)
movq %r9, 0x10(%rsp)
movb $0x0, (%r14)
testl %ebp, %ebp
je 0x7ad4
movq %r15, 0x18(%rsp)
movl $0x400, %esi            # imm = 0x400
leaq 0x830(%rsp), %rdi
callq 0x7cdd
testl %r13d, %r13d
je 0x7b05
leaq 0x830(%rsp), %rdi
callq 0x3200
movq %rax, %r15
leal 0x1(%rax), %ecx
movslq %ecx, %rdi
callq 0xf07d
movq %rax, %r13
movq %rax, 0x20(%rsp)
movslq %r15d, %r15
movq %rax, %rdi
leaq 0x830(%rsp), %rsi
movq %r15, %rdx
callq 0x34a0
movb %bl, (%r13,%r15)
movl $0x18, %edi
callq 0xf07d
movq %rax, 0x28(%rsp)
leaq 0x430(%rsp), %rdi
callq 0x3200
movq %rax, %r15
leal 0x1(%rax), %ecx
movslq %ecx, %rdi
callq 0xf07d
movq %rax, %r13
movslq %r15d, %r15
movq %rax, %rdi
leaq 0x430(%rsp), %rsi
movq %r15, %rdx
callq 0x34a0
movb %bl, (%r13,%r15)
movq 0x28(%rsp), %r9
movq %r13, 0x8(%r9)
movq 0x20(%rsp), %rax
movq %rax, 0x10(%r9)
movq 0x10(%rsp), %rax
movq %rax, (%r9)
movq 0x18(%rsp), %r15
movl 0xc(%rsp), %r13d
jmp 0x7af9
movl $0x400, %esi            # imm = 0x400
leaq 0x430(%rsp), %rdi
callq 0x7cdd
cmpb $0x0, 0x430(%rsp)
je 0x7b93
movq 0x10(%rsp), %r9
orl $0x1, %ebp
xorl %eax, %eax
xorl %edi, %edi
jmp 0x7bb2
leaq 0x430(%rsp), %r15
movsbq (%r15), %r13
testq %r13, %r13
je 0x7b2e
incq %r15
callq 0x37a0
movq (%rax), %rax
testb $0x20, 0x1(%rax,%r13,2)
je 0x7b0d
testb %r13b, %r13b
jne 0x7b5f
leaq 0x830(%rsp), %r15
movsbq (%r15), %r13
testq %r13, %r13
je 0x7a28
incq %r15
callq 0x37a0
movq (%rax), %rax
testb $0x20, 0x1(%rax,%r13,2)
je 0x7b36
testb %r13b, %r13b
je 0x7a28
leaq 0x11783(%rip), %rdi     # 0x192e9
leaq 0x430(%rsp), %rsi
leaq 0x830(%rsp), %rdx
movq 0x18(%rsp), %r15
movq %r15, %rcx
xorl %eax, %eax
callq 0xb632
xorl %edi, %edi
movl $0x3, %eax
movl 0xc(%rsp), %r13d
jmp 0x7bad
leaq 0x11719(%rip), %rdi     # 0x192b3
movq %r15, %rsi
xorl %eax, %eax
callq 0xb632
xorl %edi, %edi
movl $0x1, %eax
xorl %ebp, %ebp
movq 0x10(%rsp), %r9
leaq 0x30(%rsp), %rdx
movb 0xb(%rsp), %r11b
testl %eax, %eax
je 0x78ee
jmp 0x7c66
leaq 0x1164a(%rip), %rdi     # 0x1921a
movq %r15, %rsi
xorl %eax, %eax
movq %r9, 0x10(%rsp)
movb %r11b, 0xb(%rsp)
callq 0xb632
xorl %edi, %edi
movb 0xb(%rsp), %r11b
leaq 0x30(%rsp), %rdx
movq 0x10(%rsp), %r9
movl $0x1, %eax
movl 0xc(%rsp), %r13d
jmp 0x7bbc
leaq 0x1(%r14), %rsi
movb %cl, (%r14)
movq %rdx, %rax
negq %rax
addq %r14, %rax
incq %rax
cmpq $0x401, %rax            # imm = 0x401
jb 0x7c5e
movl %edi, %r13d
leaq 0x11655(%rip), %rdi     # 0x1927b
movq %rsi, 0x18(%rsp)
movq %r15, %rsi
xorl %eax, %eax
movq %r9, 0x10(%rsp)
movq %rdx, %r14
movb %r11b, 0xb(%rsp)
callq 0xb632
movl %r13d, %edi
movb 0xb(%rsp), %r11b
movq %r14, %rdx
movq 0x10(%rsp), %r9
movl $0x1, %eax
movq 0x18(%rsp), %r14
jmp 0x7bfa
movq %rsi, %r14
jmp 0x79e2
cmpl $0x3, %eax
jne 0x7c85
testq %r9, %r9
je 0x7c85
xorl %eax, %eax
movq %r9, %rbx
movq (%r9), %r9
movq %rax, (%rbx)
movq %rbx, %rax
testq %r9, %r9
jne 0x7c72
jmp 0x7c87
xorl %ebx, %ebx
movq %rbx, %rax
addq $0xc38, %rsp            # imm = 0xC38
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x116a2(%rip), %rdi     # 0x19345
xorl %ebx, %ebx
movq %r15, %rsi
xorl %eax, %eax
callq 0xb632
jmp 0x7c87