// File: /workspace/github_c_makefile_star2_O1/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, 0x8(%rsp)
movq %rdi, 0x18(%rsp)
movq %rsi, 0x28(%rsp)
movl $0x0, 0xc(%rsp)
movl %edx, 0x10(%rsp)
movl %edx, %r13d
movl $0x0, 0x24(%rsp)
movq %rsi, %rdi
movq %rsi, %r12
movl $0x1, %esi
callq 0x6270
testq %rax, %rax
je 0x492dc
movq %rax, %r15
leaq 0x1(%rax), %rdi
movl $0x1, %esi
callq 0x6270
testq %rax, %rax
je 0x493a8
movq %rax, %r14
jmp 0x492f5
movq %r12, %rdi
callq 0x62d0
movq %rax, %r15
addq %r12, %r15
movl $0x1, 0x24(%rsp)
xorl %r14d, %r14d
movq %r12, %rsi
movq %r15, %r12
subq %rsi, %r12
movl %r13d, %ebp
subl %r12d, %ebp
jge 0x49348
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movl $0x1, %r14d
cmpl $0x0, 0x14(%rsp)
jne 0x4954a
movl 0x8(%rsp), %edi
movq %rsi, %r15
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
leaq 0x4e244(%rip), %rdx     # 0x97573
movq 0x28(%rsp), %rcx
movl 0x10(%rsp), %r8d
xorl %eax, %eax
callq 0x491d6
movq %r15, %rsi
jmp 0x4954a
movl %ebx, 0x20(%rsp)
movslq %r12d, %rbx
movq 0x18(%rsp), %r13
movq %r13, %rdi
movq %rsi, 0x30(%rsp)
movq %rbx, %rdx
callq 0x6c60
addq %rbx, %r13
movl 0xc(%rsp), %ecx
movl 0x24(%rsp), %eax
addl %r12d, %ecx
movl %ecx, 0xc(%rsp)
testl %eax, %eax
je 0x493d7
testl %ebp, %ebp
movl 0x20(%rsp), %ebx
jle 0x49415
decl %ebp
movb $0x0, (%r13)
incq %r13
movq %r13, 0x18(%rsp)
movl $0x3, %r14d
movl %ebp, %r13d
movq 0x30(%rsp), %rsi
jmp 0x4954a
movl $0xfffffffe, %ebx       # imm = 0xFFFFFFFE
movl 0x8(%rsp), %edi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
leaq 0x4e185(%rip), %rdx     # 0x97542
movq 0x28(%rsp), %rcx
xorl %eax, %eax
callq 0x491d6
movl $0x1, %r14d
movq %r12, %rsi
jmp 0x4954a
incq %r15
movb $0x0, (%r14)
movzbl 0x1(%r14), %eax
leal -0x2(%rax), %ecx
cmpl $0x4, %ecx
movl 0x20(%rsp), %ebx
ja 0x4951a
leaq 0x4d5a2(%rip), %rdx     # 0x9699c
movslq (%rdx,%rcx,4), %rax
addq %rdx, %rax
jmpq *%rax
movq %r15, %rdi
movq %r13, %rsi
movl %ebp, %edx
callq 0x48017
jmp 0x494bc
movq %r13, 0x18(%rsp)
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movl $0x1, %r14d
cmpl $0x0, 0x14(%rsp)
movq 0x30(%rsp), %rsi
jne 0x49547
movl 0x8(%rsp), %edi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
leaq 0x4e16c(%rip), %rdx     # 0x975b1
movq 0x28(%rsp), %rcx
movl 0x10(%rsp), %r8d
xorl %eax, %eax
callq 0x491d6
movq 0x30(%rsp), %rsi
jmp 0x49547
movq %r15, %rdi
movq %r13, %rsi
movl %ebp, %edx
leaq 0x4d5ce(%rip), %rcx     # 0x96a3d
jmp 0x494b0
movq %r15, %rdi
movq %r13, %rsi
movl %ebp, %edx
leaq 0x4d5b8(%rip), %rcx     # 0x96a38
leaq 0x44f6b(%rip), %r8      # 0x8e3f2
jmp 0x494b7
movq %r15, %rdi
movq %r13, %rsi
movl %ebp, %edx
leaq 0x4d59c(%rip), %rcx     # 0x96a34
leaq 0x4c9a5(%rip), %r8      # 0x95e44
jmp 0x494b7
movq %r15, %rdi
movq %r13, %rsi
movl %ebp, %edx
leaq 0x4d58a(%rip), %rcx     # 0x96a3a
leaq 0x4eea9(%rip), %r8      # 0x98360
callq 0x4819c
movb $0x1, (%r14)
testl %eax, %eax
js 0x494e0
movl %eax, %ecx
addq %rcx, %r13
movq %r13, 0x18(%rsp)
addl %eax, 0xc(%rsp)
subl %eax, %ebp
addq $0x2, %r14
movq %r14, %rsi
xorl %r14d, %r14d
jmp 0x49547
movq %r13, 0x18(%rsp)
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movl $0x1, %r14d
cmpl $0x0, 0x14(%rsp)
jne 0x49544
movl 0x8(%rsp), %edi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
leaq 0x4e143(%rip), %rdx     # 0x9764a
movq 0x28(%rsp), %rcx
movl 0x10(%rsp), %r8d
xorl %eax, %eax
callq 0x491d6
jmp 0x49544
movq %r13, 0x18(%rsp)
movsbl %al, %ecx
movl $0xfffffffe, %ebx       # imm = 0xFFFFFFFE
movl 0x8(%rsp), %edi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
leaq 0x4e0cd(%rip), %rdx     # 0x97604
xorl %eax, %eax
callq 0x491d6
movl $0x1, %r14d
movq %r15, %rsi
movl %ebp, %r13d
testl %r14d, %r14d
je 0x492a8
cmpl $0x3, %r14d
je 0x4955d
movl %ebx, 0xc(%rsp)
movl 0xc(%rsp), %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq