// File: /workspace/github_c_makefile_star2_O0/icebert[P]pblat/lib/htmshell.c
// Function: htmlEncodeTextExtended
int htmlEncodeTextExtended(char *s, char *out, int outSize)
/* Replaces required punctuation characters with html entities to fight XSS. 
 * out result must be large enough to receive the encoded string.
 * Returns size of encoded string or -1 if output larger than outSize. 
 * To just get the final encoded size, pass in NULL for out and 0 for outSize. 
 * To output without checking sizes, pass in non-NULL for out and 0 for outSize. 
 */
{
int total = 0;
char c = 0;
do
    {
    c=*s++;
    int size = 1;
    char *newString = NULL; 
    if (c == '&') { size = 5; newString = "&amp;"; } // '&' start a control char
    if (c == '>') { size = 4; newString = "&gt;" ; } // '>' close of tag
    if (c == '<') { size = 4; newString = "&lt;" ; } // '<' open  of tag
    if (c == '/')  { size = 6; newString = "&#x2F;"; } // forward slash helps end an HTML entity
    if (c == '"')  { size = 6; newString = "&quot;"; } // double quote
    if (c == '\'') { size = 5; newString = "&#39;" ; } // single quote
    if (out)
	{
	if (outSize > 0 && (total+size+1) > outSize) // 1 for terminator
	    {
	    *out = 0;
	    return -1;
	    }
	if (size == 1)
	    *out++ = c;
	else
	    {
	    strncpy(out, newString, size);
	    out += size;
	    }
	}
    total += size;
    } while (c != 0);
return total - 1; // do not count terminating 0
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
movb $0x0, -0x21(%rbp)
movq -0x10(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x10(%rbp)
movb (%rax), %al
movb %al, -0x21(%rbp)
movl $0x1, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movsbl -0x21(%rbp), %eax
cmpl $0x26, %eax
jne 0x68c5c
movl $0x5, -0x28(%rbp)
leaq 0x77d74(%rip), %rax     # 0xe09cc
movq %rax, -0x30(%rbp)
movsbl -0x21(%rbp), %eax
cmpl $0x3e, %eax
jne 0x68c77
movl $0x4, -0x28(%rbp)
leaq 0x77d4f(%rip), %rax     # 0xe09c2
movq %rax, -0x30(%rbp)
movsbl -0x21(%rbp), %eax
cmpl $0x3c, %eax
jne 0x68c92
movl $0x4, -0x28(%rbp)
leaq 0x77d39(%rip), %rax     # 0xe09c7
movq %rax, -0x30(%rbp)
movsbl -0x21(%rbp), %eax
cmpl $0x2f, %eax
jne 0x68cad
movl $0x6, -0x28(%rbp)
leaq 0x77d57(%rip), %rax     # 0xe0a00
movq %rax, -0x30(%rbp)
movsbl -0x21(%rbp), %eax
cmpl $0x22, %eax
jne 0x68cc8
movl $0x6, -0x28(%rbp)
leaq 0x77d0e(%rip), %rax     # 0xe09d2
movq %rax, -0x30(%rbp)
movsbl -0x21(%rbp), %eax
cmpl $0x27, %eax
jne 0x68ce3
movl $0x5, -0x28(%rbp)
leaq 0x77d28(%rip), %rax     # 0xe0a07
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x68d4e
cmpl $0x0, -0x1c(%rbp)
jle 0x68d0e
movl -0x20(%rbp), %eax
addl -0x28(%rbp), %eax
addl $0x1, %eax
cmpl -0x1c(%rbp), %eax
jle 0x68d0e
movq -0x18(%rbp), %rax
movb $0x0, (%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x68d6d
cmpl $0x1, -0x28(%rbp)
jne 0x68d2a
movb -0x21(%rbp), %cl
movq -0x18(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x18(%rbp)
movb %cl, (%rax)
jmp 0x68d4c
movq -0x18(%rbp), %rdi
movq -0x30(%rbp), %rsi
movslq -0x28(%rbp), %rdx
callq 0x6370
movl -0x28(%rbp), %ecx
movq -0x18(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x18(%rbp)
jmp 0x68d4e
movl -0x28(%rbp), %eax
addl -0x20(%rbp), %eax
movl %eax, -0x20(%rbp)
movsbl -0x21(%rbp), %eax
cmpl $0x0, %eax
jne 0x68c1e
movl -0x20(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)