// File: iZhangHui[P]CppPrimer/CH10_GenericAlgorithms/examples/elimDups.cc
// Function: main
int main()
{
    vector<string> words;

    // copy contents of each book into a single vector
    string next_word;
    while (cin >> next_word) {
        // insert next book's contents at end of words
        words.push_back(next_word);
    }
	print(words);

	vector<string> cpy = words; // save the original data

	// uses string < to compare elements
	// sort and print the vector
	sort(words.begin(), words.end());

	words = cpy;  // return to the original data
	// uses the LT function to compare elements
	// should have the same output as the previous sort
	sort(words.begin(), words.end(), LT);
    print(words);

	words = cpy;  // return to the original data

	// eliminate duplicates
	sort(words.begin(), words.end());
	auto it = unique(words.begin(), words.end());
	words.erase(it, words.end());

	// sort by length using a function
	stable_sort(words.begin(), words.end(), isShorter);  
    print(words);

	words = cpy; // return to the original data
	// sort the original input on word length, shortest to longest
	sort(words.begin(), words.end(), isShorter);  
    print(words);

	// use bind to invert isShorter to sort longest to shortest
	sort(words.begin(), words.end(), bind(isShorter, _2, _1));  
    print(words);

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x170, %rsp            # imm = 0x170
movl $0x0, -0x4(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x2900
leaq -0x40(%rbp), %rdi
callq 0x21a0
movq 0xeb5d(%rip), %rdi      # 0x10fd8
leaq -0x40(%rbp), %rsi
callq 0x2180
movq %rax, -0x118(%rbp)
jmp 0x248d
movq -0x118(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x2170
movb %al, -0x119(%rbp)
jmp 0x24ab
movb -0x119(%rbp), %al
testb $0x1, %al
jne 0x24b7
jmp 0x24d9
leaq -0x20(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x2920
jmp 0x24c6
jmp 0x2474
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x27f8
leaq -0x20(%rbp), %rdi
callq 0x23b0
jmp 0x24e4
leaq -0x68(%rbp), %rdi
leaq -0x20(%rbp), %rsi
callq 0x2990
jmp 0x24f3
leaq -0x20(%rbp), %rdi
movq %rdi, -0x128(%rbp)
callq 0x2ac0
movq -0x128(%rbp), %rdi
movq %rax, -0x70(%rbp)
callq 0x2af0
movq %rax, -0x78(%rbp)
movq -0x70(%rbp), %rdi
movq -0x78(%rbp), %rsi
callq 0x2a80
jmp 0x2526
leaq -0x20(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x2b20
jmp 0x2535
leaq -0x20(%rbp), %rdi
movq %rdi, -0x130(%rbp)
callq 0x2ac0
movq -0x130(%rbp), %rdi
movq %rax, -0x80(%rbp)
callq 0x2af0
movq %rax, -0x88(%rbp)
movq -0x80(%rbp), %rdi
movq -0x88(%rbp), %rsi
leaq -0x1ee(%rip), %rdx      # 0x2380
callq 0x2d70
jmp 0x2575
leaq -0x20(%rbp), %rdi
callq 0x23b0
jmp 0x2580
leaq -0x20(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x2b20
jmp 0x258f
leaq -0x20(%rbp), %rdi
movq %rdi, -0x138(%rbp)
callq 0x2ac0
movq -0x138(%rbp), %rdi
movq %rax, -0x90(%rbp)
callq 0x2af0
movq %rax, -0x98(%rbp)
movq -0x90(%rbp), %rdi
movq -0x98(%rbp), %rsi
callq 0x2a80
jmp 0x25ce
leaq -0x20(%rbp), %rdi
movq %rdi, -0x148(%rbp)
callq 0x2ac0
movq -0x148(%rbp), %rdi
movq %rax, -0xa8(%rbp)
callq 0x2af0
movq %rax, -0xb0(%rbp)
movq -0xa8(%rbp), %rdi
movq -0xb0(%rbp), %rsi
callq 0x2dc0
movq %rax, -0x140(%rbp)
jmp 0x2614
movq -0x140(%rbp), %rax
movq %rax, -0xa0(%rbp)
leaq -0xb8(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x2e90
leaq -0x20(%rbp), %rdi
movq %rdi, -0x158(%rbp)
callq 0x2af0
movq %rax, -0xc8(%rbp)
leaq -0xc0(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x2e90
movq -0x158(%rbp), %rdi
movq -0xb8(%rbp), %rsi
movq -0xc0(%rbp), %rdx
callq 0x2e00
movq %rax, -0x150(%rbp)
jmp 0x2682
movq -0x150(%rbp), %rax
movq %rax, -0xd0(%rbp)
leaq -0x20(%rbp), %rdi
movq %rdi, -0x160(%rbp)
callq 0x2ac0
movq -0x160(%rbp), %rdi
movq %rax, -0xd8(%rbp)
callq 0x2af0
movq %rax, -0xe0(%rbp)
movq -0xd8(%rbp), %rdi
movq -0xe0(%rbp), %rsi
leaq -0x38f(%rip), %rdx      # 0x2340
callq 0x2ed0
jmp 0x26d6
leaq -0x20(%rbp), %rdi
callq 0x23b0
jmp 0x26e1
leaq -0x20(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x2b20
jmp 0x26f0
leaq -0x20(%rbp), %rdi
movq %rdi, -0x168(%rbp)
callq 0x2ac0
movq -0x168(%rbp), %rdi
movq %rax, -0xe8(%rbp)
callq 0x2af0
movq %rax, -0xf0(%rbp)
movq -0xe8(%rbp), %rdi
movq -0xf0(%rbp), %rsi
leaq -0x3ef(%rip), %rdx      # 0x2340
callq 0x2d70
jmp 0x2736
leaq -0x20(%rbp), %rdi
callq 0x23b0
jmp 0x2741
leaq -0x20(%rbp), %rdi
movq %rdi, -0x170(%rbp)
callq 0x2ac0
movq -0x170(%rbp), %rdi
movq %rax, -0xf8(%rbp)
callq 0x2af0
movq %rax, -0x100(%rbp)
leaq -0x432(%rip), %rsi      # 0x2340
movq 0xe877(%rip), %rdx      # 0x10ff0
movq 0xe840(%rip), %rcx      # 0x10fc0
leaq -0x110(%rbp), %rdi
callq 0x2f80
jmp 0x278e
movq -0xf8(%rbp), %rdi
movq -0x100(%rbp), %rsi
leaq -0x110(%rbp), %rdx
callq 0x2f20
jmp 0x27aa
leaq -0x20(%rbp), %rdi
callq 0x23b0
jmp 0x27b5
movl $0x0, -0x4(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x2fd0
leaq -0x40(%rbp), %rdi
callq 0x20c0
leaq -0x20(%rbp), %rdi
callq 0x2fd0
movl -0x4(%rbp), %eax
addq $0x170, %rsp            # imm = 0x170
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x2fd0
leaq -0x40(%rbp), %rdi
callq 0x20c0
leaq -0x20(%rbp), %rdi
callq 0x2fd0
movq -0x48(%rbp), %rdi
callq 0x21e0
nopw %cs:(%rax,%rax)