// File: iZhangHui[P]CppPrimer/CH11_AssociativeContainers/examples/multimap.cc
// Function: main
int main()
{
	// map from author to title; there can be multiple titles per author
	multimap<string, string> authors;
	// add data to authors
	authors.insert({"Alain de Botton", "On Love"});
	authors.insert({"Alain de Botton", "Status Anxiety"});
	authors.insert({"Alain de Botton", "Art of Travel"});
	authors.insert({"Alain de Botton",
							  "Architecture of Happiness"});

	string search_item("Alain de Botton"); // author we'll look for
	auto entries = authors.count(search_item); // number of elements
	auto iter = authors.find(search_item); // first entry for this author

	// loop through the number of entries there are for this author
	while(entries) {
		cout << iter->second << endl; // print each title
		++iter;     // advance to the next title
		--entries;  // keep track of how many we've printed
	}

	// definitions of authors and search_item as above
	// beg and end denote the range of elements for this author
	for (auto beg = authors.lower_bound(search_item),
			  end = authors.upper_bound(search_item);
		 beg != end; ++beg)
		cout << beg->second << endl; // print each title

	// definitions of authors and search_item as above
	// pos holds iterators that denote the range of elements for this key
	for (auto pos = authors.equal_range(search_item);
		 pos.first != pos.second; ++pos.first)
		cout << pos.first->second << endl; // print each title

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x230, %rsp            # imm = 0x230
movl $0x0, -0x4(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x1790
leaq 0x2d02(%rip), %rsi      # 0x4004
leaq 0x2d0b(%rip), %rdx      # 0x4014
leaq -0x78(%rbp), %rdi
callq 0x17e0
jmp 0x1314
leaq -0x38(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x17b0
movq %rax, -0x1c8(%rbp)
jmp 0x132a
movq -0x1c8(%rbp), %rax
movq %rax, -0x90(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x18c0
leaq 0x2cbc(%rip), %rsi      # 0x4004
leaq 0x2ccd(%rip), %rdx      # 0x401c
leaq -0xd0(%rbp), %rdi
callq 0x18f0
jmp 0x135d
leaq -0x38(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x17b0
movq %rax, -0x1d0(%rbp)
jmp 0x1376
movq -0x1d0(%rbp), %rax
movq %rax, -0xd8(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x18c0
leaq 0x2c6d(%rip), %rsi      # 0x4004
leaq 0x2c8d(%rip), %rdx      # 0x402b
leaq -0x118(%rbp), %rdi
callq 0x19d0
jmp 0x13ac
leaq -0x38(%rbp), %rdi
leaq -0x118(%rbp), %rsi
callq 0x17b0
movq %rax, -0x1d8(%rbp)
jmp 0x13c5
movq -0x1d8(%rbp), %rax
movq %rax, -0x120(%rbp)
leaq -0x118(%rbp), %rdi
callq 0x18c0
leaq 0x2c1e(%rip), %rsi      # 0x4004
leaq 0x2c4c(%rip), %rdx      # 0x4039
leaq -0x160(%rbp), %rdi
callq 0x1ab0
jmp 0x13fb
leaq -0x38(%rbp), %rdi
leaq -0x160(%rbp), %rsi
callq 0x17b0
movq %rax, -0x1e0(%rbp)
jmp 0x1414
movq -0x1e0(%rbp), %rax
movq %rax, -0x168(%rbp)
leaq -0x160(%rbp), %rdi
callq 0x18c0
leaq -0x189(%rbp), %rdi
movq %rdi, -0x1e8(%rbp)
callq 0x1190
movq -0x1e8(%rbp), %rdx
leaq 0x2bb5(%rip), %rsi      # 0x4004
leaq -0x188(%rbp), %rdi
callq 0x1140
jmp 0x145d
leaq -0x189(%rbp), %rdi
callq 0x1120
leaq -0x38(%rbp), %rdi
leaq -0x188(%rbp), %rsi
callq 0x1b90
movq %rax, -0x1f0(%rbp)
jmp 0x1482
movq -0x1f0(%rbp), %rax
movq %rax, -0x198(%rbp)
leaq -0x38(%rbp), %rdi
leaq -0x188(%rbp), %rsi
callq 0x1bc0
movq %rax, -0x1f8(%rbp)
jmp 0x14a9
movq -0x1f8(%rbp), %rax
movq %rax, -0x1a0(%rbp)
cmpq $0x0, -0x198(%rbp)
je 0x15f3
leaq -0x1a0(%rbp), %rdi
callq 0x1bf0
movq %rax, %rsi
addq $0x20, %rsi
movq 0x5af9(%rip), %rdi      # 0x6fd8
callq 0x10e0
movq %rax, -0x200(%rbp)
jmp 0x14ed
movq -0x200(%rbp), %rdi
movq 0x5acd(%rip), %rsi      # 0x6fc8
callq 0x1110
jmp 0x1502
leaq -0x1a0(%rbp), %rdi
callq 0x1c10
movq -0x198(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x198(%rbp)
jmp 0x14b7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x1775
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x18c0
jmp 0x1775
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x18c0
jmp 0x1775
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0x118(%rbp), %rdi
callq 0x18c0
jmp 0x1775
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0x160(%rbp), %rdi
callq 0x18c0
jmp 0x1775
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0x189(%rbp), %rdi
callq 0x1120
jmp 0x1775
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0x188(%rbp), %rdi
callq 0x10a0
jmp 0x1775
leaq -0x38(%rbp), %rdi
leaq -0x188(%rbp), %rsi
callq 0x1c40
movq %rax, -0x208(%rbp)
jmp 0x160c
movq -0x208(%rbp), %rax
movq %rax, -0x1a8(%rbp)
leaq -0x38(%rbp), %rdi
leaq -0x188(%rbp), %rsi
callq 0x1c70
movq %rax, -0x210(%rbp)
jmp 0x1633
movq -0x210(%rbp), %rax
movq %rax, -0x1b0(%rbp)
leaq -0x1a8(%rbp), %rdi
leaq -0x1b0(%rbp), %rsi
callq 0x1ca0
testb $0x1, %al
jne 0x165a
jmp 0x16a7
leaq -0x1a8(%rbp), %rdi
callq 0x1bf0
movq %rax, %rsi
addq $0x20, %rsi
movq 0x5964(%rip), %rdi      # 0x6fd8
callq 0x10e0
movq %rax, -0x218(%rbp)
jmp 0x1682
movq -0x218(%rbp), %rdi
movq 0x5938(%rip), %rsi      # 0x6fc8
callq 0x1110
jmp 0x1697
jmp 0x1699
leaq -0x1a8(%rbp), %rdi
callq 0x1c10
jmp 0x1641
leaq -0x38(%rbp), %rdi
leaq -0x188(%rbp), %rsi
callq 0x1cd0
movq %rdx, -0x228(%rbp)
movq %rax, -0x220(%rbp)
jmp 0x16c7
movq -0x228(%rbp), %rax
movq -0x220(%rbp), %rcx
movq %rcx, -0x1c0(%rbp)
movq %rax, -0x1b8(%rbp)
leaq -0x1c0(%rbp), %rdi
leaq -0x1c0(%rbp), %rsi
addq $0x8, %rsi
callq 0x1ca0
testb $0x1, %al
jne 0x1700
jmp 0x174d
leaq -0x1c0(%rbp), %rdi
callq 0x1bf0
movq %rax, %rsi
addq $0x20, %rsi
movq 0x58be(%rip), %rdi      # 0x6fd8
callq 0x10e0
movq %rax, -0x230(%rbp)
jmp 0x1728
movq -0x230(%rbp), %rdi
movq 0x5892(%rip), %rsi      # 0x6fc8
callq 0x1110
jmp 0x173d
jmp 0x173f
leaq -0x1c0(%rbp), %rdi
callq 0x1c10
jmp 0x16e3
movl $0x0, -0x4(%rbp)
leaq -0x188(%rbp), %rdi
callq 0x10a0
leaq -0x38(%rbp), %rdi
callq 0x1d10
movl -0x4(%rbp), %eax
addq $0x230, %rsp            # imm = 0x230
popq %rbp
retq
leaq -0x38(%rbp), %rdi
callq 0x1d10
movq -0x80(%rbp), %rdi
callq 0x1180
nopw (%rax,%rax)