// File: hanhwi[P]SimPoint/analysiscode/CmdLineParser.cpp
// Function: CmdLineParser::printExplanationPretty(CmdLineOption const*, unsigned int, std::ostream&, unsigned int)
void CmdLineParser::printExplanationPretty(const CmdLineOption *option,
        unsigned int prefixWidth, ostream &os, unsigned int lineWidth) {
    prefixWidth += 3;  // to account for the string " : " below
    string nameAndArg = prettyOptionNameAndArg(option);
    os << nameAndArg;
    if (nameAndArg.size() < prefixWidth - 3) { os << ' '; }
    for (unsigned int i = nameAndArg.size() + 1; i < prefixWidth - 3; i++) {
        os << '.';
    }
    os << " : ";

    // strip the explanation of leading, trailing, and duplicate spaces
    string expl, explanation = option->getExplanation();
    unsigned int start = 0, end = explanation.size() - 1;
    while ((start < end) && (explanation[start] == ' ')) { start++; }
    while ((start < end) && (explanation[end] == ' ')) { end--; }
    for (unsigned int i = start; i <= end; i++) {
        expl += explanation[i];
        if (explanation[i] == ' ') {
            while ((i <= end) && (explanation[i+1] == ' ')) {
                i++;
            }
        }
    }

    unsigned int position = 0;
    bool firstLine = true;
    while (expl.size() - position > lineWidth - prefixWidth) {
        if (! firstLine) {
            for (unsigned int i = 0; i < prefixWidth; i++) {
                os << ' ';
            }
        }

        // find the first index of a space that is earlier than the limit of the
        // line width
        unsigned long searchStart = min((unsigned long)position + lineWidth - prefixWidth, 
                                        (unsigned long)expl.size() - 1);
        unsigned long spaceNdx = expl.rfind(' ', searchStart);
        if ((spaceNdx == string::npos) || (spaceNdx <= position)) {
            spaceNdx = expl.find(' ', searchStart);
            if (spaceNdx == string::npos) {
                spaceNdx = expl.size();
            }
        }
        os << expl.substr(position, spaceNdx - position) << endl;
        position = spaceNdx + 1;
        firstLine = false;
    }

    if (position < expl.size()) {
        if (! firstLine) {
            for (unsigned int i = 0; i < prefixWidth; i++) {
                os << ' ';
            }
        }
        os << expl.substr(position) << endl;
    }
}

// Assembly:
subq $0x198, %rsp            # imm = 0x198
movq %rdi, 0x190(%rsp)
movl %esi, 0x18c(%rsp)
movq %rdx, 0x180(%rsp)
movl %ecx, 0x17c(%rsp)
movl 0x18c(%rsp), %eax
addl $0x3, %eax
movl %eax, 0x18c(%rsp)
movq 0x190(%rsp), %rsi
leaq 0x158(%rsp), %rdi
movq %rdi, 0x80(%rsp)
callq 0x6db0
movq 0x80(%rsp), %rsi
movq 0x180(%rsp), %rdi
callq 0x5320
jmp 0x66fa
leaq 0x158(%rsp), %rdi
callq 0x5270
movl 0x18c(%rsp), %ecx
subl $0x3, %ecx
movl %ecx, %ecx
cmpq %rcx, %rax
jae 0x6747
movq 0x180(%rsp), %rdi
movl $0x20, %esi
callq 0x5430
jmp 0x672c
jmp 0x6747
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x150(%rsp)
movl %eax, 0x14c(%rsp)
jmp 0x6d8e
leaq 0x158(%rsp), %rdi
callq 0x5270
addq $0x1, %rax
movl %eax, 0x148(%rsp)
movl 0x148(%rsp), %eax
movl 0x18c(%rsp), %ecx
subl $0x3, %ecx
cmpl %ecx, %eax
jae 0x679d
movq 0x180(%rsp), %rdi
movl $0x2e, %esi
callq 0x5430
jmp 0x6788
jmp 0x678a
movl 0x148(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x148(%rsp)
jmp 0x675f
movq 0x180(%rsp), %rdi
leaq 0x2c8fb(%rip), %rsi     # 0x330a7
callq 0x5360
jmp 0x67b3
leaq 0x128(%rsp), %rdi
callq 0x5540
movq 0x190(%rsp), %rdi
callq 0x7a50
movq %rax, 0x78(%rsp)
jmp 0x67d4
movq 0x78(%rsp), %rsi
leaq 0x108(%rsp), %rdi
callq 0x51a0
jmp 0x67e8
movl $0x0, 0x104(%rsp)
leaq 0x108(%rsp), %rdi
callq 0x5270
subq $0x1, %rax
movl %eax, 0x100(%rsp)
movl 0x104(%rsp), %ecx
xorl %eax, %eax
cmpl 0x100(%rsp), %ecx
movb %al, 0x77(%rsp)
jae 0x6850
movl 0x104(%rsp), %eax
movl %eax, %esi
leaq 0x108(%rsp), %rdi
callq 0x5760
movq %rax, 0x68(%rsp)
jmp 0x683e
movq 0x68(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x20, %eax
sete %al
movb %al, 0x77(%rsp)
movb 0x77(%rsp), %al
testb $0x1, %al
jne 0x685a
jmp 0x689f
movl 0x104(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x104(%rsp)
jmp 0x680b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x150(%rsp)
movl %eax, 0x14c(%rsp)
jmp 0x6d81
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x150(%rsp)
movl %eax, 0x14c(%rsp)
jmp 0x6d74
jmp 0x68a1
movl 0x104(%rsp), %ecx
xorl %eax, %eax
cmpl 0x100(%rsp), %ecx
movb %al, 0x67(%rsp)
jae 0x68e6
movl 0x100(%rsp), %eax
movl %eax, %esi
leaq 0x108(%rsp), %rdi
callq 0x5760
movq %rax, 0x58(%rsp)
jmp 0x68d4
movq 0x58(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x20, %eax
sete %al
movb %al, 0x67(%rsp)
movb 0x67(%rsp), %al
testb $0x1, %al
jne 0x68f0
jmp 0x6903
movl 0x100(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x100(%rsp)
jmp 0x68a1
movl 0x104(%rsp), %eax
movl %eax, 0xfc(%rsp)
movl 0xfc(%rsp), %eax
cmpl 0x100(%rsp), %eax
ja 0x6a03
movl 0xfc(%rsp), %eax
movl %eax, %esi
leaq 0x108(%rsp), %rdi
callq 0x5760
movq %rax, 0x50(%rsp)
jmp 0x6942
movq 0x50(%rsp), %rax
movsbl (%rax), %esi
leaq 0x128(%rsp), %rdi
callq 0x5240
jmp 0x6959
movl 0xfc(%rsp), %eax
movl %eax, %esi
leaq 0x108(%rsp), %rdi
callq 0x5760
movq %rax, 0x48(%rsp)
jmp 0x6976
movq 0x48(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x20, %eax
jne 0x69eb
jmp 0x6985
movl 0xfc(%rsp), %ecx
xorl %eax, %eax
cmpl 0x100(%rsp), %ecx
movb %al, 0x47(%rsp)
ja 0x69cc
movl 0xfc(%rsp), %eax
incl %eax
movl %eax, %esi
leaq 0x108(%rsp), %rdi
callq 0x5760
movq %rax, 0x38(%rsp)
jmp 0x69ba
movq 0x38(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x20, %eax
sete %al
movb %al, 0x47(%rsp)
movb 0x47(%rsp), %al
testb $0x1, %al
jne 0x69d6
jmp 0x69e9
movl 0xfc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xfc(%rsp)
jmp 0x6985
jmp 0x69eb
jmp 0x69ed
movl 0xfc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xfc(%rsp)
jmp 0x6911
movl $0x0, 0xf8(%rsp)
movb $0x1, 0xf7(%rsp)
leaq 0x128(%rsp), %rdi
callq 0x5270
movl 0xf8(%rsp), %ecx
subq %rcx, %rax
movl 0x17c(%rsp), %ecx
subl 0x18c(%rsp), %ecx
movl %ecx, %ecx
cmpq %rcx, %rax
jbe 0x6c39
testb $0x1, 0xf7(%rsp)
jne 0x6a96
movl $0x0, 0xf0(%rsp)
movl 0xf0(%rsp), %eax
cmpl 0x18c(%rsp), %eax
jae 0x6a94
movq 0x180(%rsp), %rdi
movl $0x20, %esi
callq 0x5430
jmp 0x6a7f
jmp 0x6a81
movl 0xf0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xf0(%rsp)
jmp 0x6a5b
jmp 0x6a96
movl 0xf8(%rsp), %eax
movl 0x17c(%rsp), %ecx
addq %rcx, %rax
movl 0x18c(%rsp), %ecx
subq %rcx, %rax
movq %rax, 0xe0(%rsp)
leaq 0x128(%rsp), %rdi
callq 0x5270
decq %rax
movq %rax, 0xd8(%rsp)
leaq 0xe0(%rsp), %rdi
leaq 0xd8(%rsp), %rsi
callq 0x7a60
movq %rax, 0x30(%rsp)
jmp 0x6aed
movq 0x30(%rsp), %rax
movq (%rax), %rax
movq %rax, 0xe8(%rsp)
movq 0xe8(%rsp), %rdx
leaq 0x128(%rsp), %rdi
movl $0x20, %esi
callq 0x5740
movq %rax, 0xd0(%rsp)
cmpq $-0x1, 0xd0(%rsp)
je 0x6b3e
movq 0xd0(%rsp), %rax
movl 0xf8(%rsp), %ecx
cmpq %rcx, %rax
ja 0x6b82
movq 0xe8(%rsp), %rdx
leaq 0x128(%rsp), %rdi
movl $0x20, %esi
callq 0x54f0
movq %rax, 0xd0(%rsp)
cmpq $-0x1, 0xd0(%rsp)
jne 0x6b80
leaq 0x128(%rsp), %rdi
callq 0x5270
movq %rax, 0xd0(%rsp)
jmp 0x6b82
movq 0x180(%rsp), %rax
movq %rax, 0x28(%rsp)
movl 0xf8(%rsp), %eax
movl %eax, %edx
movq 0xd0(%rsp), %rcx
subq %rdx, %rcx
leaq 0xb0(%rsp), %rdi
leaq 0x128(%rsp), %rsi
callq 0x53a0
jmp 0x6bba
movq 0x28(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
callq 0x5320
movq %rax, 0x20(%rsp)
jmp 0x6bd3
movq 0x20(%rsp), %rdi
movq 0x3d3e1(%rip), %rsi     # 0x43fc0
callq 0x53c0
jmp 0x6be6
leaq 0xb0(%rsp), %rdi
callq 0x5788
movq 0xd0(%rsp), %rax
addq $0x1, %rax
movl %eax, 0xf8(%rsp)
movb $0x0, 0xf7(%rsp)
jmp 0x6a16
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x150(%rsp)
movl %eax, 0x14c(%rsp)
leaq 0xb0(%rsp), %rdi
callq 0x5788
jmp 0x6d74
movl 0xf8(%rsp), %eax
movq %rax, 0x18(%rsp)
leaq 0x128(%rsp), %rdi
callq 0x5270
movq %rax, %rcx
movq 0x18(%rsp), %rax
cmpq %rcx, %rax
jae 0x6d45
testb $0x1, 0xf7(%rsp)
jne 0x6cb3
movl $0x0, 0xac(%rsp)
movl 0xac(%rsp), %eax
cmpl 0x18c(%rsp), %eax
jae 0x6cb1
movq 0x180(%rsp), %rdi
movl $0x20, %esi
callq 0x5430
jmp 0x6c9c
jmp 0x6c9e
movl 0xac(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xac(%rsp)
jmp 0x6c78
jmp 0x6cb3
movq 0x180(%rsp), %rax
movq %rax, 0x10(%rsp)
movl 0xf8(%rsp), %eax
movl %eax, %edx
leaq 0x88(%rsp), %rdi
leaq 0x128(%rsp), %rsi
movq $-0x1, %rcx
callq 0x53a0
jmp 0x6ce7
movq 0x10(%rsp), %rdi
leaq 0x88(%rsp), %rsi
callq 0x5320
movq %rax, 0x8(%rsp)
jmp 0x6d00
movq 0x8(%rsp), %rdi
movq 0x3d2b4(%rip), %rsi     # 0x43fc0
callq 0x53c0
jmp 0x6d13
leaq 0x88(%rsp), %rdi
callq 0x5788
jmp 0x6d45
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x150(%rsp)
movl %eax, 0x14c(%rsp)
leaq 0x88(%rsp), %rdi
callq 0x5788
jmp 0x6d74
leaq 0x108(%rsp), %rdi
callq 0x5788
leaq 0x128(%rsp), %rdi
callq 0x5788
leaq 0x158(%rsp), %rdi
callq 0x5788
addq $0x198, %rsp            # imm = 0x198
retq
leaq 0x108(%rsp), %rdi
callq 0x5788
leaq 0x128(%rsp), %rdi
callq 0x5788
leaq 0x158(%rsp), %rdi
callq 0x5788
movq 0x150(%rsp), %rdi
callq 0x5690
nopl (%rax,%rax)