// File: /workspace/github_cpp_makefile_star2_O1/iZhangHui[P]CppPrimer/CH09_SequentialContainers/examples/find_ops.cc
// Function: main
int main()
{
    string numbers("0123456789"), name("r2d2");
    // returns 1, i.e., the index of the first digit in name
    auto pos = name.find_first_of(numbers);
    if (pos != string::npos)
        cout << "found number at index: " << pos
             << " element is " << name[pos] << endl;
    else
        cout << "no number in: " << name << endl;

    pos = 0;
    // each iteration finds the next number in name
    while ((pos = name.find_first_of(numbers, pos))
                  != string::npos) {
        cout << "found number at index: " << pos
             << " element is " << name[pos] << endl;

        ++pos; // move to the next character
    }

    string river("Mississippi");

    auto first_pos = river.find("is");  // returns 1
    auto last_pos = river.rfind("is");  // returns 4
    cout << "find returned: " << first_pos
         << " rfind returned: " << last_pos << endl;

    string dept("03714p3");
    // returns 5, which is the index to the character 'p'
    pos = dept.find_first_not_of(numbers);
    cout << "first_not returned: " << pos << endl;

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
leaq -0x38(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0xd75(%rip), %rsi       # 0x2004
leaq 0xd78(%rip), %rdx       # 0x200e
leaq -0x48(%rbp), %rdi
callq 0x16d6
leaq -0x58(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0xd61(%rip), %rsi       # 0x200f
leaq 0xd5e(%rip), %rdx       # 0x2013
leaq -0x68(%rbp), %rdi
callq 0x16d6
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rcx
leaq -0x68(%rbp), %rdi
xorl %edx, %edx
callq 0x10d0
cmpq $-0x1, %rax
je 0x134e
movq %rax, %rbx
movq 0x2cf7(%rip), %rdi      # 0x3fd8
leaq 0xd2c(%rip), %rsi       # 0x2014
movl $0x17, %edx
callq 0x10b0
movq 0x2cdf(%rip), %rdi      # 0x3fd8
movq %rbx, %rsi
callq 0x1040
movq %rax, %r14
leaq 0xd21(%rip), %rsi       # 0x202c
movl $0xc, %edx
movq %rax, %rdi
callq 0x10b0
movq -0x68(%rbp), %rax
movb (%rax,%rbx), %al
leaq -0x88(%rbp), %rsi
movb %al, (%rsi)
movl $0x1, %edx
movq %r14, %rdi
callq 0x10b0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x1090
jmp 0x1391
movq 0x2c83(%rip), %rdi      # 0x3fd8
leaq 0xcdd(%rip), %rsi       # 0x2039
movl $0xe, %edx
callq 0x10b0
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %rdx
movq 0x2c63(%rip), %rdi      # 0x3fd8
callq 0x10b0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x1090
movsbl %al, %esi
movq %rbx, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1050
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rcx
leaq -0x68(%rbp), %rdi
xorl %edx, %edx
callq 0x10d0
cmpq $-0x1, %rax
je 0x1476
movq %rax, %rbx
movq 0x2c0d(%rip), %r14      # 0x3fd8
leaq -0x88(%rbp), %r13
leaq -0x68(%rbp), %r15
movl $0x17, %edx
movq %r14, %rdi
leaq 0xc2f(%rip), %rsi       # 0x2014
callq 0x10b0
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1040
movq %rax, %r12
movl $0xc, %edx
movq %rax, %rdi
leaq 0xc25(%rip), %rsi       # 0x202c
callq 0x10b0
movq -0x68(%rbp), %rax
movb (%rax,%rbx), %al
movb %al, -0x88(%rbp)
movl $0x1, %edx
movq %r12, %rdi
movq %r13, %rsi
callq 0x10b0
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x1090
movsbl %al, %esi
movq %r12, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1050
incq %rbx
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rcx
movq %r15, %rdi
movq %rbx, %rdx
callq 0x10d0
movq %rax, %rbx
cmpq $-0x1, %rax
jne 0x13d6
leaq -0x78(%rbp), %r12
movq %r12, -0x10(%r12)
leaq 0xbc2(%rip), %rsi       # 0x2048
leaq 0xbc6(%rip), %rdx       # 0x2053
leaq -0x88(%rbp), %rdi
callq 0x16d6
leaq 0xbb4(%rip), %rbx       # 0x2054
leaq -0x88(%rbp), %r15
movl $0x2, %ecx
movq %r15, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x1100
movq %rax, %r14
movl $0x2, %ecx
movq %r15, %rdi
movq %rbx, %rsi
movq $-0x1, %rdx
callq 0x10c0
movq %rax, %rbx
movq 0x2afb(%rip), %rdi      # 0x3fd8
leaq 0xb75(%rip), %rsi       # 0x2059
movl $0xf, %edx
callq 0x10b0
movq 0x2ae3(%rip), %rdi      # 0x3fd8
movq %r14, %rsi
callq 0x1040
movq %rax, %r14
leaq 0xb50(%rip), %rsi       # 0x2057
movl $0x11, %edx
movq %rax, %rdi
callq 0x10b0
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1040
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x1090
movsbl %al, %esi
movq %rbx, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1050
leaq -0x98(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0xb0e(%rip), %rsi       # 0x2069
leaq 0xb0e(%rip), %rdx       # 0x2070
leaq -0xa8(%rbp), %rdi
callq 0x16d6
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rcx
leaq -0xa8(%rbp), %rdi
xorl %edx, %edx
callq 0x10f0
movq %rax, %rbx
movq 0x2a4a(%rip), %rdi      # 0x3fd8
leaq 0xadc(%rip), %rsi       # 0x2071
movl $0x14, %edx
callq 0x10b0
movq 0x2a32(%rip), %rdi      # 0x3fd8
movq %rbx, %rsi
callq 0x1040
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x1090
movsbl %al, %esi
movq %rbx, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1050
movq -0xa8(%rbp), %rdi
cmpq %r14, %rdi
je 0x15f3
movq -0x98(%rbp), %rsi
incq %rsi
callq 0x10a0
movq -0x88(%rbp), %rdi
cmpq %r12, %rdi
je 0x160b
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x10a0
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x1624
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x10a0
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x163d
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x10a0
xorl %eax, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x167c
jmp 0x1699
movq %rax, %rbx
jmp 0x16b5
movq %rax, %rbx
movq -0xa8(%rbp), %rdi
cmpq %r14, %rdi
je 0x167f
movq -0x98(%rbp), %rsi
incq %rsi
callq 0x10a0
jmp 0x167f
jmp 0x1699
movq %rax, %rbx
movq -0x88(%rbp), %rdi
cmpq %r12, %rdi
je 0x169c
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x10a0
jmp 0x169c
movq %rax, %rbx
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x16b5
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x10a0
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x16ce
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x10a0
movq %rbx, %rdi
callq 0x1110