// File: iZhangHui[P]CppPrimer/CH16_TemplatesAndGenericProgramming/examples/compare.cc
// Function: main
int main()
{
    // instantiates int compare(const int&, const int&)
    cout << compare(1, 0) << endl;       // T is int

    // instantiates int compare(const vector<int>&, const vector<int>&)
    vector<int> vec1{1, 2, 3};
    vector<int> vec2{4, 5, 6};
    cout << compare(vec1, vec2) << endl; // T is vector<int>

    long l1, l2;
    int i1, i2;
    compare(i1, i2);      // instantiate compare(int, int)
    compare(l1, l2);      // instantiate compare(long, long)
	compare<int>(i1, l2); // uses compare(int, int)
	compare<long>(i1, l2);// uses compare(long, long)

    const char *cp1 = "hi", *cp2 = "world";
    compare(cp1, cp2);          // calls the specialization
    compare<string>(cp1, cp2);  // converts arguments to string

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x160, %rsp            # imm = 0x160
movl $0x0, -0x4(%rbp)
movl $0x1, -0x8(%rbp)
movl $0x0, -0xc(%rbp)
leaq -0x8(%rbp), %rdi
leaq -0xc(%rbp), %rsi
callq 0x1640
movl %eax, %esi
movq 0x3cf2(%rip), %rdi      # 0x4fd8
callq 0x1140
movq %rax, %rdi
movq 0x3cd3(%rip), %rsi      # 0x4fc8
callq 0x10e0
movl $0x1, -0x44(%rbp)
movl $0x2, -0x40(%rbp)
movl $0x3, -0x3c(%rbp)
leaq -0x44(%rbp), %rax
movq %rax, -0x38(%rbp)
movq $0x3, -0x30(%rbp)
leaq -0x45(%rbp), %rdi
movq %rdi, -0x120(%rbp)
callq 0x1690
movq -0x120(%rbp), %rcx
movq -0x38(%rbp), %rsi
movq -0x30(%rbp), %rdx
leaq -0x28(%rbp), %rdi
callq 0x16b0
jmp 0x1349
leaq -0x45(%rbp), %rdi
callq 0x1730
movl $0x4, -0x8c(%rbp)
movl $0x5, -0x88(%rbp)
movl $0x6, -0x84(%rbp)
leaq -0x8c(%rbp), %rax
movq %rax, -0x80(%rbp)
movq $0x3, -0x78(%rbp)
leaq -0x8d(%rbp), %rdi
movq %rdi, -0x128(%rbp)
callq 0x1690
movq -0x128(%rbp), %rcx
movq -0x80(%rbp), %rsi
movq -0x78(%rbp), %rdx
leaq -0x70(%rbp), %rdi
callq 0x16b0
jmp 0x13b0
leaq -0x8d(%rbp), %rdi
callq 0x1730
leaq -0x28(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x1750
movl %eax, -0x12c(%rbp)
jmp 0x13d1
movl -0x12c(%rbp), %esi
movq 0x3bfa(%rip), %rdi      # 0x4fd8
callq 0x1140
movq %rax, -0x138(%rbp)
jmp 0x13ec
movq -0x138(%rbp), %rdi
movq 0x3bce(%rip), %rsi      # 0x4fc8
callq 0x10e0
jmp 0x1401
leaq -0xa4(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x1640
jmp 0x1416
leaq -0x98(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x17b0
jmp 0x142b
movl -0xa0(%rbp), %eax
movl %eax, -0xac(%rbp)
leaq -0xa4(%rbp), %rdi
leaq -0xac(%rbp), %rsi
callq 0x1640
jmp 0x144c
movslq -0xa4(%rbp), %rax
movq %rax, -0xb8(%rbp)
leaq -0xb8(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x17b0
jmp 0x146f
leaq 0x1b8e(%rip), %rax      # 0x3004
movq %rax, -0xc0(%rbp)
leaq 0x1b83(%rip), %rax      # 0x3007
movq %rax, -0xc8(%rbp)
leaq -0xc0(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x1800
jmp 0x14a0
movq -0xc0(%rbp), %rax
movq %rax, -0x148(%rbp)
leaq -0xe9(%rbp), %rdi
movq %rdi, -0x140(%rbp)
callq 0x1160
movq -0x148(%rbp), %rsi
movq -0x140(%rbp), %rdx
leaq -0xe8(%rbp), %rdi
callq 0x1100
jmp 0x14dd
movq -0xc8(%rbp), %rax
movq %rax, -0x158(%rbp)
leaq -0x111(%rbp), %rdi
movq %rdi, -0x150(%rbp)
callq 0x1160
movq -0x158(%rbp), %rsi
movq -0x150(%rbp), %rdx
leaq -0x110(%rbp), %rdi
callq 0x1100
jmp 0x151a
leaq -0xe8(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x1850
jmp 0x152f
leaq -0x110(%rbp), %rdi
callq 0x1080
leaq -0x111(%rbp), %rdi
callq 0x10f0
leaq -0xe8(%rbp), %rdi
callq 0x1080
leaq -0xe9(%rbp), %rdi
callq 0x10f0
movl $0x0, -0x4(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x18b0
leaq -0x28(%rbp), %rdi
callq 0x18b0
movl -0x4(%rbp), %eax
addq $0x160, %rsp            # imm = 0x160
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x45(%rbp), %rdi
callq 0x1730
jmp 0x1630
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x8d(%rbp), %rdi
callq 0x1730
jmp 0x1627
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x161e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x1612
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x15fa
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x110(%rbp), %rdi
callq 0x1080
leaq -0x111(%rbp), %rdi
callq 0x10f0
leaq -0xe8(%rbp), %rdi
callq 0x1080
leaq -0xe9(%rbp), %rdi
callq 0x10f0
leaq -0x70(%rbp), %rdi
callq 0x18b0
leaq -0x28(%rbp), %rdi
callq 0x18b0
movq -0x50(%rbp), %rdi
callq 0x1150
nopl (%rax)