// File: /workspace/github_cpp_makefile_star2_O1/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 0x1f43c
movq 0x70(%rsp), %rax
movq 0x78(%rsp), %rcx
xorpd %xmm1, %xmm1
xorpd %xmm2, %xmm2
subq %rax, %rcx
je 0x21354
sarq $0x3, %rcx
cmpq $0x1, %rcx
adcq $0x0, %rcx
xorpd %xmm0, %xmm0
xorl %edx, %edx
movsd (%rax,%rdx,8), %xmm2
maxsd %xmm0, %xmm2
incq %rdx
movapd %xmm2, %xmm0
cmpq %rdx, %rcx
jne 0x2133f
movsd %xmm2, 0x8(%rsp)
movq 0x50(%rsp), %rax
movq 0x58(%rsp), %rcx
subq %rax, %rcx
je 0x21390
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 0x2137b
movsd %xmm1, 0x10(%rsp)
movq %r14, 0xa0(%rsp)
movslq 0x38(%rbx), %rsi
leaq 0x30(%rsp), %rdi
leaq 0xa8(%rsp), %rdx
callq 0x21cac
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
movsd %xmm0, 0x48(%rsp)
movl 0x38(%rbx), %eax
movl %ebp, 0x2c(%rsp)
movslq %ebp, %r15
testl %eax, %eax
movsd 0x8(%rsp), %xmm0
jle 0x2150a
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 0x21d34
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 0x21472
movq (%rbx), %rsi
movq 0x30(%rsp), %r8
addq %r14, %r8
movl %r12d, %edx
movl %r13d, %ecx
movsd 0x8(%rsp), %xmm0
callq 0x21966
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 0x21966
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 0x21966
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 0x21966
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 0x21966
incq %rbp
movslq 0x38(%rbx), %rax
addq $0x18, %r14
cmpq %rax, %rbp
jl 0x213ea
movslq %eax, %rsi
leaq 0x88(%rsp), %rdi
leaq 0xa8(%rsp), %rdx
callq 0x21cac
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 0x215e5
movq 0x88(%rsp), %rdi
addq %r12, %rdi
movq %r15, %rsi
callq 0x21d34
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 0x21966
movq %r14, %r12
movq %rbp, %r14
jmp 0x2153a
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 0x218c8
movq 0x1599f(%rip), %r14     # 0x36fd0
leaq 0xdda0(%rip), %rsi      # 0x2f3d8
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 0x1596d(%rip), %r14     # 0x36fd0
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31f0
testl %ebp, %ebp
jle 0x217e3
movl %ebp, %eax
movq %rax, 0x8(%rsp)
xorl %ebp, %ebp
leaq 0x7(%rsp), %r12
cmpl $0x0, 0x38(%rbx)
jle 0x216fc
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 0x21695
cmpl $0x0, 0x38(%rbx)
jle 0x21775
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 0x21708
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 0x21689
movq 0x157e6(%rip), %rbx     # 0x36fd0
leaq 0xdbf3(%rip), %rsi      # 0x2f3e4
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 0x157b4(%rip), %rdi     # 0x36fd0
callq 0x3040
movq %rax, %rdi
callq 0x31f0
leaq 0xa8(%rsp), %rdi
callq 0x33e0
movq 0x1578b(%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 0x21d66
leaq 0x30(%rsp), %rdi
callq 0x21d66
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x2189c
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x3310
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x218b6
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 0xa93b(%rip), %rdi      # 0x2c20a
leaq 0xc9e4(%rip), %rsi      # 0x2e2ba
leaq 0xdac4(%rip), %rcx      # 0x2f3a1
movl $0x7f3, %edx            # imm = 0x7F3
callq 0x31c0
jmp 0x218f8
jmp 0x218fd
jmp 0x218ed
movq %rax, %rbx
jmp 0x2192d
jmp 0x21906
jmp 0x218fd
jmp 0x218f8
movq %rax, %rbx
jmp 0x21916
movq %rax, %rbx
jmp 0x21923
jmp 0x21906
jmp 0x21906
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
callq 0x3400
leaq 0x88(%rsp), %rdi
callq 0x21d66
leaq 0x30(%rsp), %rdi
callq 0x21d66
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x21944
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x3310
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x2195e
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x3310
movq %rbx, %rdi
callq 0x3500