// File: demon386[P]git-store/./libs/program_options/src/convert.cpp
// Function: std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t>> boost::detail::convert<wchar_t, char, boost::_bi::bind_t<std::codecvt_base::result, boost::_mfi::cmf7<std::codecvt_base::result, std::__codecvt_abstract_base<wchar_t, char, __mbstate_t>, __mbstate_t&, char const*, char const*, char const*&, wchar_t*, wchar_t*, wchar_t*&>, boost::_bi::list8<boost::_bi::value<std::codecvt<wchar_t, char, __mbstate_t> const*>, boost::arg<1>, boost::arg<2>, boost::arg<3>, boost::arg<4>, boost::arg<5>, boost::arg<6>, boost::arg<7>>>>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, boost::_bi::bind_t<std::codecvt_base::result, boost::_mfi::cmf7<std::codecvt_base::result, std::__codecvt_abstract_base<wchar_t, char, __mbstate_t>, __mbstate_t&, char const*, char const*, char const*&, wchar_t*, wchar_t*, wchar_t*&>, boost::_bi::list8<boost::_bi::value<std::codecvt<wchar_t, char, __mbstate_t> const*>, boost::arg<1>, boost::arg<2>, boost::arg<3>, boost::arg<4>, boost::arg<5>, boost::arg<6>, boost::arg<7>>>)
std::basic_string<ToChar>
    convert(const std::basic_string<FromChar>& s, Fun fun)
        
    {
        std::basic_string<ToChar> result;
        
        std::mbstate_t state = std::mbstate_t();

        const FromChar* from = s.data();
        const FromChar* from_end = s.data() + s.size();
        // The interface of cvt is not really iterator-like, and it's
        // not possible the tell the required output size without the conversion.
        // All we can is convert data by pieces.
        while(from != from_end) {
            
            // std::basic_string does not provide non-const pointers to the data,
            // so converting directly into string is not possible.
            ToChar buffer[32];
            
            ToChar* to_next = buffer;
            // Need variable because boost::bind doesn't work with rvalues.
            ToChar* to_end = buffer + 32;
            std::codecvt_base::result r = 
                fun(state, from, from_end, from, buffer, to_end, to_next);
            
            if (r == std::codecvt_base::error)
                boost::throw_exception(
                    std::logic_error("character conversion failed"));
            // 'partial' is not an error, it just means not all source
            // characters were converted. However, we need to check that at
            // least one new target character was produced. If not, it means
            // the source data is incomplete, and since we don't have extra
            // data to add to source, it's error.
            if (to_next == buffer)
                boost::throw_exception(
                    std::logic_error("character conversion failed"));
            
            // Add converted characters
            result.append(buffer, to_next);
        }
        
        return result;        
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x130, %rsp            # imm = 0x130
movq %rdi, -0x118(%rbp)
movq %rdi, %rax
movq %rax, -0x110(%rbp)
leaq 0x10(%rbp), %rax
movq %rax, -0x108(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movb $0x0, -0x11(%rbp)
callq 0xd2a0
leaq -0x1c(%rbp), %rdi
xorl %esi, %esi
movl $0x8, %edx
callq 0xd310
movq -0x10(%rbp), %rdi
callq 0xd830
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rdi
callq 0xd830
movq %rax, -0x100(%rbp)
movq -0x10(%rbp), %rdi
callq 0xd430
movq %rax, %rcx
movq -0x100(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
cmpq -0x30(%rbp), %rax
je 0x21ffa
movq -0x108(%rbp), %rdi
leaq -0xb0(%rbp), %r9
movq %r9, -0xb8(%rbp)
leaq -0x30(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq %rsp, %rax
leaq -0xb8(%rbp), %rcx
movq %rcx, 0x8(%rax)
leaq -0xc0(%rbp), %rcx
movq %rcx, (%rax)
leaq -0x1c(%rbp), %rsi
leaq -0x30(%rbp), %rcx
leaq -0x28(%rbp), %r8
movq %r8, %rdx
callq 0x226a0
movl %eax, -0x11c(%rbp)
jmp 0x21f11
movl -0x11c(%rbp), %eax
movl %eax, -0xc4(%rbp)
cmpl $0x2, -0xc4(%rbp)
jne 0x21f83
leaq 0x3e2e7(%rip), %rsi     # 0x60214
leaq -0xe8(%rbp), %rdi
callq 0xd950
jmp 0x21f3b
leaq -0xe8(%rbp), %rdi
callq 0x22730
jmp 0x21f49
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
jmp 0x22020
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
leaq -0xe8(%rbp), %rdi
callq 0xdcb0
jmp 0x22020
movq -0xb8(%rbp), %rax
leaq -0xb0(%rbp), %rcx
cmpq %rcx, %rax
jne 0x21fd9
leaq 0x3e277(%rip), %rsi     # 0x60214
leaq -0xf8(%rbp), %rdi
callq 0xd950
jmp 0x21fab
leaq -0xf8(%rbp), %rdi
callq 0x22730
jmp 0x21fb9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
leaq -0xf8(%rbp), %rdi
callq 0xdcb0
jmp 0x22020
movq -0x118(%rbp), %rdi
movq -0xb8(%rbp), %rdx
leaq -0xb0(%rbp), %rsi
callq 0x227e0
jmp 0x21ff5
jmp 0x21eaf
movb $0x1, -0x11(%rbp)
testb $0x1, -0x11(%rbp)
jne 0x22010
movq -0x118(%rbp), %rdi
callq 0xdcc0
movq -0x110(%rbp), %rax
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq
movq -0x118(%rbp), %rdi
callq 0xdcc0
movq -0xd0(%rbp), %rdi
callq 0xdb30
nopl (%rax,%rax)