// File: /workspace/github_cpp_makefile_star2_O2/demon386[P]git-store/./libs/program_options/src/convert.cpp
// Function: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> boost::detail::convert<char, wchar_t, 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&, wchar_t const*, wchar_t const*, wchar_t const*&, char*, char*, char*&>, 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<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t>> 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&, wchar_t const*, wchar_t const*, wchar_t const*&, char*, char*, char*&>, 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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdi, %rbx
leaq 0x10(%rdi), %rax
movq %rax, (%rdi)
andq $0x0, 0x8(%rdi)
leaq -0x60(%rbp), %rax
andq $0x0, (%rax)
movb $0x0, 0x10(%rdi)
movq (%rsi), %rax
leaq -0x58(%rbp), %r12
movq %rax, (%r12)
movq 0x8(%rsi), %rcx
leaq (%rax,%rcx,4), %rcx
leaq -0x48(%rbp), %rdx
movq %rcx, (%rdx)
leaq -0x80(%rbp), %r14
leaq -0x40(%rbp), %r15
leaq -0x50(%rbp), %r13
cmpq %rcx, %rax
je 0x13f4e
movq %r14, -0x40(%rbp)
leaq -0x60(%rbp), %rax
movq %rax, -0x50(%rbp)
leaq 0x10(%rbp), %rdi
leaq -0x60(%rbp), %rsi
movq %r12, %rdx
leaq -0x48(%rbp), %rcx
movq %r12, %r8
movq %r14, %r9
pushq %r15
pushq %r13
callq 0x144a6
popq %rcx
popq %rdx
cmpl $0x2, %eax
je 0x13f60
movq -0x40(%rbp), %rdx
cmpq %r14, %rdx
je 0x13f79
movq %rbx, %rdi
movq %r14, %rsi
callq 0x144e8
movq -0x58(%rbp), %rax
movq -0x48(%rbp), %rcx
jmp 0x13efa
movq %rbx, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x192ce(%rip), %rsi     # 0x2d235
leaq -0x38(%rbp), %rdi
callq 0xc6d0
leaq -0x38(%rbp), %rdi
callq 0x1402e
leaq 0x192b5(%rip), %rsi     # 0x2d235
leaq -0x38(%rbp), %rdi
callq 0xc6d0
leaq -0x38(%rbp), %rdi
callq 0x1402e
jmp 0x13f96
jmp 0x13fa6
movq %rax, %r14
leaq -0x38(%rbp), %rdi
callq 0xc9b0
jmp 0x13fa9
jmp 0x13fa6
movq %rax, %r14
movq %rbx, %rdi
callq 0xc9a0
movq %r14, %rdi
callq 0xc850
nop