// File: jeffchan[P]blockchain-parser/BlockChain.cpp
// Function: BitcoinTransactionFactory::printTopBalances(unsigned int, unsigned int)
void printTopBalances(uint32_t tcount,uint32_t minBalance)
	{
		uint32_t plotCount = 0;
		uint64_t mbtc = minBalance*ONE_BTC;
		for (uint32_t i=0; i<mAddresses.size(); i++) // print one in every 10,000 addresses (just for testing right now)
		{
			BitcoinAddress *ba = mAddresses.getKey(i);
			uint64_t balance = ba->getBalance();
			if ( balance >= mbtc )
			{
				plotCount++;
			}
		}

		if ( !plotCount )
		{
			printf("No addresses found with a balance more than %d bitcoins\r\n", minBalance );
			return;
		}

		BitcoinAddress **sortPointers = new BitcoinAddress*[plotCount];
		plotCount = 0;
		for (uint32_t i=0; i<mAddresses.size(); i++) // print one in every 10,000 addresses (just for testing right now)
		{
			BitcoinAddress *ba = mAddresses.getKey(i);
			uint64_t balance = ba->getBalance();
			if ( balance >= mbtc )
			{
				sortPointers[plotCount] = ba;
				plotCount++;
			}
		}
		SortByBalance sb(sortPointers,plotCount);
		time_t currentTime;
		time(&currentTime); // get the current time.

		if ( plotCount < tcount )
		{
			tcount = plotCount;
		}
		printf("Displaying the top %d addresses by balance.\r\n", tcount );
		printf("==============================================\r\n");
		printf(" Address           : Balance  : Days Since Last Use\r\n");
		printf("==============================================\r\n");
		for (uint32_t i=0; i<tcount; i++)
		{
			BitcoinAddress *ba = sortPointers[i];
			uint64_t balance = ba->mTotalReceived-ba->mTotalSent;
			uint32_t lastUsed = ba->mLastInputTime; // the last time we sent money (not received because anyone can send us money).
			if ( ba->mLastInputTime == 0 ) // if it has never had a spend.. then we use the time of first receive..
			{
				lastUsed = ba->mFirstOutputTime;
			}
			double seconds = difftime(currentTime,time_t(lastUsed));
			double minutes = seconds/60;
			double hours = minutes/60;
			uint32_t days = (uint32_t) (hours/24);
			uint32_t adr = mAddresses.getIndex(ba)+1;
			printf("%40s,  %8d,  %4d\r\n", getKey(adr), (uint32_t)( balance / ONE_BTC ), days );
		}
		delete []sortPointers;
	}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xb0(%rbp)
movl $0x0, -0x14(%rbp)
imull $0x5f5e100, -0x10(%rbp), %eax # imm = 0x5F5E100
movl %eax, %eax
movq %rax, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movq -0xb0(%rbp), %rdi
movl -0x24(%rbp), %eax
movl %eax, -0xb4(%rbp)
callq 0x1d960
movl %eax, %ecx
movl -0xb4(%rbp), %eax
cmpl %ecx, %eax
jae 0x22b0c
movq -0xb0(%rbp), %rdi
movl -0x24(%rbp), %esi
callq 0x1d360
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
callq 0x22d80
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x20(%rbp), %rax
jb 0x22aff
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x22b01
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x22aab
cmpl $0x0, -0x14(%rbp)
jne 0x22b28
movl -0x10(%rbp), %esi
leaq 0xfd59(%rip), %rdi      # 0x32875
movb $0x0, %al
callq 0x2050
jmp 0x22d6f
movl -0x14(%rbp), %eax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x2040
movq %rax, -0x40(%rbp)
movl $0x0, -0x14(%rbp)
movl $0x0, -0x44(%rbp)
movq -0xb0(%rbp), %rdi
movl -0x44(%rbp), %eax
movl %eax, -0xb8(%rbp)
callq 0x1d960
movl %eax, %ecx
movl -0xb8(%rbp), %eax
cmpl %ecx, %eax
jae 0x22bce
movq -0xb0(%rbp), %rdi
movl -0x44(%rbp), %esi
callq 0x1d360
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rdi
callq 0x22d80
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
cmpq -0x20(%rbp), %rax
jb 0x22bc1
movq -0x50(%rbp), %rdx
movq -0x40(%rbp), %rax
movl -0x14(%rbp), %ecx
movq %rdx, (%rax,%rcx,8)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x22bc3
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x22b5e
movq -0x40(%rbp), %rsi
movl -0x14(%rbp), %edx
leaq -0x60(%rbp), %rdi
callq 0x1ea90
leaq -0x68(%rbp), %rdi
callq 0x2120
movl -0x14(%rbp), %eax
cmpl -0xc(%rbp), %eax
jae 0x22bf5
movl -0x14(%rbp), %eax
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %esi
leaq 0xfcb0(%rip), %rdi      # 0x328af
movb $0x0, %al
callq 0x2050
leaq 0xe3a4(%rip), %rdi      # 0x30fb1
movb $0x0, %al
callq 0x2050
leaq 0xfcc2(%rip), %rdi      # 0x328dd
movb $0x0, %al
callq 0x2050
leaq 0xe388(%rip), %rdi      # 0x30fb1
movb $0x0, %al
callq 0x2050
movl $0x0, -0x6c(%rbp)
movl -0x6c(%rbp), %eax
cmpl -0xc(%rbp), %eax
jae 0x22d52
movq -0x40(%rbp), %rax
movl -0x6c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x78(%rbp), %rcx
subq 0x20(%rcx), %rax
movq %rax, -0x80(%rbp)
movq -0x78(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, -0x84(%rbp)
movq -0x78(%rbp), %rax
cmpl $0x0, 0x14(%rax)
jne 0x22c8a
movq -0x78(%rbp), %rax
movl 0x1c(%rax), %eax
movl %eax, -0x84(%rbp)
movq -0x68(%rbp), %rdi
movl -0x84(%rbp), %eax
movl %eax, %esi
callq 0x20a0
movq -0xb0(%rbp), %rdi
movsd %xmm0, -0x90(%rbp)
movsd -0x90(%rbp), %xmm0
movsd 0xdf86(%rip), %xmm1     # 0x30c40
divsd %xmm1, %xmm0
movsd %xmm0, -0x98(%rbp)
movsd -0x98(%rbp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, -0xa0(%rbp)
movsd -0xa0(%rbp), %xmm0
movsd 0xdf5e(%rip), %xmm1     # 0x30c48
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movl %eax, -0xa4(%rbp)
movq -0x78(%rbp), %rsi
callq 0x1d0d0
movq -0xb0(%rbp), %rdi
addl $0x1, %eax
movl %eax, -0xa8(%rbp)
movl -0xa8(%rbp), %esi
callq 0x1efc0
movq %rax, %rsi
movq -0x80(%rbp), %rax
movl $0x5f5e100, %ecx        # imm = 0x5F5E100
xorl %edx, %edx
divq %rcx
movl %eax, %edx
movl -0xa4(%rbp), %ecx
leaq 0xfbd6(%rip), %rdi      # 0x32913
movb $0x0, %al
callq 0x2050
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
jmp 0x22c37
movq -0x40(%rbp), %rax
movq %rax, -0xc0(%rbp)
cmpq $0x0, %rax
je 0x22d6f
movq -0xc0(%rbp), %rdi
callq 0x21d0
addq $0xc0, %rsp
popq %rbp
retq
nopl (%rax,%rax)