// File: /workspace/github_cpp_makefile_star2_O3/adamiaonr[P]rid-analytics/src/argvparser.cpp
// Function: CommandLineProcessing::formatString(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, unsigned int, unsigned int)
std::string CommandLineProcessing::formatString(const std::string& _string,
        unsigned int _width,
        unsigned int _indent)
{
    // if insane parameters do nothing
    if (_indent >= _width)
        return(_string);

    // list of lines of the formated string
    list<string> lines;

    // current position in the string
    unsigned int pos = 0;

    // till the end of the string
    while (pos < _string.length())
    {
        // get the next line of the string
        string line = _string.substr(pos, _width - _indent );

#ifdef ARGVPARSER_DEBUG

        cout << "EXTRACT: '" << line << "'" << endl;
#endif

        // check for newlines in the line and break line at first occurence (if any)
        string::size_type first_newline = line.find_first_of("\n");
        if (first_newline != string::npos)
        {
            line = line.substr(0, first_newline);
        }

        // we need to check for possible breaks within words only if the extracted
        // line spans the whole allowed width
        bool check_truncation = true;
        if (line.length() < _width - _indent)
            check_truncation = false;

        // remove unecessary whitespace at front and back
        line = trimmedString(line);

#ifdef ARGVPARSER_DEBUG

        cout << "TRIMMED: '" << line << "'" << endl;
#endif

        // only perform truncation if there was enough data for a full line
        if (!check_truncation)
            pos += line.length() + 1;
        else
        {
            // look for the last whitespace character
            string::size_type last_white_space = line.find_last_of(" \a\b\f\n\r\t\v");

            if (last_white_space != string::npos) // whitespace found!
            {
                // truncated the line at the last whitespace
                line = string(line, 0, last_white_space);
                pos += last_white_space + 1;
            }
            else // no whitespace found
                // rude break! we can leave the line in its current state
                pos += _width - _indent;
        }

        if (!line.empty())
        {
#ifdef ARGVPARSER_DEBUG
            cout << "UNINDEN: '" << line << "'" << endl;
#endif

            if (_indent)
                line.insert(0, _indent, ' ');

#ifdef ARGVPARSER_DEBUG

            cout << "INDENT: '" << line << "'" << endl;
#endif

            lines.push_back(line);
        }
    }

    // concat the formated string
    string formated;
    bool first = true;
    // for all lines
    for (list<string>::iterator it = lines.begin(); it != lines.end(); ++it)
    {
        // prefix with newline if not first
        if (!first)
            formated += "\n";
        else
            first = false;

        formated += *it;
    }
    return(formated);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rsi, %r12
movq %rdi, %rbx
movl %ecx, 0xc(%rsp)
subl %ecx, %edx
movq %rdx, 0x10(%rsp)
jbe 0x20f6d
leaq 0x18(%rsp), %rax
movq %rax, 0x8(%rax)
movq %rax, (%rax)
movq $0x0, 0x10(%rax)
cmpq $0x0, 0x8(%r12)
je 0x20f16
movl 0xc(%rsp), %eax
movq %rax, 0x70(%rsp)
xorl %edx, %edx
leaq 0x50(%rsp), %r13
leaq 0x30(%rsp), %rbp
movq $0x0, (%rsp)
movq %r13, %rdi
movq %r12, %rsi
movq 0x10(%rsp), %rcx
callq 0x43c0
movl $0x1, %ecx
movq %r13, %rdi
leaq 0xf6f9(%rip), %rsi      # 0x30492
xorl %edx, %edx
callq 0x45c0
cmpq $-0x1, %rax
je 0x20ddd
movq %rbp, %rdi
movq %r13, %rsi
xorl %edx, %edx
movq %rax, %rcx
callq 0x43c0
movq %r13, %rdi
movq %rbp, %rsi
callq 0x4460
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x20ddd
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x43a0
movq 0x58(%rsp), %r14
movq %rbp, %rdi
movq %r13, %rsi
callq 0x21552
movq %r13, %rdi
movq %rbp, %r15
movq %rbp, %rsi
callq 0x4460
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x20e17
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x43a0
cmpq 0x10(%rsp), %r14
jae 0x20e31
movq 0x58(%rsp), %rax
movq (%rsp), %rcx
addl %eax, %ecx
incl %ecx
movq %rcx, (%rsp)
jmp 0x20eaa
movl $0x8, %ecx
movq %r13, %rdi
leaq 0xff1e(%rip), %rsi      # 0x30d5e
movq $-0x1, %rdx
callq 0x4790
cmpq $-0x1, %rax
je 0x20e99
movq %rax, %rbp
movq %r15, %r14
movq %r15, %rdi
movq %r13, %rsi
xorl %edx, %edx
movq %rax, %rcx
callq 0x4100
movq %r13, %rdi
movq %r14, %rsi
callq 0x4460
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x20e8f
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x43a0
movq (%rsp), %rax
addl %ebp, %eax
incl %eax
jmp 0x20ea1
movq (%rsp), %rax
addl 0x10(%rsp), %eax
movq %rax, (%rsp)
movq 0x58(%rsp), %rax
movq %r15, %rbp
testq %rax, %rax
je 0x20eec
cmpl $0x0, 0xc(%rsp)
je 0x20ecd
movq %r13, %rdi
xorl %esi, %esi
movq 0x70(%rsp), %rdx
movl $0x20, %ecx
callq 0x4780
leaq 0x18(%rsp), %rdi
movq %r13, %rsi
callq 0x22d4e
movq %rax, %rdi
leaq 0x18(%rsp), %rsi
callq 0x4090
incq 0x28(%rsp)
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x20f08
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x43a0
movl (%rsp), %edx
cmpq %rdx, 0x8(%r12)
ja 0x20d7a
leaq 0x10(%rbx), %r15
movq %r15, (%rbx)
movq $0x0, 0x8(%rbx)
movb $0x0, 0x10(%rbx)
movb $0x1, %bpl
leaq 0xf55f(%rip), %r14      # 0x30492
leaq 0x18(%rsp), %r12
movq (%r12), %r12
leaq 0x18(%rsp), %rax
cmpq %rax, %r12
je 0x20f8a
testb $0x1, %bpl
jne 0x20f57
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4760
movq 0x10(%r12), %rsi
movq 0x18(%r12), %rdx
xorl %ebp, %ebp
movq %rbx, %rdi
callq 0x4150
jmp 0x20f38
leaq 0x10(%rbx), %rax
movq %rax, (%rbx)
movq (%r12), %rsi
movq 0x8(%r12), %rdx
addq %rsi, %rdx
movq %rbx, %rdi
callq 0x1bdb4
jmp 0x20f94
leaq 0x18(%rsp), %rdi
callq 0x21fac
movq %rbx, %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x20fb1
jmp 0x20fb1
movq %rax, %r14
jmp 0x20fe0
jmp 0x20fb1
movq %rax, %r14
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x20fe0
movq 0x60(%rsp), %rsi
jmp 0x20fd8
movq %rax, %r14
movq (%rbx), %rdi
cmpq %r15, %rdi
je 0x20fe0
movq (%r15), %rsi
incq %rsi
callq 0x43a0
leaq 0x18(%rsp), %rdi
callq 0x21fac
movq %r14, %rdi
callq 0x4700