// File: /workspace/github_cpp_makefile_star2_O2/iZhangHui[P]CppPrimer/CH11_AssociativeContainers/examples/word_transform.cc
// Function: word_transform(std::basic_ifstream<char, std::char_traits<char>>&, std::basic_ifstream<char, std::char_traits<char>>&)
void word_transform(ifstream& map_file, ifstream& input)
{
	auto trans_map = buildMap(map_file); // store the transformations

	// for debugging purposes print the map after its built
	cout << "Here is our transformation map: \n\n";
	for (auto entry : trans_map)
		cout << "key: "   << entry.first
			 << "\tvalue: " << entry.second << endl;
	cout << "\n\n";

	// do the transformation of the given text
	string text;                    // hold each line from the input
	while (getline(input, text)) {  // read a line of input
		istringstream stream(text); // read each word
		string word;
		bool firstword = true;      // controls whether a space is printed
		while (stream >> word) {
			if (firstword)
				firstword = false;
			else
				cout << " ";  // print a space between words
			// transform returns its first argument or its transformation
			cout << transform(word, trans_map); // print the output
		}
		cout << endl;        // done with this line of input
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1f8, %rsp            # imm = 0x1F8
movq %rsi, -0x30(%rbp)
movq %rdi, %rsi
leaq -0xa0(%rbp), %rdi
callq 0x23bc
movq 0x2a24(%rip), %rdi      # 0x4fd0
leaq 0xa5e(%rip), %rsi       # 0x3011
callq 0x2160
leaq -0x98(%rbp), %r15
movq 0x10(%r15), %r12
leaq -0x220(%rbp), %r14
leaq 0xa63(%rip), %r13       # 0x3034
leaq 0xa62(%rip), %rbx       # 0x303a
cmpq %r15, %r12
je 0x263b
leaq 0x20(%r12), %rsi
movq %r14, %rdi
callq 0x2a10
movq 0x29df(%rip), %rdi      # 0x4fd0
movq %r13, %rsi
callq 0x2160
movq %rax, %rdi
movq %r14, %rsi
callq 0x2150
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2160
movq %rax, %rdi
leaq -0x200(%rbp), %rsi
callq 0x2150
movq %rax, %rdi
callq 0x20f0
movq %r14, %rdi
callq 0x2a4a
movq %r12, %rdi
callq 0x2110
movq %rax, %r12
jmp 0x25d8
movq 0x298e(%rip), %rdi      # 0x4fd0
leaq 0x9e8(%rip), %rsi       # 0x3031
callq 0x2160
leaq -0x60(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq -0x70(%rbp), %r14
leaq -0x220(%rbp), %r15
leaq -0x50(%rbp), %r13
leaq -0xa0(%rbp), %r12
movq 0x2955(%rip), %rbx      # 0x4fd0
movq -0x30(%rbp), %rdi
movq %r14, %rsi
callq 0x2060
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x2725
movq %r15, %rdi
movq %r14, %rsi
pushq $0x8
popq %rdx
callq 0x2230
leaq -0x40(%rbp), %rax
movq %rax, -0x50(%rbp)
andq $0x0, -0x48(%rbp)
movb $0x0, -0x40(%rbp)
movb $0x1, %r14b
movq %r15, %rdi
movq %r13, %rsi
callq 0x21c0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x2704
testb $0x1, %r14b
jne 0x26e9
movq %rbx, %rdi
leaq 0x95d(%rip), %rsi       # 0x3041
callq 0x2160
movq %r13, %rdi
movq %r12, %rsi
callq 0x254f
xorl %r14d, %r14d
movq %rbx, %rdi
movq %rax, %rsi
callq 0x2150
jmp 0x26bb
movq %rbx, %rdi
callq 0x20f0
movq %r13, %rdi
callq 0x20d0
movq %r15, %rdi
callq 0x20e0
leaq -0x70(%rbp), %r14
jmp 0x267b
leaq -0x70(%rbp), %rdi
callq 0x20d0
leaq -0xa0(%rbp), %rdi
callq 0x2a78
addq $0x1f8, %rsp            # imm = 0x1F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2752
jmp 0x276d
jmp 0x2757
movq %rax, %rbx
jmp 0x278e
movq %rax, %rbx
jmp 0x2785
movq %rax, %rbx
leaq -0x220(%rbp), %rdi
callq 0x2a4a
jmp 0x278e
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x20d0
leaq -0x220(%rbp), %rdi
callq 0x20e0
leaq -0x70(%rbp), %rdi
callq 0x20d0
leaq -0xa0(%rbp), %rdi
callq 0x2a78
movq %rbx, %rdi
callq 0x2250