// File: iZhangHui[P]CppPrimer/CH11_AssociativeContainers/exercises/ex11_03_04.cc
// Function: main
int main(int argc, char const *argv[])
{
	// count the 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) {
		for (auto& ch : word)
			ch = tolower(ch);

		// strip - iterator erase(iterator __first, iterator __last)
		word.erase(remove_if(word.begin(), word.end(), ispunct), word.end());
		++word_count[word];
	}

	for (const auto& w : word_count)
		cout <<  w.first << " occurs " << w.second << " times" << endl;

	// get an iterator positioned on the first element
	auto map_it = word_count.cbegin();
	// compare the current iterator to the off-the-end iterator
	while (map_it != word_count.cend()) {
		// dereference the iterator to print the element key--value pairs
		cout << map_it->first << " occurs "
			 << map_it->second << " times" << endl;
		++map_it;  // increment the iterator to denote the next element
	}

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x170, %rsp            # imm = 0x170
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x2750
leaq -0x60(%rbp), %rdi
callq 0x21a0
movq 0x5c66(%rip), %rdi      # 0x7fd8
leaq -0x60(%rbp), %rsi
callq 0x2190
movq %rax, -0x100(%rbp)
jmp 0x2384
movq -0x100(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x2180
movb %al, -0x101(%rbp)
jmp 0x23a2
movb -0x101(%rbp), %al
testb $0x1, %al
jne 0x23b1
jmp 0x2539
leaq -0x60(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rdi
callq 0x20f0
movq %rax, -0x80(%rbp)
movq -0x78(%rbp), %rdi
callq 0x20b0
movq %rax, -0x88(%rbp)
leaq -0x80(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x2770
testb $0x1, %al
jne 0x23ec
jmp 0x2444
leaq -0x80(%rbp), %rdi
callq 0x27b0
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rax
movsbl (%rax), %edi
callq 0x21b0
movb %al, %cl
movq -0x90(%rbp), %rax
movb %cl, (%rax)
leaq -0x80(%rbp), %rdi
callq 0x27d0
jmp 0x23d6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x20c0
leaq -0x40(%rbp), %rdi
callq 0x2b20
jmp 0x273d
leaq -0x60(%rbp), %rdi
movq %rdi, -0x118(%rbp)
callq 0x20f0
movq -0x118(%rbp), %rdi
movq %rax, -0xa8(%rbp)
callq 0x20b0
movq %rax, -0xb0(%rbp)
movq -0xa8(%rbp), %rdi
movq -0xb0(%rbp), %rsi
movq 0x5b6d(%rip), %rdx      # 0x7ff0
callq 0x27f0
movq %rax, -0x110(%rbp)
jmp 0x2491
movq -0x110(%rbp), %rax
movq %rax, -0xa0(%rbp)
leaq -0x98(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x2840
leaq -0x60(%rbp), %rdi
movq %rdi, -0x128(%rbp)
callq 0x20b0
movq %rax, -0xc0(%rbp)
leaq -0xb8(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x2840
movq -0x128(%rbp), %rdi
movq -0x98(%rbp), %rsi
movq -0xb8(%rbp), %rdx
callq 0x2050
movq %rax, -0x120(%rbp)
jmp 0x24ff
movq -0x120(%rbp), %rax
movq %rax, -0xc8(%rbp)
leaq -0x40(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x2880
movq %rax, -0x130(%rbp)
jmp 0x2523
movq -0x130(%rbp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
jmp 0x236b
leaq -0x40(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq -0xd0(%rbp), %rdi
callq 0x2960
movq %rax, -0xd8(%rbp)
movq -0xd0(%rbp), %rdi
callq 0x2990
movq %rax, -0xe0(%rbp)
leaq -0xd8(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x29c0
testb $0x1, %al
jne 0x2586
jmp 0x2635
leaq -0xd8(%rbp), %rdi
callq 0x29f0
movq %rax, -0xe8(%rbp)
movq -0xe8(%rbp), %rsi
movq 0x5a21(%rip), %rdi      # 0x7fc8
callq 0x2110
movq %rax, -0x138(%rbp)
jmp 0x25b5
movq -0x138(%rbp), %rdi
leaq 0x2a51(%rip), %rsi      # 0x5014
callq 0x2120
movq %rax, -0x140(%rbp)
jmp 0x25d1
movq -0x140(%rbp), %rdi
movq -0xe8(%rbp), %rax
movq 0x20(%rax), %rsi
callq 0x2060
movq %rax, -0x148(%rbp)
jmp 0x25f1
movq -0x148(%rbp), %rdi
leaq 0x2a1e(%rip), %rsi      # 0x501d
callq 0x2120
movq %rax, -0x150(%rbp)
jmp 0x260d
movq -0x150(%rbp), %rdi
movq 0x599d(%rip), %rsi      # 0x7fb8
callq 0x2160
jmp 0x2622
jmp 0x2624
leaq -0xd8(%rbp), %rdi
callq 0x2a10
jmp 0x256a
leaq -0x40(%rbp), %rdi
callq 0x2a40
movq %rax, -0xf0(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x2aa0
movq %rax, -0xf8(%rbp)
leaq -0xf0(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
callq 0x2a70
testb $0x1, %al
jne 0x2671
jmp 0x2718
leaq -0xf0(%rbp), %rdi
callq 0x2ad0
movq %rax, %rsi
movq 0x5941(%rip), %rdi      # 0x7fc8
callq 0x2110
movq %rax, -0x158(%rbp)
jmp 0x2695
movq -0x158(%rbp), %rdi
leaq 0x2971(%rip), %rsi      # 0x5014
callq 0x2120
movq %rax, -0x160(%rbp)
jmp 0x26b1
leaq -0xf0(%rbp), %rdi
callq 0x2ad0
movq -0x160(%rbp), %rdi
movq 0x20(%rax), %rsi
callq 0x2060
movq %rax, -0x168(%rbp)
jmp 0x26d6
movq -0x168(%rbp), %rdi
leaq 0x2939(%rip), %rsi      # 0x501d
callq 0x2120
movq %rax, -0x170(%rbp)
jmp 0x26f2
movq -0x170(%rbp), %rdi
movq 0x58b8(%rip), %rsi      # 0x7fb8
callq 0x2160
jmp 0x2707
leaq -0xf0(%rbp), %rdi
callq 0x2af0
jmp 0x2645
movl $0x0, -0x4(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x20c0
leaq -0x40(%rbp), %rdi
callq 0x2b20
movl -0x4(%rbp), %eax
addq $0x170, %rsp            # imm = 0x170
popq %rbp
retq
movq -0x68(%rbp), %rdi
callq 0x21f0
nopw %cs:(%rax,%rax)