// File: 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
subq $0x2c0, %rsp            # imm = 0x2C0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rsi
leaq -0x40(%rbp), %rdi
callq 0x2440
movq 0x5869(%rip), %rdi      # 0x7fd0
leaq 0x28a3(%rip), %rsi      # 0x5011
callq 0x21a0
jmp 0x2775
leaq -0x40(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rdi
callq 0x2fb0
movq %rax, -0x60(%rbp)
movq -0x58(%rbp), %rdi
callq 0x2fe0
movq %rax, -0x68(%rbp)
leaq -0x60(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x3010
testb $0x1, %al
jne 0x27ad
jmp 0x2894
leaq -0x60(%rbp), %rdi
callq 0x3040
movq %rax, %rsi
leaq -0xa8(%rbp), %rdi
callq 0x3060
jmp 0x27c7
movq 0x5802(%rip), %rdi      # 0x7fd0
leaq 0x285f(%rip), %rsi      # 0x5034
callq 0x21a0
movq %rax, -0x278(%rbp)
jmp 0x27e3
movq -0x278(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x2190
movq %rax, -0x280(%rbp)
jmp 0x27ff
movq -0x280(%rbp), %rdi
leaq 0x282d(%rip), %rsi      # 0x503a
callq 0x21a0
movq %rax, -0x288(%rbp)
jmp 0x281b
movq -0x288(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x2190
movq %rax, -0x290(%rbp)
jmp 0x2837
movq -0x290(%rbp), %rdi
movq 0x5773(%rip), %rsi      # 0x7fb8
callq 0x21f0
jmp 0x284c
leaq -0xa8(%rbp), %rdi
callq 0x30c0
leaq -0x60(%rbp), %rdi
callq 0x30f0
jmp 0x2797
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x2a63
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x30c0
jmp 0x2a63
movq 0x5735(%rip), %rdi      # 0x7fd0
leaq 0x278f(%rip), %rsi      # 0x5031
callq 0x21a0
jmp 0x28a9
leaq -0xc8(%rbp), %rdi
callq 0x2240
movq -0x10(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x2060
movq %rax, -0x298(%rbp)
jmp 0x28ce
movq -0x298(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x2220
movb %al, -0x299(%rbp)
jmp 0x28ec
movb -0x299(%rbp), %al
testb $0x1, %al
jne 0x28fb
jmp 0x2a39
leaq -0x248(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
movl $0x8, %edx
callq 0x22a0
jmp 0x2915
leaq -0x268(%rbp), %rdi
callq 0x2240
movb $0x1, -0x269(%rbp)
leaq -0x248(%rbp), %rdi
leaq -0x268(%rbp), %rsi
callq 0x2230
movq %rax, -0x2a8(%rbp)
jmp 0x2944
movq -0x2a8(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x2220
movb %al, -0x2a9(%rbp)
jmp 0x2962
movb -0x2a9(%rbp), %al
testb $0x1, %al
jne 0x2971
jmp 0x2a07
testb $0x1, -0x269(%rbp)
je 0x29bd
movb $0x0, -0x269(%rbp)
jmp 0x29d4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x2a57
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x268(%rbp), %rdi
callq 0x2130
leaq -0x248(%rbp), %rdi
callq 0x2100
jmp 0x2a57
movq 0x560c(%rip), %rdi      # 0x7fd0
leaq 0x2676(%rip), %rsi      # 0x5041
callq 0x21a0
jmp 0x29d2
jmp 0x29d4
leaq -0x268(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x26d0
movq %rax, -0x2b8(%rbp)
jmp 0x29ed
movq -0x2b8(%rbp), %rsi
movq 0x55d5(%rip), %rdi      # 0x7fd0
callq 0x2190
jmp 0x2a02
jmp 0x2928
movq 0x55c2(%rip), %rdi      # 0x7fd0
movq 0x55a3(%rip), %rsi      # 0x7fb8
callq 0x21f0
jmp 0x2a1c
leaq -0x268(%rbp), %rdi
callq 0x2130
leaq -0x248(%rbp), %rdi
callq 0x2100
jmp 0x28b5
leaq -0xc8(%rbp), %rdi
callq 0x2130
leaq -0x40(%rbp), %rdi
callq 0x2ee0
addq $0x2c0, %rsp            # imm = 0x2C0
popq %rbp
retq
leaq -0xc8(%rbp), %rdi
callq 0x2130
leaq -0x40(%rbp), %rdi
callq 0x2ee0
movq -0x48(%rbp), %rdi
callq 0x22d0
nopw %cs:(%rax,%rax)