// File: /workspace/github_c_makefile_star2_O3/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, 0x4(%rsp)
testq %rdi, %rdi
je 0x7ab9
movq %rdi, %rbx
callq 0x37a0
movq %rax, %r13
movq (%rax), %rax
leaq -0x1(%rbx), %r12
movsbq 0x1(%r12), %rcx
incq %r12
testb $0x20, 0x1(%rax,%rcx,2)
jne 0x77f7
xorl %r14d, %r14d
testb %cl, %cl
je 0x7abc
movq %rbx, 0x8(%rsp)
movb $0x3d, %bpl
leaq 0x830(%rsp), %rdx
xorl %ebx, %ebx
xorl %eax, %eax
movq %rdx, %r10
xorl %r15d, %r15d
movq %r13, 0x10(%rsp)
leaq 0x1(%r12), %r9
cmpl $0x2, %r15d
je 0x7847
cmpl $0x1, %r15d
je 0x786d
testl %r15d, %r15d
jne 0x7892
cmpq %rdx, %r10
setne %sil
cmpl $0x0, 0x4(%rsp)
je 0x7884
testb %sil, %sil
jne 0x7884
testb %al, %al
jne 0x7884
cmpb $0x22, %cl
jne 0x7884
movq %r9, %r12
movb $0x1, %al
jmp 0x7a35
cmpb $0x3d, %cl
jne 0x7ad1
movl $0x2, %r15d
movb $0x20, %bpl
movq %r9, %r12
jmp 0x78a8
testb %al, %al
je 0x78b0
cmpb $0x22, %cl
jne 0x78b0
movq %r9, %r12
jmp 0x7911
cmpb $0x20, %cl
je 0x7909
movzbl %cl, %ecx
testl %ecx, %ecx
je 0x7a9f
xorl %r15d, %r15d
movb $0x3d, %bpl
movq %rdx, %r10
jmp 0x7a35
testb %al, %al
setne %sil
cmpb %bpl, %cl
setne %dil
testb %cl, %cl
setne %r8b
andb %dil, %r8b
orb %sil, %r8b
cmpb $0x1, %r8b
jne 0x7911
movl %ecx, %esi
xorb $0x20, %sil
orb %al, %sil
je 0x7ae3
testb %al, %al
je 0x78ea
testb %cl, %cl
je 0x7aec
movb %cl, (%r10)
movq %rdx, %rcx
negq %rcx
addq %r10, %rcx
incq %rcx
cmpq $0x400, %rcx            # imm = 0x400
ja 0x7af5
incq %r10
movq %r9, %r12
jmp 0x7a35
movq %r10, 0x28(%rsp)
movb $0x0, (%r10)
movl $0x400, %esi            # imm = 0x400
testl %r15d, %r15d
je 0x7a0d
leaq 0x430(%rsp), %rdi
callq 0x7b39
cmpl $0x0, 0x4(%rsp)
je 0x7a3e
movb %bpl, 0x3(%rsp)
leaq 0x430(%rsp), %rdi
callq 0x3200
movq %rax, %r13
movq %rax, %rdi
shlq $0x20, %rdi
movabsq $0x100000000, %rax      # imm = 0x100000000
addq %rax, %rdi
sarq $0x20, %rdi
callq 0xee10
movq %rax, %rbp
movslq %r13d, %r13
movq %rax, %rdi
movq %rax, 0x20(%rsp)
leaq 0x430(%rsp), %rsi
movq %r13, %rdx
callq 0x34a0
movb %r14b, (%rbp,%r13)
movl $0x18, %edi
callq 0xee10
movq %rax, 0x18(%rsp)
leaq 0x30(%rsp), %rdi
callq 0x3200
movq %rax, %r13
movq %rax, %rdi
shlq $0x20, %rdi
movabsq $0x100000000, %rax      # imm = 0x100000000
addq %rax, %rdi
sarq $0x20, %rdi
callq 0xee10
movq %rax, %rbp
movslq %r13d, %r13
movq %rax, %rdi
leaq 0x30(%rsp), %rsi
movq %r13, %rdx
callq 0x34a0
movb %r14b, (%rbp,%r13)
movq 0x10(%rsp), %r13
movq 0x18(%rsp), %rcx
movq %rbp, 0x8(%rcx)
movb 0x3(%rsp), %bpl
movq 0x20(%rsp), %rax
movq %rax, 0x10(%rcx)
movq %rbx, (%rcx)
movq %rcx, %rbx
jmp 0x7a22
leaq 0x30(%rsp), %rdi
callq 0x7b39
cmpb $0x0, 0x30(%rsp)
je 0x7ada
orl $0x1, %r15d
xorl %eax, %eax
leaq 0x830(%rsp), %rdx
movq 0x28(%rsp), %r10
movb (%r12), %cl
jmp 0x7831
leaq 0x30(%rsp), %rax
movsbq (%rax), %rcx
testq %rcx, %rcx
je 0x7a5c
incq %rax
movq (%r13), %rdx
testb $0x20, 0x1(%rdx,%rcx,2)
je 0x7a43
jmp 0x7a7f
leaq 0x430(%rsp), %rax
movsbq (%rax), %rcx
testq %rcx, %rcx
je 0x7940
incq %rax
movq (%r13), %rdx
testb $0x20, 0x1(%rdx,%rcx,2)
je 0x7a64
leaq 0x11873(%rip), %rdi     # 0x192f9
leaq 0x30(%rsp), %rsi
leaq 0x430(%rsp), %rdx
movq 0x8(%rsp), %rcx
xorl %eax, %eax
callq 0xb41e
testq %rbx, %rbx
je 0x7ab9
xorl %eax, %eax
movq %rbx, %r14
movq (%rbx), %rbx
movq %rax, (%r14)
movq %r14, %rax
testq %rbx, %rbx
jne 0x7aa6
jmp 0x7abc
xorl %r14d, %r14d
movq %r14, %rax
addq $0xc38, %rsp            # imm = 0xC38
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1187d(%rip), %rdi     # 0x19355
jmp 0x7afc
leaq 0x117e2(%rip), %rdi     # 0x192c3
jmp 0x7afc
leaq 0x11740(%rip), %rdi     # 0x1922a
jmp 0x7afc
leaq 0x11769(%rip), %rdi     # 0x1925c
jmp 0x7afc
leaq 0x1178f(%rip), %rdi     # 0x1928b
xorl %r14d, %r14d
movq 0x8(%rsp), %rsi
xorl %eax, %eax
callq 0xb41e
jmp 0x7abc