// File: /workspace/github_c_makefile_star2_O2/Paxa[P]fast_excel/libxlsxwriter/src/xmlwriter.c
// Function: lxw_escape_url_characters
char *
lxw_escape_url_characters(const char *string, uint8_t escape_hash)
{

    size_t escape_len = sizeof("%XX") - 1;
    size_t encoded_len = (strlen(string) * escape_len + 1);

    char *encoded = (char *) calloc(encoded_len, 1);
    char *p_encoded = encoded;

    while (*string) {
        switch (*string) {
            case ' ':
            case '"':
            case '<':
            case '>':
            case '[':
            case ']':
            case '`':
            case '^':
            case '{':
            case '}':
                lxw_snprintf(p_encoded, escape_len + 1, "%%%2x", *string);
                p_encoded += escape_len;
                break;
            case '#':
                /* This is only escaped for "external:" style links. */
                if (escape_hash) {
                    lxw_snprintf(p_encoded, escape_len + 1, "%%%2x", *string);
                    p_encoded += escape_len;
                }
                else {
                    *p_encoded = *string;
                    p_encoded++;
                }
                break;
            case '%':
                /* Only escape % if it isn't already an escape. */
                if (!isxdigit(*(string + 1)) || !isxdigit(*(string + 2))) {
                    lxw_snprintf(p_encoded, escape_len + 1, "%%%2x", *string);
                    p_encoded += escape_len;
                }
                else {
                    *p_encoded = *string;
                    p_encoded++;
                }
                break;
            default:
                *p_encoded = *string;
                p_encoded++;
                break;
        }
        string++;
    }

    return encoded;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %esi, 0xc(%rsp)
movq %rdi, %r14
callq 0xc4c0
leaq (%rax,%rax,2), %rdi
incq %rdi
pushq $0x1
popq %rsi
callq 0xc850
movq %rax, %r12
addq $0x2, %r14
leaq 0x9d9a(%rip), %r15      # 0x466d0
leaq 0x9dd8(%rip), %r13      # 0x46715
pushq $0x4
popq %rbp
pushq $0x3
popq %rbx
movq %rax, 0x10(%rsp)
movb -0x2(%r14), %al
movzbl %al, %ecx
leal -0x3e(%rcx), %edx
cmpl $0x3f, %edx
ja 0x3c967
movabsq $-0x5ffffffa5fffffff, %rsi # imm = 0xA0000005A0000001
btq %rdx, %rsi
jb 0x3c99b
leal -0x20(%rcx), %edx
cmpl $0x5, %edx
ja 0x3c98c
movslq (%r15,%rdx,4), %rdx
addq %r15, %rdx
jmpq *%rdx
cmpb $0x0, 0xc(%rsp)
je 0x3c9e3
movq %r12, %rdi
movq %rbp, %rsi
movq %r13, %rdx
pushq $0x23
jmp 0x3c9e0
cmpl $0x3c, %ecx
je 0x3c99b
testl %ecx, %ecx
je 0x3c9f4
movb %al, (%r12)
jmp 0x3c9ef
movq %r12, %rdi
movq %rbp, %rsi
movq %r13, %rdx
xorl %eax, %eax
callq 0xc5b0
movq %rbx, %rax
addq %rax, %r12
incq %r14
jmp 0x3c948
callq 0xd170
movq (%rax), %rax
movsbq -0x1(%r14), %rcx
testb $0x10, 0x1(%rax,%rcx,2)
je 0x3c9d5
movsbq (%r14), %rcx
testb $0x10, 0x1(%rax,%rcx,2)
jne 0x3c9ea
movq %r12, %rdi
movq %rbp, %rsi
movq %r13, %rdx
pushq $0x25
popq %rcx
jmp 0x3c9a4
movb $0x23, (%r12)
jmp 0x3c9ef
movb $0x25, (%r12)
pushq $0x1
popq %rax
jmp 0x3c9ae
movq 0x10(%rsp), %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq