// File: /workspace/github_cpp_makefile_star2_O1/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, %r12      # imm = 0x900000008
movq %r12, 0x20(%rsi)
leaq -0x78(%rbp), %rbx
leaq -0x48(%rbp), %rcx
movl $0xa, %edx
movq %rbx, %rdi
callq 0x16fc
movq 0x8(%rbx), %r15
movq (%rbx), %rax
subq %rax, %r15
je 0x1301
sarq $0x2, %r15
xorl %r13d, %r13d
leaq -0xc0(%rbp), %r14
movq -0x78(%rbp), %rax
movq -0x70(%rbp), %rsi
movl (%rax), %eax
addq %r13, %rax
movl %eax, -0xc0(%rbp)
cmpq -0x68(%rbp), %rsi
je 0x12ee
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, -0x70(%rbp)
jmp 0x12f9
movq %rbx, %rdi
movq %r14, %rdx
callq 0x17ec
incq %r13
cmpq %r13, %r15
jne 0x12c9
movq -0x78(%rbp), %r15
movq -0x70(%rbp), %r13
cmpq %r13, %r15
je 0x1340
movq 0x2cc3(%rip), %rbx      # 0x3fd8
leaq 0xce8(%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 0x131c
movq 0x2c91(%rip), %rdi      # 0x3fd8
movq (%rdi), %rax
addq -0x18(%rax), %rdi
movl $0xa, %esi
callq 0x1090
movsbl %al, %esi
movq 0x2c76(%rip), %rbx      # 0x3fd8
movq %rbx, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1060
leaq -0xc0(%rbp), %rsi
movups 0xce4(%rip), %xmm0      # 0x2064
movaps %xmm0, 0x10(%rsi)
movups 0xcc9(%rip), %xmm0      # 0x2054
movaps %xmm0, (%rsi)
movq %r12, 0x20(%rsi)
leaq -0x48(%rbp), %rdi
leaq -0x60(%rbp), %rcx
movl $0xa, %edx
callq 0x16fc
movq -0x40(%rbp), %r15
movq -0x48(%rbp), %rax
subq %rax, %r15
je 0x13ec
sarq $0x2, %r15
xorl %r13d, %r13d
leaq -0x48(%rbp), %r14
movq -0x48(%rbp), %rdx
addq %r13, %rdx
movq -0x40(%rbp), %rsi
cmpq -0x38(%rbp), %rsi
je 0x13db
movl (%rdx), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, -0x40(%rbp)
jmp 0x13e3
movq %r14, %rdi
callq 0x190e
addq $0x4, %r13
decq %r15
jne 0x13bc
movq -0x48(%rbp), %r13
movq -0x40(%rbp), %r12
cmpq %r12, %r13
je 0x142c
movq 0x2bd8(%rip), %r14      # 0x3fd8
leaq 0xbfd(%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 0x1407
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x1090
movsbl %al, %esi
movq 0x2b8e(%rip), %rbx      # 0x3fd8
movq %rbx, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1060
leaq -0xc0(%rbp), %rsi
movups 0xbfc(%rip), %xmm0      # 0x2064
movaps %xmm0, 0x10(%rsi)
movups 0xbe1(%rip), %xmm0      # 0x2054
movaps %xmm0, (%rsi)
movabsq $0x900000008, %r12      # imm = 0x900000008
movq %r12, 0x20(%rsi)
leaq -0x60(%rbp), %rdi
leaq -0x90(%rbp), %rcx
movl $0xa, %edx
callq 0x16fc
movq -0x60(%rbp), %rax
movq -0x58(%rbp), %rcx
subq %rax, %rcx
je 0x14c1
sarq $0x2, %rcx
xorl %edx, %edx
cmpl $0x4, (%rax,%rdx,4)
jg 0x14c1
movl $0x0, (%rax,%rdx,4)
incq %rdx
cmpq %rdx, %rcx
jne 0x14ac
movq -0x60(%rbp), %rax
cmpq %rax, -0x58(%rbp)
je 0x1516
movl $0x1, %r13d
xorl %ecx, %ecx
movq 0x2afe(%rip), %r14      # 0x3fd8
leaq 0xb23(%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 -0x60(%rbp), %rax
movq -0x58(%rbp), %rdx
subq %rax, %rdx
sarq $0x2, %rdx
incl %r13d
cmpq %rcx, %rdx
jne 0x14e1
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x1090
movsbl %al, %esi
movq 0x2aa4(%rip), %rbx      # 0x3fd8
movq %rbx, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1060
leaq -0xc0(%rbp), %rsi
movups 0xb12(%rip), %xmm0      # 0x2064
movaps %xmm0, 0x10(%rsi)
movups 0xaf7(%rip), %xmm0      # 0x2054
movaps %xmm0, (%rsi)
movq %r12, 0x20(%rsi)
leaq -0x90(%rbp), %rdi
leaq -0x29(%rbp), %rcx
movl $0xa, %edx
callq 0x16fc
movq -0x90(%rbp), %r12
movq -0x88(%rbp), %rax
cmpq %rax, %r12
je 0x15a3
movq %r12, %rcx
cmpl $0x4, (%rcx)
jg 0x15a3
movl $0x0, (%rcx)
addq $0x4, %rcx
cmpq %rax, %rcx
jne 0x158f
cmpq -0x88(%rbp), %r12
je 0x15e3
movq 0x2a25(%rip), %r14      # 0x3fd8
leaq 0xa4a(%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 0x15ba
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x1090
movsbl %al, %esi
movq 0x29d7(%rip), %rdi      # 0x3fd8
callq 0x1030
movq %rax, %rdi
callq 0x1060
movq -0x90(%rbp), %rdi
testq %rdi, %rdi
je 0x1626
movq -0x80(%rbp), %rsi
subq %rdi, %rsi
callq 0x10b0
movq -0x60(%rbp), %rdi
testq %rdi, %rdi
je 0x163b
movq -0x50(%rbp), %rsi
subq %rdi, %rsi
callq 0x10b0
movq -0x48(%rbp), %rdi
testq %rdi, %rdi
je 0x1650
movq -0x38(%rbp), %rsi
subq %rdi, %rsi
callq 0x10b0
movq -0x78(%rbp), %rdi
testq %rdi, %rdi
je 0x1665
movq -0x68(%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 0x16a8
jmp 0x16c2
jmp 0x16dc
jmp 0x168b
jmp 0x16a8
jmp 0x16c2
jmp 0x16dc
jmp 0x16c2
jmp 0x16dc
movq %rax, %rbx
movq -0x90(%rbp), %rdi
testq %rdi, %rdi
je 0x16ab
movq -0x80(%rbp), %rsi
subq %rdi, %rsi
callq 0x10b0
jmp 0x16ab
movq %rax, %rbx
movq -0x60(%rbp), %rdi
testq %rdi, %rdi
je 0x16c5
movq -0x50(%rbp), %rsi
subq %rdi, %rsi
callq 0x10b0
jmp 0x16c5
movq %rax, %rbx
movq -0x48(%rbp), %rdi
testq %rdi, %rdi
je 0x16df
movq -0x38(%rbp), %rsi
subq %rdi, %rsi
callq 0x10b0
jmp 0x16df
movq %rax, %rbx
movq -0x78(%rbp), %rdi
testq %rdi, %rdi
je 0x16f4
movq -0x68(%rbp), %rsi
subq %rdi, %rsi
callq 0x10b0
movq %rbx, %rdi
callq 0x1100