// File: /workspace/github_cpp_makefile_star2_O3/kebwi[P]Trifid/src/SteerablePyramid.cpp
// Function: SteerablePyramid::GenerateHistograms(int, char*)
void SteerablePyramid::GenerateHistograms(int numBins, char* filename)
{
	vector<Float_t> maxCoeffs, maxThumbnailPixels;
	FindStrongestCoefficients(maxCoeffs, maxThumbnailPixels);
	Float_t maxCoeff = 0;
	for (int i = 0; i < maxCoeffs.size(); i++)
		if (maxCoeffs[i] > maxCoeff)
			maxCoeff = maxCoeffs[i];
	Float_t maxThumbnailPixel = 0;
	for (int i = 0; i < maxThumbnailPixels.size(); i++)
		if (maxThumbnailPixels[i] > maxThumbnailPixel)
			maxThumbnailPixel = maxThumbnailPixels[i];
	
	Float_t binSpan = maxCoeff / numBins;
	
	//Generate coefficient histograms
	vector<vector<int> > coeffHistograms(numLevels_);
	for (int i = 0; i < numLevels_; i++)
	{
		coeffHistograms[i].resize(numBins);
		
		int horDim = width_ / pow(2, i);
		int verDim = height_ / pow(2, i);
		
		if (i == 0)
			AccumulateHistograms(h0Coeffs_, horDim, verDim, coeffHistograms[i], binSpan);
		AccumulateHistograms(b1Coeffs_[i], horDim, verDim, coeffHistograms[i], binSpan);
		AccumulateHistograms(b2Coeffs_[i], horDim, verDim, coeffHistograms[i], binSpan);
		AccumulateHistograms(b3Coeffs_[i], horDim, verDim, coeffHistograms[i], binSpan);
		AccumulateHistograms(b4Coeffs_[i], horDim, verDim, coeffHistograms[i], binSpan);
	}
	
	binSpan = maxThumbnailPixel / numBins;
	
	//Generate thumbnail histograms
	vector<vector<int> > thumbnailHistograms(numLevels_);
	for (int i = 0; i < numLevels_; i++)
	{
		thumbnailHistograms[i].resize(numBins);
		
		int horDim = width_ / pow(2, i + 1);
		int verDim = height_ / pow(2, i + 1);
		
		AccumulateHistograms(l1Coeffs_[i], horDim, verDim, thumbnailHistograms[i], binSpan);
	}
	
	//Dump the histograms to a tab delimited file
	ofstream ofs;
	ofs.open(filename);
	assert(ofs);
	
	cout << "Histograms:" << endl;
	for (int i = 0; i < numBins; i++)
	{
		for (int j = 0; j < numLevels_; j++)
		{
			ofs << coeffHistograms[j][i] << '\t';
			cout << coeffHistograms[j][i] << '\t';
		}
		for (int j = 0; j < numLevels_; j++)
		{
			ofs << thumbnailHistograms[j][i] << '\t';
			cout << thumbnailHistograms[j][i] << '\t';
		}
		ofs << endl;
		
		cout << endl;
	}
	cout << "Done" << endl;
	
	ofs.close();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2a8, %rsp            # imm = 0x2A8
movq %rdx, %r14
movl %esi, %ebp
movq %rdi, %rbx
xorpd %xmm0, %xmm0
leaq 0x70(%rsp), %rsi
movapd %xmm0, (%rsi)
xorl %eax, %eax
movq %rax, 0x10(%rsi)
leaq 0x50(%rsp), %rdx
movq %rax, 0x10(%rdx)
movapd %xmm0, (%rdx)
callq 0x1f19a
movq 0x70(%rsp), %rax
movq 0x78(%rsp), %rcx
xorpd %xmm1, %xmm1
subq %rax, %rcx
je 0x210ce
sarq $0x3, %rcx
cmpq $0x1, %rcx
adcq $0x0, %rcx
xorpd %xmm0, %xmm0
xorl %edx, %edx
movsd (%rax,%rdx,8), %xmm1
maxsd %xmm0, %xmm1
incq %rdx
movapd %xmm1, %xmm0
cmpq %rdx, %rcx
jne 0x210b9
movsd %xmm1, 0x8(%rsp)
movq 0x50(%rsp), %rax
movq 0x58(%rsp), %rcx
subq %rax, %rcx
xorpd %xmm1, %xmm1
je 0x2110e
sarq $0x3, %rcx
cmpq $0x1, %rcx
adcq $0x0, %rcx
xorpd %xmm0, %xmm0
xorl %edx, %edx
movsd (%rax,%rdx,8), %xmm1
maxsd %xmm0, %xmm1
incq %rdx
movapd %xmm1, %xmm0
cmpq %rdx, %rcx
jne 0x210f9
movsd %xmm1, 0x10(%rsp)
movq %r14, 0xa0(%rsp)
movslq 0x38(%rbx), %rsi
leaq 0x30(%rsp), %rdi
leaq 0xa8(%rsp), %rdx
callq 0x21a3c
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
movsd %xmm0, 0x48(%rsp)
movslq 0x38(%rbx), %rsi
movl %ebp, 0x2c(%rsp)
movslq %ebp, %r15
testq %rsi, %rsi
jle 0x21287
movsd 0x8(%rsp), %xmm0
divsd 0x48(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
xorl %r14d, %r14d
xorl %ebp, %ebp
movq 0x30(%rsp), %rdi
addq %r14, %rdi
movq %r15, %rsi
callq 0x21aba
xorps %xmm0, %xmm0
cvtsi2sdl 0x30(%rbx), %xmm0
movsd %xmm0, 0x18(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
movsd %xmm0, 0x20(%rsp)
callq 0x32a0
movsd 0x18(%rsp), %xmm1
divsd %xmm0, %xmm1
cvttsd2si %xmm1, %r12d
xorps %xmm0, %xmm0
cvtsi2sdl 0x34(%rbx), %xmm0
movsd %xmm0, 0x18(%rsp)
movsd 0x20(%rsp), %xmm0
callq 0x32a0
movsd 0x18(%rsp), %xmm1
divsd %xmm0, %xmm1
cvttsd2si %xmm1, %r13d
testq %rbp, %rbp
jne 0x211ef
movq (%rbx), %rsi
movq 0x30(%rsp), %r8
movl %r12d, %edx
movl %r13d, %ecx
movsd 0x8(%rsp), %xmm0
callq 0x216e2
movq 0x8(%rbx), %rax
movq (%rax,%rbp,8), %rsi
movq 0x30(%rsp), %r8
addq %r14, %r8
movl %r12d, %edx
movl %r13d, %ecx
movsd 0x8(%rsp), %xmm0
callq 0x216e2
movq 0x10(%rbx), %rax
movq (%rax,%rbp,8), %rsi
movq 0x30(%rsp), %r8
addq %r14, %r8
movl %r12d, %edx
movl %r13d, %ecx
movsd 0x8(%rsp), %xmm0
callq 0x216e2
movq 0x18(%rbx), %rax
movq (%rax,%rbp,8), %rsi
movq 0x30(%rsp), %r8
addq %r14, %r8
movl %r12d, %edx
movl %r13d, %ecx
movsd 0x8(%rsp), %xmm0
callq 0x216e2
movq 0x20(%rbx), %rax
movq (%rax,%rbp,8), %rsi
movq 0x30(%rsp), %r8
addq %r14, %r8
movl %r12d, %edx
movl %r13d, %ecx
movsd 0x8(%rsp), %xmm0
callq 0x216e2
incq %rbp
movslq 0x38(%rbx), %rsi
addq $0x18, %r14
cmpq %rsi, %rbp
jl 0x2116a
leaq 0x88(%rsp), %rdi
leaq 0xa8(%rsp), %rdx
callq 0x21a3c
movsd 0x10(%rsp), %xmm0
divsd 0x48(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
xorl %r12d, %r12d
xorl %r14d, %r14d
movslq 0x38(%rbx), %rax
cmpq %rax, %r14
jge 0x2135f
movq 0x88(%rsp), %rdi
addq %r12, %rdi
movq %r15, %rsi
callq 0x21aba
xorps %xmm0, %xmm0
cvtsi2sdl 0x30(%rbx), %xmm0
movsd %xmm0, 0x8(%rsp)
leaq 0x1(%r14), %rbp
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
movsd %xmm0, 0x20(%rsp)
callq 0x32a0
movsd 0x8(%rsp), %xmm1
divsd %xmm0, %xmm1
cvttsd2si %xmm1, %r13d
xorps %xmm0, %xmm0
cvtsi2sdl 0x34(%rbx), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0x20(%rsp), %xmm0
callq 0x32a0
movsd 0x8(%rsp), %xmm1
divsd %xmm0, %xmm1
cvttsd2si %xmm1, %ecx
movq 0x28(%rbx), %rax
movq (%rax,%r14,8), %rsi
leaq 0x18(%r12), %r14
addq 0x88(%rsp), %r12
movl %r13d, %edx
movq %r12, %r8
movsd 0x10(%rsp), %xmm0
callq 0x216e2
movq %r14, %r12
movq %rbp, %r14
jmp 0x212b4
leaq 0xa8(%rsp), %rdi
callq 0x34d0
leaq 0xa8(%rsp), %rdi
movq 0xa0(%rsp), %rsi
movl $0x10, %edx
callq 0x3050
movl 0x2c(%rsp), %ebp
movq 0xa8(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0xc8(%rsp,%rax)
jne 0x21644
movq 0x15c25(%rip), %r14     # 0x36fd0
leaq 0xd08e(%rip), %rsi      # 0x2e440
movl $0xb, %edx
movq %r14, %rdi
callq 0x3360
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x32e0
movsbl %al, %esi
movq 0x15bf3(%rip), %r14     # 0x36fd0
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31f0
testl %ebp, %ebp
jle 0x2155f
movl %ebp, %eax
movq %rax, 0x8(%rsp)
xorl %ebp, %ebp
leaq 0x7(%rsp), %r12
cmpl $0x0, 0x38(%rbx)
jle 0x214f1
xorl %r13d, %r13d
xorl %r15d, %r15d
movq 0x30(%rsp), %rax
movq (%rax,%r13), %rax
movl (%rax,%rbp,4), %esi
leaq 0xa8(%rsp), %rdi
callq 0x34e0
movb $0x9, 0x7(%rsp)
movl $0x1, %edx
movq %rax, %rdi
movq %r12, %rsi
callq 0x3360
movq 0x30(%rsp), %rax
movq (%rax,%r13), %rax
movl (%rax,%rbp,4), %esi
movq %r14, %rdi
callq 0x34e0
movb $0x9, 0x7(%rsp)
movl $0x1, %edx
movq %rax, %rdi
movq %r12, %rsi
callq 0x3360
incq %r15
movslq 0x38(%rbx), %rax
addq $0x18, %r13
cmpq %rax, %r15
jl 0x21413
testl %eax, %eax
jle 0x214f1
xorl %r13d, %r13d
xorl %r15d, %r15d
movq 0x88(%rsp), %rax
movq (%rax,%r13), %rax
movl (%rax,%rbp,4), %esi
leaq 0xa8(%rsp), %rdi
callq 0x34e0
movb $0x9, 0x7(%rsp)
movl $0x1, %edx
movq %rax, %rdi
movq %r12, %rsi
callq 0x3360
movq 0x88(%rsp), %rax
movq (%rax,%r13), %rax
movl (%rax,%rbp,4), %esi
movq %r14, %rdi
callq 0x34e0
movb $0x9, 0x7(%rsp)
movl $0x1, %edx
movq %rax, %rdi
movq %r12, %rsi
callq 0x3360
incq %r15
movslq 0x38(%rbx), %rax
addq $0x18, %r13
cmpq %rax, %r15
jl 0x21484
movq 0xa8(%rsp), %rax
movq -0x18(%rax), %rdi
leaq 0xa8(%rsp), %rax
addq %rax, %rdi
movl $0xa, %esi
callq 0x32e0
movsbl %al, %esi
leaq 0xa8(%rsp), %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31f0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x32e0
movsbl %al, %esi
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31f0
incq %rbp
cmpq 0x8(%rsp), %rbp
jne 0x21403
movq 0x15a6a(%rip), %rbx     # 0x36fd0
leaq 0xcedf(%rip), %rsi      # 0x2e44c
movl $0x4, %edx
movq %rbx, %rdi
callq 0x3360
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x32e0
movsbl %al, %esi
movq 0x15a38(%rip), %rdi     # 0x36fd0
callq 0x3040
movq %rax, %rdi
callq 0x31f0
leaq 0xa8(%rsp), %rdi
callq 0x33e0
movq 0x15a0f(%rip), %rax     # 0x36fc8
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq 0xb0(%rsp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, 0xa8(%rsp,%rcx)
callq 0x3270
leaq 0x1a0(%rsp), %rdi
callq 0x30e0
leaq 0x88(%rsp), %rdi
callq 0x21aec
leaq 0x30(%rsp), %rdi
callq 0x21aec
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x21618
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x3310
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x21632
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x3310
addq $0x2a8, %rsp            # imm = 0x2A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x9b97(%rip), %rdi      # 0x2b1e2
leaq 0xbcd0(%rip), %rsi      # 0x2d322
leaq 0xcdb0(%rip), %rcx      # 0x2e409
movl $0x7f3, %edx            # imm = 0x7F3
callq 0x31c0
jmp 0x21674
jmp 0x21679
jmp 0x21669
movq %rax, %rbx
jmp 0x216a9
jmp 0x21682
jmp 0x21679
jmp 0x21674
movq %rax, %rbx
jmp 0x21692
movq %rax, %rbx
jmp 0x2169f
jmp 0x21682
jmp 0x21682
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
callq 0x3400
leaq 0x88(%rsp), %rdi
callq 0x21aec
leaq 0x30(%rsp), %rdi
callq 0x21aec
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x216c0
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x3310
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x216da
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x3310
movq %rbx, %rdi
callq 0x3500