// File: /workspace/github_cpp_makefile_star2_O3/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 0x15a2
movl %eax, %eax
incl (%rbx,%rax,4)
decq %r12
jne 0x12ce
movl (%rbx), %eax
movl $0x4, %ecx
movq %rbx, %rdx
leaq (%rbx,%rcx), %rsi
movl (%rbx,%rcx), %edi
cmpl %edi, %eax
cmovlel %edi, %eax
cmovlq %rsi, %rdx
addq $0x4, %rcx
cmpq $0x80, %rcx
jne 0x12f0
movl (%rdx), %r15d
testl %r15d, %r15d
je 0x1378
leaq 0xd47(%rip), %r12       # 0x2063
movq 0x2cb5(%rip), %r14      # 0x3fd8
xorl %r13d, %r13d
movq %r12, %rsi
cmpl %r15d, (%rbx,%r13,4)
jl 0x1336
leaq 0xd2a(%rip), %rsi       # 0x2060
movl $0x2, %edx
movq %r14, %rdi
callq 0x10f0
incq %r13
cmpq $0x20, %r13
jne 0x1326
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 0x1323
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 0x2bf7(%rip), %r12      # 0x3fd8
movq %r15, %rdi
leaq -0x38(%rbp), %rsi
movq %r15, %rdx
callq 0x1724
callq 0x1040
movq %rax, %r14
cmpq $0x1f, %rax
ja 0x1404
incl (%rbx,%r14,4)
jmp 0x1437
movl $0xc, %edx
movq %r12, %rdi
leaq 0xc53(%rip), %rsi       # 0x2066
callq 0x10f0
movq %r12, %rdi
movq %r14, %rsi
callq 0x1060
movl $0x1, %edx
movq %rax, %rdi
leaq 0xc32(%rip), %rsi       # 0x2064
callq 0x10f0
decq %r13
jne 0x13e1
movq (%r12), %rax
addq -0x18(%rax), %r12
movq %r12, %rdi
movl $0xa, %esi
callq 0x10c0
movsbl %al, %esi
movq 0x2b7d(%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 0x146c
movq 0x2b56(%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 (%rbx), %eax
movl $0x4, %ecx
movq %rbx, %rdx
leaq (%rbx,%rcx), %rsi
movl (%rbx,%rcx), %edi
cmpl %edi, %eax
cmovlel %edi, %eax
cmovlq %rsi, %rdx
addq $0x4, %rcx
cmpq $0x80, %rcx
jne 0x14be
movl (%rdx), %r14d
testl %r14d, %r14d
je 0x153f
leaq 0xb79(%rip), %r12       # 0x2063
xorl %r13d, %r13d
movq %r12, %rsi
cmpl %r14d, (%rbx,%r13,4)
jl 0x14fd
leaq 0xb63(%rip), %rsi       # 0x2060
movl $0x2, %edx
movq %r15, %rdi
callq 0x10f0
incq %r13
cmpq $0x20, %r13
jne 0x14ed
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 0x14ea
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 0x158a
jmp 0x1577
jmp 0x158a
jmp 0x1577
jmp 0x158a
jmp 0x1577
movq %rax, %r14
movl $0x80, %esi
movq -0x30(%rbp), %rdi
callq 0x10e0
jmp 0x158d
movq %rax, %r14
movl $0x80, %esi
movq %rbx, %rdi
callq 0x10e0
movq %r14, %rdi
callq 0x1120