// File: chhylp123[P]hifiasm/hist.cpp
// Function: print_hist_lines(int, int, long const*)
void print_hist_lines(int n_cnt, int start_cnt, const int64_t *cnt)
{
	const int hist_max = 100;
	int i, start, low_i, max_i, max;
	// determine the start point
	assert(n_cnt > start_cnt);
	start = cnt[1] > 0? 1 : 2;

	// find the low point from the left
	low_i = start > start_cnt? start : start_cnt;
	for (i = low_i; i < n_cnt; ++i)
		if (cnt[i] > cnt[i-1]) break;
	low_i = i - 1;
	fprintf(stderr, "[M::%s] lowest: count[%d] = %ld\n", __func__, low_i, (long)cnt[low_i]);

	// find the highest peak
	max_i = start > start_cnt? start : start_cnt, max = cnt[max_i];
	for (i = max_i; i < n_cnt; ++i)
		if (cnt[i] > max)
			max = cnt[i], max_i = i;
	fprintf(stderr, "[M::%s] highest: count[%d] = %ld\n", __func__, max_i, (long)cnt[max_i]);

	for (i = start; i < n_cnt; ++i) {
		int x, exceed = 0;
		x = (int)((double)hist_max * cnt[i] / cnt[max_i] + .499);
		if (x > hist_max) exceed = 1, x = hist_max; // may happen if cnt[2] is higher
		if (i > max_i && x == 0) break;
		ha_hist_line(i, x, exceed, cnt[i]);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movl %edi, -0x4(%rbp)
movl %esi, -0x8(%rbp)
movq %rdx, -0x10(%rbp)
movl $0x64, -0x14(%rbp)
movl -0x4(%rbp), %eax
cmpl -0x8(%rbp), %eax
jle 0x192123
jmp 0x192142
leaq 0x1f90b2(%rip), %rdi    # 0x38b1dc
leaq 0x1f90bd(%rip), %rsi    # 0x38b1ee
movl $0x14, %edx
leaq 0x1f90ba(%rip), %rcx    # 0x38b1f7
callq 0x2130
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdx
movl $0x2, %eax
movl $0x1, %ecx
cmpq $0x0, %rdx
cmovgl %ecx, %eax
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x8(%rbp), %eax
jle 0x19216e
movl -0x1c(%rbp), %eax
movl %eax, -0x34(%rbp)
jmp 0x192174
movl -0x8(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
movl %eax, -0x20(%rbp)
movl -0x20(%rbp), %eax
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x4(%rbp), %eax
jge 0x1921b6
movq -0x10(%rbp), %rax
movslq -0x18(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x10(%rbp), %rcx
movl -0x18(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
cmpq (%rcx,%rdx,8), %rax
jle 0x1921a9
jmp 0x1921b6
jmp 0x1921ab
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x192180
movl -0x18(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x20(%rbp)
movq 0x231e1a(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movl -0x20(%rbp), %ecx
movq -0x10(%rbp), %rax
movslq -0x20(%rbp), %rdx
movq (%rax,%rdx,8), %r8
leaq 0x1f9049(%rip), %rsi    # 0x38b228
leaq 0x1f9063(%rip), %rdx    # 0x38b249
movb $0x0, %al
callq 0x22a0
movl -0x1c(%rbp), %eax
cmpl -0x8(%rbp), %eax
jle 0x1921fd
movl -0x1c(%rbp), %eax
movl %eax, -0x38(%rbp)
jmp 0x192203
movl -0x8(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, -0x28(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x4(%rbp), %eax
jge 0x19225d
movq -0x10(%rbp), %rax
movslq -0x18(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x28(%rbp), %rcx
cmpq %rcx, %rax
jle 0x192250
movq -0x10(%rbp), %rax
movslq -0x18(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, -0x28(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0x24(%rbp)
jmp 0x192252
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x19221e
movq 0x231d7c(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movl -0x24(%rbp), %ecx
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rdx
movq (%rax,%rdx,8), %r8
leaq 0x1f8fdd(%rip), %rsi    # 0x38b25a
leaq 0x1f8fc5(%rip), %rdx    # 0x38b249
movb $0x0, %al
callq 0x22a0
movl -0x1c(%rbp), %eax
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x4(%rbp), %eax
jge 0x19232f
movl $0x0, -0x30(%rbp)
movq -0x10(%rbp), %rax
movslq -0x18(%rbp), %rcx
cvtsi2sdq (%rax,%rcx,8), %xmm1
movsd 0x1f7fe6(%rip), %xmm0   # 0x38a2a0
mulsd %xmm1, %xmm0
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
cvtsi2sdq (%rax,%rcx,8), %xmm1
divsd %xmm1, %xmm0
movsd 0x1ecd68(%rip), %xmm1   # 0x37f040
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x2c(%rbp)
cmpl $0x64, -0x2c(%rbp)
jle 0x1922f7
movl $0x1, -0x30(%rbp)
movl $0x64, -0x2c(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x24(%rbp), %eax
jle 0x192307
cmpl $0x0, -0x2c(%rbp)
jne 0x192307
jmp 0x19232f
movl -0x18(%rbp), %edi
movl -0x2c(%rbp), %esi
movl -0x30(%rbp), %edx
movq -0x10(%rbp), %rax
movslq -0x18(%rbp), %rcx
movq (%rax,%rcx,8), %rcx
callq 0x192340
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x192291
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)