// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movl %ecx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movq -0x18(%rbp), %rdi
movl $0x1, %esi
callq 0x6260
movq %rax, -0x48(%rbp)
movq $0x0, -0x50(%rbp)
cmpq $0x0, -0x48(%rbp)
je 0x6a7f8
movq -0x48(%rbp), %rdi
addq $0x1, %rdi
movl $0x1, %esi
callq 0x6260
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
jne 0x6a7f6
movl -0x20(%rbp), %edi
movq -0x30(%rbp), %rcx
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
leaq 0x76d44(%rip), %rdx     # 0xe152b
movb $0x0, %al
callq 0x6a680
movl %eax, -0x4(%rbp)
jmp 0x6aa58
jmp 0x6a80e
movq -0x18(%rbp), %rdi
xorl %esi, %esi
callq 0x6260
movq %rax, -0x48(%rbp)
movl $0x1, -0x3c(%rbp)
movq -0x48(%rbp), %rax
movq -0x18(%rbp), %rcx
subq %rcx, %rax
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %eax
cmpl -0x38(%rbp), %eax
jle 0x6a85c
cmpl $0x0, -0x24(%rbp)
je 0x6a836
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6aa58
movl -0x20(%rbp), %edi
movq -0x30(%rbp), %rcx
movl -0x1c(%rbp), %r8d
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
leaq 0x76d0f(%rip), %rdx     # 0xe155c
movb $0x0, %al
callq 0x6a680
movl %eax, -0x4(%rbp)
jmp 0x6aa58
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movslq -0x54(%rbp), %rdx
callq 0x6c60
movl -0x54(%rbp), %ecx
movq -0x10(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x10(%rbp)
movl -0x54(%rbp), %eax
addl -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x54(%rbp), %ecx
movl -0x38(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x38(%rbp)
cmpl $0x0, -0x3c(%rbp)
je 0x6a8f6
cmpl $0x1, -0x38(%rbp)
jge 0x6a8d6
cmpl $0x0, -0x24(%rbp)
je 0x6a8b0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6aa58
movl -0x20(%rbp), %edi
movq -0x30(%rbp), %rcx
movl -0x1c(%rbp), %r8d
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
leaq 0x76cd3(%rip), %rdx     # 0xe159a
movb $0x0, %al
callq 0x6a680
movl %eax, -0x4(%rbp)
jmp 0x6aa58
movl -0x38(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x10(%rbp)
movb $0x0, (%rax)
jmp 0x6aa52
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
movq -0x50(%rbp), %rax
movb $0x0, (%rax)
movq -0x50(%rbp), %rax
movb 0x1(%rax), %al
movb %al, -0x59(%rbp)
movsbl -0x59(%rbp), %eax
cmpl $0x2, %eax
jne 0x6a934
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl -0x38(%rbp), %edx
callq 0x68c00
movl %eax, -0x58(%rbp)
jmp 0x6a9dd
movsbl -0x59(%rbp), %eax
cmpl $0x3, %eax
jne 0x6a955
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl -0x38(%rbp), %edx
callq 0x69360
movl %eax, -0x58(%rbp)
jmp 0x6a9db
movsbl -0x59(%rbp), %eax
cmpl $0x4, %eax
jne 0x6a973
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl -0x38(%rbp), %edx
callq 0x69270
movl %eax, -0x58(%rbp)
jmp 0x6a9d9
movsbl -0x59(%rbp), %eax
cmpl $0x5, %eax
jne 0x6a991
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl -0x38(%rbp), %edx
callq 0x69180
movl %eax, -0x58(%rbp)
jmp 0x6a9d7
movsbl -0x59(%rbp), %eax
cmpl $0x6, %eax
jne 0x6a9af
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl -0x38(%rbp), %edx
callq 0x69450
movl %eax, -0x58(%rbp)
jmp 0x6a9d5
movl -0x20(%rbp), %edi
movq -0x50(%rbp), %rax
movsbl 0x1(%rax), %ecx
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
leaq 0x76c27(%rip), %rdx     # 0xe15ed
movb $0x0, %al
callq 0x6a680
movl %eax, -0x4(%rbp)
jmp 0x6aa58
jmp 0x6a9d7
jmp 0x6a9d9
jmp 0x6a9db
jmp 0x6a9dd
movq -0x50(%rbp), %rax
movb $0x1, (%rax)
cmpl $0x0, -0x58(%rbp)
jge 0x6aa1c
cmpl $0x0, -0x24(%rbp)
je 0x6a9f9
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6aa58
movl -0x20(%rbp), %edi
movq -0x30(%rbp), %rcx
movl -0x1c(%rbp), %r8d
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
leaq 0x76c23(%rip), %rdx     # 0xe1633
movb $0x0, %al
callq 0x6a680
movl %eax, -0x4(%rbp)
jmp 0x6aa58
movl -0x58(%rbp), %ecx
movq -0x10(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x10(%rbp)
movl -0x58(%rbp), %eax
addl -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x58(%rbp), %ecx
movl -0x38(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x38(%rbp)
movq -0x50(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x18(%rbp)
jmp 0x6a796
movl -0x34(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)