// File: /workspace/github_cpp_makefile_star2_O1/xelia-it[P]mustache/third-party/catch2/single_include/catch2/catch.hpp
// Function: Catch::XmlEncode::encodeTo(std::ostream&) const
void XmlEncode::encodeTo( std::ostream& os ) const {
        // Apostrophe escaping not necessary if we always use " to write attributes
        // (see: http://www.w3.org/TR/xml/#syntax)

        for( std::size_t idx = 0; idx < m_str.size(); ++ idx ) {
            unsigned char c = m_str[idx];
            switch (c) {
            case '<':   os << "&lt;"; break;
            case '&':   os << "&amp;"; break;

            case '>':
                // See: http://www.w3.org/TR/xml/#syntax
                if (idx > 2 && m_str[idx - 1] == ']' && m_str[idx - 2] == ']')
                    os << "&gt;";
                else
                    os << c;
                break;

            case '\"':
                if (m_forWhat == ForAttributes)
                    os << "&quot;";
                else
                    os << c;
                break;

            default:
                // Check for control characters and invalid utf-8

                // Escape control characters in standard ascii
                // see http://stackoverflow.com/questions/404107/why-are-control-characters-illegal-in-xml-1-0
                if (c < 0x09 || (c > 0x0D && c < 0x20) || c == 0x7F) {
                    hexEscapeChar(os, c);
                    break;
                }

                // Plain ASCII: Write it to stream
                if (c < 0x7F) {
                    os << c;
                    break;
                }

                // UTF-8 territory
                // Check if the encoding is valid and if it is not, hex escape bytes.
                // Important: We do not check the exact decoded values for validity, only the encoding format
                // First check that this bytes is a valid lead byte:
                // This means that it is not encoded as 1111 1XXX
                // Or as 10XX XXXX
                if (c <  0xC0 ||
                    c >= 0xF8) {
                    hexEscapeChar(os, c);
                    break;
                }

                auto encBytes = trailingBytes(c);
                // Are there enough bytes left to avoid accessing out-of-bounds memory?
                if (idx + encBytes - 1 >= m_str.size()) {
                    hexEscapeChar(os, c);
                    break;
                }
                // The header is valid, check data
                // The next encBytes bytes must together be a valid utf-8
                // This means: bitpattern 10XX XXXX and the extracted value is sane (ish)
                bool valid = true;
                uint32_t value = headerValue(c);
                for (std::size_t n = 1; n < encBytes; ++n) {
                    unsigned char nc = m_str[idx + n];
                    valid &= ((nc & 0xC0) == 0x80);
                    value = (value << 6) | (nc & 0x3F);
                }

                if (
                    // Wrong bit pattern of following bytes
                    (!valid) ||
                    // Overlong encodings
                    (value < 0x80) ||
                    (0x80 <= value && value < 0x800   && encBytes > 2) ||
                    (0x800 < value && value < 0x10000 && encBytes > 3) ||
                    // Encoded value out of range
                    (value >= 0x110000)
                    ) {
                    hexEscapeChar(os, c);
                    break;
                }

                // If we got here, this is in fact a valid(ish) utf-8 sequence
                for (std::size_t n = 0; n < encBytes; ++n) {
                    os << m_str[idx + n];
                }
                idx += encBytes - 1;
                break;
            }
        }
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq 0x8(%rdi), %rcx
testq %rcx, %rcx
je 0x32326
movq %rsi, %rbx
movq %rdi, %r14
xorl %r13d, %r13d
leaq 0x4a861(%rip), %r15     # 0x7c955
leaq -0x60(%rbp), %r12
movq (%r14), %rax
movb (%rax,%r13), %dl
movzbl %dl, %esi
cmpl $0x3b, %esi
jg 0x32125
cmpl $0x22, %esi
je 0x32166
cmpl $0x26, %esi
jne 0x32140
movl $0x5, %edx
movq %rbx, %rdi
leaq 0x4a82a(%rip), %rsi     # 0x7c94a
jmp 0x321b4
cmpl $0x3e, %esi
je 0x3217a
cmpl $0x3c, %esi
jne 0x32140
movl $0x4, %edx
movq %rbx, %rdi
leaq 0x4a807(%rip), %rsi     # 0x7c945
jmp 0x321b4
cmpb $0x9, %dl
jb 0x3215c
leal -0xe(%rdx), %edi
cmpb $0x12, %dil
setae %dil
cmpb $0x7f, %dl
setne %r8b
testb %dil, %r8b
jne 0x321a1
movq %rbx, %rdi
callq 0x32442
jmp 0x321b9
cmpl $0x1, 0x20(%r14)
jne 0x321a6
movl $0x6, %edx
movq %rbx, %rdi
movq %r15, %rsi
jmp 0x321b4
cmpq $0x3, %r13
jb 0x321a6
cmpb $0x5d, -0x1(%rax,%r13)
jne 0x321a6
cmpb $0x5d, -0x2(%rax,%r13)
jne 0x321a6
movl $0x4, %edx
movq %rbx, %rdi
leaq 0x4a7b1(%rip), %rsi     # 0x7c950
jmp 0x321b4
cmpb $0x7e, %dl
ja 0x321ce
movb %dl, -0x60(%rbp)
movl $0x1, %edx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x1b5e0
incq %r13
movq 0x8(%r14), %rcx
cmpq %rcx, %r13
jb 0x320f8
jmp 0x32326
addb $0x8, %dl
cmpb $-0x39, %dl
jbe 0x3215c
movl %esi, %edi
andl $-0x20, %edi
cmpl $0xc0, %edi
je 0x321f8
movl %esi, %edx
andl $-0x10, %edx
cmpl $0xe0, %edx
jne 0x32202
movl $0x3, %r15d
jmp 0x321fe
movl $0x2, %r15d
xorl %edx, %edx
jmp 0x3221b
movl %esi, %edx
andl $-0x8, %edx
cmpl $0xf0, %edx
jne 0x32335
movl $0x4, %r15d
movb $0x1, %dl
leaq (%r15,%r13), %r9
decq %r9
cmpq %rcx, %r9
jae 0x32312
movl $0x1f, %ecx
cmpl $0xc0, %edi
je 0x32266
movl %esi, %r8d
andl $-0x10, %r8d
movl $0xf, %ecx
cmpl $0xe0, %r8d
je 0x32266
movl %esi, %r8d
andl $-0x8, %r8d
movl $0x7, %ecx
cmpl $0xf0, %r8d
jne 0x323a4
movq %r9, -0x68(%rbp)
andl %esi, %ecx
addq %r13, %rax
movb $0x1, %r9b
movl $0x1, %r10d
movl %ecx, %r8d
movzbl (%rax,%r10), %ecx
movl %ecx, %r11d
andl $-0x40, %r11d
cmpl $0x80, %r11d
sete %r11b
andb %r11b, %r9b
shll $0x6, %r8d
andl $0x3f, %ecx
orl %r8d, %ecx
incq %r10
cmpq %r10, %r15
jne 0x32278
cmpl $0xc0, %edi
setne %al
cmpl $0x800, %r8d            # imm = 0x800
setb %dil
testb %r9b, %r9b
je 0x32312
cmpl $0x80, %r8d
jb 0x32312
andb %dil, %al
jne 0x32312
addl $0xfffff7ff, %ecx       # imm = 0xFFFFF7FF
cmpl $0xf7ff, %ecx           # imm = 0xF7FF
setb %al
testb %al, %dl
jne 0x32312
cmpl $0x10ffff, %r8d         # imm = 0x10FFFF
ja 0x32312
movq (%r14), %rax
movb (%rax,%r13), %al
movb %al, -0x60(%rbp)
movl $0x1, %edx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x1b5e0
incq %r13
decq %r15
jne 0x322ea
movq -0x68(%rbp), %r13
jmp 0x3231a
movq %rbx, %rdi
callq 0x32442
leaq 0x4a634(%rip), %r15     # 0x7c955
jmp 0x321b9
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq -0x40(%rbp), %rbx
movq %rbx, %rdi
callq 0x2d4f4
leaq 0x49b8d(%rip), %rax     # 0x7bed5
leaq -0x78(%rbp), %rsi
movq %rax, (%rsi)
movq $0x3c60, 0x8(%rsi)      # imm = 0x3C60
movq 0x10(%rbx), %rdi
callq 0x22e23
movq -0x30(%rbp), %rdi
leaq 0x49e00(%rip), %rsi     # 0x7c16b
movl $0x19, %edx
callq 0x1b5e0
movq -0x30(%rbp), %rdi
leaq 0x4b9b8(%rip), %rsi     # 0x7dd38
movl $0x2e, %edx
callq 0x1b5e0
movq -0x30(%rbp), %rsi
addq $0x8, %rsi
leaq -0x60(%rbp), %rdi
callq 0x1b7f0
leaq -0x60(%rbp), %rdi
callq 0x23e3c
leaq -0x40(%rbp), %rbx
movq %rbx, %rdi
callq 0x2d4f4
leaq 0x49b1e(%rip), %rax     # 0x7bed5
leaq -0x78(%rbp), %rsi
movq %rax, (%rsi)
movq $0x3c6d, 0x8(%rsi)      # imm = 0x3C6D
movq 0x10(%rbx), %rdi
callq 0x22e23
movq -0x30(%rbp), %rdi
leaq 0x49d91(%rip), %rsi     # 0x7c16b
movl $0x19, %edx
callq 0x1b5e0
movq -0x30(%rbp), %rdi
leaq 0x4b949(%rip), %rsi     # 0x7dd38
movl $0x2e, %edx
callq 0x1b5e0
movq -0x30(%rbp), %rsi
addq $0x8, %rsi
leaq -0x60(%rbp), %rdi
callq 0x1b7f0
leaq -0x60(%rbp), %rdi
callq 0x23e3c
jmp 0x32415
movq %rax, %rbx
leaq -0x50(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x32431
callq 0x1b4d0
jmp 0x32431
jmp 0x3242e
movq %rax, %rbx
leaq -0x40(%rbp), %rdi
callq 0x2d53a
movq %rbx, %rdi
callq 0x1b910