// File: 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
subq $0x180, %rsp            # imm = 0x180
movl $0x0, -0x4(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x26d0
leaq -0x58(%rbp), %rdi
callq 0x2160
movq 0x4cc5(%rip), %rdi      # 0x6fe0
leaq -0x58(%rbp), %rsi
callq 0x2150
movq %rax, -0x108(%rbp)
jmp 0x232d
movq -0x108(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x2140
movb %al, -0x109(%rbp)
jmp 0x234b
movb -0x109(%rbp), %al
testb $0x1, %al
jne 0x235a
jmp 0x2495
movl $0x0, -0xa4(%rbp)
leaq -0xa0(%rbp), %rdi
leaq -0x58(%rbp), %rsi
leaq -0xa4(%rbp), %rdx
callq 0x2730
jmp 0x237d
leaq -0x38(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x26f0
movb %dl, -0x119(%rbp)
movq %rax, -0x118(%rbp)
jmp 0x239c
movb -0x119(%rbp), %al
movq -0x118(%rbp), %rcx
movq %rcx, -0xb8(%rbp)
movb %al, -0xb0(%rbp)
movb -0xb0(%rbp), %al
movb %al, -0x70(%rbp)
movq -0xb8(%rbp), %rax
movq %rax, -0x78(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x2770
movq 0x4bf3(%rip), %rdi      # 0x6fd0
leaq 0x1c20(%rip), %rsi      # 0x4004
callq 0x20e0
movq %rax, -0x128(%rbp)
jmp 0x23f2
movq -0x128(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x20d0
movq %rax, -0x130(%rbp)
jmp 0x240b
movq -0x130(%rbp), %rdi
movb -0x70(%rbp), %cl
leaq 0x1bf0(%rip), %rax      # 0x400c
leaq 0x1bf7(%rip), %rsi      # 0x401a
testb $0x1, %cl
cmovneq %rax, %rsi
callq 0x20e0
movq %rax, -0x138(%rbp)
jmp 0x2438
movq -0x138(%rbp), %rdi
movq 0x4b7a(%rip), %rsi      # 0x6fc0
callq 0x2120
jmp 0x244d
leaq -0x78(%rbp), %rdi
callq 0x2790
movq 0x20(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x20(%rax)
jmp 0x2314
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x26b5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x2770
jmp 0x26b5
leaq -0x38(%rbp), %rdi
callq 0x27b0
movq %rax, -0xc0(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x2810
movq %rax, -0xc8(%rbp)
leaq -0xc0(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x27e0
testb $0x1, %al
jne 0x24d1
jmp 0x25ad
leaq -0xc0(%rbp), %rdi
callq 0x2840
movq %rax, %rsi
leaq -0xf0(%rbp), %rdi
callq 0x2860
jmp 0x24ee
movq 0x4adb(%rip), %rdi      # 0x6fd0
leaq -0xf0(%rbp), %rsi
callq 0x20d0
movq %rax, -0x140(%rbp)
jmp 0x250a
movq -0x140(%rbp), %rdi
leaq 0x1b0a(%rip), %rsi      # 0x4022
callq 0x20e0
movq %rax, -0x148(%rbp)
jmp 0x2526
movq -0x148(%rbp), %rdi
movq -0xd0(%rbp), %rsi
callq 0x2050
movq %rax, -0x150(%rbp)
jmp 0x2542
movq -0x150(%rbp), %rdi
leaq 0x1adb(%rip), %rsi      # 0x402b
callq 0x20e0
movq %rax, -0x158(%rbp)
jmp 0x255e
movq -0x158(%rbp), %rdi
movq 0x4a54(%rip), %rsi      # 0x6fc0
callq 0x2120
jmp 0x2573
leaq -0xf0(%rbp), %rdi
callq 0x2770
leaq -0xc0(%rbp), %rdi
callq 0x28a0
jmp 0x24a5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0xf0(%rbp), %rdi
callq 0x2770
jmp 0x26b5
leaq -0x38(%rbp), %rdi
callq 0x27b0
movq %rax, -0xf8(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x2810
movq %rax, -0x100(%rbp)
leaq -0xf8(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0x27e0
testb $0x1, %al
jne 0x25e9
jmp 0x2690
leaq -0xf8(%rbp), %rdi
callq 0x28d0
movq %rax, %rsi
movq 0x49d1(%rip), %rdi      # 0x6fd0
callq 0x20d0
movq %rax, -0x160(%rbp)
jmp 0x260d
movq -0x160(%rbp), %rdi
leaq 0x1a07(%rip), %rsi      # 0x4022
callq 0x20e0
movq %rax, -0x168(%rbp)
jmp 0x2629
leaq -0xf8(%rbp), %rdi
callq 0x28d0
movq -0x168(%rbp), %rdi
movq 0x20(%rax), %rsi
callq 0x2050
movq %rax, -0x170(%rbp)
jmp 0x264e
movq -0x170(%rbp), %rdi
leaq 0x19cf(%rip), %rsi      # 0x402b
callq 0x20e0
movq %rax, -0x178(%rbp)
jmp 0x266a
movq -0x178(%rbp), %rdi
movq 0x4948(%rip), %rsi      # 0x6fc0
callq 0x2120
jmp 0x267f
leaq -0xf8(%rbp), %rdi
callq 0x28a0
jmp 0x25bd
movl $0x0, -0x4(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x20a0
leaq -0x38(%rbp), %rdi
callq 0x28f0
movl -0x4(%rbp), %eax
addq $0x180, %rsp            # imm = 0x180
popq %rbp
retq
leaq -0x58(%rbp), %rdi
callq 0x20a0
leaq -0x38(%rbp), %rdi
callq 0x28f0
movq -0x60(%rbp), %rdi
callq 0x21a0