// File: /workspace/github_cpp_makefile_star2_O2/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
movl %edx, %r12d
movq %rsi, %r15
movq %rdi, %rbx
subl %ecx, %r12d
jbe 0x1c0fb
movq %rbx, 0x8(%rsp)
leaq 0x20(%rsp), %rax
movq %rax, 0x8(%rax)
movq %rax, (%rax)
andq $0x0, 0x10(%rax)
movl %ecx, 0x14(%rsp)
movl %ecx, %eax
movq %rax, 0x18(%rsp)
xorl %ebx, %ebx
leaq 0x38(%rsp), %r13
leaq 0x58(%rsp), %rbp
movl %ebx, %r14d
cmpq %r14, 0x8(%r15)
jbe 0x1c10b
movq %r13, %rdi
movq %r15, %rsi
movq %r14, %rdx
movq %r12, %rcx
callq 0x43e0
movq %r13, %rdi
leaq 0xe642(%rip), %rsi      # 0x2a652
xorl %edx, %edx
callq 0x4210
cmpq $-0x1, %rax
je 0x1c040
movq %rbp, %rdi
movq %r13, %rsi
xorl %edx, %edx
movq %rax, %rcx
callq 0x43e0
movq %r13, %rdi
movq %rbp, %rsi
callq 0x4460
movq %rbp, %rdi
callq 0x41c0
movq 0x40(%rsp), %rbx
movq %rbp, %rdi
movq %r13, %rsi
callq 0x1c5bc
movq %r13, %rdi
movq %rbp, %rsi
callq 0x4460
movq %rbp, %rdi
callq 0x41c0
cmpq %r12, %rbx
jae 0x1c075
movq 0x40(%rsp), %rax
leal (%r14,%rax), %ebx
incl %ebx
jmp 0x1c0c3
movq %r13, %rdi
leaq 0xee9f(%rip), %rsi      # 0x2af1e
pushq $-0x1
popq %rdx
callq 0x4380
cmpq $-0x1, %rax
je 0x1c0ba
movq %rax, %rbx
movq %rbp, %rdi
movq %r13, %rsi
xorl %edx, %edx
movq %rax, %rcx
callq 0x4100
movq %r13, %rdi
movq %rbp, %rsi
callq 0x4460
movq %rbp, %rdi
callq 0x41c0
addl %r14d, %ebx
incl %ebx
jmp 0x1c0be
leal (%r12,%r14), %ebx
movq 0x40(%rsp), %rax
testq %rax, %rax
je 0x1c0ee
cmpl $0x0, 0x14(%rsp)
je 0x1c0e1
movq %r13, %rdi
xorl %esi, %esi
movq 0x18(%rsp), %rdx
pushq $0x20
popq %rcx
callq 0x47b0
leaq 0x20(%rsp), %rdi
movq %r13, %rsi
callq 0x1c9fe
movq %r13, %rdi
callq 0x41c0
jmp 0x1bfe8
movq %rbx, %rdi
movq %r15, %rsi
callq 0x4510
movq %rbx, %rax
jmp 0x1c170
movq 0x8(%rsp), %rcx
leaq 0x10(%rcx), %rax
movq %rax, (%rcx)
andq $0x0, 0x8(%rcx)
movb $0x0, 0x10(%rcx)
movb $0x1, %bpl
leaq 0xe528(%rip), %r14      # 0x2a652
leaq 0x20(%rsp), %rbx
movq (%rbx), %rbx
leaq 0x20(%rsp), %rax
cmpq %rax, %rbx
je 0x1c161
testb $0x1, %bpl
jne 0x1c14f
movq 0x8(%rsp), %rdi
movq %r14, %rsi
callq 0x4760
leaq 0x10(%rbx), %rsi
xorl %ebp, %ebp
movq 0x8(%rsp), %rdi
callq 0x4790
jmp 0x1c12f
leaq 0x20(%rsp), %rdi
callq 0x1cd4e
movq 0x8(%rsp), %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1c18a
jmp 0x1c18a
movq %rax, %r14
jmp 0x1c1a1
jmp 0x1c18a
movq %rax, %r14
leaq 0x38(%rsp), %rdi
jmp 0x1c19c
movq %rax, %r14
movq 0x8(%rsp), %rdi
callq 0x41c0
leaq 0x20(%rsp), %rdi
callq 0x1cd4e
movq %r14, %rdi
callq 0x4700
nop