// File: iZhangHui[P]CppPrimer/CH10_GenericAlgorithms/examples/rcomma.cc
// Function: main
int main()
{
	string line;
	getline(cin, line);

	// find the first element in a comma-separated list
	auto comma = find(line.cbegin(), line.cend(), ',');
	cout << string(line.cbegin(), comma) << endl;
	
	// find the last element in a comma-separated list
	auto rcomma = find(line.crbegin(), line.crend(), ',');
	
	// WRONG: will generate the word in reverse order
	cout << string(line.crbegin(), rcomma) << endl;
	
	// ok: get a forward iterator and read to the end of line
	cout << string(rcomma.base(), line.cend()) << endl;

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x190, %rsp            # imm = 0x190
movl $0x0, -0x4(%rbp)
leaq -0x28(%rbp), %rdi
movq %rdi, -0x128(%rbp)
callq 0x2180
movq -0x128(%rbp), %rsi
movq 0x3c70(%rip), %rdi      # 0x5fe0
callq 0x2040
jmp 0x2377
leaq -0x28(%rbp), %rdi
movq %rdi, -0x138(%rbp)
callq 0x2090
movq -0x138(%rbp), %rdi
movq %rax, -0x48(%rbp)
callq 0x2050
movq %rax, -0x50(%rbp)
movb $0x2c, -0x51(%rbp)
movq -0x48(%rbp), %rdi
movq -0x50(%rbp), %rsi
leaq -0x51(%rbp), %rdx
callq 0x26e0
movq %rax, -0x130(%rbp)
jmp 0x23b9
movq -0x130(%rbp), %rax
movq %rax, -0x40(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x2090
movq %rax, -0x80(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x88(%rbp)
leaq -0x89(%rbp), %rdi
movq %rdi, -0x140(%rbp)
callq 0x21d0
movq -0x140(%rbp), %rcx
movq -0x80(%rbp), %rsi
movq -0x88(%rbp), %rdx
leaq -0x78(%rbp), %rdi
callq 0x2730
jmp 0x240c
movq 0x3bbd(%rip), %rdi      # 0x5fd0
leaq -0x78(%rbp), %rsi
callq 0x2120
movq %rax, -0x148(%rbp)
jmp 0x2425
movq -0x148(%rbp), %rdi
movq 0x3b8d(%rip), %rsi      # 0x5fc0
callq 0x2130
jmp 0x243a
leaq -0x78(%rbp), %rdi
callq 0x20a0
leaq -0x89(%rbp), %rdi
callq 0x2150
leaq -0xa0(%rbp), %rdi
movq %rdi, -0x158(%rbp)
leaq -0x28(%rbp), %rsi
movq %rsi, -0x160(%rbp)
callq 0x2100
movq -0x160(%rbp), %rsi
leaq -0xa8(%rbp), %rdi
movq %rdi, -0x150(%rbp)
callq 0x20f0
movq -0x158(%rbp), %rsi
movq -0x150(%rbp), %rdx
movb $0x2c, -0xa9(%rbp)
leaq -0x98(%rbp), %rdi
leaq -0xa9(%rbp), %rcx
callq 0x27b0
jmp 0x24b1
leaq -0xd8(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x2100
leaq -0xe0(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x2820
jmp 0x24d6
leaq -0xe1(%rbp), %rdi
movq %rdi, -0x168(%rbp)
callq 0x21d0
movq -0x168(%rbp), %rcx
leaq -0xd0(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
leaq -0xe0(%rbp), %rdx
callq 0x2840
jmp 0x250c
movq 0x3abd(%rip), %rdi      # 0x5fd0
leaq -0xd0(%rbp), %rsi
callq 0x2120
movq %rax, -0x170(%rbp)
jmp 0x2528
movq -0x170(%rbp), %rdi
movq 0x3a8a(%rip), %rsi      # 0x5fc0
callq 0x2130
jmp 0x253d
leaq -0xd0(%rbp), %rdi
callq 0x20a0
leaq -0xe1(%rbp), %rdi
callq 0x2150
leaq -0x98(%rbp), %rdi
callq 0x28e0
movq %rax, -0x178(%rbp)
jmp 0x256a
movq -0x178(%rbp), %rax
movq %rax, -0x110(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x2050
movq %rax, -0x118(%rbp)
leaq -0x119(%rbp), %rdi
movq %rdi, -0x180(%rbp)
callq 0x21d0
movq -0x180(%rbp), %rcx
movq -0x110(%rbp), %rsi
movq -0x118(%rbp), %rdx
leaq -0x108(%rbp), %rdi
callq 0x2730
jmp 0x25be
movq 0x3a0b(%rip), %rdi      # 0x5fd0
leaq -0x108(%rbp), %rsi
callq 0x2120
movq %rax, -0x188(%rbp)
jmp 0x25da
movq -0x188(%rbp), %rdi
movq 0x39d8(%rip), %rsi      # 0x5fc0
callq 0x2130
jmp 0x25ef
leaq -0x108(%rbp), %rdi
callq 0x20a0
leaq -0x119(%rbp), %rdi
callq 0x2150
movl $0x0, -0x4(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x20a0
movl -0x4(%rbp), %eax
addq $0x190, %rsp            # imm = 0x190
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x26cb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x2657
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x20a0
leaq -0x89(%rbp), %rdi
callq 0x2150
jmp 0x26cb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x268b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x20a0
leaq -0xe1(%rbp), %rdi
callq 0x2150
jmp 0x26cb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x26bf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x108(%rbp), %rdi
callq 0x20a0
leaq -0x119(%rbp), %rdi
callq 0x2150
leaq -0x28(%rbp), %rdi
callq 0x20a0
movq -0x30(%rbp), %rdi
callq 0x21c0
nopl (%rax)