// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %rbx
subq $0x58, %rsp
leaq -0x48(%rbp), %r14
movq %r14, -0x10(%r14)
movq $0x0, -0x8(%r14)
movb $0x0, (%r14)
movq 0x2d9c(%rip), %rdi      # 0x3fe0
movq (%rdi), %rax
addq -0x18(%rax), %rdi
movl $0xa, %esi
callq 0x1070
movsbl %al, %edx
movq 0x2d81(%rip), %rdi      # 0x3fe0
leaq -0x58(%rbp), %rsi
callq 0x10d0
movq -0x58(%rbp), %rdi
movq -0x50(%rbp), %rsi
addq %rdi, %rsi
leaq -0x38(%rbp), %rdx
movb $0x2c, (%rdx)
callq 0x1461
movq -0x58(%rbp), %rsi
leaq -0x28(%rbp), %r15
movq %r15, -0x10(%r15)
leaq -0x38(%rbp), %rdi
movq %rax, %rdx
callq 0x14fc
movq -0x38(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq 0x2d2a(%rip), %rdi      # 0x3fd0
callq 0x1090
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x1070
movsbl %al, %esi
movq %rbx, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1040
movq -0x38(%rbp), %rdi
cmpq %r15, %rdi
je 0x12ea
movq -0x28(%rbp), %rsi
incq %rsi
callq 0x1080
movq -0x58(%rbp), %rax
movq -0x50(%rbp), %rdx
addq %rax, %rdx
leaq -0x68(%rbp), %rcx
movb $0x2c, (%rcx)
leaq -0x38(%rbp), %rsi
movq %rdx, (%rsi)
leaq -0x70(%rbp), %rdx
movq %rax, (%rdx)
leaq -0x60(%rbp), %rdi
callq 0x1579
movq -0x58(%rbp), %rax
addq -0x50(%rbp), %rax
movq -0x60(%rbp), %rcx
leaq -0x38(%rbp), %rdi
movq %r15, (%rdi)
leaq -0x70(%rbp), %rsi
movq %rax, (%rsi)
leaq -0x68(%rbp), %rdx
movq %rcx, (%rdx)
callq 0x1634
movq -0x38(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq 0x2c88(%rip), %rdi      # 0x3fd0
callq 0x1090
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x1070
movsbl %al, %esi
movq %rbx, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1040
movq -0x38(%rbp), %rdi
cmpq %r15, %rdi
je 0x138c
movq -0x28(%rbp), %rsi
incq %rsi
callq 0x1080
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
addq -0x50(%rbp), %rdx
leaq -0x38(%rbp), %rdi
movq %r15, (%rdi)
callq 0x14fc
movq -0x38(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq 0x2c1d(%rip), %rdi      # 0x3fd0
callq 0x1090
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x1070
movsbl %al, %esi
movq %rbx, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1040
movq -0x38(%rbp), %rdi
cmpq %r15, %rdi
je 0x13f7
movq -0x28(%rbp), %rsi
incq %rsi
callq 0x1080
movq -0x58(%rbp), %rdi
cmpq %r14, %rdi
je 0x140c
movq -0x48(%rbp), %rsi
incq %rsi
callq 0x1080
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1423
jmp 0x1423
jmp 0x1423
jmp 0x1423
jmp 0x1423
movq %rax, %rbx
jmp 0x1444
jmp 0x142c
jmp 0x142c
movq %rax, %rbx
movq -0x38(%rbp), %rdi
cmpq %r15, %rdi
je 0x1444
movq -0x28(%rbp), %rsi
incq %rsi
callq 0x1080
movq -0x58(%rbp), %rdi
cmpq %r14, %rdi
je 0x1459
movq -0x48(%rbp), %rsi
incq %rsi
callq 0x1080
movq %rbx, %rdi
callq 0x10b0