// File: iZhangHui[P]CppPrimer/CH16_TemplatesAndGenericProgramming/examples/trail-ret.cc
// Function: main
int main()
{
	vector<int> vi = {1,2,3,4,5};
	Blob<string> ca = { "hi", "bye" };

	auto& i = reffcn(vi.begin(), vi.end()); // reffcn should return int&
	auto& s = reffcn(ca.begin(), ca.end()); // reffcn should return string&

	vi = {1,2,3,4};
	for (auto i : vi)
		cout << i << " ";
	cout << endl;

	auto& ref = reffcn(vi.begin(), vi.end());  // ref is int&
	// auto ref = reffcn(vi.begin(), vi.end());
	ref = 5; // changes the value of *beg to which ref refers
	for (auto i : vi)
		cout << i << " ";
	cout << endl;

	auto val = valfcn(vi.begin(), vi.end()); // val is int
	cout << val << endl;  // will print 5

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x270, %rsp            # imm = 0x270
movl $0x0, -0x4(%rbp)
movups 0x3ccb(%rip), %xmm0     # 0x6004
movaps %xmm0, -0x50(%rbp)
movl $0x5, -0x40(%rbp)
leaq -0x50(%rbp), %rax
movq %rax, -0x30(%rbp)
movq $0x5, -0x28(%rbp)
leaq -0x51(%rbp), %rdi
movq %rdi, -0x1b8(%rbp)
callq 0x29a0
movq -0x1b8(%rbp), %rcx
movq -0x30(%rbp), %rsi
movq -0x28(%rbp), %rdx
leaq -0x20(%rbp), %rdi
callq 0x29c0
jmp 0x237e
leaq -0x51(%rbp), %rdi
callq 0x2a40
movb $0x1, -0xd3(%rbp)
leaq -0xc8(%rbp), %rax
movq %rax, -0x1c8(%rbp)
movq %rax, -0xd0(%rbp)
leaq -0xd1(%rbp), %rdi
movq %rdi, -0x1c0(%rbp)
callq 0x21d0
movq -0x1c8(%rbp), %rdi
movq -0x1c0(%rbp), %rdx
leaq 0x3c4d(%rip), %rsi      # 0x6018
callq 0x2130
jmp 0x23d2
leaq -0xa8(%rbp), %rax
movq %rax, -0x1d8(%rbp)
movq %rax, -0xd0(%rbp)
leaq -0xd2(%rbp), %rdi
movq %rdi, -0x1d0(%rbp)
callq 0x21d0
movq -0x1d8(%rbp), %rdi
movq -0x1d0(%rbp), %rdx
leaq 0x3c0c(%rip), %rsi      # 0x601b
callq 0x2130
jmp 0x2416
movb $0x0, -0xd3(%rbp)
leaq -0xc8(%rbp), %rax
movq %rax, -0x88(%rbp)
movq $0x2, -0x80(%rbp)
movq -0x88(%rbp), %rsi
movq -0x80(%rbp), %rdx
leaq -0x78(%rbp), %rdi
callq 0x2a60
jmp 0x2449
leaq -0xc8(%rbp), %rax
movq %rax, -0x1e8(%rbp)
addq $0x40, %rax
movq %rax, -0x1e0(%rbp)
movq -0x1e0(%rbp), %rdi
addq $-0x20, %rdi
movq %rdi, -0x1f0(%rbp)
callq 0x20a0
movq -0x1e8(%rbp), %rcx
movq -0x1f0(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x1e0(%rbp)
jne 0x2462
leaq -0xd2(%rbp), %rdi
callq 0x2120
leaq -0xd1(%rbp), %rdi
callq 0x2120
leaq -0x20(%rbp), %rdi
movq %rdi, -0x200(%rbp)
callq 0x2ab0
movq -0x200(%rbp), %rdi
movq %rax, -0xe8(%rbp)
callq 0x2ae0
movq %rax, -0xf0(%rbp)
movq -0xe8(%rbp), %rdi
movq -0xf0(%rbp), %rsi
callq 0x2a90
movq %rax, -0x1f8(%rbp)
jmp 0x24f1
movq -0x1f8(%rbp), %rax
movq %rax, -0xe0(%rbp)
leaq -0x110(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x2b30
jmp 0x2511
leaq -0x128(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x2b60
jmp 0x2523
leaq -0x110(%rbp), %rdi
leaq -0x128(%rbp), %rsi
callq 0x2b10
movq %rax, -0x208(%rbp)
jmp 0x253f
leaq -0x128(%rbp), %rdi
callq 0x2bd0
leaq -0x110(%rbp), %rdi
callq 0x2bd0
movq -0x208(%rbp), %rax
movq %rax, -0xf8(%rbp)
movl $0x1, -0x148(%rbp)
movl $0x2, -0x144(%rbp)
movl $0x3, -0x140(%rbp)
movl $0x4, -0x13c(%rbp)
leaq -0x148(%rbp), %rax
movq %rax, -0x138(%rbp)
movq $0x4, -0x130(%rbp)
movq -0x138(%rbp), %rsi
movq -0x130(%rbp), %rdx
leaq -0x20(%rbp), %rdi
callq 0x2bf0
jmp 0x25bf
leaq -0x20(%rbp), %rax
movq %rax, -0x150(%rbp)
movq -0x150(%rbp), %rdi
callq 0x2ab0
movq %rax, -0x158(%rbp)
movq -0x150(%rbp), %rdi
callq 0x2ae0
movq %rax, -0x160(%rbp)
leaq -0x158(%rbp), %rdi
leaq -0x160(%rbp), %rsi
callq 0x2c40
testb $0x1, %al
jne 0x260c
jmp 0x27ab
leaq -0x158(%rbp), %rdi
callq 0x2c80
movl (%rax), %eax
movl %eax, -0x164(%rbp)
movl -0x164(%rbp), %esi
movq 0x7993(%rip), %rdi      # 0x9fc0
callq 0x21b0
movq %rax, -0x210(%rbp)
jmp 0x263b
movq -0x210(%rbp), %rdi
leaq 0x39d6(%rip), %rsi      # 0x601f
callq 0x20e0
jmp 0x2650
jmp 0x2652
leaq -0x158(%rbp), %rdi
callq 0x2ca0
jmp 0x25f0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x51(%rbp), %rdi
callq 0x2a40
jmp 0x298c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x26fa
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x26ee
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0xc8(%rbp), %rax
movq %rax, -0x220(%rbp)
addq $0x40, %rax
movq %rax, -0x218(%rbp)
movq -0x218(%rbp), %rdi
addq $-0x20, %rdi
movq %rdi, -0x228(%rbp)
callq 0x20a0
movq -0x220(%rbp), %rcx
movq -0x228(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x218(%rbp)
jne 0x26bb
jmp 0x26ee
leaq -0xd2(%rbp), %rdi
callq 0x2120
leaq -0xd1(%rbp), %rdi
callq 0x2120
testb $0x1, -0xd3(%rbp)
jne 0x2711
jmp 0x275e
movq -0xd0(%rbp), %rax
leaq -0xc8(%rbp), %rcx
cmpq %rax, %rcx
movq %rax, -0x230(%rbp)
je 0x275c
movq -0x230(%rbp), %rdi
addq $-0x20, %rdi
movq %rdi, -0x238(%rbp)
callq 0x20a0
movq -0x238(%rbp), %rax
leaq -0xc8(%rbp), %rcx
cmpq %rcx, %rax
movq %rax, -0x230(%rbp)
jne 0x272b
jmp 0x275e
jmp 0x2983
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x297a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x279a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x128(%rbp), %rdi
callq 0x2bd0
leaq -0x110(%rbp), %rdi
callq 0x2bd0
jmp 0x297a
movq 0x780e(%rip), %rdi      # 0x9fc0
movq 0x77e7(%rip), %rsi      # 0x9fa0
callq 0x2110
jmp 0x27c0
leaq -0x20(%rbp), %rdi
movq %rdi, -0x248(%rbp)
callq 0x2ab0
movq -0x248(%rbp), %rdi
movq %rax, -0x178(%rbp)
callq 0x2ae0
movq %rax, -0x180(%rbp)
movq -0x178(%rbp), %rdi
movq -0x180(%rbp), %rsi
callq 0x2a90
movq %rax, -0x240(%rbp)
jmp 0x2806
movq -0x240(%rbp), %rax
movq %rax, -0x170(%rbp)
movq -0x170(%rbp), %rax
movl $0x5, (%rax)
leaq -0x20(%rbp), %rax
movq %rax, -0x188(%rbp)
movq -0x188(%rbp), %rdi
callq 0x2ab0
movq %rax, -0x190(%rbp)
movq -0x188(%rbp), %rdi
callq 0x2ae0
movq %rax, -0x198(%rbp)
leaq -0x190(%rbp), %rdi
leaq -0x198(%rbp), %rsi
callq 0x2c40
testb $0x1, %al
jne 0x286b
jmp 0x28bf
leaq -0x190(%rbp), %rdi
callq 0x2c80
movl (%rax), %eax
movl %eax, -0x19c(%rbp)
movl -0x19c(%rbp), %esi
movq 0x7734(%rip), %rdi      # 0x9fc0
callq 0x21b0
movq %rax, -0x250(%rbp)
jmp 0x289a
movq -0x250(%rbp), %rdi
leaq 0x3777(%rip), %rsi      # 0x601f
callq 0x20e0
jmp 0x28af
jmp 0x28b1
leaq -0x190(%rbp), %rdi
callq 0x2ca0
jmp 0x2852
movq 0x76fa(%rip), %rdi      # 0x9fc0
movq 0x76d3(%rip), %rsi      # 0x9fa0
callq 0x2110
jmp 0x28d4
leaq -0x20(%rbp), %rdi
movq %rdi, -0x260(%rbp)
callq 0x2ab0
movq -0x260(%rbp), %rdi
movq %rax, -0x1a8(%rbp)
callq 0x2ae0
movq %rax, -0x1b0(%rbp)
movq -0x1a8(%rbp), %rdi
movq -0x1b0(%rbp), %rsi
callq 0x2cc0
movl %eax, -0x254(%rbp)
jmp 0x2919
movl -0x254(%rbp), %eax
movl %eax, -0x1a0(%rbp)
movl -0x1a0(%rbp), %esi
movq 0x768e(%rip), %rdi      # 0x9fc0
callq 0x21b0
movq %rax, -0x268(%rbp)
jmp 0x2940
movq -0x268(%rbp), %rdi
movq 0x7652(%rip), %rsi      # 0x9fa0
callq 0x2110
jmp 0x2955
movl $0x0, -0x4(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x2cf0
leaq -0x20(%rbp), %rdi
callq 0x2d10
movl -0x4(%rbp), %eax
addq $0x270, %rsp            # imm = 0x270
popq %rbp
retq
leaq -0x78(%rbp), %rdi
callq 0x2cf0
leaq -0x20(%rbp), %rdi
callq 0x2d10
movq -0x60(%rbp), %rdi
callq 0x21c0
nopw %cs:(%rax,%rax)
nop