// File: 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
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x50(%rbp)
movq $0x0, -0x18(%rbp)
movq -0x50(%rbp), %rdi
movq -0x18(%rbp), %rax
movq %rax, -0x58(%rbp)
callq 0x52500
movq %rax, %rcx
movq -0x58(%rbp), %rax
cmpq %rcx, %rax
jae 0x6e745
movq -0x50(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x527f0
movb (%rax), %al
movb %al, -0x19(%rbp)
movzbl -0x19(%rbp), %eax
addl $-0x22, %eax
movl %eax, %ecx
movq %rcx, -0x60(%rbp)
subl $0x1c, %eax
ja 0x6e542
movq -0x60(%rbp), %rax
leaq 0xcec78(%rip), %rcx     # 0x13d0fc
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x10(%rbp), %rdi
leaq 0xd160d(%rip), %rsi     # 0x13faa5
callq 0x52710
jmp 0x6e732
movq -0x10(%rbp), %rdi
leaq 0xd15fd(%rip), %rsi     # 0x13faaa
callq 0x52710
jmp 0x6e732
cmpq $0x2, -0x18(%rbp)
jbe 0x6e502
movq -0x50(%rbp), %rdi
movq -0x18(%rbp), %rsi
subq $0x1, %rsi
callq 0x527f0
movsbl (%rax), %eax
cmpl $0x5d, %eax
jne 0x6e502
movq -0x50(%rbp), %rdi
movq -0x18(%rbp), %rsi
subq $0x2, %rsi
callq 0x527f0
movsbl (%rax), %eax
cmpl $0x5d, %eax
jne 0x6e502
movq -0x10(%rbp), %rdi
leaq 0xd15b5(%rip), %rsi     # 0x13fab0
callq 0x52710
jmp 0x6e50f
movq -0x10(%rbp), %rdi
movzbl -0x19(%rbp), %esi
callq 0x52aa0
jmp 0x6e732
movq -0x50(%rbp), %rax
cmpl $0x1, 0x20(%rax)
jne 0x6e530
movq -0x10(%rbp), %rdi
leaq 0xd158c(%rip), %rsi     # 0x13fab5
callq 0x52710
jmp 0x6e53d
movq -0x10(%rbp), %rdi
movzbl -0x19(%rbp), %esi
callq 0x52aa0
jmp 0x6e732
movzbl -0x19(%rbp), %eax
cmpl $0x9, %eax
jl 0x6e566
movzbl -0x19(%rbp), %eax
cmpl $0xd, %eax
jle 0x6e55d
movzbl -0x19(%rbp), %eax
cmpl $0x20, %eax
jl 0x6e566
movzbl -0x19(%rbp), %eax
cmpl $0x7f, %eax
jne 0x6e578
movq -0x10(%rbp), %rdi
movzbl -0x19(%rbp), %esi
callq 0x6e750
jmp 0x6e732
movzbl -0x19(%rbp), %eax
cmpl $0x7f, %eax
jge 0x6e593
movq -0x10(%rbp), %rdi
movzbl -0x19(%rbp), %esi
callq 0x52aa0
jmp 0x6e732
movzbl -0x19(%rbp), %eax
cmpl $0xc0, %eax
jl 0x6e5a9
movzbl -0x19(%rbp), %eax
cmpl $0xf8, %eax
jl 0x6e5bb
movq -0x10(%rbp), %rdi
movzbl -0x19(%rbp), %esi
callq 0x6e750
jmp 0x6e732
movzbl -0x19(%rbp), %edi
callq 0x6e810
movq -0x50(%rbp), %rdi
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rax
addq -0x28(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x68(%rbp)
callq 0x52500
movq %rax, %rcx
movq -0x68(%rbp), %rax
cmpq %rcx, %rax
jb 0x6e5ff
movq -0x10(%rbp), %rdi
movzbl -0x19(%rbp), %esi
callq 0x6e750
jmp 0x6e732
movb $0x1, -0x29(%rbp)
movzbl -0x19(%rbp), %edi
callq 0x6e950
movl %eax, -0x30(%rbp)
movq $0x1, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x28(%rbp), %rax
jae 0x6e682
movq -0x50(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq -0x38(%rbp), %rsi
callq 0x527f0
movb (%rax), %al
movb %al, -0x39(%rbp)
movzbl -0x39(%rbp), %eax
andl $0xc0, %eax
cmpl $0x80, %eax
sete %al
andb $0x1, %al
movzbl %al, %ecx
movb -0x29(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
andl %ecx, %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movb %al, -0x29(%rbp)
movl -0x30(%rbp), %eax
shll $0x6, %eax
movzbl -0x39(%rbp), %ecx
andl $0x3f, %ecx
orl %ecx, %eax
movl %eax, -0x30(%rbp)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x6e617
testb $0x1, -0x29(%rbp)
je 0x6e6ce
cmpl $0x80, -0x30(%rbp)
jb 0x6e6ce
movl $0x80, %eax
cmpl -0x30(%rbp), %eax
ja 0x6e6ab
cmpl $0x800, -0x30(%rbp)     # imm = 0x800
jae 0x6e6ab
cmpq $0x2, -0x28(%rbp)
ja 0x6e6ce
movl $0x800, %eax            # imm = 0x800
cmpl -0x30(%rbp), %eax
jae 0x6e6c5
cmpl $0x10000, -0x30(%rbp)   # imm = 0x10000
jae 0x6e6c5
cmpq $0x3, -0x28(%rbp)
ja 0x6e6ce
cmpl $0x110000, -0x30(%rbp)  # imm = 0x110000
jb 0x6e6dd
movq -0x10(%rbp), %rdi
movzbl -0x19(%rbp), %esi
callq 0x6e750
jmp 0x6e732
movq $0x0, -0x48(%rbp)
movq -0x48(%rbp), %rax
cmpq -0x28(%rbp), %rax
jae 0x6e722
movq -0x50(%rbp), %rdi
movq -0x10(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x18(%rbp), %rsi
addq -0x48(%rbp), %rsi
callq 0x527f0
movq -0x70(%rbp), %rdi
movsbl (%rax), %esi
callq 0x52870
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x6e6e5
movq -0x28(%rbp), %rax
subq $0x1, %rax
addq -0x18(%rbp), %rax
movq %rax, -0x18(%rbp)
jmp 0x6e734
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0x6e430
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax,%rax)