// File: /workspace/github_c_makefile_star2_O3/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
pushq %rax
movl %esi, %ebx
movq %rdi, %r14
callq 0xc480
leaq (%rax,%rax,2), %rdi
incq %rdi
movl $0x1, %esi
callq 0xc7f0
movq %rax, %r13
addq $0x2, %r14
leaq 0x9f04(%rip), %rbp      # 0x496e0
leaq 0x9f42(%rip), %r12      # 0x49725
movabsq $-0x5ffffffa5fffffff, %r15 # imm = 0xA0000005A0000001
movq %rax, (%rsp)
movb -0x2(%r14), %al
movzbl %al, %ecx
cmpl $0x3d, %ecx
jle 0x3f814
leal -0x3e(%rcx), %edx
cmpl $0x3f, %edx
ja 0x3f895
btq %rdx, %r15
jb 0x3f841
jmp 0x3f895
leal -0x20(%rcx), %edx
cmpl $0x5, %edx
ja 0x3f83c
movslq (%rbp,%rdx,4), %rdx
addq %rbp, %rdx
jmpq *%rdx
testb %bl, %bl
je 0x3f89b
movl $0x4, %esi
movq %r13, %rdi
movq %r12, %rdx
movl $0x23, %ecx
jmp 0x3f84c
cmpl $0x3c, %ecx
jne 0x3f891
movl $0x4, %esi
movq %r13, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0xc570
movl $0x3, %eax
addq %rax, %r13
incq %r14
jmp 0x3f7f1
callq 0xd0f0
movq (%rax), %rax
movsbq -0x1(%r14), %rcx
testb $0x10, 0x1(%rax,%rcx,2)
je 0x3f87f
movsbq (%r14), %rcx
testb $0x10, 0x1(%rax,%rcx,2)
jne 0x3f8a2
movl $0x4, %esi
movq %r13, %rdi
movq %r12, %rdx
movl $0x25, %ecx
jmp 0x3f84c
testl %ecx, %ecx
je 0x3f8ae
movb %al, (%r13)
jmp 0x3f8a7
movb $0x23, (%r13)
jmp 0x3f8a7
movb $0x25, (%r13)
movl $0x1, %eax
jmp 0x3f858
movq (%rsp), %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq