// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, -0x38(%rbp)
movl 0x2000000(%rdi), %r13d
testq %r13, %r13
je 0x10a1d
movl %esi, %ebx
imull $0x5f5e100, %edx, %r15d # imm = 0x5F5E100
movq -0x38(%rbp), %rax
movq 0x2000008(%rax), %rax
movq %r13, %rcx
shlq $0x4, %rcx
leaq (%rcx,%rcx,4), %rsi
xorl %edi, %edi
xorl %ecx, %ecx
movq 0x28(%rax,%rdi), %r8
subq 0x20(%rax,%rdi), %r8
cmpq %r15, %r8
sbbl $-0x1, %ecx
addq $0x50, %rdi
cmpq %rdi, %rsi
jne 0x109b8
testl %ecx, %ecx
je 0x10a1d
movl %ecx, %edi
shlq $0x3, %rdi
callq 0x2040
movq %rax, -0x30(%rbp)
testq %r13, %r13
je 0x10a3b
movq -0x38(%rbp), %rax
movq 0x2000008(%rax), %rax
xorl %r12d, %r12d
movq -0x30(%rbp), %rdx
movq 0x28(%rax), %rcx
subq 0x20(%rax), %rcx
cmpq %r15, %rcx
jb 0x10a12
movl %r12d, %ecx
movq %rax, (%rdx,%rcx,8)
incl %r12d
addq $0x50, %rax
decq %r13
jne 0x109fb
jmp 0x10a3e
leaq 0x8780(%rip), %rdi      # 0x191a4
movl %edx, %esi
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2050
xorl %r12d, %r12d
leaq 0xe19b(%rip), %rax      # 0x1ebe0
leaq -0x48(%rbp), %rdi
movq %rax, (%rdi)
movq -0x30(%rbp), %rsi
movl %r12d, %edx
callq 0xb2d4
leaq -0x40(%rbp), %rdi
callq 0x2130
cmpl %ebx, %r12d
cmovbl %r12d, %ebx
leaq 0x876f(%rip), %rdi      # 0x191de
movl %ebx, %esi
xorl %eax, %eax
callq 0x2050
leaq 0x8ec4(%rip), %r12      # 0x19943
movq %r12, %rdi
callq 0x2260
leaq 0x9120(%rip), %rdi      # 0x19bae
callq 0x2260
movq %r12, %rdi
callq 0x2260
testl %ebx, %ebx
je 0x10b3b
movl %ebx, %r15d
xorl %r14d, %r14d
movq -0x30(%rbp), %rax
movq (%rax,%r14,8), %rbx
movl 0x14(%rbx), %eax
testl %eax, %eax
jne 0x10abb
movl 0x1c(%rbx), %eax
movq 0x28(%rbx), %r12
subq 0x20(%rbx), %r12
movq -0x40(%rbp), %rdi
movl %eax, %esi
callq 0x20a0
movsd 0x6d0a(%rip), %xmm1     # 0x177e0
divsd %xmm1, %xmm0
divsd %xmm1, %xmm0
divsd 0x6d02(%rip), %xmm0     # 0x177e8
cvttsd2si %xmm0, %r13
movq -0x38(%rbp), %rdi
subq 0x2000008(%rdi), %rbx
shrq $0x4, %rbx
imull $0xcccccccd, %ebx, %esi # imm = 0xCCCCCCCD
incl %esi
callq 0xe002
movq %rax, %rsi
movq %r12, %rax
movabsq $-0x543388ee7b9e3103, %rcx # imm = 0xABCC77118461CEFD
mulq %rcx
shrq $0x1a, %rdx
leaq 0x86e7(%rip), %rdi      # 0x1920c
movl %r13d, %ecx
xorl %eax, %eax
callq 0x2050
incq %r14
cmpq %r14, %r15
jne 0x10aa9
movq -0x30(%rbp), %rdi
callq 0x2200
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop