// File: 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
subq $0x2a0, %rsp            # imm = 0x2A0
movl $0x0, -0x4(%rbp)
movabsq $0x530000006d, %rax     # imm = 0x530000006D
movq %rax, -0x198(%rbp)
movq %rax, -0x10(%rbp)
movaps 0x2d12(%rip), %xmm0     # 0x4030
movaps %xmm0, -0x20(%rbp)
leaq -0x10(%rbp), %rax
movq %rax, -0x1a8(%rbp)
movl $0x53, -0x24(%rbp)
leaq -0x20(%rbp), %rdi
movq %rdi, -0x1c0(%rbp)
callq 0x1a60
movq -0x1c0(%rbp), %rdi
movq %rax, -0x1c8(%rbp)
callq 0x1a70
movq -0x1c8(%rbp), %rdi
movq %rax, %rsi
leaq -0x24(%rbp), %rdx
movq %rdx, -0x1a0(%rbp)
callq 0x1a10
movq %rax, -0x30(%rbp)
movq 0x5c5c(%rip), %rdi      # 0x6fd8
leaq 0x2cdd(%rip), %rsi      # 0x4060
callq 0x10f0
movq %rax, %rdi
movl -0x24(%rbp), %esi
callq 0x1180
movq -0x1c0(%rbp), %rdi
movq %rax, -0x1b8(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x1b0(%rbp)
callq 0x1a70
movq -0x1b8(%rbp), %rdi
movq %rax, %rcx
movq -0x1b0(%rbp), %rax
subq %rcx, %rax
leaq 0x2c9f(%rip), %rax      # 0x406b
leaq 0x2ca8(%rip), %rsi      # 0x407b
cmoveq %rax, %rsi
callq 0x10f0
movq %rax, %rdi
movq 0x5be2(%rip), %rsi      # 0x6fc8
callq 0x1120
movq -0x1a8(%rbp), %rsi
movq -0x1a0(%rbp), %rdx
leaq -0x1c(%rbp), %rdi
callq 0x1a10
movq %rax, %rcx
movq -0x198(%rbp), %rax
movq %rcx, -0x30(%rbp)
movq %rax, -0x60(%rbp)
movups 0x2c2d(%rip), %xmm0     # 0x4048
movaps %xmm0, -0x70(%rbp)
leaq -0x70(%rbp), %rax
movq %rax, -0x58(%rbp)
movq $0x6, -0x50(%rbp)
leaq -0x71(%rbp), %rdi
movq %rdi, -0x190(%rbp)
callq 0x1a90
movq -0x190(%rbp), %rcx
movq -0x58(%rbp), %rsi
movq -0x50(%rbp), %rdx
leaq -0x48(%rbp), %rdi
callq 0x1ab0
jmp 0x1459
leaq -0x71(%rbp), %rdi
callq 0x1b30
movl $0x2a, -0x24(%rbp)
leaq -0x48(%rbp), %rdi
movq %rdi, -0x1d8(%rbp)
callq 0x1ba0
movq -0x1d8(%rbp), %rdi
movq %rax, -0x98(%rbp)
callq 0x1bd0
movq %rax, -0xa0(%rbp)
movq -0x98(%rbp), %rdi
movq -0xa0(%rbp), %rsi
leaq -0x24(%rbp), %rdx
callq 0x1b50
movq %rax, -0x1d0(%rbp)
jmp 0x14b3
movq -0x1d0(%rbp), %rax
movq %rax, -0x90(%rbp)
movq 0x5b10(%rip), %rdi      # 0x6fd8
leaq 0x2b91(%rip), %rsi      # 0x4060
callq 0x10f0
movq %rax, -0x1e0(%rbp)
jmp 0x14dd
movq -0x1e0(%rbp), %rdi
movl -0x24(%rbp), %esi
callq 0x1180
movq %rax, -0x1e8(%rbp)
jmp 0x14f5
leaq -0x48(%rbp), %rdi
callq 0x1bd0
movq %rax, -0xa8(%rbp)
leaq -0x90(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x1c00
movq -0x1e8(%rbp), %rdi
movb %al, %cl
leaq 0x2b43(%rip), %rax      # 0x406b
leaq 0x2b4c(%rip), %rsi      # 0x407b
testb %cl, %cl
cmovneq %rax, %rsi
callq 0x10f0
movq %rax, -0x1f0(%rbp)
jmp 0x1543
movq -0x1f0(%rbp), %rdi
movq 0x5a77(%rip), %rsi      # 0x6fc8
callq 0x1120
jmp 0x1558
movb $0x1, -0x13c(%rbp)
leaq -0x130(%rbp), %rax
movq %rax, -0x200(%rbp)
movq %rax, -0x138(%rbp)
leaq -0x139(%rbp), %rdi
movq %rdi, -0x1f8(%rbp)
callq 0x11a0
movq -0x200(%rbp), %rdi
movq -0x1f8(%rbp), %rdx
leaq 0x2aeb(%rip), %rsi      # 0x4087
callq 0x1150
jmp 0x15a3
leaq -0x110(%rbp), %rax
movq %rax, -0x210(%rbp)
movq %rax, -0x138(%rbp)
leaq -0x13a(%rbp), %rdi
movq %rdi, -0x208(%rbp)
callq 0x11a0
movq -0x210(%rbp), %rdi
movq -0x208(%rbp), %rdx
leaq 0x2aac(%rip), %rsi      # 0x408c
callq 0x1150
jmp 0x15e7
leaq -0xf0(%rbp), %rax
movq %rax, -0x220(%rbp)
movq %rax, -0x138(%rbp)
leaq -0x13b(%rbp), %rdi
movq %rdi, -0x218(%rbp)
callq 0x11a0
movq -0x220(%rbp), %rdi
movq -0x218(%rbp), %rdx
leaq 0x2a6d(%rip), %rsi      # 0x4091
callq 0x1150
jmp 0x162b
movb $0x0, -0x13c(%rbp)
leaq -0x130(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq $0x3, -0xc8(%rbp)
leaq -0x13d(%rbp), %rdi
movq %rdi, -0x228(%rbp)
callq 0x1c40
movq -0x228(%rbp), %rcx
movq -0xd0(%rbp), %rsi
movq -0xc8(%rbp), %rdx
leaq -0xc0(%rbp), %rdi
callq 0x1c60
jmp 0x1681
leaq -0x13d(%rbp), %rdi
callq 0x1d10
leaq -0x130(%rbp), %rax
movq %rax, -0x238(%rbp)
addq $0x60, %rax
movq %rax, -0x230(%rbp)
movq -0x230(%rbp), %rdi
addq $-0x20, %rdi
movq %rdi, -0x240(%rbp)
callq 0x10a0
movq -0x238(%rbp), %rcx
movq -0x240(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x230(%rbp)
jne 0x16a6
leaq -0x13b(%rbp), %rdi
callq 0x1130
leaq -0x13a(%rbp), %rdi
callq 0x1130
leaq -0x139(%rbp), %rdi
callq 0x1130
leaq -0x161(%rbp), %rdi
movq %rdi, -0x248(%rbp)
callq 0x11a0
movq -0x248(%rbp), %rdx
leaq 0x297a(%rip), %rsi      # 0x4096
leaq -0x160(%rbp), %rdi
callq 0x1150
jmp 0x172a
leaq -0x161(%rbp), %rdi
callq 0x1130
leaq -0xc0(%rbp), %rdi
movq %rdi, -0x258(%rbp)
callq 0x1d80
movq -0x258(%rbp), %rdi
movq %rax, -0x178(%rbp)
callq 0x1db0
movq %rax, -0x180(%rbp)
movq -0x178(%rbp), %rdi
movq -0x180(%rbp), %rsi
leaq -0x160(%rbp), %rdx
callq 0x1d30
movq %rax, -0x250(%rbp)
jmp 0x1786
movq -0x250(%rbp), %rax
movq %rax, -0x170(%rbp)
movq 0x583d(%rip), %rdi      # 0x6fd8
leaq 0x28be(%rip), %rsi      # 0x4060
callq 0x10f0
movq %rax, -0x260(%rbp)
jmp 0x17b0
movq -0x260(%rbp), %rdi
leaq -0x160(%rbp), %rsi
callq 0x10e0
movq %rax, -0x268(%rbp)
jmp 0x17cc
leaq -0xc0(%rbp), %rdi
callq 0x1db0
movq %rax, -0x188(%rbp)
leaq -0x170(%rbp), %rdi
leaq -0x188(%rbp), %rsi
callq 0x1de0
movq -0x268(%rbp), %rdi
movb %al, %cl
leaq 0x2869(%rip), %rax      # 0x406b
leaq 0x2872(%rip), %rsi      # 0x407b
testb %cl, %cl
cmovneq %rax, %rsi
callq 0x10f0
movq %rax, -0x270(%rbp)
jmp 0x181d
movq -0x270(%rbp), %rdi
movq 0x579d(%rip), %rsi      # 0x6fc8
callq 0x1120
jmp 0x1832
movl $0x0, -0x4(%rbp)
leaq -0x160(%rbp), %rdi
callq 0x10a0
leaq -0xc0(%rbp), %rdi
callq 0x1e10
leaq -0x48(%rbp), %rdi
callq 0x1e30
movl -0x4(%rbp), %eax
addq $0x2a0, %rsp            # imm = 0x2A0
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0x71(%rbp), %rdi
callq 0x1b30
jmp 0x1a02
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x19f9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x194f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x1943
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x1937
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0x13d(%rbp), %rdi
callq 0x1d10
leaq -0x130(%rbp), %rax
movq %rax, -0x280(%rbp)
addq $0x60, %rax
movq %rax, -0x278(%rbp)
movq -0x278(%rbp), %rdi
addq $-0x20, %rdi
movq %rdi, -0x288(%rbp)
callq 0x10a0
movq -0x280(%rbp), %rcx
movq -0x288(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x278(%rbp)
jne 0x1904
jmp 0x1937
leaq -0x13b(%rbp), %rdi
callq 0x1130
leaq -0x13a(%rbp), %rdi
callq 0x1130
leaq -0x139(%rbp), %rdi
callq 0x1130
testb $0x1, -0x13c(%rbp)
jne 0x1966
jmp 0x19b3
movq -0x138(%rbp), %rax
leaq -0x130(%rbp), %rcx
cmpq %rax, %rcx
movq %rax, -0x290(%rbp)
je 0x19b1
movq -0x290(%rbp), %rdi
addq $-0x20, %rdi
movq %rdi, -0x298(%rbp)
callq 0x10a0
movq -0x298(%rbp), %rax
leaq -0x130(%rbp), %rcx
cmpq %rcx, %rax
movq %rax, -0x290(%rbp)
jne 0x1980
jmp 0x19b3
jmp 0x19f9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0x161(%rbp), %rdi
callq 0x1130
jmp 0x19ed
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0x160(%rbp), %rdi
callq 0x10a0
leaq -0xc0(%rbp), %rdi
callq 0x1e10
leaq -0x48(%rbp), %rdi
callq 0x1e30
movq -0x80(%rbp), %rdi
callq 0x1190
nopl (%rax,%rax)