// File: iZhangHui[P]CppPrimer/CH17_SpecializedLibraryFacilities/examples/normalInts.cc
// Function: main
int main()
{
	default_random_engine e;        // generates random integers
	normal_distribution<> n(4,1.5); // mean 4, standard deviation 1.5
	vector<unsigned> vals(9);       // nine elements each 0

	for (size_t i = 0; i != 200; ++i) {
		unsigned v = lround(n(e));  // round to the nearest integer
		if (v < vals.size())        // if this result is in range 
			++vals[v];              // count how often each number appears
	}

	int sum = accumulate(vals.begin(), vals.end(), 0);

	if (sum != 200)
		cout << "discarded " << 200 - sum << " results" << endl;

	for (size_t j = 0; j != vals.size(); ++j)
		cout << j << ": " << string(vals[j], '*') << endl;

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
movl $0x0, -0x4(%rbp)
leaq -0x10(%rbp), %rdi
callq 0x1640
leaq -0x30(%rbp), %rdi
movsd 0x1cf1(%rip), %xmm0     # 0x3008
movsd 0x1cf1(%rip), %xmm1     # 0x3010
callq 0x1660
leaq -0x49(%rbp), %rdi
movq %rdi, -0xb8(%rbp)
callq 0x16b0
movq -0xb8(%rbp), %rdx
leaq -0x48(%rbp), %rdi
movl $0x9, %esi
callq 0x16d0
jmp 0x134b
leaq -0x49(%rbp), %rdi
callq 0x1740
movq $0x0, -0x68(%rbp)
cmpq $0xc8, -0x68(%rbp)
je 0x1408
leaq -0x30(%rbp), %rdi
leaq -0x10(%rbp), %rsi
callq 0x1760
movsd %xmm0, -0xc0(%rbp)
jmp 0x1381
movsd -0xc0(%rbp), %xmm0
callq 0x1030
movl %eax, -0x6c(%rbp)
movl -0x6c(%rbp), %eax
movq %rax, -0xc8(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x1790
movq %rax, %rcx
movq -0xc8(%rbp), %rax
cmpq %rcx, %rax
jae 0x13f5
movl -0x6c(%rbp), %eax
movl %eax, %esi
leaq -0x48(%rbp), %rdi
callq 0x17b0
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x13f5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x49(%rbp), %rdi
callq 0x1740
jmp 0x1636
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x162d
jmp 0x13f7
movq -0x68(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x68(%rbp)
jmp 0x135c
leaq -0x48(%rbp), %rdi
movq %rdi, -0xd8(%rbp)
callq 0x1830
movq -0xd8(%rbp), %rdi
movq %rax, -0x78(%rbp)
callq 0x1860
movq %rax, -0x80(%rbp)
movq -0x78(%rbp), %rdi
movq -0x80(%rbp), %rsi
xorl %edx, %edx
callq 0x17d0
movl %eax, -0xcc(%rbp)
jmp 0x1443
movl -0xcc(%rbp), %eax
movl %eax, -0x70(%rbp)
cmpl $0xc8, -0x70(%rbp)
je 0x14c3
movq 0x4b7c(%rip), %rdi      # 0x5fd8
leaq 0x1bfd(%rip), %rsi      # 0x3060
callq 0x1120
movq %rax, -0xe0(%rbp)
jmp 0x1471
movq -0xe0(%rbp), %rdi
movl -0x70(%rbp), %eax
movl $0xc8, %esi
subl %eax, %esi
callq 0x1180
movq %rax, -0xe8(%rbp)
jmp 0x1490
movq -0xe8(%rbp), %rdi
leaq 0x1bcd(%rip), %rsi      # 0x306b
callq 0x1120
movq %rax, -0xf0(%rbp)
jmp 0x14ac
movq -0xf0(%rbp), %rdi
movq 0x4b0e(%rip), %rsi      # 0x5fc8
callq 0x1150
jmp 0x14c1
jmp 0x14c3
movq $0x0, -0x88(%rbp)
movq -0x88(%rbp), %rax
movq %rax, -0xf8(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x1790
movq %rax, %rcx
movq -0xf8(%rbp), %rax
cmpq %rcx, %rax
je 0x1611
movq -0x88(%rbp), %rsi
movq 0x4ad2(%rip), %rdi      # 0x5fd8
callq 0x1040
movq %rax, -0x100(%rbp)
jmp 0x1514
movq -0x100(%rbp), %rdi
leaq 0x1b52(%rip), %rsi      # 0x3074
callq 0x1120
movq %rax, -0x108(%rbp)
jmp 0x1530
movq -0x88(%rbp), %rsi
leaq -0x48(%rbp), %rdi
callq 0x17b0
movl (%rax), %eax
movq %rax, -0x118(%rbp)
leaq -0xa9(%rbp), %rdi
movq %rdi, -0x110(%rbp)
callq 0x11a0
movq -0x118(%rbp), %rsi
movq -0x110(%rbp), %rcx
leaq -0xa8(%rbp), %rdi
movl $0x2a, %edx
callq 0x10b0
jmp 0x157d
movq -0x108(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x1110
movq %rax, -0x120(%rbp)
jmp 0x1599
movq -0x120(%rbp), %rdi
movq 0x4a21(%rip), %rsi      # 0x5fc8
callq 0x1150
jmp 0x15ae
leaq -0xa8(%rbp), %rdi
callq 0x10a0
leaq -0xa9(%rbp), %rdi
callq 0x1160
movq -0x88(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x88(%rbp)
jmp 0x14ce
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x1603
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x10a0
leaq -0xa9(%rbp), %rdi
callq 0x1160
jmp 0x162d
movl $0x0, -0x4(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x1890
movl -0x4(%rbp), %eax
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
leaq -0x48(%rbp), %rdi
callq 0x1890
movq -0x58(%rbp), %rdi
callq 0x1190
nop