// File: /workspace/github_cpp_makefile_star2_O2/iZhangHui[P]CppPrimer/CH16_TemplatesAndGenericProgramming/exercises/ex16_47.cc
// Function: main
int main(int argc, char const *argv[])
{
	int i = 0, j = 0, k = 0, l = 0;
	cout << i << " " << j << " " << k << " " << l << endl;

	f(42, i);        // f changes its argument i
	flip1(f, j, 42); // f called through flip1 leaves j unchanged
	flip2(f, k, 42); // ok: k is changed
	cout << "=========================================" << endl;
	g(1, i);
	flip(g, i, 42);  // ok: rvalue-ness of the third argument is preserved
	cout << i << " " << j << " " << k << " " << l << endl;
	cout << "=========================================" << endl;

	// test for lvalue reference
	string s1;
	string s2;
	flip(func_lvalue, s1, s2);
	cout << s1 << " " << s2 << endl;

	// test for rvalue reference
	flip(func_rvalue, 99, 88);

	// void flip1(F, T1, T2) [with F = void (*)(int&&, int&&); T1 = int; T2 = int]’:
	// ex16_47.cc:88:27:   required from here
	// ex16_47.cc:28:3: error: cannot bind ‘int’ lvalue to ‘int&&’
	// f(t2, t1);
	// ^
	// flip1(func_rvalue, 99, 88);

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
leaq -0x58(%rbp), %r12
andl $0x0, (%r12)
leaq -0x54(%rbp), %rbx
andl $0x0, (%rbx)
movq 0x2c78(%rip), %rdi      # 0x3fd8
xorl %esi, %esi
callq 0x10b0
leaq 0xc96(%rip), %r15       # 0x2004
movq %rax, %rdi
movq %r15, %rsi
callq 0x1070
movq %rax, %rdi
xorl %esi, %esi
callq 0x10b0
movq %rax, %rdi
movq %r15, %rsi
callq 0x1070
movq %rax, %rdi
xorl %esi, %esi
callq 0x10b0
movq %rax, %rdi
movq %r15, %rsi
callq 0x1070
movq %rax, %rdi
xorl %esi, %esi
callq 0x10b0
movq %rax, %rdi
callq 0x1040
pushq $0x2a
popq %r13
movl %r13d, %edi
movq %r12, %rsi
callq 0x121c
leaq -0x48(%rbp), %r14
andl $0x0, (%r14)
movl %r13d, %edi
movq %r14, %rsi
callq 0x121c
movl %r13d, %edi
movq %rbx, %rsi
callq 0x121c
leaq 0xc2a(%rip), %rsi       # 0x2013
movq 0x2be8(%rip), %r13      # 0x3fd8
movq %r13, %rdi
callq 0x1070
movq %rax, %rdi
callq 0x1040
movl $0x1, (%r14)
movq %r14, %rdi
movq %r12, %rsi
callq 0x125e
movl $0x2a, (%r14)
leaq -0x48(%rbp), %rdi
movq %r12, %rsi
callq 0x125e
movl (%r12), %esi
movq %r13, %rdi
callq 0x10b0
movq %rax, %rdi
movq %r15, %rsi
callq 0x1070
movq %rax, %rdi
xorl %esi, %esi
callq 0x10b0
movq %rax, %rdi
movq %r15, %rsi
callq 0x1070
movl (%rbx), %esi
movq %rax, %rdi
callq 0x10b0
movq %rax, %rdi
movq %r15, %rsi
callq 0x1070
movq %rax, %rdi
xorl %esi, %esi
callq 0x10b0
movq %rax, %rdi
callq 0x1040
movq %r13, %rdi
leaq 0xb91(%rip), %rsi       # 0x2013
callq 0x1070
movq %rax, %rdi
callq 0x1040
leaq -0x38(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
xorl %ecx, %ecx
movb %cl, (%rax)
leaq -0x68(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %cl, (%rax)
leaq -0x78(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x129c
movq 0x2b15(%rip), %rdi      # 0x3fd8
leaq -0x48(%rbp), %rsi
callq 0x1060
leaq 0xb31(%rip), %rsi       # 0x2004
movq %rax, %rdi
callq 0x1070
leaq -0x78(%rbp), %rsi
movq %rax, %rdi
callq 0x1060
movq %rax, %rdi
callq 0x1040
leaq -0x50(%rbp), %rsi
movl $0x63, (%rsi)
leaq -0x4c(%rbp), %rdi
movl $0x58, (%rdi)
callq 0x12c6
leaq -0x78(%rbp), %rdi
callq 0x1030
leaq -0x48(%rbp), %rdi
callq 0x1030
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x152d
movq %rax, %rbx
leaq -0x78(%rbp), %rdi
callq 0x1030
leaq -0x48(%rbp), %rdi
callq 0x1030
movq %rbx, %rdi
callq 0x10c0