// File: /workspace/github_c_makefile_star2_O2/videolan[P]bitstream/examples/./bitstream/common.h
// Function: bitstream_xml_escape_chars
static inline size_t bitstream_xml_escape_chars(const char *str, char *out)
{
    size_t len = 1;

    while (*str) {
        uint32_t codepoint = 0xFFFD;
        const char *p = str;
        int size = 1;

        unsigned char c = *str++;
        if (c < 0x80) {
            codepoint = c;
            switch (c) {
                case '<': p = "&lt;"; size = 4; break;
                case '>': p = "&gt;"; size = 4; break;
                case '"': p = "&quot;"; size = 6; break;
                case '\'': p = "&apos;"; size = 6; break;
                case '&': p = "&amp;"; size = 5; break;
            }
        } else if ((c & 0xE0) == 0xC0) {
            if ((str[0] & 0xC0) == 0x80) {
                codepoint = ((c & 0x1F) << 6) |
                    (str[0] & 0x3F);
                size = 2;
                str += 1;
            }
        } else if ((c & 0xF0) == 0xE0) {
            if ((str[0] & 0xC0) == 0x80 &&
                (str[1] & 0xC0) == 0x80) {
                codepoint = ((c & 0x0F) << 12) |
                    ((str[0] & 0x3F) << 6) |
                    (str[1] & 0x3F);
                size = 3;
                str += 2;
            }
        } else if ((c & 0xF8) == 0xF0) {
            if ((str[0] & 0xC0) == 0x80 &&
                (str[1] & 0xC0) == 0x80 &&
                (str[2] & 0xC0) == 0x80) {
                codepoint = ((c & 0x07) << 18) |
                    ((str[0] & 0x3F) << 12) |
                    ((str[1] & 0x3F) << 6) |
                    (str[2] & 0x3F);
                size = 4;
                str += 3;
            }
        }

        // #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]
        if (codepoint == 0xFFFD ||
            !(codepoint == 0x9 ||
              codepoint == 0xA ||
              codepoint == 0xD ||
              (codepoint >= 0x20 && codepoint <= 0xD7FF) ||
              (codepoint >= 0xE000 && codepoint <= 0xFFFD) ||
              (codepoint >= 0x10000 && codepoint <= 0x10FFFF))) {
            p = "\uFFFD";
            size = 3;
        }

        if (out) {
            memcpy(out, p, size);
            out += size;
        }
        len += size;
    }

    if (out)
        *out = '\0';
    return len;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %rsi
pushq $0x1
popq %rbx
pushq $0x3
popq %r12
leaq 0x51f9(%rip), %r13      # 0x11a63
movzbl (%rsi), %eax
testl %eax, %eax
je 0xca63
leaq 0x1(%rsi), %rbp
testb %al, %al
js 0xc8bb
cmpl $0x22, %eax
je 0xc994
cmpl $0x26, %eax
je 0xc951
cmpl $0x27, %eax
je 0xc96b
cmpl $0x3c, %eax
je 0xc95f
cmpl $0x3e, %eax
jne 0xc979
pushq $0x4
popq %rcx
leaq 0x5196(%rip), %rsi      # 0x11a4a
pushq $0x3e
jmp 0xc9a0
movl %eax, %ecx
andl $-0x20, %ecx
cmpl $0xc0, %ecx
jne 0xc8f5
movzbl (%rbp), %ecx
movl %ecx, %edx
andl $-0x40, %edx
cmpl $0x80, %edx
jne 0xc9c6
andl $0x1f, %eax
shll $0x6, %eax
andl $0x3f, %ecx
orl %eax, %ecx
leaq 0x2(%rsi), %rbp
movl %ecx, %eax
pushq $0x2
jmp 0xc97b
movl %eax, %ecx
andl $-0x10, %ecx
cmpl $0xe0, %ecx
jne 0xc9f2
movsbl (%rbp), %ecx
movl %ecx, %edx
andl $0xc0, %edx
cmpl $0x80, %edx
jne 0xc9c6
movzbl 0x2(%rsi), %edx
movl %edx, %edi
andl $-0x40, %edi
cmpl $0x80, %edi
jne 0xc9c6
shll $0xc, %eax
movzwl %ax, %eax
andl $0x3f, %ecx
shll $0x6, %ecx
orl %eax, %ecx
andl $0x3f, %edx
orl %ecx, %edx
leaq 0x3(%rsi), %rbp
movl %edx, %eax
movl %r12d, %ecx
jmp 0xc97c
pushq $0x5
popq %rcx
leaq 0x5102(%rip), %rsi      # 0x11a5d
pushq $0x26
jmp 0xc9a0
pushq $0x4
popq %rcx
leaq 0x50dc(%rip), %rsi      # 0x11a45
jmp 0xc9a1
pushq $0x6
popq %rcx
leaq 0x50e1(%rip), %rsi      # 0x11a56
pushq $0x27
jmp 0xc9a0
pushq $0x1
popq %rcx
cmpl $0xd, %eax
ja 0xc98b
movl $0x2600, %edx           # imm = 0x2600
btl %eax, %edx
jb 0xc9cc
cmpl $0xfffd, %eax           # imm = 0xFFFD
je 0xc9c6
jmp 0xc9a1
pushq $0x6
popq %rcx
leaq 0x50b1(%rip), %rsi      # 0x11a4f
pushq $0x22
popq %rax
leal -0x10000(%rax), %edx
cmpl $0x100000, %edx         # imm = 0x100000
jb 0xc9cc
leal -0x20(%rax), %edx
cmpl $0xd7e0, %edx           # imm = 0xD7E0
jb 0xc9cc
addl $0xffff2000, %eax       # imm = 0xFFFF2000
cmpl $0x1ffe, %eax           # imm = 0x1FFE
jb 0xc9cc
movq %r13, %rsi
movl %r12d, %ecx
movl %ecx, %r15d
testq %r14, %r14
je 0xc9e4
movq %r14, %rdi
movq %r15, %rdx
callq 0x2150
addq %r15, %r14
jmp 0xc9e7
xorl %r14d, %r14d
addq %r15, %rbx
movq %rbp, %rsi
jmp 0xc86a
movl %eax, %ecx
andl $-0x8, %ecx
cmpl $0xf0, %ecx
jne 0xc9c6
movsbl (%rbp), %ecx
movl %ecx, %edx
andl $0xc0, %edx
cmpl $0x80, %edx
jne 0xc9c6
movsbl 0x2(%rsi), %edx
movl %edx, %edi
andl $0xc0, %edi
cmpl $0x80, %edi
jne 0xc9c6
movzbl 0x3(%rsi), %edi
movl %edi, %r8d
andl $-0x40, %r8d
cmpl $0x80, %r8d
jne 0xc9c6
andl $0x7, %eax
shll $0x12, %eax
andl $0x3f, %ecx
shll $0xc, %ecx
orl %eax, %ecx
andl $0x3f, %edx
shll $0x6, %edx
orl %ecx, %edx
andl $0x3f, %edi
orl %edx, %edi
leaq 0x4(%rsi), %rbp
movl %edi, %eax
pushq $0x4
jmp 0xc97b
testq %r14, %r14
je 0xca6c
movb $0x0, (%r14)
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq