// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movups 0x1c09(%rip), %xmm0     # 0x4020
leaq -0xb0(%rbp), %rsi
movaps %xmm0, (%rsi)
movl $0x5, 0x10(%rsi)
leaq -0x48(%rbp), %rdi
leaq -0xc0(%rbp), %rcx
movl $0x5, %edx
callq 0x27ec
leaq -0xa0(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0x1be5(%rip), %rsi      # 0x4034
leaq 0x1be0(%rip), %rdx      # 0x4036
leaq -0xb0(%rbp), %r15
movq %r15, %rdi
callq 0x2b18
leaq -0x90(%rbp), %r14
leaq -0x80(%rbp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0x1bbc(%rip), %rsi      # 0x4037
leaq 0x1bb8(%rip), %rdx      # 0x403a
movq %r14, %rdi
callq 0x2b18
leaq -0xb0(%rbp), %rax
leaq -0xc0(%rbp), %rcx
movq %rax, (%rcx)
movq $0x2, 0x8(%rcx)
leaq -0x50(%rbp), %rdi
movq $0x0, -0x8(%rdi)
leaq -0x58(%rbp), %rsi
leaq -0x29(%rbp), %rdx
callq 0x2bb2
movq $-0x40, %r14
movq -0x10(%rbx), %rdi
cmpq %rdi, %rbx
je 0x24d7
movq (%rbx), %rsi
incq %rsi
callq 0x2120
addq $-0x20, %rbx
addq $0x20, %r14
jne 0x24c3
movq -0x58(%rbp), %rcx
movq -0x50(%rbp), %rax
movq %rcx, -0x70(%rbp)
movq %rax, -0x68(%rbp)
testq %rax, %rax
je 0x250b
movq 0x3abb(%rip), %rcx      # 0x5fb8
cmpb $0x0, (%rcx)
je 0x2507
incl 0xc(%rax)
jmp 0x250b
lock
incl 0xc(%rax)
movq $0x0, -0x60(%rbp)
movq -0x50(%rbp), %rbx
testq %rbx, %rbx
je 0x2531
movq 0x3a95(%rip), %rax      # 0x5fb8
cmpb $0x0, (%rax)
je 0x252d
incl 0xc(%rbx)
jmp 0x2531
lock
incl 0xc(%rbx)
leaq -0x68(%rbp), %r14
leaq -0x70(%rbp), %rdi
callq 0x2832
testq %rbx, %rbx
je 0x2572
movq 0x3a6e(%rip), %rax      # 0x5fb8
cmpb $0x0, (%rax)
je 0x255a
movl 0xc(%rbx), %eax
leal -0x1(%rax), %ecx
movl %ecx, 0xc(%rbx)
jmp 0x2564
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
lock
xaddl %eax, 0xc(%rbx)
cmpl $0x1, %eax
jne 0x2572
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x18(%rax)
movq -0x68(%rbp), %rdi
testq %rdi, %rdi
je 0x25a7
movq 0x3a36(%rip), %rax      # 0x5fb8
cmpb $0x0, (%rax)
je 0x2592
movl 0xc(%rdi), %eax
leal -0x1(%rax), %ecx
movl %ecx, 0xc(%rdi)
jmp 0x259c
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
lock
xaddl %eax, 0xc(%rdi)
cmpl $0x1, %eax
jne 0x25a7
movq (%rdi), %rax
callq *0x18(%rax)
movaps 0x1a62(%rip), %xmm0     # 0x4010
leaq -0xa0(%rbp), %rdx
movups %xmm0, -0x10(%rdx)
leaq -0x48(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x2f6c
movq -0x48(%rbp), %r15
movq -0x40(%rbp), %r12
cmpq %r12, %r15
je 0x2608
movq 0x39e3(%rip), %rbx      # 0x5fc0
leaq 0x1a57(%rip), %r14      # 0x403b
movl (%r15), %esi
movq %rbx, %rdi
callq 0x21b0
movl $0x1, %edx
movq %rax, %rdi
movq %r14, %rsi
callq 0x2130
addq $0x4, %r15
cmpq %r12, %r15
jne 0x25e4
movq 0x39b1(%rip), %rdi      # 0x5fc0
movq (%rdi), %rax
addq -0x18(%rax), %rdi
movl $0xa, %esi
callq 0x2100
movsbl %al, %esi
movq 0x3996(%rip), %rbx      # 0x5fc0
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20a0
movq -0x48(%rbp), %r12
movl $0x5, (%r12)
movq -0x40(%rbp), %r13
cmpq %r13, %r12
je 0x2682
movq 0x396a(%rip), %r14      # 0x5fc0
leaq 0x19de(%rip), %r15      # 0x403b
movl (%r12), %esi
movq %r14, %rdi
callq 0x21b0
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x2130
addq $0x4, %r12
cmpq %r13, %r12
jne 0x265d
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2100
movsbl %al, %esi
movq 0x3920(%rip), %rdi      # 0x5fc0
callq 0x2030
movq %rax, %rdi
callq 0x20a0
movq -0x48(%rbp), %rax
movl (%rax), %esi
movq 0x3906(%rip), %rdi      # 0x5fc0
callq 0x21b0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2100
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20a0
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x26f7
callq 0x29f4
movq -0x48(%rbp), %rdi
testq %rdi, %rdi
je 0x270c
movq -0x38(%rbp), %rsi
subq %rdi, %rsi
callq 0x2120
xorl %eax, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x27be
movq %rdx, %r15
movq %rax, %r12
testq %rbx, %rbx
je 0x2738
movq %rbx, %rdi
callq 0x2287
leaq -0xb0(%rbp), %rbx
movq %r14, %rdi
movq %r12, %rsi
movl %r15d, %edx
movq %rbx, %rcx
callq 0x2230
movq (%rbx), %rbx
jmp 0x27c1
movq %rax, %rbx
leaq -0x70(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x21f6
movb $0x1, %al
jmp 0x277b
movq %rax, %rbx
xorl %eax, %eax
jmp 0x277b
movq %rax, %rbx
xorl %eax, %eax
movq %r15, %r14
cmpq %r14, %r15
sete %cl
orb %al, %cl
jne 0x27cf
addq $-0x10, %r14
leaq -0xb0(%rbp), %r15
movq -0x10(%r14), %rdi
cmpq %rdi, %r14
je 0x27a4
movq (%r14), %rsi
incq %rsi
callq 0x2120
leaq -0x20(%r14), %rax
addq $-0x10, %r14
cmpq %r15, %r14
movq %rax, %r14
jne 0x2790
jmp 0x27cf
jmp 0x27be
jmp 0x27be
jmp 0x27be
jmp 0x27be
movq %rax, %rbx
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x27cf
callq 0x29f4
movq -0x48(%rbp), %rdi
testq %rdi, %rdi
je 0x27e4
movq -0x38(%rbp), %rsi
subq %rdi, %rsi
callq 0x2120
movq %rbx, %rdi
callq 0x21c0