// File: /workspace/github_cpp_makefile_star2_O2/iZhangHui[P]CppPrimer/CH11_AssociativeContainers/examples/wcEx.cc
// Function: main
int main()
{
	// count number of times each word occurs in the input
	map<string, size_t> word_count; // empty map from string to size_t
	string word;
	while (cin >> word) {
		auto ret = word_count.insert({word, 0});
		cout << "insert " << word << (ret.second ? " successfully" : " failed") << endl;
		++ret.first->second;
		// ++word_count.insert({word, 0}).first->second;
	}

	for(auto it = word_count.cbegin(); it != word_count.cend(); ++it) {
		auto w = *it;
		cout <<  w.first << " occurs " << w.second << " times" << endl;
	}

	// get iterator positioned on the first element
	auto map_it = word_count.cbegin();
	// for each element in the map
	while (map_it != word_count.cend()) {
		// print the element key, value pairs
		cout << map_it->first << " occurs "
			 << map_it->second << " times" << endl;
		++map_it;  // increment iterator to denote the next element
	}

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
leaq -0x50(%rbp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
leaq -0x90(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq -0xa0(%rbp), %r14
leaq -0x80(%rbp), %r15
leaq 0xcff(%rip), %r12       # 0x201a
movq 0x2cbe(%rip), %rdi      # 0x3fe0
movq %r14, %rsi
callq 0x1130
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x13ab
movq %r15, %rdi
movq %r14, %rsi
callq 0x1140
andq $0x0, -0x60(%rbp)
leaq -0x58(%rbp), %rdi
movq %r15, %rsi
callq 0x1598
movq %rax, %rbx
movl %edx, %r13d
movq %r15, %rdi
callq 0x1080
movq 0x2c67(%rip), %rdi      # 0x3fd0
leaq 0xc94(%rip), %rsi       # 0x2004
callq 0x10e0
movq %rax, %rdi
movq %r14, %rsi
callq 0x10d0
testb $0x1, %r13b
movq %r12, %rsi
leaq 0xc7e(%rip), %rcx       # 0x200c
cmovneq %rcx, %rsi
movq %rax, %rdi
callq 0x10e0
movq %rax, %rdi
callq 0x1090
incq 0x40(%rbx)
jmp 0x131b
movq -0x40(%rbp), %r12
leaq -0x80(%rbp), %rbx
movq 0x2c16(%rip), %r14      # 0x3fd0
leaq 0xc61(%rip), %r15       # 0x2022
leaq 0xc63(%rip), %r13       # 0x202b
leaq -0x50(%rbp), %rax
cmpq %rax, %r12
je 0x1428
leaq 0x20(%r12), %rsi
movq %rbx, %rdi
callq 0x14ee
movq %r14, %rdi
movq %rbx, %rsi
callq 0x10d0
movq %rax, %rdi
movq %r15, %rsi
callq 0x10e0
movq -0x60(%rbp), %rsi
movq %rax, %rdi
callq 0x10a0
movq %rax, %rdi
movq %r13, %rsi
callq 0x10e0
movq %rax, %rdi
callq 0x1090
movq %rbx, %rdi
callq 0x1080
movq %r12, %rdi
callq 0x1120
movq %rax, %r12
jmp 0x13c8
movq -0x40(%rbp), %r12
movq 0x2b9d(%rip), %rbx      # 0x3fd0
leaq 0xbe8(%rip), %r14       # 0x2022
leaq 0xbea(%rip), %r15       # 0x202b
leaq -0x50(%rbp), %rax
cmpq %rax, %r12
je 0x148f
leaq 0x20(%r12), %rsi
movq %rbx, %rdi
callq 0x10d0
movq %rax, %rdi
movq %r14, %rsi
callq 0x10e0
movq 0x40(%r12), %rsi
movq %rax, %rdi
callq 0x10a0
movq %rax, %rdi
movq %r15, %rsi
callq 0x10e0
movq %rax, %rdi
callq 0x1090
movq %r12, %rdi
callq 0x1120
movq %rax, %r12
jmp 0x1441
leaq -0xa0(%rbp), %rdi
callq 0x1080
leaq -0x58(%rbp), %rdi
callq 0x151c
xorl %eax, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x14bf
jmp 0x14c4
jmp 0x14bf
jmp 0x14bf
jmp 0x14bf
movq %rax, %rbx
jmp 0x14d0
movq %rax, %rbx
leaq -0x80(%rbp), %rdi
callq 0x1080
leaq -0xa0(%rbp), %rdi
callq 0x1080
leaq -0x58(%rbp), %rdi
callq 0x151c
movq %rbx, %rdi
callq 0x1180
nop