// File: /workspace/github_cpp_makefile_star2_O3/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 0x27c6
leaq -0xa0(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0x1be5(%rip), %rsi      # 0x4034
leaq 0x1be0(%rip), %rdx      # 0x4036
leaq -0xb0(%rbp), %rbx
movq %rbx, %rdi
callq 0x2ad8
leaq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x1bbc(%rip), %rsi      # 0x4037
leaq 0x1bb8(%rip), %rdx      # 0x403a
callq 0x2ad8
leaq -0xc0(%rbp), %rcx
movq %rbx, (%rcx)
movq $0x2, 0x8(%rcx)
leaq -0x50(%rbp), %rdi
movq $0x0, -0x8(%rdi)
leaq -0x58(%rbp), %rsi
leaq -0x29(%rbp), %rdx
callq 0x2b76
movq $-0x40, %rbx
movq -0x10(%r14), %rdi
cmpq %rdi, %r14
je 0x24cd
movq (%r14), %rsi
incq %rsi
callq 0x2120
addq $-0x20, %r14
addq $0x20, %rbx
jne 0x24b9
movq -0x58(%rbp), %rax
movq -0x50(%rbp), %rcx
movq %rax, -0x70(%rbp)
movq %rcx, -0x68(%rbp)
testq %rcx, %rcx
je 0x24fd
movq 0x3ac5(%rip), %rax      # 0x5fb8
cmpb $0x0, (%rax)
je 0x2507
incl 0xc(%rcx)
jmp 0x250b
movq $0x0, -0x60(%rbp)
jmp 0x2526
lock
incl 0xc(%rcx)
movq -0x50(%rbp), %rbx
movq $0x0, -0x60(%rbp)
testq %rbx, %rbx
je 0x2526
cmpb $0x0, (%rax)
je 0x252d
incl 0xc(%rbx)
jmp 0x2531
movb $0x1, %r13b
xorl %ebx, %ebx
jmp 0x2534
lock
incl 0xc(%rbx)
xorl %r13d, %r13d
leaq -0x68(%rbp), %r14
leaq -0x70(%rbp), %rdi
callq 0x280c
testb %r13b, %r13b
jne 0x2575
movq 0x3a6b(%rip), %rax      # 0x5fb8
cmpb $0x0, (%rax)
je 0x255d
movl 0xc(%rbx), %eax
leal -0x1(%rax), %ecx
movl %ecx, 0xc(%rbx)
jmp 0x2567
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
lock
xaddl %eax, 0xc(%rbx)
cmpl $0x1, %eax
jne 0x2575
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x18(%rax)
movq -0x68(%rbp), %rdi
testq %rdi, %rdi
je 0x25aa
movq 0x3a33(%rip), %rax      # 0x5fb8
cmpb $0x0, (%rax)
je 0x2595
movl 0xc(%rdi), %eax
leal -0x1(%rax), %ecx
movl %ecx, 0xc(%rdi)
jmp 0x259f
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
lock
xaddl %eax, 0xc(%rdi)
cmpl $0x1, %eax
jne 0x25aa
movq (%rdi), %rax
callq *0x18(%rax)
movaps 0x1a5f(%rip), %xmm0     # 0x4010
leaq -0xa0(%rbp), %rdx
movups %xmm0, -0x10(%rdx)
leaq -0x48(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x2f20
movq -0x48(%rbp), %r15
movq -0x40(%rbp), %r12
cmpq %r12, %r15
je 0x260b
movq 0x39e0(%rip), %rbx      # 0x5fc0
leaq 0x1a54(%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 0x25e7
movq 0x39ae(%rip), %rdi      # 0x5fc0
movq (%rdi), %rax
addq -0x18(%rax), %rdi
movl $0xa, %esi
callq 0x2100
movsbl %al, %esi
movq 0x3993(%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 0x2685
movq 0x3967(%rip), %r14      # 0x5fc0
leaq 0x19db(%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 0x2660
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2100
movsbl %al, %esi
movq 0x391d(%rip), %rdi      # 0x5fc0
callq 0x2030
movq %rax, %rdi
callq 0x20a0
movq -0x48(%rbp), %rax
movl (%rax), %esi
movq 0x3903(%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 0x26fa
callq 0x29c2
movq -0x48(%rbp), %rdi
testq %rdi, %rdi
je 0x270f
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 0x2797
movq %rdx, %r15
movq %rax, %r12
testb %r13b, %r13b
jne 0x2738
movq %rbx, %rdi
callq 0x2281
leaq -0xb0(%rbp), %rbx
movq %r14, %rdi
movq %r12, %rsi
movl %r15d, %edx
movq %rbx, %rcx
callq 0x222a
movq (%rbx), %rbx
jmp 0x279a
movq %rax, %rbx
leaq -0x70(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x21f0
jmp 0x27a8
movq %rax, %rbx
movq -0xb0(%rbp), %rdi
cmpq %r15, %rdi
je 0x27a8
movq -0xa0(%rbp), %rsi
incq %rsi
callq 0x2120
jmp 0x27a8
movq %rax, %rbx
jmp 0x27a8
jmp 0x2797
jmp 0x2797
jmp 0x2797
jmp 0x2797
movq %rax, %rbx
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x27a8
callq 0x29c2
movq -0x48(%rbp), %rdi
testq %rdi, %rdi
je 0x27bd
movq -0x38(%rbp), %rsi
subq %rdi, %rsi
callq 0x2120
movq %rbx, %rdi
callq 0x21c0
nop