// File: iZhangHui[P]CppPrimer/CH11_AssociativeContainers/examples/map1.cc
// Function: main
int main()
{
	map <string, size_t> word_count; // empty map

	// insert a value-initialized element with key Anna;
	// assign 1 to the value of that element
	word_count["Anna"] = 1;

	// fetch the element indexed by Anna; prints 1
	cout << word_count["Anna"] << endl;

	++word_count["Anna"];        // fetch the element and add 1 to it
	cout << word_count["Anna"] << endl; // prints 2

	// various ways to add word to word_count
	string word;
	word_count.insert({word, 1});
	word_count.insert(make_pair(word, 1));
	word_count.insert(pair<string, size_t>(word, 1));
	word_count.insert(map<string, size_t>::value_type(word, 1));

	typedef map<string,size_t>::value_type valType;
	word_count.insert(valType(word, 1));

	// use value returned by insert
	pair<map<string, size_t>::iterator, bool> insert_ret;

	// if Anna not already in word_count, insert it with value 1
	insert_ret = word_count.insert({"Anna", 1});

	if (insert_ret.second == false)    // Anna was already in the map
		insert_ret.first->second++;    // increment current value
	cout << word_count["Anna"] << endl;

	// get an iterator to an element in word_count
	auto map_it = word_count.begin();

	// *map_it is a reference to a pair<const string, size_t> object
	cout << map_it->first;         // prints the key for this element
	cout << " " << map_it->second; // prints the value of the element
	++map_it->second;     // ok: we can change the value through an iterator
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x3b0, %rsp            # imm = 0x3B0
movl $0x0, -0x4(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x2f20
leaq -0x59(%rbp), %rdi
movq %rdi, -0x2e0(%rbp)
callq 0x2200
movq -0x2e0(%rbp), %rdx
leaq 0x3afb(%rip), %rsi      # 0x6004
leaq -0x58(%rbp), %rdi
callq 0x21a0
jmp 0x2514
leaq -0x38(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x2f40
movq %rax, -0x2e8(%rbp)
jmp 0x252a
movq -0x2e8(%rbp), %rax
movq $0x1, (%rax)
leaq -0x58(%rbp), %rdi
callq 0x20c0
leaq -0x59(%rbp), %rdi
callq 0x2170
leaq -0x91(%rbp), %rdi
movq %rdi, -0x2f0(%rbp)
callq 0x2200
movq -0x2f0(%rbp), %rdx
leaq 0x3a99(%rip), %rsi      # 0x6004
leaq -0x90(%rbp), %rdi
callq 0x21a0
jmp 0x2579
leaq -0x38(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x2f40
movq %rax, -0x2f8(%rbp)
jmp 0x2592
movq -0x2f8(%rbp), %rax
movq (%rax), %rsi
movq 0x7a35(%rip), %rdi      # 0x9fd8
callq 0x2060
movq %rax, -0x300(%rbp)
jmp 0x25b1
movq -0x300(%rbp), %rdi
movq 0x7a09(%rip), %rsi      # 0x9fc8
callq 0x2160
jmp 0x25c6
leaq -0x90(%rbp), %rdi
callq 0x20c0
leaq -0x91(%rbp), %rdi
callq 0x2170
leaq -0xb9(%rbp), %rdi
movq %rdi, -0x308(%rbp)
callq 0x2200
movq -0x308(%rbp), %rdx
leaq 0x3a05(%rip), %rsi      # 0x6004
leaq -0xb8(%rbp), %rdi
callq 0x21a0
jmp 0x260d
leaq -0x38(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x2f40
movq %rax, -0x310(%rbp)
jmp 0x2626
movq -0x310(%rbp), %rax
movq (%rax), %rcx
incq %rcx
movq %rcx, (%rax)
leaq -0xb8(%rbp), %rdi
callq 0x20c0
leaq -0xb9(%rbp), %rdi
callq 0x2170
leaq -0xe1(%rbp), %rdi
movq %rdi, -0x318(%rbp)
callq 0x2200
movq -0x318(%rbp), %rdx
leaq 0x3995(%rip), %rsi      # 0x6004
leaq -0xe0(%rbp), %rdi
callq 0x21a0
jmp 0x267d
leaq -0x38(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x2f40
movq %rax, -0x320(%rbp)
jmp 0x2696
movq -0x320(%rbp), %rax
movq (%rax), %rsi
movq 0x7931(%rip), %rdi      # 0x9fd8
callq 0x2060
movq %rax, -0x328(%rbp)
jmp 0x26b5
movq -0x328(%rbp), %rdi
movq 0x7905(%rip), %rsi      # 0x9fc8
callq 0x2160
jmp 0x26ca
leaq -0xe0(%rbp), %rdi
callq 0x20c0
leaq -0xe1(%rbp), %rdi
callq 0x2170
leaq -0x108(%rbp), %rdi
movq %rdi, -0x330(%rbp)
callq 0x21b0
movq -0x330(%rbp), %rsi
movl $0x1, -0x134(%rbp)
leaq -0x130(%rbp), %rdi
leaq -0x134(%rbp), %rdx
callq 0x3060
jmp 0x271b
leaq -0x38(%rbp), %rdi
leaq -0x130(%rbp), %rsi
callq 0x3020
movb %dl, -0x339(%rbp)
movq %rax, -0x338(%rbp)
jmp 0x273a
movb -0x339(%rbp), %al
movq -0x338(%rbp), %rcx
movq %rcx, -0x148(%rbp)
movb %al, -0x140(%rbp)
leaq -0x130(%rbp), %rdi
callq 0x30a0
movl $0x1, -0x174(%rbp)
leaq -0x170(%rbp), %rdi
leaq -0x108(%rbp), %rsi
leaq -0x174(%rbp), %rdx
callq 0x3100
jmp 0x2786
leaq -0x38(%rbp), %rdi
leaq -0x170(%rbp), %rsi
callq 0x30c0
movb %dl, -0x349(%rbp)
movq %rax, -0x348(%rbp)
jmp 0x27a5
movb -0x349(%rbp), %al
movq -0x348(%rbp), %rcx
movq %rcx, -0x188(%rbp)
movb %al, -0x180(%rbp)
leaq -0x170(%rbp), %rdi
callq 0x3140
movl $0x1, -0x1b4(%rbp)
leaq -0x1b0(%rbp), %rdi
leaq -0x108(%rbp), %rsi
leaq -0x1b4(%rbp), %rdx
callq 0x31a0
jmp 0x27f1
leaq -0x38(%rbp), %rdi
leaq -0x1b0(%rbp), %rsi
callq 0x3160
movb %dl, -0x359(%rbp)
movq %rax, -0x358(%rbp)
jmp 0x2810
movb -0x359(%rbp), %al
movq -0x358(%rbp), %rcx
movq %rcx, -0x1c8(%rbp)
movb %al, -0x1c0(%rbp)
leaq -0x1b0(%rbp), %rdi
callq 0x31e0
movl $0x1, -0x1f4(%rbp)
leaq -0x1f0(%rbp), %rdi
leaq -0x108(%rbp), %rsi
leaq -0x1f4(%rbp), %rdx
callq 0x3060
jmp 0x285c
leaq -0x38(%rbp), %rdi
leaq -0x1f0(%rbp), %rsi
callq 0x3020
movb %dl, -0x369(%rbp)
movq %rax, -0x368(%rbp)
jmp 0x287b
movb -0x369(%rbp), %al
movq -0x368(%rbp), %rcx
movq %rcx, -0x208(%rbp)
movb %al, -0x200(%rbp)
leaq -0x1f0(%rbp), %rdi
callq 0x30a0
movl $0x1, -0x234(%rbp)
leaq -0x230(%rbp), %rdi
leaq -0x108(%rbp), %rsi
leaq -0x234(%rbp), %rdx
callq 0x3060
jmp 0x28c7
leaq -0x38(%rbp), %rdi
leaq -0x230(%rbp), %rsi
callq 0x3020
movb %dl, -0x379(%rbp)
movq %rax, -0x378(%rbp)
jmp 0x28e6
movb -0x379(%rbp), %al
movq -0x378(%rbp), %rcx
movq %rcx, -0x248(%rbp)
movb %al, -0x240(%rbp)
leaq -0x230(%rbp), %rdi
callq 0x30a0
leaq -0x258(%rbp), %rdi
callq 0x3200
jmp 0x291a
movl $0x1, -0x294(%rbp)
leaq 0x36d9(%rip), %rsi      # 0x6004
leaq -0x290(%rbp), %rdi
leaq -0x294(%rbp), %rdx
callq 0x3230
jmp 0x2940
leaq -0x38(%rbp), %rdi
leaq -0x290(%rbp), %rsi
callq 0x3020
movb %dl, -0x389(%rbp)
movq %rax, -0x388(%rbp)
jmp 0x295f
movb -0x389(%rbp), %al
movq -0x388(%rbp), %rcx
movq %rcx, -0x2a8(%rbp)
movb %al, -0x2a0(%rbp)
movq -0x2a8(%rbp), %rax
movq %rax, -0x268(%rbp)
movb -0x2a0(%rbp), %al
movb %al, -0x260(%rbp)
leaq -0x258(%rbp), %rdi
leaq -0x268(%rbp), %rsi
callq 0x32b0
leaq -0x290(%rbp), %rdi
callq 0x30a0
movb -0x250(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x2b78
leaq -0x258(%rbp), %rdi
callq 0x32e0
movq 0x20(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x20(%rax)
jmp 0x2b78
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x2a06
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x20c0
leaq -0x59(%rbp), %rdi
callq 0x2170
jmp 0x2cf1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x2a3a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x20c0
leaq -0x91(%rbp), %rdi
callq 0x2170
jmp 0x2cf1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x2a71
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x20c0
leaq -0xb9(%rbp), %rdi
callq 0x2170
jmp 0x2cf1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x2aa8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x20c0
leaq -0xe1(%rbp), %rdi
callq 0x2170
jmp 0x2cf1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x2ce5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x130(%rbp), %rdi
callq 0x30a0
jmp 0x2ce5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x170(%rbp), %rdi
callq 0x3140
jmp 0x2ce5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x1b0(%rbp), %rdi
callq 0x31e0
jmp 0x2ce5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x1f0(%rbp), %rdi
callq 0x30a0
jmp 0x2ce5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x230(%rbp), %rdi
callq 0x30a0
jmp 0x2ce5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x290(%rbp), %rdi
callq 0x30a0
jmp 0x2ce5
leaq -0x2c9(%rbp), %rdi
movq %rdi, -0x398(%rbp)
callq 0x2200
movq -0x398(%rbp), %rdx
leaq 0x346b(%rip), %rsi      # 0x6004
leaq -0x2c8(%rbp), %rdi
callq 0x21a0
jmp 0x2ba7
leaq -0x38(%rbp), %rdi
leaq -0x2c8(%rbp), %rsi
callq 0x2f40
movq %rax, -0x3a0(%rbp)
jmp 0x2bc0
movq -0x3a0(%rbp), %rax
movq (%rax), %rsi
movq 0x7407(%rip), %rdi      # 0x9fd8
callq 0x2060
movq %rax, -0x3a8(%rbp)
jmp 0x2bdf
movq -0x3a8(%rbp), %rdi
movq 0x73db(%rip), %rsi      # 0x9fc8
callq 0x2160
jmp 0x2bf4
leaq -0x2c8(%rbp), %rdi
callq 0x20c0
leaq -0x2c9(%rbp), %rdi
callq 0x2170
leaq -0x38(%rbp), %rdi
callq 0x3300
movq %rax, -0x2d8(%rbp)
leaq -0x2d8(%rbp), %rdi
callq 0x32e0
movq %rax, %rsi
movq 0x73a6(%rip), %rdi      # 0x9fd8
callq 0x2110
jmp 0x2c39
movq 0x7398(%rip), %rdi      # 0x9fd8
leaq 0x33c2(%rip), %rsi      # 0x6009
callq 0x2120
movq %rax, -0x3b0(%rbp)
jmp 0x2c55
leaq -0x2d8(%rbp), %rdi
callq 0x32e0
movq -0x3b0(%rbp), %rdi
movq 0x20(%rax), %rsi
callq 0x2060
jmp 0x2c73
leaq -0x2d8(%rbp), %rdi
callq 0x32e0
movq 0x20(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x20(%rax)
movl $0x0, -0x4(%rbp)
leaq -0x108(%rbp), %rdi
callq 0x20c0
leaq -0x38(%rbp), %rdi
callq 0x3330
movl -0x4(%rbp), %eax
addq $0x3b0, %rsp            # imm = 0x3B0
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x2cd9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x2c8(%rbp), %rdi
callq 0x20c0
leaq -0x2c9(%rbp), %rdi
callq 0x2170
leaq -0x108(%rbp), %rdi
callq 0x20c0
leaq -0x38(%rbp), %rdi
callq 0x3330
movq -0x68(%rbp), %rdi
callq 0x21f0
nopw %cs:(%rax,%rax)