// File: /workspace/github_cpp_makefile_star2_O2/iZhangHui[P]CppPrimer/CH10_GenericAlgorithms/examples/use_find.cc
// Function: main
int main()
{
	int ia[] = {27, 210, 12, 47, 109, 83};
	int val = 83;
	int* result = find(begin(ia), end(ia), val);
	cout << "The value " << val
	     << (result == end(ia)
	           ? " is not present" : " is present") << endl;
	
	// search starting from ia[1] up to but not including ia[4]
	result = find(ia + 1, ia + 4, val);
	
	// initialize the vector with some values
	vector<int> vec = {27, 210, 12, 47, 109, 83};
	val = 42; // value we'll look for

	// result2 will denote the element we want if it's in vec, 
	// or vec.cend() if not
	auto result2 = find(vec.cbegin(), vec.cend(), val);

	// report the result
	cout << "The value " << val
	     << (result2 == vec.cend()
	           ? " is not present" : " is present") << endl;
	
	// now use find to look in a list of strings
	list<string> lst = {"val1", "val2", "val3"};

	string sval = "a value";  // value we'll look for
	// this call to find looks through string elements in a list
	auto result3 = find(lst.cbegin(), lst.cend(), sval);
	cout << "The value " << sval
	     << (result3 == lst.cend()
	           ? " is not present" : " is present") << endl;

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movaps 0xdb9(%rip), %xmm0      # 0x2080
leaq -0x50(%rbp), %r15
movaps %xmm0, -0x10(%r15)
movabsq $0x530000006d, %r13     # imm = 0x530000006D
movq %r13, (%r15)
leaq -0x30(%rbp), %r14
movl $0x53, (%r14)
leaq -0x48(%rbp), %rbx
leaq -0x60(%rbp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x161f
movq %rax, %r12
movq 0x2cd3(%rip), %rdi      # 0x3fd8
leaq 0xcf8(%rip), %rsi       # 0x2004
callq 0x10f0
movl (%r14), %esi
movq %rax, %rdi
callq 0x1150
cmpq %rbx, %r12
leaq 0xce9(%rip), %r12       # 0x200f
leaq 0xcf2(%rip), %rbx       # 0x201f
movq %rbx, %rsi
cmoveq %r12, %rsi
movq %rax, %rdi
callq 0x10f0
movq %rax, %rdi
callq 0x10a0
leaq -0x5c(%rbp), %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x161f
leaq -0xe0(%rbp), %rsi
movaps 0xd1f(%rip), %xmm0      # 0x2080
movaps %xmm0, (%rsi)
movq %r13, 0x10(%rsi)
leaq -0x78(%rbp), %r15
pushq $0x6
popq %rdx
leaq -0x48(%rbp), %rcx
movq %r15, %rdi
callq 0x1562
movl $0x2a, (%r14)
movq (%r15), %rdi
movq 0x8(%r15), %rsi
movq %r14, %rdx
callq 0x17ab
movq %rax, %r14
movq 0x2c3d(%rip), %rdi      # 0x3fd8
leaq 0xc62(%rip), %rsi       # 0x2004
callq 0x10f0
movl -0x30(%rbp), %esi
movq %rax, %rdi
callq 0x1150
cmpq -0x70(%rbp), %r14
movq %rbx, %rsi
cmoveq %r12, %rsi
movq %rax, %rdi
callq 0x10f0
movq %rax, %rdi
callq 0x10a0
leaq 0xc57(%rip), %rsi       # 0x202b
leaq -0xe0(%rbp), %r14
leaq -0x29(%rbp), %rdx
movq %r14, %rdi
callq 0x1060
leaq -0xc0(%rbp), %r15
leaq 0xc3b(%rip), %rsi       # 0x2030
leaq -0x2c(%rbp), %rdx
movq %r15, %rdi
callq 0x1060
leaq -0xa0(%rbp), %r15
leaq 0xc26(%rip), %rsi       # 0x2035
leaq -0x2b(%rbp), %rdx
movq %r15, %rdi
callq 0x1060
leaq -0x48(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
pushq $0x3
popq %rdx
leaq -0x2a(%rbp), %rcx
callq 0x1598
pushq $0x40
popq %r14
leaq (%r14,%rbp), %rdi
addq $-0xe0, %rdi
callq 0x1090
addq $-0x20, %r14
cmpq $-0x20, %r14
jne 0x1436
leaq 0xbe3(%rip), %rsi       # 0x203a
leaq -0xe0(%rbp), %rdi
leaq -0x29(%rbp), %rdx
callq 0x1060
leaq -0x48(%rbp), %r14
movq (%r14), %rdi
leaq -0xe0(%rbp), %rdx
movq %r14, %rsi
callq 0x197c
movq %rax, %r15
movq 0x2b51(%rip), %rdi      # 0x3fd8
leaq 0xb76(%rip), %rsi       # 0x2004
callq 0x10f0
leaq -0xe0(%rbp), %rsi
movq %rax, %rdi
callq 0x10e0
cmpq %r14, %r15
cmoveq %r12, %rbx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x10f0
movq %rax, %rdi
callq 0x10a0
leaq -0xe0(%rbp), %rdi
callq 0x1090
leaq -0x48(%rbp), %rdi
callq 0x15d2
leaq -0x78(%rbp), %rdi
callq 0x1706
xorl %eax, %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x1543
movq %rax, %rbx
pushq $0x40
popq %r14
leaq (%r14,%rbp), %rdi
addq $-0xe0, %rdi
callq 0x1090
addq $-0x20, %r14
cmpq $-0x20, %r14
jne 0x14fa
jmp 0x1551
jmp 0x1518
movq %rax, %rbx
addq $-0x20, %r15
movq %r15, %rdi
callq 0x1090
cmpq %r14, %r15
jne 0x151b
jmp 0x1551
jmp 0x154e
jmp 0x1534
jmp 0x154e
movq %rax, %rbx
leaq -0xe0(%rbp), %rdi
callq 0x1090
leaq -0x48(%rbp), %rdi
callq 0x15d2
jmp 0x1551
movq %rax, %rbx
leaq -0x78(%rbp), %rdi
callq 0x1706
movq %rbx, %rdi
callq 0x1160