// File: /workspace/github_cpp_makefile_star2_O3/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 %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movups 0xda0(%rip), %xmm0      # 0x2014
leaq -0x70(%rbp), %rbx
movaps %xmm0, 0x10(%rbx)
movups 0xd81(%rip), %xmm0      # 0x2004
movaps %xmm0, (%rbx)
movabsq $0x900000008, %rax      # imm = 0x900000008
movq %rax, 0x20(%rbx)
leaq -0x40(%rbp), %r14
leaq -0x88(%rbp), %rcx
movl $0xa, %edx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1752
xorps %xmm0, %xmm0
movaps %xmm0, (%rbx)
movq $0x0, 0x10(%rbx)
leaq -0x88(%rbp), %rdi
movq %r14, %rsi
callq 0x1798
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
leaq -0x8c(%rbp), %rdx
movl $0x2a, (%rdx)
callq 0x19fc
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rcx
cmpq %rcx, %rax
setne %dl
addq $-0x4, %rcx
cmpq %rax, %rcx
seta %sil
andb %dl, %sil
cmpb $0x1, %sil
jne 0x1326
addq $0x4, %rax
movl -0x4(%rax), %edx
movl (%rcx), %esi
movl %esi, -0x4(%rax)
movl %edx, (%rcx)
addq $-0x4, %rcx
leaq 0x4(%rax), %rdx
cmpq %rcx, %rax
movq %rdx, %rax
jb 0x130c
leaq -0x40(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x1818
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
leaq -0x70(%rbp), %rdx
callq 0x1905
movq -0x40(%rbp), %r15
movq -0x38(%rbp), %r12
cmpq %r12, %r15
je 0x1386
movq 0x2c7d(%rip), %rbx      # 0x3fd8
leaq 0xcca(%rip), %r14       # 0x202c
movl (%r15), %esi
movq %rbx, %rdi
callq 0x10f0
movl $0x1, %edx
movq %rax, %rdi
movq %r14, %rsi
callq 0x10c0
addq $0x4, %r15
cmpq %r12, %r15
jne 0x1362
movq 0x2c4b(%rip), %rdi      # 0x3fd8
movq (%rdi), %rax
addq -0x18(%rax), %rdi
movl $0xa, %esi
callq 0x1090
movsbl %al, %esi
movq 0x2c30(%rip), %rbx      # 0x3fd8
movq %rbx, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1060
movq -0x70(%rbp), %r12
movq -0x68(%rbp), %r13
cmpq %r13, %r12
je 0x13f8
movq 0x2c0c(%rip), %r14      # 0x3fd8
leaq 0xc59(%rip), %r15       # 0x202c
movl (%r12), %esi
movq %r14, %rdi
callq 0x10f0
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x10c0
addq $0x4, %r12
cmpq %r13, %r12
jne 0x13d3
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x1090
movsbl %al, %esi
movq 0x2bc2(%rip), %rbx      # 0x3fd8
movq %rbx, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1060
movq -0x40(%rbp), %r12
movq -0x38(%rbp), %rax
movq %rax, %rsi
subq %r12, %rsi
movq %rsi, %rdx
sarq $0x4, %rdx
testq %rdx, %rdx
jle 0x1483
andq $-0x10, %rsi
movq %rsi, %rcx
addq %r12, %rcx
incq %rdx
leaq 0x8(%r12), %r13
testb $0x1, -0x8(%r13)
jne 0x14ba
testb $0x1, -0x4(%r13)
jne 0x14c0
testb $0x1, (%r13)
jne 0x14cf
testb $0x1, 0x4(%r13)
jne 0x14cb
decq %rdx
addq $0x10, %r13
cmpq $0x1, %rdx
jg 0x1452
movq %rax, %rsi
subq %rcx, %rsi
jmp 0x1486
movq %r12, %rcx
sarq $0x2, %rsi
cmpq $0x1, %rsi
je 0x14ae
cmpq $0x2, %rsi
je 0x14a5
cmpq $0x3, %rsi
jne 0x14c6
testb $0x1, (%rcx)
jne 0x14b5
addq $0x4, %rcx
testb $0x1, (%rcx)
jne 0x14b5
addq $0x4, %rcx
testb $0x1, (%rcx)
cmoveq %rax, %rcx
movq %rcx, %r13
jmp 0x14cf
addq $-0x8, %r13
jmp 0x14cf
addq $-0x4, %r13
jmp 0x14cf
movq %rax, %r13
jmp 0x14fd
addq $0x4, %r13
cmpq %rax, %r13
sete %dl
leaq 0x4(%r13), %rcx
cmpq %rax, %rcx
sete %sil
orb %dl, %sil
jne 0x14fd
movl (%rcx), %edx
testb $0x1, %dl
jne 0x14f4
movl %edx, (%r13)
addq $0x4, %r13
addq $0x4, %rcx
cmpq %rax, %rcx
jne 0x14e5
cmpq %r13, %r12
je 0x1535
movq 0x2acf(%rip), %r14      # 0x3fd8
leaq 0xb1c(%rip), %r15       # 0x202c
movl (%r12), %esi
movq %r14, %rdi
callq 0x10f0
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x10c0
addq $0x4, %r12
cmpq %r13, %r12
jne 0x1510
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x1090
movsbl %al, %esi
movq 0x2a85(%rip), %rbx      # 0x3fd8
movq %rbx, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1060
leaq -0x40(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x1818
movq -0x70(%rbp), %rax
cmpq %rax, -0x68(%rbp)
je 0x1581
movq %rax, -0x68(%rbp)
movq -0x40(%rbp), %r14
movq -0x38(%rbp), %r12
cmpq %r12, %r14
je 0x1603
leaq -0x70(%rbp), %r15
movl (%r14), %eax
testb $0x1, %al
jne 0x15ba
movq -0x68(%rbp), %rsi
cmpq -0x60(%rbp), %rsi
je 0x15af
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, -0x68(%rbp)
jmp 0x15ba
movq %r15, %rdi
movq %r14, %rdx
callq 0x1aaa
addq $0x4, %r14
cmpq %r12, %r14
jne 0x1592
movq -0x70(%rbp), %r12
movq -0x68(%rbp), %r13
cmpq %r13, %r12
je 0x1603
movq 0x2a01(%rip), %r14      # 0x3fd8
leaq 0xa4e(%rip), %r15       # 0x202c
movl (%r12), %esi
movq %r14, %rdi
callq 0x10f0
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x10c0
addq $0x4, %r12
cmpq %r13, %r12
jne 0x15de
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x1090
movsbl %al, %esi
movq 0x29b7(%rip), %rbx      # 0x3fd8
movq %rbx, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1060
movq -0x40(%rbp), %r12
movq -0x38(%rbp), %r13
cmpq %r13, %r12
je 0x1671
movq 0x2993(%rip), %r14      # 0x3fd8
leaq 0x9e0(%rip), %r15       # 0x202c
movl (%r12), %esi
movq %r14, %rdi
callq 0x10f0
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x10c0
addq $0x4, %r12
cmpq %r13, %r12
jne 0x164c
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x1090
movsbl %al, %esi
movq 0x2949(%rip), %rdi      # 0x3fd8
callq 0x1030
movq %rax, %rdi
callq 0x1060
movq -0x88(%rbp), %rdi
testq %rdi, %rdi
je 0x16b4
movq -0x78(%rbp), %rsi
subq %rdi, %rsi
callq 0x10b0
movq -0x70(%rbp), %rdi
testq %rdi, %rdi
je 0x16c9
movq -0x60(%rbp), %rsi
subq %rdi, %rsi
callq 0x10b0
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x16de
movq -0x30(%rbp), %rsi
subq %rdi, %rsi
callq 0x10b0
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1704
movq %rax, %rbx
jmp 0x171f
jmp 0x1704
jmp 0x1704
jmp 0x1704
jmp 0x1704
jmp 0x1704
jmp 0x1704
jmp 0x1704
movq %rax, %rbx
movq -0x88(%rbp), %rdi
testq %rdi, %rdi
je 0x171f
movq -0x78(%rbp), %rsi
subq %rdi, %rsi
callq 0x10b0
movq -0x70(%rbp), %rdi
testq %rdi, %rdi
je 0x1734
movq -0x60(%rbp), %rsi
subq %rdi, %rsi
callq 0x10b0
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x1749
movq -0x30(%rbp), %rsi
subq %rdi, %rsi
callq 0x10b0
movq %rbx, %rdi
callq 0x1100
nop