// File: /workspace/github_c_makefile_star2_O3/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 0x10848
movq %rdi, %rsi
movl $0x1, %r14d
leaq 0x4349(%rip), %rbp      # 0x1495b
movl $0x2600, %r12d          # imm = 0x2600
leaq 0x1(%rsi), %r13
movzbl %al, %eax
testb %al, %al
js 0x1065e
movl $0x1, %ecx
cmpl $0x26, %eax
jle 0x1069c
cmpl $0x27, %eax
je 0x10724
movl $0x4, %ecx
cmpl $0x3c, %eax
je 0x1073a
cmpl $0x3e, %eax
jne 0x107d6
movl $0x3e, %eax
leaq 0x42e9(%rip), %rsi      # 0x14942
jmp 0x107ed
movl %eax, %ecx
andl $-0x20, %ecx
cmpl $0xc0, %ecx
jne 0x106c4
movzbl (%r13), %edx
movl %edx, %ecx
andl $-0x40, %ecx
cmpl $0x80, %ecx
jne 0x10812
andl $0x1f, %eax
shll $0x6, %eax
andl $0x3f, %edx
orl %eax, %edx
leaq 0x2(%rsi), %r13
movl $0x2, %ecx
movl %edx, %eax
jmp 0x107db
cmpl $0x22, %eax
je 0x10746
cmpl $0x26, %eax
jne 0x107db
movl $0x26, %eax
movl $0x5, %ecx
leaq 0x4296(%rip), %rsi      # 0x14955
jmp 0x107ed
movl %eax, %ecx
andl $-0x10, %ecx
cmpl $0xe0, %ecx
jne 0x1075c
movsbl (%r13), %ecx
movl %ecx, %edx
andl $0xc0, %edx
cmpl $0x80, %edx
jne 0x10812
movzbl 0x2(%rsi), %edx
movl %edx, %edi
andl $-0x40, %edi
cmpl $0x80, %edi
jne 0x10812
shll $0xc, %eax
movzwl %ax, %eax
andl $0x3f, %ecx
shll $0x6, %ecx
orl %eax, %ecx
andl $0x3f, %edx
orl %ecx, %edx
leaq 0x3(%rsi), %r13
movl $0x3, %ecx
jmp 0x10695
movl $0x27, %eax
movl $0x6, %ecx
leaq 0x4219(%rip), %rsi      # 0x1494e
jmp 0x107ed
leaq 0x41fc(%rip), %rsi      # 0x1493d
jmp 0x107ed
movl $0x22, %eax
movl $0x6, %ecx
leaq 0x41f0(%rip), %rsi      # 0x14947
jmp 0x107ed
movl %eax, %ecx
andl $-0x8, %ecx
cmpl $0xf0, %ecx
jne 0x10812
movsbl (%r13), %ecx
movl %ecx, %edx
andl $0xc0, %edx
cmpl $0x80, %edx
jne 0x10812
movsbl 0x2(%rsi), %edx
movl %edx, %edi
andl $0xc0, %edi
cmpl $0x80, %edi
jne 0x10812
movzbl 0x3(%rsi), %edi
movl %edi, %r8d
andl $-0x40, %r8d
cmpl $0x80, %r8d
jne 0x10812
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), %r13
movl $0x4, %ecx
movl %edi, %eax
jmp 0x107db
movl $0x1, %ecx
cmpl $0xd, %eax
ja 0x107e6
btl %eax, %r12d
jb 0x1081a
cmpl $0xfffd, %eax           # imm = 0xFFFD
je 0x10812
leal -0x10000(%rax), %edx
cmpl $0x100000, %edx         # imm = 0x100000
jb 0x1081a
leal -0x20(%rax), %edx
cmpl $0xd7e0, %edx           # imm = 0xD7E0
jb 0x1081a
addl $0xffff2000, %eax       # imm = 0xFFFF2000
cmpl $0x1ffe, %eax           # imm = 0x1FFE
jb 0x1081a
movl $0x3, %ecx
movq %rbp, %rsi
movl %ecx, %r15d
testq %rbx, %rbx
je 0x10832
movq %rbx, %rdi
movq %r15, %rdx
callq 0x2150
addq %r15, %rbx
jmp 0x10834
xorl %ebx, %ebx
addq %r15, %r14
movb (%r13), %al
movq %r13, %rsi
testb %al, %al
jne 0x10618
jmp 0x1084e
movl $0x1, %r14d
testq %rbx, %rbx
je 0x10856
movb $0x0, (%rbx)
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq