// File: /workspace/github_cpp_makefile_star2_O1/iZhangHui[P]CppPrimer/CH09_SequentialContainers/examples/str_assignOps.cc
// Function: main
int main()
{
    string s = "some string", s2 = "some other string";
    // equivalent ways to insert all the characters from s2 at beginning of s
    // insert iterator range before s.begin()
    s.insert(s.begin(), s2.begin(), s2.end());
    cout << "insert iterators version:        " << s << endl;

    s = "some string";
    s.insert(0, s2); // insert a copy of s2 before position 0 in s
    cout << "insert string at given position: " << s << endl;

    s = "some string";
    // insert s2.size() characters from s2 starting at s2[0] before s[0]
    s.insert(0, s2, 0, s2.size());
    cout << "insert positional version:       " << s << endl;


    // s = "";  // s is now empty
    s = "x";
    vector<char> c_vec(1, 'a');
    // insert characters from c_vec into s
    s.insert(s.begin(), c_vec.begin(), c_vec.end());
    s.insert(s.size(), 5, '!'); // add five exclamation points at the end of s
    cout << s << endl;

    s.erase(s.size() - 5, 5);   // erase the last five characters from s
    cout << s << endl;

    s = "";  // s is now empty
    const char *cp = "Stately, plump Buck";
    s.assign(cp, 7);            // s == "Stately"
    cout << s << endl;
    s.insert(s.size(), cp + 7); // s == "Stately, plump Buck"
    cout << s << endl;

    s = "C++ Primer";  // reset s and s2
    s2 = s;            // to "C++ Primer"
    s.insert(s.size(), " 4th Ed."); // s == "C++ Primer 4th Ed."
    s2.append(" 4th Ed."); // equivalent: appends " 4th Ed." to s2;
    cout << s << " " << s2 << endl;

    // two ways to replace "4th" by "5th"
    // 1. insert and erase
    s.erase(11, 3);                 // s == "C++ Primer Ed."
    s.insert(11, "5th");            // s == "C++ Primer 5th Ed."

    // 2. use replace
    // erase three characters starting at position 11
    //  and then insert "5th"
    s2.replace(11, 3, "5th"); // equivalent: s == s2

    cout << s << " " << s2 << endl;

    // two ways to replace "5th" by "Fifth"
    // 1. use replace if we know where the string we want to replace is
    s.replace(11, 3, "Fifth"); // s == "C++ Primer Fifth Ed."

    // 2. call find first to get position from which to replace
    auto pos = s2.find("5th");
    if (pos != string::npos)
        s2.replace(pos, 3, "Fifth");
    else
        cout << "something's wrong, s2 is: " << s2 << endl;
    cout << s << " " << s2 << endl;

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x40, %rsp
leaq -0x30(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0xd3a(%rip), %rsi       # 0x2004
leaq 0xd3e(%rip), %rdx       # 0x200f
leaq -0x40(%rbp), %rdi
callq 0x1950
leaq -0x50(%rbp), %r12
movq %r12, -0x10(%r12)
leaq 0xd26(%rip), %rsi       # 0x2010
leaq 0xd30(%rip), %rdx       # 0x2021
leaq -0x60(%rbp), %rdi
callq 0x1950
movq -0x60(%rbp), %rcx
movq -0x58(%rbp), %r8
leaq -0x40(%rbp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x10e0
movq 0x2cc2(%rip), %rdi      # 0x3fd8
leaq 0xd05(%rip), %rsi       # 0x2022
movl $0x21, %edx
callq 0x10f0
movq -0x40(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq 0x2ca2(%rip), %rdi      # 0x3fd8
callq 0x10f0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x10a0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1060
leaq -0x40(%rbp), %rdi
movq 0x8(%rdi), %rdx
leaq 0xc90(%rip), %rcx       # 0x2004
movl $0xb, %r8d
xorl %esi, %esi
callq 0x1110
movq -0x60(%rbp), %rcx
movq -0x58(%rbp), %r8
leaq -0x40(%rbp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x10e0
movq 0x2c3b(%rip), %rdi      # 0x3fd8
leaq 0xca0(%rip), %rsi       # 0x2044
movl $0x21, %edx
callq 0x10f0
movq -0x40(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq 0x2c1b(%rip), %rdi      # 0x3fd8
callq 0x10f0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x10a0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1060
leaq -0x40(%rbp), %rdi
movq 0x8(%rdi), %rdx
leaq 0xc09(%rip), %rcx       # 0x2004
movl $0xb, %r8d
xorl %esi, %esi
callq 0x1110
leaq -0x60(%rbp), %rdx
movq 0x8(%rdx), %r8
leaq -0x40(%rbp), %rdi
xorl %esi, %esi
xorl %ecx, %ecx
callq 0x10d0
movq 0x2bb4(%rip), %rdi      # 0x3fd8
leaq 0xc3b(%rip), %rsi       # 0x2066
movl $0x21, %edx
callq 0x10f0
movq -0x40(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq 0x2b94(%rip), %rdi      # 0x3fd8
callq 0x10f0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x10a0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1060
leaq -0x40(%rbp), %rdi
movq 0x8(%rdi), %rdx
leaq 0xc06(%rip), %rcx       # 0x2088
movl $0x1, %r8d
xorl %esi, %esi
callq 0x1110
movl $0x1, %edi
callq 0x10b0
movq %rax, %rbx
movq %rax, %r8
incq %r8
movb $0x61, (%rax)
leaq -0x40(%rbp), %rdi
movq (%rdi), %rdx
movq %rdx, %rsi
movq %rax, %rcx
callq 0x19ea
leaq -0x40(%rbp), %rdi
movq 0x8(%rdi), %rsi
movl $0x5, %edx
movl $0x21, %ecx
callq 0x1160
movq -0x40(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq 0x2afb(%rip), %rdi      # 0x3fd8
callq 0x10f0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x10a0
movsbl %al, %esi
movq %r14, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1060
leaq -0x40(%rbp), %rdi
movq 0x8(%rdi), %rsi
addq $-0x5, %rsi
movl $0x5, %edx
callq 0x1040
movq -0x40(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq 0x2aa7(%rip), %rdi      # 0x3fd8
callq 0x10f0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x10a0
movsbl %al, %esi
movq %r14, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1060
leaq -0x40(%rbp), %rdi
movq 0x8(%rdi), %rdx
leaq 0xad4(%rip), %rcx       # 0x2043
xorl %esi, %esi
xorl %r8d, %r8d
callq 0x1110
leaq -0x40(%rbp), %rdi
movq 0x8(%rdi), %rdx
leaq 0xb02(%rip), %rcx       # 0x208a
movl $0x7, %r8d
xorl %esi, %esi
callq 0x1110
movq -0x40(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq 0x2a34(%rip), %rdi      # 0x3fd8
callq 0x10f0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x10a0
movsbl %al, %esi
movq %r14, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1060
leaq -0x40(%rbp), %rdi
movq 0x8(%rdi), %rsi
leaq 0xaaf(%rip), %rcx       # 0x2091
movl $0xc, %r8d
xorl %edx, %edx
callq 0x10e0
movq -0x40(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq 0x29da(%rip), %rdi      # 0x3fd8
callq 0x10f0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x10a0
movsbl %al, %esi
movq %r14, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1060
leaq -0x40(%rbp), %rdi
movq 0x8(%rdi), %rdx
leaq 0xa62(%rip), %rcx       # 0x209e
movl $0xa, %r8d
xorl %esi, %esi
callq 0x1110
leaq -0x60(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x1050
leaq -0x40(%rbp), %rdi
movq 0x8(%rdi), %rsi
leaq 0xa44(%rip), %rcx       # 0x20a9
movl $0x8, %r8d
xorl %edx, %edx
callq 0x10e0
leaq 0xa30(%rip), %rsi       # 0x20a9
leaq -0x60(%rbp), %rdi
callq 0x1150
movq -0x40(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq 0x2947(%rip), %rdi      # 0x3fd8
callq 0x10f0
movq %rax, %r14
leaq 0x9a2(%rip), %rsi       # 0x2042
movl $0x1, %edx
movq %rax, %rdi
callq 0x10f0
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
movq %r14, %rdi
callq 0x10f0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x10a0
movsbl %al, %esi
movq %r14, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1060
leaq -0x40(%rbp), %rdi
movl $0xb, %esi
movl $0x3, %edx
callq 0x1040
leaq 0x9b1(%rip), %rcx       # 0x20b2
leaq -0x40(%rbp), %rdi
movl $0xb, %esi
movl $0x3, %r8d
xorl %edx, %edx
callq 0x10e0
leaq 0x994(%rip), %rcx       # 0x20b2
leaq -0x60(%rbp), %rdi
movl $0xb, %esi
movl $0x3, %edx
movl $0x3, %r8d
callq 0x10e0
movq -0x40(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq 0x2892(%rip), %rdi      # 0x3fd8
callq 0x10f0
movq %rax, %r14
leaq 0x8ed(%rip), %rsi       # 0x2042
movl $0x1, %edx
movq %rax, %rdi
callq 0x10f0
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
movq %r14, %rdi
callq 0x10f0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x10a0
movsbl %al, %esi
movq %r14, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1060
leaq 0x913(%rip), %rcx       # 0x20b6
leaq -0x40(%rbp), %rdi
movl $0xb, %esi
movl $0x3, %edx
movl $0x5, %r8d
callq 0x10e0
leaq 0x8ef(%rip), %rsi       # 0x20b2
leaq -0x60(%rbp), %rdi
movl $0x3, %ecx
xorl %edx, %edx
callq 0x1120
cmpq $-0x1, %rax
je 0x17f9
leaq 0x8d6(%rip), %rcx       # 0x20b6
leaq -0x60(%rbp), %rdi
movl $0x3, %edx
movl $0x5, %r8d
movq %rax, %rsi
callq 0x10e0
jmp 0x184f
movq 0x27d8(%rip), %rdi      # 0x3fd8
leaq 0x8b5(%rip), %rsi       # 0x20bc
movl $0x1a, %edx
callq 0x10f0
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
movq 0x27b8(%rip), %rdi      # 0x3fd8
callq 0x10f0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x10a0
movsbl %al, %esi
movq %r14, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1060
movq -0x40(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq 0x277a(%rip), %rdi      # 0x3fd8
callq 0x10f0
movq %rax, %r14
leaq 0x7d5(%rip), %rsi       # 0x2042
movl $0x1, %edx
movq %rax, %rdi
callq 0x10f0
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
movq %r14, %rdi
callq 0x10f0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x10a0
movsbl %al, %esi
movq %r14, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1060
movl $0x1, %esi
movq %rbx, %rdi
callq 0x10c0
movq -0x60(%rbp), %rdi
cmpq %r12, %rdi
je 0x18d6
movq -0x50(%rbp), %rsi
incq %rsi
callq 0x10c0
movq -0x40(%rbp), %rdi
cmpq %r15, %rdi
je 0x18eb
movq -0x30(%rbp), %rsi
incq %rsi
callq 0x10c0
xorl %eax, %eax
addq $0x40, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
jmp 0x190e
jmp 0x1909
jmp 0x1909
movq %rax, %r14
jmp 0x1933
jmp 0x190e
jmp 0x190e
movq %rax, %r14
jmp 0x191e
movq %rax, %r14
movl $0x1, %esi
movq %rbx, %rdi
callq 0x10c0
movq -0x60(%rbp), %rdi
cmpq %r12, %rdi
je 0x1933
movq -0x50(%rbp), %rsi
incq %rsi
callq 0x10c0
movq -0x40(%rbp), %rdi
cmpq %r15, %rdi
je 0x1948
movq -0x30(%rbp), %rsi
incq %rsi
callq 0x10c0
movq %r14, %rdi
callq 0x1130