// File: /workspace/github_cpp_makefile_star2_O3/iZhangHui[P]CppPrimer/CH12_DynamicMemory/exercises/ex12_28.cc
// Function: main
int main(int argc, char const *argv[])
{
	ifstream infile;
	vector<string> file;
	map<string, set<decltype(file.size())>> wm;

	// Test data CH12_DynamicMemory/examples/data/storyDataFile
	if (argc < 2 || !(infile.open(argv[1]), infile)) {
		cerr << "No input file!" << endl;
		return EXIT_FAILURE;
	}

	string text;
	while (getline(infile, text)) {
		file.push_back(text);
		istringstream line(text);
		string str;
		while (line >> str) {
			string word;
			remove_copy_if(str.cbegin(), str.cend(), back_inserter(word), ispunct);
			wm[word].insert(file.size());
		}
	}

	while (true) {
		cout << "enter word to look for, or q to quite: ";
		string s;

		if (!(cin >> s) || s == "q")
			break;

		auto found = wm.find(s);
		if (found != wm.end()) {
			cout << s << " occurs " << found->second.size() << "time(s)" << endl;
			for (auto num : found->second) {
				cout << "\t(line " << num  << ") " << file[num - 1] << endl;
			}
		} else {
			cout << s << " occurs 0 time" << endl;
		}
	}
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x438, %rsp            # imm = 0x438
movq %rsi, %rbx
movl %edi, %r14d
leaq -0x460(%rbp), %rdi
callq 0x21a0
xorl %eax, %eax
movq %rax, -0x50(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0x60(%rbp)
leaq -0xd0(%rbp), %rcx
movl $0x0, (%rcx)
movq %rax, 0x8(%rcx)
movq %rcx, 0x10(%rcx)
movq %rcx, 0x18(%rcx)
movq %rax, 0x20(%rcx)
cmpl $0x2, %r14d
jl 0x2440
movq 0x8(%rbx), %rsi
leaq -0x460(%rbp), %rdi
movl $0x8, %edx
callq 0x20d0
movq -0x460(%rbp), %rax
movq -0x18(%rax), %rcx
testb $0x5, -0x440(%rbp,%rcx)
je 0x24c0
movq 0x3ba9(%rip), %rbx      # 0x5ff0
leaq 0x1bb6(%rip), %rsi      # 0x4004
movl $0xe, %edx
movq %rbx, %rdi
callq 0x21b0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq 0x3b77(%rip), %rdi      # 0x5ff0
callq 0x2030
movl $0x1, %ebx
movq %rax, %rdi
callq 0x20f0
leaq -0xd8(%rbp), %rdi
callq 0x2afa
leaq -0x60(%rbp), %rdi
callq 0x2a7e
leaq -0x460(%rbp), %rdi
callq 0x2060
movl %ebx, %eax
addq $0x438, %rsp            # imm = 0x438
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq -0x90(%rbp), %rcx
movq %rcx, -0x10(%rcx)
movq $0x0, -0x8(%rcx)
movb $0x0, (%rcx)
leaq -0x70(%rbp), %r15
movq -0x18(%rax), %rdi
leaq -0x460(%rbp), %rax
addq %rax, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %edx
leaq -0x460(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x2250
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x2658
leaq -0x60(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x29b2
leaq -0x258(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
movl $0x8, %edx
callq 0x2220
leaq -0x38(%rbp), %rax
movq %rax, -0x48(%rbp)
movq $0x0, -0x40(%rbp)
movb $0x0, -0x38(%rbp)
leaq -0x258(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x21d0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x2614
movq %r15, %r14
movq %r15, -0x80(%rbp)
movq $0x0, -0x78(%rbp)
movb $0x0, -0x70(%rbp)
movq -0x40(%rbp), %rbx
testq %rbx, %rbx
je 0x25c1
movq -0x48(%rbp), %r13
xorl %r15d, %r15d
movsbl (%r13,%r15), %r12d
movl %r12d, %edi
callq 0x2260
testl %eax, %eax
jne 0x25b9
leaq -0x80(%rbp), %rdi
movl %r12d, %esi
callq 0x2140
incq %r15
cmpq %r15, %rbx
jne 0x259b
leaq -0xd8(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x29fe
movq -0x58(%rbp), %rcx
subq -0x60(%rbp), %rcx
sarq $0x5, %rcx
movq %rcx, -0xa8(%rbp)
movq %rax, %rdi
leaq -0xa8(%rbp), %rsi
movq %r14, %r15
callq 0x325e
movq -0x80(%rbp), %rdi
cmpq %r15, %rdi
je 0x2556
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x2180
jmp 0x2556
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x262d
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2180
leaq -0x258(%rbp), %rdi
movq 0x3985(%rip), %rsi      # 0x5fc0
callq 0x21e0
leaq -0x1e0(%rbp), %rdi
callq 0x2090
movq -0x460(%rbp), %rax
jmp 0x24da
leaq -0x248(%rbp), %r13
leaq -0x258(%rbp), %rbx
movl $0x27, %edx
movq 0x3956(%rip), %rdi      # 0x5fc8
leaq 0x199a(%rip), %rsi      # 0x4013
callq 0x21b0
movq %r13, -0x258(%rbp)
movq $0x0, -0x250(%rbp)
movb $0x0, -0x248(%rbp)
movq 0x393a(%rip), %rdi      # 0x5fd8
movq %rbx, %rsi
callq 0x21d0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
je 0x26e1
xorl %ebx, %ebx
movq -0x258(%rbp), %rdi
cmpq %r13, %rdi
je 0x26d1
movq -0x248(%rbp), %rsi
incq %rsi
callq 0x2180
testb %bl, %bl
leaq -0x258(%rbp), %rbx
jne 0x2666
jmp 0x289d
movq %rbx, %rdi
leaq 0x1950(%rip), %rsi      # 0x403b
callq 0x2080
testl %eax, %eax
je 0x26b4
leaq -0xd8(%rbp), %rdi
movq %rbx, %rsi
callq 0x3380
movq %rax, %r15
movq -0x258(%rbp), %rsi
movq -0x250(%rbp), %rdx
leaq -0xd0(%rbp), %rax
cmpq %rax, %r15
je 0x284c
movq 0x389d(%rip), %rdi      # 0x5fc8
callq 0x21b0
movq %rax, %r14
movl $0x8, %edx
movq %rax, %rdi
leaq 0x18fb(%rip), %rsi      # 0x403d
callq 0x21b0
movq 0x68(%r15), %rsi
movq %r14, %rdi
callq 0x20e0
movq %rax, %r12
movl $0x7, %edx
movq %rax, %rdi
leaq 0x18e1(%rip), %rsi      # 0x4046
callq 0x21b0
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq %r12, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20f0
movq 0x58(%r15), %r12
addq $0x48, %r15
movb $0x1, %bl
cmpq %r15, %r12
je 0x2840
movq 0x20(%r12), %r13
movl $0x7, %edx
movq 0x3812(%rip), %rdi      # 0x5fc8
leaq 0x1891(%rip), %rsi      # 0x404e
callq 0x21b0
movq 0x37ff(%rip), %rdi      # 0x5fc8
movq %r13, %rsi
callq 0x20e0
movq %rax, %r14
movl $0x2, %edx
movq %rax, %rdi
leaq 0x1873(%rip), %rsi      # 0x4056
callq 0x21b0
movq -0x60(%rbp), %rax
shlq $0x5, %r13
movq -0x20(%rax,%r13), %rsi
movq -0x18(%rax,%r13), %rdx
movq %r14, %rdi
callq 0x21b0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20f0
movq %r12, %rdi
callq 0x21c0
movq %rax, %r12
cmpq %r15, %rax
jne 0x27a5
leaq -0x248(%rbp), %r13
jmp 0x26b6
movq 0x3775(%rip), %rdi      # 0x5fc8
callq 0x21b0
movq %rax, %r15
movl $0xe, %edx
movq %rax, %rdi
leaq 0x17ef(%rip), %rsi      # 0x4059
callq 0x21b0
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq %r15, %rdi
callq 0x2030
movb $0x1, %bl
movq %rax, %rdi
callq 0x20f0
jmp 0x26b6
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rax
cmpq %rax, %rdi
je 0x28bf
movq -0x90(%rbp), %rsi
incq %rsi
callq 0x2180
xorl %ebx, %ebx
jmp 0x248b
movq %rax, %rbx
jmp 0x2989
jmp 0x28d9
jmp 0x28d9
jmp 0x28d4
movq %rax, %rbx
jmp 0x28eb
movq %rax, %rbx
jmp 0x2967
movq %rax, %rbx
leaq -0x248(%rbp), %r13
movq -0x258(%rbp), %rdi
cmpq %r13, %rdi
je 0x2967
movq -0x248(%rbp), %rsi
incq %rsi
callq 0x2180
jmp 0x2967
movq %rax, %rbx
jmp 0x291a
jmp 0x2914
movq %rax, %rbx
jmp 0x292f
movq %rax, %rbx
movq %r14, %r15
movq -0x80(%rbp), %rdi
cmpq %r15, %rdi
je 0x292f
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x2180
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x2948
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2180
movq 0x3671(%rip), %rsi      # 0x5fc0
leaq -0x258(%rbp), %rdi
callq 0x21e0
leaq -0x1e0(%rbp), %rdi
callq 0x2090
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rax
cmpq %rax, %rdi
je 0x2989
movq -0x90(%rbp), %rsi
incq %rsi
callq 0x2180
leaq -0xd8(%rbp), %rdi
callq 0x2afa
leaq -0x60(%rbp), %rdi
callq 0x2a7e
leaq -0x460(%rbp), %rdi
callq 0x2060
movq %rbx, %rdi
callq 0x2230