// File: /workspace/github_cpp_makefile_star2_O2/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
andq $0x0, -0x30(%rbp)
leaq -0xd0(%rbp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
xorps %xmm0, %xmm0
movaps %xmm0, -0x40(%rbp)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
cmpl $0x2, %r14d
jl 0x23f8
movq 0x8(%rbx), %rsi
leaq -0x460(%rbp), %rdi
pushq $0x8
popq %rdx
callq 0x20f0
movq -0x460(%rbp), %rax
movq -0x18(%rax), %rax
testb $0x5, -0x440(%rbp,%rax)
je 0x244b
movq 0x3bf1(%rip), %rdi      # 0x5ff0
leaq 0x1bfe(%rip), %rsi      # 0x4004
callq 0x2160
movq %rax, %rdi
callq 0x20d0
pushq $0x1
popq %rbx
leaq -0xd8(%rbp), %rdi
callq 0x286e
leaq -0x40(%rbp), %rdi
callq 0x2834
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 -0x98(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq -0xa8(%rbp), %rsi
leaq -0x258(%rbp), %r12
leaq -0x68(%rbp), %r15
leaq -0x88(%rbp), %rbx
leaq -0x48(%rbp), %r13
leaq -0x460(%rbp), %rdi
callq 0x2050
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x2562
leaq -0x40(%rbp), %rdi
leaq -0xa8(%rbp), %r14
movq %r14, %rsi
callq 0x277e
movq %r12, %rdi
movq %r14, %rsi
pushq $0x8
popq %rdx
callq 0x2220
leaq -0x58(%rbp), %rax
movq %rax, -0x68(%rbp)
andq $0x0, -0x60(%rbp)
movb $0x0, -0x58(%rbp)
movq %r12, %rdi
movq %r15, %rsi
callq 0x21c0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x2546
leaq -0x78(%rbp), %rax
movq %rax, -0x88(%rbp)
andq $0x0, -0x80(%rbp)
movb $0x0, -0x78(%rbp)
movq -0x68(%rbp), %rdi
movq -0x60(%rbp), %rsi
addq %rdi, %rsi
movq %rbx, %rdx
movq 0x3adb(%rip), %rcx      # 0x5fe8
callq 0x2bc2
leaq -0xd8(%rbp), %rdi
movq %rbx, %rsi
callq 0x27ba
movq -0x38(%rbp), %rcx
subq -0x40(%rbp), %rcx
sarq $0x5, %rcx
movq %rcx, -0x48(%rbp)
movq %rax, %rdi
movq %r13, %rsi
callq 0x3050
movq %rbx, %rdi
callq 0x20b0
jmp 0x24cb
movq %r15, %rdi
callq 0x20b0
movq %r12, %rdi
callq 0x20c0
leaq -0xa8(%rbp), %rsi
jmp 0x247b
movq 0x3a57(%rip), %rbx      # 0x5fc0
leaq -0x258(%rbp), %r15
leaq 0x1adf(%rip), %r14      # 0x4056
movq %rbx, %rdi
leaq 0x1a92(%rip), %rsi      # 0x4013
callq 0x2160
leaq -0x248(%rbp), %rax
movq %rax, -0x258(%rbp)
andq $0x0, -0x250(%rbp)
movb $0x0, -0x248(%rbp)
movq 0x3a26(%rip), %rdi      # 0x5fd0
movq %r15, %rsi
callq 0x21c0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x26dc
movq %r15, %rdi
leaq 0x1a6d(%rip), %rsi      # 0x403b
callq 0x2823
testb %al, %al
jne 0x26dc
leaq -0xd8(%rbp), %rdi
movq %r15, %rsi
callq 0x31e2
movq %rax, %r15
leaq -0xd0(%rbp), %rax
cmpq %rax, %r15
je 0x26a2
movq %rbx, %rdi
leaq -0x258(%rbp), %rsi
callq 0x2150
movq %rax, %rdi
leaq 0x1a27(%rip), %rsi      # 0x403d
callq 0x2160
movq 0x68(%r15), %rsi
movq %rax, %rdi
callq 0x2100
movq %rax, %rdi
leaq 0x1a15(%rip), %rsi      # 0x4046
callq 0x2160
movq %rax, %rdi
callq 0x20d0
movq 0x58(%r15), %r12
addq $0x48, %r15
cmpq %r15, %r12
je 0x26c8
movq 0x20(%r12), %r13
movq %rbx, %rdi
leaq 0x19f4(%rip), %rsi      # 0x404e
callq 0x2160
movq %rax, %rdi
movq %r13, %rsi
callq 0x2100
movq %rax, %rdi
movq %r14, %rsi
callq 0x2160
movq -0x40(%rbp), %rcx
shlq $0x5, %r13
leaq (%rcx,%r13), %rsi
addq $-0x20, %rsi
movq %rax, %rdi
callq 0x2150
movq %rax, %rdi
callq 0x20d0
movq %r12, %rdi
callq 0x21b0
movq %rax, %r12
jmp 0x2646
movq %rbx, %rdi
leaq -0x258(%rbp), %rsi
callq 0x2150
movq %rax, %rdi
leaq 0x199e(%rip), %rsi      # 0x4059
callq 0x2160
movq %rax, %rdi
callq 0x20d0
leaq -0x258(%rbp), %r15
movq %r15, %rdi
callq 0x20b0
jmp 0x2577
leaq -0x258(%rbp), %rdi
callq 0x20b0
leaq -0xa8(%rbp), %rdi
callq 0x20b0
xorl %ebx, %ebx
jmp 0x2416
movq %rax, %rbx
jmp 0x2755
jmp 0x2714
jmp 0x2706
jmp 0x2706
movq %rax, %rbx
jmp 0x2749
jmp 0x2714
jmp 0x2725
movq %rax, %rbx
jmp 0x2734
movq %rax, %rbx
leaq -0x258(%rbp), %rdi
callq 0x20b0
jmp 0x2749
movq %rax, %rbx
leaq -0x88(%rbp), %rdi
callq 0x20b0
leaq -0x68(%rbp), %rdi
callq 0x20b0
leaq -0x258(%rbp), %rdi
callq 0x20c0
leaq -0xa8(%rbp), %rdi
callq 0x20b0
leaq -0xd8(%rbp), %rdi
callq 0x286e
leaq -0x40(%rbp), %rdi
callq 0x2834
leaq -0x460(%rbp), %rdi
callq 0x2060
movq %rbx, %rdi
callq 0x2230