// File: /workspace/github_cpp_makefile_star2_O1/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 0x174e
xorps %xmm0, %xmm0
movaps %xmm0, (%rbx)
movq $0x0, 0x10(%rbx)
leaq -0x88(%rbp), %rdi
movq %r14, %rsi
callq 0x1794
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
leaq -0x8c(%rbp), %rdx
movl $0x2a, (%rdx)
callq 0x19f8
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 0x1814
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
leaq -0x70(%rbp), %rdx
callq 0x18f3
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
movq %r12, %rcx
testq %rdx, %rdx
jle 0x147e
andq $-0x10, %rsi
movq %rsi, %rcx
addq %r12, %rcx
incq %rdx
leaq 0x8(%r12), %r13
testb $0x1, -0x8(%r13)
jne 0x14bb
testb $0x1, -0x4(%r13)
jne 0x14c1
testb $0x1, (%r13)
jne 0x14cb
testb $0x1, 0x4(%r13)
jne 0x14c7
decq %rdx
addq $0x10, %r13
cmpq $0x1, %rdx
jg 0x1455
movq %rax, %rdx
subq %rcx, %rdx
sarq $0x2, %rdx
cmpq $0x1, %rdx
je 0x14af
cmpq $0x2, %rdx
je 0x14a6
movq %rax, %r13
cmpq $0x3, %rdx
jne 0x14cb
testb $0x1, (%rcx)
jne 0x14b6
addq $0x4, %rcx
testb $0x1, (%rcx)
jne 0x14b6
addq $0x4, %rcx
testb $0x1, (%rcx)
cmoveq %rax, %rcx
movq %rcx, %r13
jmp 0x14cb
addq $-0x8, %r13
jmp 0x14cb
addq $-0x4, %r13
jmp 0x14cb
addq $0x4, %r13
cmpq %rax, %r13
sete %dl
leaq 0x4(%r13), %rcx
cmpq %rax, %rcx
sete %sil
orb %dl, %sil
jne 0x14f9
movl (%rcx), %edx
testb $0x1, %dl
jne 0x14f0
movl %edx, (%r13)
addq $0x4, %r13
addq $0x4, %rcx
cmpq %rax, %rcx
jne 0x14e1
cmpq %r13, %r12
je 0x1531
movq 0x2ad3(%rip), %r14      # 0x3fd8
leaq 0xb20(%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 0x150c
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x1090
movsbl %al, %esi
movq 0x2a89(%rip), %rbx      # 0x3fd8
movq %rbx, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1060
leaq -0x40(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x1814
movq -0x70(%rbp), %rax
cmpq %rax, -0x68(%rbp)
je 0x157d
movq %rax, -0x68(%rbp)
movq -0x40(%rbp), %r14
movq -0x38(%rbp), %r12
cmpq %r12, %r14
je 0x15bf
leaq -0x70(%rbp), %r15
movl (%r14), %eax
testb $0x1, %al
jne 0x15b6
movq -0x68(%rbp), %rsi
cmpq -0x60(%rbp), %rsi
je 0x15ab
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, -0x68(%rbp)
jmp 0x15b6
movq %r15, %rdi
movq %r14, %rdx
callq 0x1a9a
addq $0x4, %r14
cmpq %r12, %r14
jne 0x158e
movq -0x70(%rbp), %r12
movq -0x68(%rbp), %r13
cmpq %r13, %r12
je 0x15ff
movq 0x2a05(%rip), %r14      # 0x3fd8
leaq 0xa52(%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 0x15da
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x1090
movsbl %al, %esi
movq 0x29bb(%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 0x166d
movq 0x2997(%rip), %r14      # 0x3fd8
leaq 0x9e4(%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 0x1648
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x1090
movsbl %al, %esi
movq 0x294d(%rip), %rdi      # 0x3fd8
callq 0x1030
movq %rax, %rdi
callq 0x1060
movq -0x88(%rbp), %rdi
testq %rdi, %rdi
je 0x16b0
movq -0x78(%rbp), %rsi
subq %rdi, %rsi
callq 0x10b0
movq -0x70(%rbp), %rdi
testq %rdi, %rdi
je 0x16c5
movq -0x60(%rbp), %rsi
subq %rdi, %rsi
callq 0x10b0
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x16da
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 0x1700
movq %rax, %rbx
jmp 0x171b
jmp 0x1700
jmp 0x1700
jmp 0x1700
jmp 0x1700
jmp 0x1700
jmp 0x1700
jmp 0x1700
movq %rax, %rbx
movq -0x88(%rbp), %rdi
testq %rdi, %rdi
je 0x171b
movq -0x78(%rbp), %rsi
subq %rdi, %rsi
callq 0x10b0
movq -0x70(%rbp), %rdi
testq %rdi, %rdi
je 0x1730
movq -0x60(%rbp), %rsi
subq %rdi, %rsi
callq 0x10b0
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x1745
movq -0x30(%rbp), %rsi
subq %rdi, %rsi
callq 0x10b0
movq %rbx, %rdi
callq 0x1100
nop