// File: /workspace/github_cpp_makefile_star2_O2/iZhangHui[P]CppPrimer/CH10_GenericAlgorithms/examples/reverse.cc
// Function: main
int main()
{
	vector<int> v1 = {0,1,2,3,4,5,6,7,8,9};
	vector<int> v2;
	vector<int> v3 = v1;

	find(v1.begin(), v1.end(), 42);  // find first element equal to 42 
	find_if(v1.begin(), v1.end(),    // find first odd element
	        [](int i) { return i % 2; });

	// puts elements in v1 into reverse order
	reverse(v1.begin(), v1.end());  
	v1 = v3;  // restore original data

	// copies elements from v1 into v2 in reverse order; v1 is unchanged
	reverse_copy(v1.begin(), v1.end(), back_inserter(v2));

	for (auto i : v1) 
		cout << i << " ";   // prints 0 1 2 . . . 8 9
	cout << endl;
	for (auto i : v2) 
		cout << i << " ";   // prints 9 8 7 . . . 1 0
	cout << endl;

	// removes the odd elements from v1
	auto it = remove_if(v1.begin(), v1.end(), 
	                    [](int i) { return i % 2; });
	// prints 0 2 4 6 8
	for_each(v1.begin(), it, [](int i) { cout << i << " "; });
	cout << endl;

	v1 = v3;    // restore original data
	v2.clear(); // make v2 empty again

	// copies only the even elements from v1 into v2; v1 is unchanged
	remove_copy_if(v1.begin(), v1.end(), back_inserter(v2),
	               [](int i) { return i % 2; });
	for (auto i : v2) 
		cout << i << " ";  // prints 0 2 4 6 8
	cout << endl;
	for (auto i : v1)      // prints 0 1 2 . . . 8 9
		cout << i << " ";
	cout << endl;

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x60, %rsp
movups 0xdb2(%rip), %xmm0      # 0x2014
leaq -0x60(%rbp), %rbx
movaps %xmm0, 0x10(%rbx)
movups 0xd93(%rip), %xmm0      # 0x2004
movaps %xmm0, (%rbx)
movabsq $0x900000008, %rax      # imm = 0x900000008
movq %rax, 0x20(%rbx)
leaq -0x38(%rbp), %r14
pushq $0xa
popq %rdx
leaq -0x78(%rbp), %rcx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x158c
xorps %xmm0, %xmm0
movaps %xmm0, (%rbx)
andq $0x0, 0x10(%rbx)
leaq -0x78(%rbp), %rdi
movq %r14, %rsi
callq 0x15c2
movq -0x38(%rbp), %rdi
movq -0x30(%rbp), %rsi
leaq -0x7c(%rbp), %rdx
movl $0x2a, (%rdx)
callq 0x185c
movq -0x38(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x18e9
leaq -0x38(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x161a
movq -0x38(%rbp), %rdi
movq -0x30(%rbp), %rsi
leaq -0x60(%rbp), %rdx
callq 0x16ee
movq -0x38(%rbp), %r15
movq -0x30(%rbp), %r12
movq 0x2cd8(%rip), %rbx      # 0x3fd8
leaq 0xd25(%rip), %r14       # 0x202c
cmpq %r12, %r15
je 0x1328
movl (%r15), %esi
movq %rbx, %rdi
callq 0x10f0
movq %rax, %rdi
movq %r14, %rsi
callq 0x10a0
addq $0x4, %r15
jmp 0x1307
movq 0x2ca9(%rip), %rdi      # 0x3fd8
callq 0x1060
movq -0x60(%rbp), %r15
movq -0x58(%rbp), %r12
movq 0x2c95(%rip), %rbx      # 0x3fd8
leaq 0xce2(%rip), %r14       # 0x202c
cmpq %r12, %r15
je 0x136b
movl (%r15), %esi
movq %rbx, %rdi
callq 0x10f0
movq %rax, %rdi
movq %r14, %rsi
callq 0x10a0
addq $0x4, %r15
jmp 0x134a
movq 0x2c66(%rip), %rdi      # 0x3fd8
callq 0x1060
movq -0x38(%rbp), %r15
movq -0x30(%rbp), %r12
movq %r12, %rcx
subq %r15, %rcx
movq %rcx, %rdx
sarq $0x4, %rdx
movq %r15, %rax
testq %rdx, %rdx
jle 0x13b8
testb $0x1, (%rax)
jne 0x13f9
testb $0x1, 0x4(%rax)
jne 0x13e9
testb $0x1, 0x8(%rax)
jne 0x13ef
testb $0x1, 0xc(%rax)
jne 0x13f5
addq $0x10, %rax
decq %rdx
addq $-0x10, %rcx
jmp 0x138f
sarq $0x2, %rcx
cmpq $0x1, %rcx
je 0x13e0
cmpq $0x2, %rcx
je 0x13d7
cmpq $0x3, %rcx
jne 0x1424
testb $0x1, (%rax)
jne 0x13f9
addq $0x4, %rax
testb $0x1, (%rax)
jne 0x13f9
addq $0x4, %rax
testb $0x1, (%rax)
cmoveq %r12, %rax
jmp 0x13f9
addq $0x4, %rax
jmp 0x13f9
addq $0x8, %rax
jmp 0x13f9
addq $0xc, %rax
cmpq %r12, %rax
je 0x1424
movq %rax, %rcx
addq $0x4, %rax
cmpq %r12, %rax
je 0x1421
movl (%rax), %edx
addq $0x4, %rax
testb $0x1, %dl
jne 0x1405
movl %edx, (%rcx)
addq $0x4, %rcx
addq $-0x4, %rax
jmp 0x1401
movq %rcx, %r12
movq 0x2bad(%rip), %rbx      # 0x3fd8
leaq 0xbfa(%rip), %r14       # 0x202c
cmpq %r12, %r15
je 0x1453
movl (%r15), %esi
movq %rbx, %rdi
callq 0x10f0
movq %rax, %rdi
movq %r14, %rsi
callq 0x10a0
addq $0x4, %r15
jmp 0x1432
movq 0x2b7e(%rip), %rdi      # 0x3fd8
callq 0x1060
leaq -0x38(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x161a
movq -0x60(%rbp), %rax
cmpq %rax, -0x58(%rbp)
je 0x147a
movq %rax, -0x58(%rbp)
movq -0x38(%rbp), %rbx
movq -0x30(%rbp), %r15
leaq -0x60(%rbp), %r14
cmpq %r15, %rbx
je 0x14a1
testb $0x1, (%rbx)
jne 0x149b
movq %r14, %rdi
movq %rbx, %rsi
callq 0x193a
addq $0x4, %rbx
jmp 0x1486
movq -0x60(%rbp), %r15
movq -0x58(%rbp), %r12
movq 0x2b28(%rip), %rbx      # 0x3fd8
leaq 0xb75(%rip), %r14       # 0x202c
cmpq %r12, %r15
je 0x14d8
movl (%r15), %esi
movq %rbx, %rdi
callq 0x10f0
movq %rax, %rdi
movq %r14, %rsi
callq 0x10a0
addq $0x4, %r15
jmp 0x14b7
movq 0x2af9(%rip), %rdi      # 0x3fd8
callq 0x1060
movq -0x38(%rbp), %r15
movq -0x30(%rbp), %r12
movq 0x2ae5(%rip), %rbx      # 0x3fd8
leaq 0xb32(%rip), %r14       # 0x202c
cmpq %r12, %r15
je 0x151b
movl (%r15), %esi
movq %rbx, %rdi
callq 0x10f0
movq %rax, %rdi
movq %r14, %rsi
callq 0x10a0
addq $0x4, %r15
jmp 0x14fa
movq 0x2ab6(%rip), %rdi      # 0x3fd8
callq 0x1060
leaq -0x78(%rbp), %rdi
callq 0x1782
leaq -0x60(%rbp), %rdi
callq 0x1782
leaq -0x38(%rbp), %rdi
callq 0x1782
xorl %eax, %eax
addq $0x60, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1566
movq %rax, %rbx
jmp 0x1572
jmp 0x1566
jmp 0x1566
jmp 0x1566
jmp 0x1566
jmp 0x1566
jmp 0x1566
jmp 0x1566
movq %rax, %rbx
leaq -0x78(%rbp), %rdi
callq 0x1782
leaq -0x60(%rbp), %rdi
callq 0x1782
leaq -0x38(%rbp), %rdi
callq 0x1782
movq %rbx, %rdi
callq 0x1100