// File: /workspace/github_c_makefile_star2_O3/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 $0x28, %rsp
movl %r8d, 0xc(%rsp)
movl %ecx, 0x4(%rsp)
movl %edx, %ebx
movq %rsi, %rbp
movq %rdi, %r14
xorl %r13d, %r13d
movq %rsi, 0x10(%rsp)
movl %edx, 0x8(%rsp)
movq %rbp, %rdi
movl $0x1, %esi
callq 0x6270
testq %rax, %rax
movq %rax, 0x20(%rsp)
je 0x49624
movq %rax, %r15
leaq 0x1(%rax), %rdi
movl $0x1, %esi
callq 0x6270
testq %rax, %rax
je 0x4975e
movq %rax, %r12
jmp 0x49635
movq %rbp, %rdi
callq 0x62d0
movq %rax, %r15
addq %rbp, %r15
xorl %r12d, %r12d
movq %rbp, %rsi
movq %r15, %rbp
subq %rsi, %rbp
subl %ebp, %ebx
jl 0x49724
movq %r13, 0x18(%rsp)
movslq %ebp, %r13
movq %r14, %rdi
movq %r13, %rdx
callq 0x6c60
addq %r13, %r14
movq 0x18(%rsp), %r13
addl %ebp, %r13d
cmpq $0x0, 0x20(%rsp)
je 0x4973e
movb $0x0, (%r12)
movzbl 0x1(%r12), %ecx
leal -0x2(%rcx), %eax
cmpl $0x4, %eax
ja 0x497c8
incq %r15
leaq 0x4d3eb(%rip), %rcx     # 0x96a7c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %r15, %rdi
movq %r14, %rsi
movl %ebx, %edx
callq 0x483a8
jmp 0x49705
movq %r15, %rdi
movq %r14, %rsi
movl %ebx, %edx
leaq 0x4d465(%rip), %rcx     # 0x96b1d
jmp 0x496f9
movq %r15, %rdi
movq %r14, %rsi
movl %ebx, %edx
leaq 0x4d44f(%rip), %rcx     # 0x96b18
leaq 0x44d62(%rip), %r8      # 0x8e432
jmp 0x49700
movq %r15, %rdi
movq %r14, %rsi
movl %ebx, %edx
leaq 0x4d433(%rip), %rcx     # 0x96b14
leaq 0x4c83c(%rip), %r8      # 0x95f24
jmp 0x49700
movq %r15, %rdi
movq %r14, %rsi
movl %ebx, %edx
leaq 0x4d421(%rip), %rcx     # 0x96b1a
leaq 0x4ed54(%rip), %r8      # 0x98454
callq 0x4852c
movb $0x1, (%r12)
testl %eax, %eax
js 0x49748
movl %eax, %ecx
addq %rcx, %r14
addl %eax, %r13d
subl %eax, %ebx
addq $0x2, %r12
movq %r12, %rbp
jmp 0x495ee
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
cmpl $0x0, 0xc(%rsp)
jne 0x497b6
leaq 0x4df17(%rip), %rdx     # 0x97653
jmp 0x49796
testl %ebx, %ebx
jle 0x49782
movb $0x0, (%r14)
jmp 0x497b6
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
cmpl $0x0, 0xc(%rsp)
jne 0x497b6
leaq 0x4dfce(%rip), %rdx     # 0x9772a
jmp 0x49796
leaq 0x4debd(%rip), %rdx     # 0x97622
movl $0xfffffffe, %r13d      # imm = 0xFFFFFFFE
movl 0x4(%rsp), %edi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
movq 0x10(%rsp), %rcx
xorl %eax, %eax
callq 0x49529
jmp 0x497b6
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
cmpl $0x0, 0xc(%rsp)
jne 0x497b6
leaq 0x4defb(%rip), %rdx     # 0x97691
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
movl 0x4(%rsp), %edi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movq 0x10(%rsp), %rcx
movl 0x8(%rsp), %r8d
xorl %eax, %eax
callq 0x49529
movl %r13d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movsbl %cl, %ecx
leaq 0x4df12(%rip), %rdx     # 0x976e4
movl $0xfffffffe, %r13d      # imm = 0xFFFFFFFE
movl 0x4(%rsp), %edi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
xorl %eax, %eax
callq 0x49529
jmp 0x497b6