// File: /workspace/github_cpp_makefile_star2_O3/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 $0x28, %rsp
xorps %xmm0, %xmm0
leaq -0x50(%rbp), %r14
movaps %xmm0, (%r14)
movq $0x0, 0x10(%r14)
movl $0x2c, %edi
callq 0x10b0
movq %rax, %rbx
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movups %xmm0, 0x10(%rax)
movups %xmm0, 0x1c(%rax)
movq 0x2d2e(%rip), %r15      # 0x3fe0
leaq -0x2c(%rbp), %r12
movl $0xcccccccd, %r13d      # imm = 0xCCCCCCCD
movq %r15, %rdi
movq %r12, %rsi
callq 0x1100
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x1311
movl -0x2c(%rbp), %eax
cmpl $0x64, %eax
ja 0x12fe
movq -0x48(%rbp), %rsi
cmpq -0x40(%rbp), %rsi
je 0x12f3
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, -0x48(%rbp)
jmp 0x12fe
movq %r14, %rdi
movq %r12, %rdx
callq 0x1632
movl -0x2c(%rbp), %eax
imulq %r13, %rax
shrq $0x21, %rax
andl $-0x4, %eax
incl (%rbx,%rax)
jmp 0x12bc
movq 0x2cb8(%rip), %rdi      # 0x3fd0
leaq 0xce5(%rip), %rsi       # 0x2004
movl $0xe, %edx
callq 0x10d0
movq -0x48(%rbp), %rsi
subq -0x50(%rbp), %rsi
sarq $0x2, %rsi
movq 0x2c94(%rip), %rdi      # 0x3fd0
callq 0x1060
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x10a0
movsbl %al, %esi
movq %r15, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1070
movq -0x50(%rbp), %r13
movq -0x48(%rbp), %r14
cmpq %r14, %r13
je 0x13ab
movq 0x2c51(%rip), %r15      # 0x3fd0
leaq 0xc8b(%rip), %r12       # 0x2011
movl (%r13), %esi
movq %r15, %rdi
callq 0x1060
movl $0x1, %edx
movq %rax, %rdi
movq %r12, %rsi
callq 0x10d0
addq $0x4, %r13
cmpq %r14, %r13
jne 0x1386
movq 0x2c1e(%rip), %rdi      # 0x3fd0
movq (%rdi), %rax
addq -0x18(%rax), %rdi
movl $0xa, %esi
callq 0x10a0
movsbl %al, %esi
movq 0x2c03(%rip), %rdi      # 0x3fd0
callq 0x1030
movq %rax, %rdi
callq 0x1070
movq 0x2bef(%rip), %rdi      # 0x3fd0
leaq 0xc2f(%rip), %rsi       # 0x2017
movl $0xe, %edx
callq 0x10d0
movq 0x2bd7(%rip), %rdi      # 0x3fd0
movl $0xb, %esi
callq 0x1060
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x10a0
movsbl %al, %esi
movq %r14, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1070
xorl %r12d, %r12d
movq 0x2b99(%rip), %r14      # 0x3fd0
leaq 0xbd3(%rip), %r15       # 0x2011
movl (%rbx,%r12), %esi
movq %r14, %rdi
callq 0x1060
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x10d0
addq $0x4, %r12
cmpq $0x2c, %r12
jne 0x143e
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x10a0
movsbl %al, %esi
movq 0x2b4e(%rip), %rdi      # 0x3fd0
callq 0x1030
movq %rax, %rdi
callq 0x1070
movl $0x2c, %edi
callq 0x10b0
movq %rax, %r14
xorps %xmm0, %xmm0
movups %xmm0, 0x1c(%rax)
movups %xmm0, 0x10(%rax)
movups %xmm0, (%rax)
movq -0x50(%rbp), %rax
movq -0x48(%rbp), %rcx
cmpq %rcx, %rax
je 0x14d6
movl $0xcccccccd, %edx       # imm = 0xCCCCCCCD
movl (%rax), %esi
imulq %rdx, %rsi
shrq $0x21, %rsi
andl $-0x4, %esi
incl (%r14,%rsi)
addq $0x4, %rax
cmpq %rcx, %rax
jne 0x14bc
movq 0x2af3(%rip), %rdi      # 0x3fd0
leaq 0xb2f(%rip), %rsi       # 0x2013
movl $0x12, %edx
callq 0x10d0
movq 0x2adb(%rip), %rdi      # 0x3fd0
movl $0xb, %esi
callq 0x1060
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x10a0
movsbl %al, %esi
movq %r15, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1070
xorl %r13d, %r13d
movq 0x2a9d(%rip), %r15      # 0x3fd0
leaq 0xad7(%rip), %r12       # 0x2011
movl (%r14,%r13), %esi
movq %r15, %rdi
callq 0x1060
movl $0x1, %edx
movq %rax, %rdi
movq %r12, %rsi
callq 0x10d0
addq $0x4, %r13
cmpq $0x2c, %r13
jne 0x153a
movq (%r15), %rax
addq -0x18(%rax), %r15
movq %r15, %rdi
movl $0xa, %esi
callq 0x10a0
movsbl %al, %esi
movq 0x2a52(%rip), %rdi      # 0x3fd0
callq 0x1030
movq %rax, %rdi
callq 0x1070
movl $0x2c, %esi
movq %r14, %rdi
callq 0x10c0
movl $0x2c, %esi
movq %rbx, %rdi
callq 0x10c0
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x15ba
movq -0x40(%rbp), %rsi
subq %rdi, %rsi
callq 0x10c0
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x15e7
jmp 0x15d5
jmp 0x15e7
jmp 0x15e7
jmp 0x15e7
movq %rax, %r15
movl $0x2c, %esi
movq %r14, %rdi
callq 0x10c0
jmp 0x15ea
movq %rax, %r15
movl $0x2c, %esi
movq %rbx, %rdi
callq 0x10c0
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x160c
movq -0x40(%rbp), %rsi
subq %rdi, %rsi
callq 0x10c0
movq %r15, %rdi
callq 0x1110