// File: /workspace/github_cpp_makefile_star2_O3/iZhangHui[P]CppPrimer/CH03_StringsVectorsAndArrays/examples/vecSubs.cc
// Function: main
int main()
{
	vector<int> v = {0,1,2,3,4,5,6,7,8,9};
	auto sz = v.size(); 
	decltype(sz) i = 0;
	// duplicate contents of v onto the back of v
	while (i != sz) {
		v.push_back(*v.begin() + i);
		++i;
	}
	// prints 0...9 0...9
	for (auto it : v)
		cout << it << " ";
	cout << endl;
	
	// alternative way to stop when we get to the original last element
	vector<int> alt_v = {0,1,2,3,4,5,6,7,8,9}; // vector with values 0...9
	for (decltype(alt_v.size()) i = 0, sz = alt_v.size(); i != sz; ++i)
		alt_v.push_back(alt_v[i]);

	// prints 0...9 0...9
	for (auto it : alt_v)
		cout << it << " ";
	cout << endl;

	vector<int> v2 = {0,1,2,3,4,5,6,7,8,9}; // vector with values 0 ... 9
	decltype(v2.size()) ix = 0;   // we'll use ix to index the vector

	// set the elements with values less than 5 to 0
	while (ix != v2.size() && v2[ix] < 5) {
		v2[ix] = 0; // changes the value of the element in v
		++ix;       // increment the index so the next iteration fetches the next element
	}

	// print the elements using subscripts
	for (unsigned i = 0; i != v2.size(); ++i)
		cout << v2[i] << " ";
	cout << endl;

	// equivalent but using iterators
	vector<int> alt_v2 = {0,1,2,3,4,5,6,7,8,9}; // vector with values 0...9
	// set the elements to 0 up to the first one that is 5 or greater
	auto it = alt_v2.begin();
	while (it != alt_v2.end() && *it < 5) {
		*it = 0;   // changes the value of the element in alt_v2
		++it;      // advance the iterator to denote the next element
	}
	for (auto it = alt_v2.begin(); // it denotes first element in alt_v2
	          it != alt_v2.end();  // so long as it denotes an element
	          ++it)          // increment the iterator to next element
		cout << *it << " ";  // print element denoted by it from alt_v2
	cout << endl;

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movups 0xded(%rip), %xmm0      # 0x2064
leaq -0xc0(%rbp), %rsi
movaps %xmm0, 0x10(%rsi)
movups 0xdcb(%rip), %xmm0      # 0x2054
movaps %xmm0, (%rsi)
movabsq $0x900000008, %rax      # imm = 0x900000008
movq %rax, 0x20(%rsi)
leaq -0x60(%rbp), %rbx
leaq -0x48(%rbp), %rcx
movl $0xa, %edx
movq %rbx, %rdi
callq 0x1710
movq (%rbx), %r15
movq 0x8(%rbx), %r13
movq %r13, %r12
subq %r15, %r12
je 0x130c
sarq $0x2, %r12
xorl %r15d, %r15d
leaq -0xc0(%rbp), %r14
movq -0x60(%rbp), %rax
movq -0x58(%rbp), %rsi
movl (%rax), %eax
addq %r15, %rax
movl %eax, -0xc0(%rbp)
cmpq -0x50(%rbp), %rsi
je 0x12f1
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, -0x58(%rbp)
jmp 0x12fc
movq %rbx, %rdi
movq %r14, %rdx
callq 0x17f2
incq %r15
cmpq %r15, %r12
jne 0x12cc
movq -0x60(%rbp), %r15
movq -0x58(%rbp), %r13
cmpq %r13, %r15
je 0x1343
movq 0x2cc0(%rip), %rbx      # 0x3fd8
leaq 0xce5(%rip), %r14       # 0x2004
movl (%r15), %esi
movq %rbx, %rdi
callq 0x10f0
movl $0x1, %edx
movq %rax, %rdi
movq %r14, %rsi
callq 0x10c0
addq $0x4, %r15
cmpq %r13, %r15
jne 0x131f
movq 0x2c8e(%rip), %rdi      # 0x3fd8
movq (%rdi), %rax
addq -0x18(%rax), %rdi
movl $0xa, %esi
callq 0x1090
movsbl %al, %esi
movq 0x2c73(%rip), %rbx      # 0x3fd8
movq %rbx, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1060
leaq -0xc0(%rbp), %rsi
movups 0xce1(%rip), %xmm0      # 0x2064
movaps %xmm0, 0x10(%rsi)
movups 0xcc6(%rip), %xmm0      # 0x2054
movaps %xmm0, (%rsi)
movabsq $0x900000008, %rax      # imm = 0x900000008
movq %rax, 0x20(%rsi)
leaq -0x48(%rbp), %rdi
leaq -0x78(%rbp), %rcx
movl $0xa, %edx
callq 0x1710
movq -0x48(%rbp), %r13
movq -0x40(%rbp), %r12
movq %r12, %r15
subq %r13, %r15
je 0x1404
sarq $0x2, %r15
xorl %r12d, %r12d
leaq -0x48(%rbp), %r14
movq -0x48(%rbp), %rdx
addq %r12, %rdx
movq -0x40(%rbp), %rsi
cmpq -0x38(%rbp), %rsi
je 0x13eb
movl (%rdx), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, -0x40(%rbp)
jmp 0x13f3
movq %r14, %rdi
callq 0x1914
addq $0x4, %r12
decq %r15
jne 0x13cc
movq -0x48(%rbp), %r13
movq -0x40(%rbp), %r12
cmpq %r12, %r13
je 0x143c
movq 0x2bc8(%rip), %r14      # 0x3fd8
leaq 0xbed(%rip), %r15       # 0x2004
movl (%r13), %esi
movq %r14, %rdi
callq 0x10f0
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x10c0
addq $0x4, %r13
cmpq %r12, %r13
jne 0x1417
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x1090
movsbl %al, %esi
movq 0x2b7e(%rip), %rbx      # 0x3fd8
movq %rbx, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1060
leaq -0xc0(%rbp), %rsi
movups 0xbec(%rip), %xmm0      # 0x2064
movaps %xmm0, 0x10(%rsi)
movups 0xbd1(%rip), %xmm0      # 0x2054
movaps %xmm0, (%rsi)
movabsq $0x900000008, %rax      # imm = 0x900000008
movq %rax, 0x20(%rsi)
leaq -0x78(%rbp), %rdi
leaq -0x90(%rbp), %rcx
movl $0xa, %edx
callq 0x1710
movq -0x78(%rbp), %rax
movq -0x70(%rbp), %rcx
movq %rcx, %rdx
subq %rax, %rdx
je 0x1524
sarq $0x2, %rdx
xorl %esi, %esi
cmpl $0x4, (%rax,%rsi,4)
jg 0x14d4
movl $0x0, (%rax,%rsi,4)
incq %rsi
cmpq %rsi, %rdx
jne 0x14bf
cmpq %rax, %rcx
je 0x1524
movl $0x1, %r13d
xorl %ecx, %ecx
movq 0x2af0(%rip), %r14      # 0x3fd8
leaq 0xb15(%rip), %r15       # 0x2004
movl (%rax,%rcx,4), %esi
movq %r14, %rdi
callq 0x10f0
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x10c0
movl %r13d, %ecx
movq -0x78(%rbp), %rax
movq -0x70(%rbp), %rdx
subq %rax, %rdx
sarq $0x2, %rdx
incl %r13d
cmpq %rcx, %rdx
jne 0x14ef
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x1090
movsbl %al, %esi
movq 0x2a96(%rip), %rbx      # 0x3fd8
movq %rbx, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1060
leaq -0xc0(%rbp), %rsi
movups 0xb04(%rip), %xmm0      # 0x2064
movaps %xmm0, 0x10(%rsi)
movups 0xae9(%rip), %xmm0      # 0x2054
movaps %xmm0, (%rsi)
movabsq $0x900000008, %rax      # imm = 0x900000008
movq %rax, 0x20(%rsi)
leaq -0x90(%rbp), %rdi
leaq -0x29(%rbp), %rcx
movl $0xa, %edx
callq 0x1710
movq -0x90(%rbp), %r12
movq -0x88(%rbp), %rax
cmpq %rax, %r12
je 0x15f7
movq %r12, %rcx
cmpl $0x4, (%rcx)
jg 0x15bb
movl $0x0, (%rcx)
addq $0x4, %rcx
cmpq %rax, %rcx
jne 0x15a7
cmpq %rax, %r12
je 0x15f7
movq 0x2a11(%rip), %r14      # 0x3fd8
leaq 0xa36(%rip), %r15       # 0x2004
movl (%r12), %esi
movq %r14, %rdi
callq 0x10f0
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x10c0
addq $0x4, %r12
cmpq -0x88(%rbp), %r12
jne 0x15ce
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x1090
movsbl %al, %esi
movq 0x29c3(%rip), %rdi      # 0x3fd8
callq 0x1030
movq %rax, %rdi
callq 0x1060
movq -0x90(%rbp), %rdi
testq %rdi, %rdi
je 0x163a
movq -0x80(%rbp), %rsi
subq %rdi, %rsi
callq 0x10b0
movq -0x78(%rbp), %rdi
testq %rdi, %rdi
je 0x164f
movq -0x68(%rbp), %rsi
subq %rdi, %rsi
callq 0x10b0
movq -0x48(%rbp), %rdi
testq %rdi, %rdi
je 0x1664
movq -0x38(%rbp), %rsi
subq %rdi, %rsi
callq 0x10b0
movq -0x60(%rbp), %rdi
testq %rdi, %rdi
je 0x1679
movq -0x50(%rbp), %rsi
subq %rdi, %rsi
callq 0x10b0
xorl %eax, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x16bc
jmp 0x16d6
jmp 0x16f0
jmp 0x169f
jmp 0x16bc
jmp 0x16d6
jmp 0x16f0
jmp 0x16d6
jmp 0x16f0
movq %rax, %rbx
movq -0x90(%rbp), %rdi
testq %rdi, %rdi
je 0x16bf
movq -0x80(%rbp), %rsi
subq %rdi, %rsi
callq 0x10b0
jmp 0x16bf
movq %rax, %rbx
movq -0x78(%rbp), %rdi
testq %rdi, %rdi
je 0x16d9
movq -0x68(%rbp), %rsi
subq %rdi, %rsi
callq 0x10b0
jmp 0x16d9
movq %rax, %rbx
movq -0x48(%rbp), %rdi
testq %rdi, %rdi
je 0x16f3
movq -0x38(%rbp), %rsi
subq %rdi, %rsi
callq 0x10b0
jmp 0x16f3
movq %rax, %rbx
movq -0x60(%rbp), %rdi
testq %rdi, %rdi
je 0x1708
movq -0x50(%rbp), %rsi
subq %rdi, %rsi
callq 0x10b0
movq %rbx, %rdi
callq 0x1100