// File: /workspace/github_c_makefile_star2_O1/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, %rbx
movb (%rdi), %al
testb %al, %al
je 0x116aa
movq %rdi, %r15
movl $0x1, %r14d
leaq 0x4435(%rip), %rbp      # 0x1589b
movl $0x2600, %r13d          # imm = 0x2600
leaq 0x1(%r15), %rdx
movzbl %al, %eax
testb %al, %al
js 0x114ad
movl $0x1, %ecx
cmpl $0x26, %eax
jle 0x114ec
cmpl $0x27, %eax
je 0x11579
cmpl $0x3e, %eax
je 0x1158a
cmpl $0x3c, %eax
jne 0x1163b
movl $0x4, %ecx
leaq 0x43d5(%rip), %rsi      # 0x1587d
jmp 0x1163e
movl %eax, %ecx
andl $-0x20, %ecx
cmpl $0xc0, %ecx
jne 0x1150f
movzbl (%rdx), %edi
movl %edi, %ecx
andl $-0x40, %ecx
cmpl $0x80, %ecx
jne 0x115ac
andl $0x1f, %eax
shll $0x6, %eax
andl $0x3f, %edi
orl %eax, %edi
movq %r15, %rsi
addq $0x2, %r15
movl $0x2, %ecx
movl %edi, %eax
jmp 0x11641
cmpl $0x22, %eax
je 0x1159b
cmpl $0x26, %eax
jne 0x1163b
movl $0x5, %ecx
leaq 0x438b(%rip), %rsi      # 0x15895
jmp 0x1163e
movl %eax, %ecx
andl $-0x10, %ecx
cmpl $0xe0, %ecx
jne 0x115b6
movsbl (%rdx), %esi
movl %esi, %edi
andl $0xc0, %edi
movl $0x1, %ecx
cmpl $0x80, %edi
jne 0x11636
movzbl 0x2(%r15), %edi
movl %edi, %r8d
andl $-0x40, %r8d
cmpl $0x80, %r8d
jne 0x11636
shll $0xc, %eax
movzwl %ax, %eax
andl $0x3f, %esi
shll $0x6, %esi
orl %eax, %esi
andl $0x3f, %edi
orl %esi, %edi
movq %r15, %rsi
addq $0x3, %r15
movl $0x3, %ecx
jmp 0x114e5
movl $0x6, %ecx
leaq 0x4309(%rip), %rsi      # 0x1588e
jmp 0x1163e
movl $0x4, %ecx
leaq 0x42ec(%rip), %rsi      # 0x15882
jmp 0x1163e
movl $0x6, %ecx
leaq 0x42e0(%rip), %rsi      # 0x15887
jmp 0x1163e
movl $0x1, %ecx
jmp 0x11636
movl %eax, %esi
andl $-0x8, %esi
movl $0x1, %ecx
cmpl $0xf0, %esi
jne 0x11636
movsbl (%rdx), %esi
movl %esi, %edi
andl $0xc0, %edi
cmpl $0x80, %edi
jne 0x11636
movsbl 0x2(%r15), %r8d
movl %r8d, %edi
andl $0xc0, %edi
cmpl $0x80, %edi
jne 0x11636
movzbl 0x3(%r15), %edi
movl %edi, %r9d
andl $-0x40, %r9d
cmpl $0x80, %r9d
jne 0x11636
andl $0x7, %eax
shll $0x12, %eax
andl $0x3f, %esi
shll $0xc, %esi
orl %eax, %esi
andl $0x3f, %r8d
shll $0x6, %r8d
orl %esi, %r8d
andl $0x3f, %edi
orl %r8d, %edi
movq %r15, %rsi
addq $0x4, %r15
movl $0x4, %ecx
jmp 0x114e5
movl $0xfffd, %eax           # imm = 0xFFFD
movq %r15, %rsi
movq %rdx, %r15
cmpl $0xd, %eax
ja 0x1164c
btl %eax, %r13d
jb 0x11680
cmpl $0xfffd, %eax           # imm = 0xFFFD
je 0x11678
leal -0x10000(%rax), %edx
cmpl $0x100000, %edx         # imm = 0x100000
jb 0x11680
leal -0x20(%rax), %edx
cmpl $0xd7e0, %edx           # imm = 0xD7E0
jb 0x11680
addl $0xffff2000, %eax       # imm = 0xFFFF2000
cmpl $0x1ffe, %eax           # imm = 0x1FFE
jb 0x11680
movl $0x3, %ecx
movq %rbp, %rsi
movl %ecx, %r12d
testq %rbx, %rbx
je 0x11698
movq %rbx, %rdi
movq %r12, %rdx
callq 0x3150
addq %r12, %rbx
jmp 0x1169a
xorl %ebx, %ebx
addq %r12, %r14
movb (%r15), %al
testb %al, %al
jne 0x1146c
jmp 0x116b0
movl $0x1, %r14d
testq %rbx, %rbx
je 0x116b8
movb $0x0, (%rbx)
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq