// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
xorl %r15d, %r15d
leaq 0x402b1(%rip), %r12     # 0x7492d
pushq $0x22
popq %r13
movq 0x8(%r14), %rcx
cmpq %rcx, %r15
jae 0x348a1
movq (%r14), %rax
movzbl (%rax,%r15), %esi
cmpl $0x22, %esi
je 0x346e3
cmpl $0x26, %esi
je 0x346b5
cmpl $0x3e, %esi
je 0x346c1
cmpl $0x3c, %esi
jne 0x346f7
movq %rbx, %rdi
leaq 0x4026a(%rip), %rsi     # 0x7491d
jmp 0x346f0
movq %rbx, %rdi
leaq 0x40263(%rip), %rsi     # 0x74922
jmp 0x346f0
cmpq $0x3, %r15
jb 0x3471c
cmpb $0x5d, -0x1(%rax,%r15)
jne 0x3471c
cmpb $0x5d, -0x2(%rax,%r15)
jne 0x3471c
movq %rbx, %rdi
leaq 0x40247(%rip), %rsi     # 0x74928
jmp 0x346f0
cmpl $0x1, 0x20(%r14)
jne 0x34724
movq %rbx, %rdi
movq %r12, %rsi
callq 0x24570
jmp 0x3472f
cmpb $0x9, %sil
jb 0x34712
leal -0xe(%rsi), %edx
cmpb $0x12, %dl
setae %dl
cmpl $0x7f, %esi
setne %dil
testb %dl, %dil
jne 0x34737
movq %rbx, %rdi
callq 0x348b0
jmp 0x3472f
movq %rbx, %rdi
pushq $0x3e
popq %rsi
jmp 0x3472a
movq %rbx, %rdi
movl %r13d, %esi
callq 0x24670
incq %r15
jmp 0x34680
cmpb $0x7e, %sil
ja 0x34746
movsbl %sil, %esi
movq %rbx, %rdi
jmp 0x3472a
leal 0x8(%rsi), %edx
cmpb $-0x39, %dl
jbe 0x34712
movl %esi, %edx
andl $-0x20, %edx
cmpl $0xc0, %edx
jne 0x3476e
leaq 0x1(%r15), %rdx
pushq $0x2
popq %r9
pushq $0x1f
popq %r8
cmpq %rcx, %rdx
jae 0x34712
jmp 0x347a4
movl %esi, %edx
andl $-0x10, %edx
xorl %r9d, %r9d
cmpl $0xe0, %edx
setne %r9b
leaq (%r15,%r9), %rdi
addq $0x2, %rdi
cmpq %rcx, %rdi
jae 0x34712
addq $0x3, %r9
xorl %ecx, %ecx
cmpl $0xe0, %edx
sete %cl
leal 0x7(,%rcx,8), %r8d
andl %esi, %r8d
movzbl 0x1(%rax,%r15), %ecx
movl %ecx, %edi
andl $-0x40, %edi
cmpl $0x80, %edi
sete %dl
shll $0x6, %r8d
andl $0x3f, %ecx
orl %r8d, %ecx
cmpl $0x2, %r9d
movq %r9, -0x30(%rbp)
jbe 0x34823
movq %r9, %r10
movl $0x80, %r9d
xorl %r9d, %edi
movl %ecx, %r8d
movzbl 0x2(%rax,%r15), %ecx
movl %ecx, %edx
andl $-0x40, %edx
xorl %r9d, %edx
orl %edi, %edx
sete %dl
shll $0x6, %r8d
andl $0x3f, %ecx
orl %r8d, %ecx
cmpl $0x3, %r10d
je 0x34823
movzbl 0x3(%rax,%r15), %eax
movl %eax, %edi
andl $-0x40, %edi
cmpl $0x80, %edi
sete %dil
andb %dil, %dl
shll $0x6, %ecx
andl $0x3f, %eax
orl %ecx, %eax
movl %eax, %ecx
testb %dl, %dl
je 0x3483a
cmpl $0x7f, %ecx
jbe 0x3483a
cmpl $0x3, -0x30(%rbp)
jb 0x34852
cmpl $0x800, %ecx            # imm = 0x800
jae 0x34852
movq %rbx, %rdi
callq 0x348b0
leaq 0x400e4(%rip), %r12     # 0x7492d
pushq $0x22
popq %r13
jmp 0x3472f
leal -0x801(%rcx), %eax
cmpl $0xf7ff, %eax           # imm = 0xF7FF
setb %al
cmpl $0x4, -0x30(%rbp)
setae %dl
testb %al, %dl
jne 0x3483a
movq %r15, %r13
movq -0x30(%rbp), %r12
cmpl $0x10ffff, %ecx         # imm = 0x10FFFF
jbe 0x3488f
jmp 0x3483a
movq (%r14), %rax
movsbl (%rax,%r13), %esi
movq %rbx, %rdi
callq 0x24670
incq %r13
subq $0x1, %r12
jae 0x3487c
movq -0x30(%rbp), %rax
addq %rax, %r15
decq %r15
jmp 0x34842
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq