// File: /workspace/github_c_makefile_star2_O2/icebert[P]pblat/lib/htmshell.c
// Function: htmlEscapeAllStrings
int htmlEscapeAllStrings(char *buffer, char *s, int bufSize, boolean noAbort, boolean noWarnOverflow)
/* Escape all strings. *
 * Returns final size not including terminating 0. 
 * User needs to pre-allocate enough space that escape functions will never run out of space.
 * This function should be efficient on statements with many strings to be escaped. */
{
char *sOrig = s;
int sz = 0;
int remainder = bufSize;
boolean done = FALSE;
while (1)
    {
    char *start = strchr(s, htmlSafefPunc);
    char *end = NULL;
    if (start)
	{
    	end = strchr(start+1, htmlSafefPunc); // skip over punc mark
	if (!end)
	    {
	    return htmlSafefAbort(noAbort, -2, "Unexpected error in htmlEscapeAllStrings. s=[%s]", sOrig);
	    }
	}
    else
	{
	// just copy remainder of the input string to output
    	start = strchr(s, 0); // find end of string
	done = TRUE;	
	}
    // move any non-escaped part
    int moveSize = start - s;
    if (moveSize > remainder)
	{
	if (noWarnOverflow) return -1; // speed
	return htmlSafefAbort(noAbort, -1, "Buffer too small in htmlEscapeAllStrings. s=[%s] bufSize = %d", sOrig, bufSize);
	}
    memmove(buffer, s, moveSize);
    buffer += moveSize;
    sz += moveSize;
    remainder -= moveSize;
    if (done)
	{
	if (remainder < 1)
	    {
	    if (noWarnOverflow) return -1; // speed
	    return htmlSafefAbort(noAbort, -1, "Buffer too small for terminating zero in htmlEscapeAllStrings. s=[%s] bufSize = %d", sOrig, bufSize);
	    }
	--remainder;
	*buffer++ = 0;  // terminating 0
	// do not include term 0 in sz count;
	break;
	}
    // escape the quoted part
    s = start + 1;
    *end = 0;  // mark end of "input" string, replacing htmlSafefPunc. input string is temporary anyway.

    int escSize;
    char enc = *(end+1);
    if (enc == (enum htmlSafefEncoding) html)
	{
	escSize = htmlEncodeTextExtended(s,buffer,remainder);
	}
    else if (enc == (enum htmlSafefEncoding) js)
	escSize = javascriptEncodeTextExtended(s,buffer,remainder);
    else if (enc == (enum htmlSafefEncoding) css)
	escSize = cssEncodeTextExtended(s,buffer,remainder);
    else if (enc == (enum htmlSafefEncoding) attr)
	escSize = attrEncodeTextExtended(s,buffer,remainder);
    else if (enc == (enum htmlSafefEncoding) url)
	{
	escSize = urlEncodeTextExtended(s,buffer,remainder);
	}
    else 
	{
	return htmlSafefAbort(noAbort, -2, "Unexpected error in htmlEscapeAllStrings. (enum htmlSafefEncoding)=%c", *(end+1));
	}
    *end = htmlSafefPunc;  // restore mark, helps error message
	
    if (escSize < 0)
	{
	if (noWarnOverflow) return -1; // speed
	return htmlSafefAbort(noAbort, -1, "Buffer too small for escaping in htmlEscapeAllStrings. s=[%s] bufSize = %d", sOrig, bufSize);
	}

    buffer += escSize;
    sz += escSize;
    remainder -= escSize;
    s = end + 2; // skip past htmlSafefPunc and htmlSafefEncoding (encoding type)
    }
return sz;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %r8d, 0x14(%rsp)
movl %ecx, 0xc(%rsp)
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %r13
xorl %r15d, %r15d
pushq $0x1
popq %r12
movq %rsi, 0x18(%rsp)
movl %edx, 0x10(%rsp)
movq %r14, %rdi
movl %r12d, %esi
callq 0x6270
testq %rax, %rax
movq %r13, 0x30(%rsp)
movq %rax, 0x28(%rsp)
je 0x42f45
leaq 0x1(%rax), %rdi
movq %rax, %rbx
movl %r12d, %esi
callq 0x6270
testq %rax, %rax
je 0x4306d
movq %rax, %r12
movl %ebp, %r13d
jmp 0x42f59
movl %ebp, %r13d
movq %r14, %rdi
callq 0x62d0
movq %rax, %rbx
addq %r14, %rbx
xorl %r12d, %r12d
movq %r14, %rsi
movq %rbx, %rbp
subq %r14, %rbp
subl %ebp, %r13d
jl 0x43042
movq 0x30(%rsp), %r14
movq %r15, 0x20(%rsp)
movslq %ebp, %r15
movq %r14, %rdi
movq %r15, %rdx
callq 0x6c60
addq %r15, %r14
movq 0x20(%rsp), %r15
addl %ebp, %r15d
cmpq $0x0, 0x28(%rsp)
je 0x43052
movb $0x0, (%r12)
movzbl 0x1(%r12), %ecx
leal -0x2(%rcx), %eax
cmpl $0x4, %eax
ja 0x4309a
movl %r13d, %ebp
incq %rbx
leaq 0x429be(%rip), %rcx     # 0x8597c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %rbx, %rdi
movq %r14, %r13
movq %r14, %rsi
movl %ebp, %edx
callq 0x41c7d
jmp 0x4301f
movq %rbx, %rdi
movq %r14, %r13
movq %r14, %rsi
movl %ebp, %edx
callq 0x4210a
jmp 0x4301f
movq %rbx, %rdi
movq %r14, %r13
movq %r14, %rsi
movl %ebp, %edx
callq 0x42044
jmp 0x4301f
movq %rbx, %rdi
movq %r14, %r13
movq %r14, %rsi
movl %ebp, %edx
callq 0x41fe1
jmp 0x4301f
movq %rbx, %rdi
movq %r14, %r13
movq %r14, %rsi
movl %ebp, %edx
callq 0x420a7
movb $0x1, (%r12)
testl %eax, %eax
js 0x4305d
movl %eax, %ecx
addq %rcx, %r13
addl %eax, %r15d
subl %eax, %ebp
addq $0x2, %r12
movq %r12, %r14
pushq $0x1
popq %r12
jmp 0x42f0b
cmpl $0x0, 0x14(%rsp)
jne 0x43094
leaq 0x43503(%rip), %rdx     # 0x86553
jmp 0x430bf
testl %r13d, %r13d
jle 0x4308d
movb $0x0, (%r14)
jmp 0x430db
cmpl $0x0, 0x14(%rsp)
jne 0x43094
leaq 0x435bf(%rip), %rdx     # 0x8662a
jmp 0x430bf
leaq 0x434ae(%rip), %rdx     # 0x86522
pushq $-0x2
popq %r15
movl 0xc(%rsp), %edi
movl %r15d, %esi
movq 0x18(%rsp), %rcx
xorl %eax, %eax
callq 0x42e1b
jmp 0x430db
cmpl $0x0, 0x14(%rsp)
je 0x430b8
pushq $-0x1
popq %r15
jmp 0x430db
movsbl %cl, %ecx
leaq 0x43540(%rip), %rdx     # 0x865e4
pushq $-0x2
popq %r15
movl 0xc(%rsp), %edi
movl %r15d, %esi
xorl %eax, %eax
callq 0x42e1b
jmp 0x430db
leaq 0x434d2(%rip), %rdx     # 0x86591
pushq $-0x1
popq %r15
movl 0xc(%rsp), %edi
movl %r15d, %esi
movq 0x18(%rsp), %rcx
movl 0x10(%rsp), %r8d
xorl %eax, %eax
callq 0x42e1b
movl %r15d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq