// File: /workspace/github_cpp_makefile_star2_O1/iZhangHui[P]CppPrimer/CH17_SpecializedLibraryFacilities/examples/rand2.cc
// Function: main
int main()
{
	vector<int> vals(32);     // preallocate so each element is 0 
	default_random_engine e;  // generates numbers
	uniform_int_distribution<unsigned> u(0,31); // inclusive range 
	for (size_t i = 0; i != 100; ++i)
		++vals[u(e)];         // count how often each number appears
	int m = *max_element(vals.begin(), vals.end());
	for (int i = m; i != 0; --i) {
		for (size_t j = 0; j != vals.size(); ++j)
			if (vals[j] > i-1) cout << "* ";
			else               cout << "  ";
		cout << endl;
	}

	vector<int> vals2(32);     // preallocate so each element 0 value
	default_random_engine e2;  // restart the sequence
	normal_distribution<> n(15,5); // mean 15, standard deviation 5
	for (size_t i = 0; i != 100; ++i) {
		size_t v = lround(n(e));
		if (v < vals.size())
			++vals[v];         // count how often each number appears
		else
			cout << "discarding: " << v << " ";
	}
	cout << endl;

	cout << std::accumulate(vals.begin(), vals.end(), 0) << endl;
	m = *max_element(vals.begin(), vals.end());
	for (int i = m; i != 0; --i) {
		for (size_t j = 0; j != vals.size(); ++j)
			if (vals[j] > i-1) cout << "* ";
			else               cout << "  ";
		cout << endl;
	}

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl $0x80, %edi
callq 0x10d0
movq %rax, %rbx
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movups %xmm0, 0x10(%rax)
movups %xmm0, 0x20(%rax)
movups %xmm0, 0x30(%rax)
movups %xmm0, 0x40(%rax)
movups %xmm0, 0x50(%rax)
movups %xmm0, 0x60(%rax)
movups %xmm0, 0x70(%rax)
leaq -0x38(%rbp), %r14
movq $0x1, (%r14)
movabsq $0x1f00000000, %rax     # imm = 0x1F00000000
leaq -0x40(%rbp), %r15
movq %rax, (%r15)
movl $0x64, %r12d
movq %r15, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x1592
movl %eax, %eax
incl (%rbx,%rax,4)
decq %r12
jne 0x12ce
movl $0x4, %eax
movq %rbx, %rcx
movl (%rcx), %edx
cmpl (%rbx,%rax), %edx
jge 0x12f9
leaq (%rbx,%rax), %rcx
addq $0x4, %rax
cmpq $0x80, %rax
jne 0x12ee
movl (%rcx), %r15d
testl %r15d, %r15d
je 0x1370
leaq 0xd4f(%rip), %r12       # 0x2063
movq 0x2cbd(%rip), %r14      # 0x3fd8
xorl %r13d, %r13d
movq %r12, %rsi
cmpl %r15d, (%rbx,%r13,4)
jl 0x132e
leaq 0xd32(%rip), %rsi       # 0x2060
movl $0x2, %edx
movq %r14, %rdi
callq 0x10f0
incq %r13
cmpq $0x20, %r13
jne 0x131e
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x10c0
movsbl %al, %esi
movq %r14, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1070
decl %r15d
jne 0x131b
movl $0x80, %edi
callq 0x10d0
xorps %xmm0, %xmm0
movups %xmm0, 0x70(%rax)
movups %xmm0, 0x60(%rax)
movups %xmm0, 0x50(%rax)
movups %xmm0, 0x40(%rax)
movups %xmm0, 0x30(%rax)
movups %xmm0, 0x20(%rax)
movups %xmm0, 0x10(%rax)
movq %rax, -0x30(%rbp)
movups %xmm0, (%rax)
movabsq $0x402e000000000000, %rax # imm = 0x402E000000000000
leaq -0x60(%rbp), %r15
movq %rax, (%r15)
movabsq $0x4014000000000000, %rax # imm = 0x4014000000000000
movq %rax, 0x8(%r15)
movq $0x0, 0x10(%r15)
movb $0x0, 0x18(%r15)
movl $0x64, %r13d
movq 0x2bff(%rip), %r12      # 0x3fd8
movq %r15, %rdi
leaq -0x38(%rbp), %rsi
movq %r15, %rdx
callq 0x1712
callq 0x1040
movq %rax, %r14
cmpq $0x1f, %rax
ja 0x13fc
incl (%rbx,%r14,4)
jmp 0x142f
movl $0xc, %edx
movq %r12, %rdi
leaq 0xc5b(%rip), %rsi       # 0x2066
callq 0x10f0
movq %r12, %rdi
movq %r14, %rsi
callq 0x1060
movl $0x1, %edx
movq %rax, %rdi
leaq 0xc3a(%rip), %rsi       # 0x2064
callq 0x10f0
decq %r13
jne 0x13d9
movq (%r12), %rax
addq -0x18(%rax), %r12
movq %r12, %rdi
movl $0xa, %esi
callq 0x10c0
movsbl %al, %esi
movq 0x2b85(%rip), %rdi      # 0x3fd8
callq 0x1030
movq %rax, %rdi
callq 0x1070
xorl %esi, %esi
xorl %eax, %eax
addl (%rbx,%rax), %esi
addq $0x4, %rax
cmpq $0x80, %rax
jne 0x1464
movq 0x2b5e(%rip), %r15      # 0x3fd8
movq %r15, %rdi
callq 0x1110
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x10c0
movsbl %al, %esi
movq %r14, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1070
movl $0x4, %eax
movq %rbx, %rcx
movl (%rcx), %edx
cmpl (%rbx,%rax), %edx
jge 0x14bf
leaq (%rbx,%rax), %rcx
addq $0x4, %rax
cmpq $0x80, %rax
jne 0x14b4
movl (%rcx), %r14d
testl %r14d, %r14d
je 0x152f
leaq 0xb89(%rip), %r12       # 0x2063
xorl %r13d, %r13d
movq %r12, %rsi
cmpl %r14d, (%rbx,%r13,4)
jl 0x14ed
leaq 0xb73(%rip), %rsi       # 0x2060
movl $0x2, %edx
movq %r15, %rdi
callq 0x10f0
incq %r13
cmpq $0x20, %r13
jne 0x14dd
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x10c0
movsbl %al, %esi
movq %r15, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1070
decl %r14d
jne 0x14da
movl $0x80, %esi
movq -0x30(%rbp), %rdi
callq 0x10e0
movl $0x80, %esi
movq %rbx, %rdi
callq 0x10e0
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x157a
jmp 0x1567
jmp 0x157a
jmp 0x1567
jmp 0x157a
jmp 0x1567
movq %rax, %r14
movl $0x80, %esi
movq -0x30(%rbp), %rdi
callq 0x10e0
jmp 0x157d
movq %rax, %r14
movl $0x80, %esi
movq %rbx, %rdi
callq 0x10e0
movq %r14, %rdi
callq 0x1120