// File: /workspace/github_cpp_makefile_star2_O2/iZhangHui[P]CppPrimer/CH03_StringsVectorsAndArrays/examples/vecScores.cc
// Function: main
int main()
{
	// hold the grades we read from the standard input
	vector<unsigned> grades;

	// count the number of grades by clusters of ten: 
	// 0--9, 10--19, . ..  90--99, 100
	vector<unsigned> scores(11, 0); // 11 buckets, all initially 0
	unsigned grade;
	while (cin >> grade) {      // read the grades
		if (grade <= 100)       // handle only valid grades
			grades.push_back(grade);
			++scores[grade/10]; // increment the counter for the current cluster
	}
	cout << "grades.size = " << grades.size() << endl;
	for (auto it : grades)
		cout << it << " " ;
	cout << endl;

	cout << "scores.size = " << scores.size() << endl;
	for (auto it : scores)
		cout << it << " " ;
	cout << endl;

	// equivalent program using iterators instead of subscripts
	vector<unsigned> alt_scores(11, 0);  // 11 buckets, all initially 0
	// for each grade in the input
	for (auto it = grades.begin(); it != grades.end(); ++it) {
		unsigned i = *it;
		// increment the counter for the current cluster
		++(*(alt_scores.begin() + i/10));
	}

	cout << "alt_scores.size = " << alt_scores.size() << endl;
	for (auto it = alt_scores.begin(); it != alt_scores.end(); ++it) 
		cout << *it << " " ;
	cout << endl;

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
xorps %xmm0, %xmm0
movaps %xmm0, -0x50(%rbp)
andq $0x0, -0x40(%rbp)
leaq -0x68(%rbp), %rdx
andl $0x0, (%rdx)
leaq -0x80(%rbp), %rdi
pushq $0xb
popq %rsi
leaq -0x2c(%rbp), %rcx
callq 0x14d4
movq 0x2d49(%rip), %rbx      # 0x3fe0
leaq -0x2c(%rbp), %r14
leaq -0x50(%rbp), %r15
pushq $0xa
popq %r12
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1100
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x12e0
movl -0x2c(%rbp), %eax
cmpl $0x64, %eax
ja 0x12d2
movq %r15, %rdi
movq %r14, %rsi
callq 0x1534
movl -0x2c(%rbp), %eax
xorl %edx, %edx
divl %r12d
movq -0x80(%rbp), %rcx
incl (%rcx,%rax,4)
jmp 0x12a3
movq 0x2ce9(%rip), %rdi      # 0x3fd0
leaq 0xd16(%rip), %rsi       # 0x2004
callq 0x10b0
movq -0x48(%rbp), %rsi
subq -0x50(%rbp), %rsi
sarq $0x2, %rsi
movq %rax, %rdi
callq 0x1080
movq %rax, %rdi
callq 0x1060
movq -0x50(%rbp), %r15
movq -0x48(%rbp), %r13
movq 0x2cb2(%rip), %rbx      # 0x3fd0
leaq 0xcec(%rip), %r14       # 0x2011
cmpq %r13, %r15
je 0x1346
movl (%r15), %esi
movq %rbx, %rdi
callq 0x1080
movq %rax, %rdi
movq %r14, %rsi
callq 0x10b0
addq $0x4, %r15
jmp 0x1325
movq 0x2c83(%rip), %rdi      # 0x3fd0
callq 0x1060
movq 0x2c77(%rip), %rdi      # 0x3fd0
leaq 0xcb7(%rip), %rsi       # 0x2017
callq 0x10b0
movq -0x78(%rbp), %rsi
subq -0x80(%rbp), %rsi
sarq $0x2, %rsi
movq %rax, %rdi
callq 0x1080
movq %rax, %rdi
callq 0x1060
movq -0x80(%rbp), %r15
movq -0x78(%rbp), %r13
movq 0x2c40(%rip), %rbx      # 0x3fd0
leaq 0xc7a(%rip), %r14       # 0x2011
cmpq %r13, %r15
je 0x13b8
movl (%r15), %esi
movq %rbx, %rdi
callq 0x1080
movq %rax, %rdi
movq %r14, %rsi
callq 0x10b0
addq $0x4, %r15
jmp 0x1397
movq 0x2c11(%rip), %rdi      # 0x3fd0
callq 0x1060
leaq -0x84(%rbp), %rdx
andl $0x0, (%rdx)
leaq -0x68(%rbp), %rdi
pushq $0xb
popq %rsi
leaq -0x2d(%rbp), %rcx
callq 0x14d4
movq -0x50(%rbp), %rcx
movq -0x48(%rbp), %rsi
movq -0x68(%rbp), %rdi
cmpq %rsi, %rcx
je 0x13ff
movl (%rcx), %eax
xorl %edx, %edx
divl %r12d
incl (%rdi,%rax,4)
addq $0x4, %rcx
jmp 0x13ea
movq 0x2bca(%rip), %rdi      # 0x3fd0
leaq 0xc06(%rip), %rsi       # 0x2013
callq 0x10b0
movq -0x60(%rbp), %rsi
subq -0x68(%rbp), %rsi
sarq $0x2, %rsi
movq %rax, %rdi
callq 0x1080
movq %rax, %rdi
callq 0x1060
movq -0x68(%rbp), %r15
movq 0x2b97(%rip), %rbx      # 0x3fd0
leaq 0xbd1(%rip), %r14       # 0x2011
cmpq -0x60(%rbp), %r15
je 0x1462
movl (%r15), %esi
movq %rbx, %rdi
callq 0x1080
movq %rax, %rdi
movq %r14, %rsi
callq 0x10b0
addq $0x4, %r15
jmp 0x1440
movq 0x2b67(%rip), %rdi      # 0x3fd0
callq 0x1060
leaq -0x68(%rbp), %rdi
callq 0x1568
leaq -0x80(%rbp), %rdi
callq 0x1568
leaq -0x50(%rbp), %rdi
callq 0x1568
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x14b7
movq %rax, %rbx
jmp 0x14c3
jmp 0x14a7
jmp 0x14b7
jmp 0x14b7
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
callq 0x1568
jmp 0x14ba
jmp 0x14b7
movq %rax, %rbx
leaq -0x80(%rbp), %rdi
callq 0x1568
leaq -0x50(%rbp), %rdi
callq 0x1568
movq %rbx, %rdi
callq 0x1110