// File: /workspace/github_c_makefile_star2_O3/icebert[P]pblat/lib/cheapcgi.c
// Function: cgiMakeSelectDropList
char *cgiMakeSelectDropList(boolean multiple, char *name, struct slPair *valsAndLabels,
                            char *selected, char *anyAll,char *extraClasses, char *event, char *javascript, char *style, char *id)
// Returns allocated string of HTML defining a drop-down select
// (if multiple, REQUIRES ui-dropdownchecklist.js)
// valsAndLabels: val (pair->name) must be filled in but label (pair->val) may be NULL.
// selected: if not NULL is a val found in the valsAndLabels (multiple then comma delimited list).
//           If null and anyAll not NULL, that will be selected
// anyAll: if not NULL is the string for an initial option. It can contain val and label,
//         delimited by a comma
// event: click, etc.
// javacript: what to execute when the event happens.
// style: inline style
// id is optional
{
struct dyString *output = dyStringNew(1024);
boolean checked = FALSE;

dyStringPrintf(output,"<SELECT name='%s'",name);
if (multiple)
    dyStringAppend(output," MULTIPLE");
if (extraClasses != NULL)
    dyStringPrintf(output," class='%s%s'",extraClasses,(multiple ? " filterBy" : ""));
else if (multiple)
    dyStringAppend(output," class='filterBy'");

char *autoId = NULL;
if (javascript)
    {
    if (!id)
	{
    	id = name;
	}
    }
if (id)
    dyStringPrintf(output, " id='%s'", id);
if (javascript)
    {
    jsOnEventById(event, id, javascript);
    freeMem(autoId);
    }

if (style)
    {
    dyStringPrintf(output, " style='%s'", style);
    }

dyStringAppend(output,">\n");

// Handle initial option "Any" or "All"
if (anyAll != NULL)
    {
    char *val = anyAll;  // Could contain a label after the value
    char *label = strchr(val,',');  // Could contain a label after the value
    if (label != NULL)
        {
        val = cloneString(anyAll);
        label = strchr(val,',');  // again because this is new mem
        *label = '\0';
        label = label+1;
        }
    else
        label = val;
    checked = TRUE; // The default case
    if (selected != NULL)
        {
        if (multiple)
            checked = (findWordByDelimiter(val,',', selected) != NULL);
        else
            checked = sameString(val,selected);
        }
    dyStringPrintf(output, "<OPTION%s VALUE='%s'>%s</OPTION>\n",(checked ? " SELECTED" : ""),
                   val, javaScriptLiteralEncode(label));
    if (label != val)
        freeMem(val);
    }

// All other options
struct slPair *valPair = valsAndLabels;
for (; valPair != NULL; valPair = valPair->next)
    {
    checked = FALSE;
    if (selected != NULL)
        {
        if (multiple)
            checked = (findWordByDelimiter(valPair->name,',', selected) != NULL);
        else
            checked = sameString(valPair->name,selected);
        }
    char *label = valPair->name;
    if (valPair->val != NULL)
        label = valPair->val;
    dyStringPrintf(output, "<OPTION%s VALUE='%s'>%s</OPTION>\n",(checked ? " SELECTED" : ""),
                   (char *)valPair->name, javaScriptLiteralEncode(label));
    }

dyStringPrintf(output,"</SELECT>\n");

return dyStringCannibalize(&output);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r9, %r12
movq %r8, 0x8(%rsp)
movq %rcx, %rbx
movq %rdx, %r14
movq %rsi, %r13
movl %edi, %r15d
movl $0x400, %edi            # imm = 0x400
callq 0x264e0
movq %rax, %rbp
movq %rax, 0x10(%rsp)
leaq 0x4f95f(%rip), %rsi     # 0x96485
movq %rax, %rdi
movq %r13, %rdx
xorl %eax, %eax
callq 0x26883
movl %r15d, 0x4(%rsp)
testl %r15d, %r15d
je 0x46b5f
leaq 0x4f953(%rip), %rsi     # 0x96497
movq %rbp, %rdi
callq 0x2674f
testq %r12, %r12
je 0x46b86
leaq 0x4f957(%rip), %rcx     # 0x964af
movq 0x8(%rsp), %r15
jmp 0x46b70
testq %r12, %r12
movq 0x8(%rsp), %r15
je 0x46b9a
leaq 0x518e4(%rip), %rcx     # 0x98454
leaq 0x4f92a(%rip), %rsi     # 0x964a1
movq %rbp, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0x26883
jmp 0x46b9a
leaq 0x4f92c(%rip), %rsi     # 0x964b9
movq %rbp, %rdi
callq 0x2674f
movq 0x8(%rsp), %r15
movq 0x68(%rsp), %rax
testq %rax, %rax
cmovneq %rax, %r13
movq 0x58(%rsp), %r12
testq %r12, %r12
cmoveq %rax, %r13
testq %r13, %r13
je 0x46bd0
leaq 0x4f522(%rip), %rsi     # 0x960e0
movq %rbp, %rdi
movq %r13, %rdx
xorl %eax, %eax
callq 0x26883
movq 0x58(%rsp), %r12
movq 0x60(%rsp), %rdx
testq %r12, %r12
je 0x46c15
movq %rbp, %r15
movq 0x50(%rsp), %rbp
movq %rbp, %rdi
callq 0x441cf
leaq 0x4f002(%rip), %rdi     # 0x95bf3
movq %r13, %rsi
movq %rbp, %rdx
movq %r15, %rbp
movq 0x8(%rsp), %r15
movq %r12, %rcx
xorl %eax, %eax
callq 0x4403b
xorl %edi, %edi
callq 0x2e0a0
movq 0x60(%rsp), %rdx
testq %rdx, %rdx
je 0x46c2b
leaq 0x4f731(%rip), %rsi     # 0x96352
movq %rbp, %rdi
xorl %eax, %eax
callq 0x26883
leaq 0x50860(%rip), %rsi     # 0x97492
movq %rbp, %rdi
callq 0x2674f
testq %r15, %r15
je 0x46cea
movq %r15, %rdi
movl $0x2c, %esi
callq 0x6270
testq %rax, %rax
je 0x46c78
movq %r15, %rdi
callq 0x1feba
movq %rax, %r15
movq %rax, %rdi
movl $0x2c, %esi
callq 0x6270
movq %rax, %r13
movb $0x0, (%rax)
incq %r13
jmp 0x46c7b
movq %r15, %r13
testq %rbx, %rbx
je 0x46c9c
cmpl $0x0, 0x4(%rsp)
je 0x46ca5
movq %r15, %rdi
movl $0x2c, %esi
movq %rbx, %rdx
callq 0x21c4a
testq %rax, %rax
je 0x46cb4
leaq 0x4f6bb(%rip), %r12     # 0x9635e
jmp 0x46cbb
movq %r15, %rdi
movq %rbx, %rsi
callq 0x6a50
testl %eax, %eax
je 0x46c9c
leaq 0x51799(%rip), %r12     # 0x98454
movq %r13, %rdi
callq 0x44fc8
leaq 0x4f801(%rip), %rsi     # 0x964cb
movq %rbp, %rdi
movq %r12, %rdx
movq %r15, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0x26883
cmpq %r15, %r13
je 0x46cea
movq %r15, %rdi
callq 0x2e0a0
movq %rbp, %r15
testq %r14, %r14
je 0x46d9d
leaq 0x4f7ce(%rip), %r12     # 0x964cb
movq 0x8(%r14), %r13
testq %rbx, %rbx
je 0x46d3a
cmpl $0x0, 0x4(%rsp)
je 0x46d4e
movq %r13, %rdi
movl $0x2c, %esi
movq %rbx, %rdx
callq 0x21c4a
movq 0x8(%r14), %r13
movq 0x10(%r14), %rdi
testq %rdi, %rdi
cmoveq %r13, %rdi
leaq 0x51721(%rip), %rbp     # 0x98454
testq %rax, %rax
jne 0x46d6f
jmp 0x46d76
movq 0x10(%r14), %rdi
testq %rdi, %rdi
cmoveq %r13, %rdi
leaq 0x51708(%rip), %rbp     # 0x98454
jmp 0x46d76
movq %r13, %rdi
movq %rbx, %rsi
callq 0x6a50
movq 0x10(%r14), %rdi
testq %rdi, %rdi
cmoveq %r13, %rdi
leaq 0x516e9(%rip), %rbp     # 0x98454
testl %eax, %eax
jne 0x46d76
leaq 0x4f5e8(%rip), %rbp     # 0x9635e
callq 0x44fc8
movq %r15, %rdi
movq %r12, %rsi
movq %rbp, %rdx
movq %r13, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0x26883
movq (%r14), %r14
testq %r14, %r14
jne 0x46cfd
leaq 0x4f5db(%rip), %rsi     # 0x9637f
movq %r15, %rdi
xorl %eax, %eax
callq 0x26883
leaq 0x10(%rsp), %rdi
callq 0x2653c
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq