// File: /workspace/github_cpp_makefile_star2_O1/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 0x21449
leaq 0x18(%rsp), %rax
movq %rax, 0x8(%rax)
movq %rax, (%rax)
movq $0x0, 0x10(%rax)
cmpq $0x0, 0x8(%r12)
je 0x213f0
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 0x1043c(%rip), %rsi     # 0x316b2
xorl %edx, %edx
callq 0x45c0
cmpq $-0x1, %rax
je 0x212ba
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 0x212ba
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x43a0
movq 0x58(%rsp), %r14
movq %rbp, %rdi
movq %r13, %rsi
callq 0x21a2c
movq %r13, %rdi
movq %rbp, %r15
movq %rbp, %rsi
callq 0x4460
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x212f4
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x43a0
cmpq 0x10(%rsp), %r14
jae 0x2130d
movl 0x58(%rsp), %eax
movq (%rsp), %rcx
addl %eax, %ecx
incl %ecx
movq %rcx, (%rsp)
jmp 0x21381
movl $0x8, %ecx
movq %r13, %rdi
leaq 0x10c62(%rip), %rsi     # 0x31f7e
movq $-0x1, %rdx
callq 0x4790
cmpq $-0x1, %rax
je 0x21375
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 0x2136b
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x43a0
movq (%rsp), %rax
addl %ebp, %eax
incl %eax
jmp 0x2137d
movq (%rsp), %rax
addl 0x10(%rsp), %eax
movq %rax, (%rsp)
cmpq $0x0, 0x58(%rsp)
movq %r15, %rbp
je 0x213c6
cmpl $0x0, 0xc(%rsp)
je 0x213a7
movq %r13, %rdi
xorl %esi, %esi
movq 0x70(%rsp), %rdx
movl $0x20, %ecx
callq 0x4780
leaq 0x18(%rsp), %rdi
movq %r13, %rsi
callq 0x2324c
movq %rax, %rdi
leaq 0x18(%rsp), %rsi
callq 0x4090
incq 0x28(%rsp)
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x213e2
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x43a0
movl (%rsp), %edx
cmpq %rdx, 0x8(%r12)
ja 0x21257
leaq 0x10(%rbx), %r15
movq %r15, (%rbx)
movq $0x0, 0x8(%rbx)
movb $0x0, 0x10(%rbx)
movb $0x1, %bpl
leaq 0x102a5(%rip), %r14     # 0x316b2
leaq 0x18(%rsp), %r12
movq (%r12), %r12
leaq 0x18(%rsp), %rax
cmpq %rax, %r12
je 0x21466
testb $0x1, %bpl
je 0x2142a
xorl %ebp, %ebp
jmp 0x21435
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4760
movq 0x10(%r12), %rsi
movq 0x18(%r12), %rdx
movq %rbx, %rdi
callq 0x4150
jmp 0x21412
leaq 0x10(%rbx), %rax
movq %rax, (%rbx)
movq (%r12), %rsi
movq 0x8(%r12), %rdx
addq %rsi, %rdx
movq %rbx, %rdi
callq 0x1c27c
jmp 0x21470
leaq 0x18(%rsp), %rdi
callq 0x2246c
movq %rbx, %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2148d
jmp 0x2148d
movq %rax, %r14
jmp 0x214bc
jmp 0x2148d
movq %rax, %r14
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x214bc
movq 0x60(%rsp), %rsi
jmp 0x214b4
movq %rax, %r14
movq (%rbx), %rdi
cmpq %r15, %rdi
je 0x214bc
movq (%r15), %rsi
incq %rsi
callq 0x43a0
leaq 0x18(%rsp), %rdi
callq 0x2246c
movq %r14, %rdi
callq 0x4700