// File: /workspace/github_c_makefile_star2_O3/c-zhou[P]oatk/syncmer.c
// Function: hist_plot
static void hist_plot(int64_t *hist, uint32_t n, const char *h, FILE *fo)
{
    if (n < 5) return;

    uint32_t i, j, b, p_cnt, cnts[n];
    int32_t c, c_digits;
    double tot_cnt, cnt;
    
    tot_cnt = .0;
    cnts[0] = cnts[1] = cnts[2] = 0;
    for (i = 3; i < n; ++i) {
        cnts[i] = (uint32_t) hist[i];
        tot_cnt += cnts[i];
    }
    tot_cnt *= .99;
    cnt = .0;
    b = 0;
    for (i = 0; i < n; ++i) {
        cnt += cnts[i];
        if (cnt >= tot_cnt) {
            b = i + 1;
            break;
        }
    }
    p_cnt = 0;
    for (i = 0; i < b; ++i)
        if (p_cnt < cnts[i])
            p_cnt = cnts[i];

    c_digits = 0;
    for (i = 0; i < b; ++i) {
        c = hist[i] >> 32;
        int d = c > 0? 0 : 1;
        do {
            c /= 10;
            ++d;
        } while (c != 0);
        if (d > c_digits) c_digits = d;
    }
    if (b < n) ++c_digits;

    double per_dot = MAX(1, p_cnt / 100);
    uint32_t d;
    for (i = 0; i < b; ++i) {
        c = hist[i] >> 32;
        cnt = (uint32_t) hist[i];
        fprintf(fo, "[M::%s] [%s] %*d: ", __func__, h, c_digits, c);
        d = (uint32_t) (cnt / per_dot);
        for (j = 0; j < MIN(d, 100); ++j) fputc('*', fo);
        d = cnt/per_dot > 100? (uint32_t) log10(cnt/per_dot/100) : 0;
        for (j = 0; j < MAX(d, 0); ++j) fputc('+', fo);
        fprintf(fo, " %d\n", (int) cnt);
    }
    if (b < n) {
        c = hist[b-1] >> 32;
        cnt = .0;
        for (i = b; i < n; ++i)
            cnt += (uint32_t) hist[i];
        fprintf(fo, "[M::%s] [%s] >%*d: ", __func__, h, c_digits-1, c);
        d = (uint32_t) (cnt / per_dot);
        for (j = 0; j < MIN(d, 100); ++j) fputc('*', fo);
        d = cnt/per_dot > 100? (uint32_t) log10(cnt/per_dot/100) : 0;
        for (j = 0; j < MAX(d, 0); ++j) fputc('+', fo);
        fprintf(fo, " %d\n", (int) cnt);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdx, -0x40(%rbp)
cmpl $0x5, %esi
jb 0x12d35
movq %rcx, %rbx
movq %rsp, %r15
movl %esi, %r10d
movq %rsp, %rcx
leaq 0xf(,%r10,4), %rdx
andq $-0x10, %rdx
movq %rcx, %rax
subq %rdx, %rax
movq %rax, %rsp
negq %rdx
movl $0x0, 0x8(%rcx,%rdx)
movq $0x0, (%rax)
xorpd %xmm0, %xmm0
movl $0x3, %ecx
movl (%rdi,%rcx,8), %edx
xorps %xmm1, %xmm1
cvtsi2sd %rdx, %xmm1
movl %edx, (%rax,%rcx,4)
addsd %xmm1, %xmm0
incq %rcx
cmpq %rcx, %r10
jne 0x12a56
mulsd 0xcdd8(%rip), %xmm0     # 0x1f850
movq %r10, %rcx
negq %rcx
xorpd %xmm1, %xmm1
movl $0x1, %r12d
movsd 0xcdb8(%rip), %xmm2     # 0x1f848
movsd %xmm2, -0x38(%rbp)
movapd %xmm1, %xmm2
movl -0x4(%rax,%r12,4), %edx
xorps %xmm1, %xmm1
cvtsi2sd %rdx, %xmm1
addsd %xmm2, %xmm1
ucomisd %xmm0, %xmm1
jae 0x12ace
leaq (%rcx,%r12), %rdx
incq %rdx
incq %r12
cmpq $0x1, %rdx
jne 0x12a95
xorl %r12d, %r12d
movl $0x1, %r8d
jmp 0x12c61
movq %r10, -0x50(%rbp)
leaq -0x1(%r12), %rdx
xorl %ecx, %ecx
movq $-0x1, %r9
movl %ecx, %r8d
movl 0x4(%rax,%r9,4), %ecx
cmpl %ecx, %r8d
cmoval %r8d, %ecx
incq %r9
cmpq %r9, %rdx
jne 0x12ae0
xorl %eax, %eax
xorl %r8d, %r8d
movl 0x4(%rdi,%rax,8), %r10d
xorl %edx, %edx
testl %r10d, %r10d
setle %dl
movslq %r10d, %r9
imulq $0x66666667, %r9, %r10  # imm = 0x66666667
movq %r10, %r11
shrq $0x3f, %r11
sarq $0x22, %r10
addl %r11d, %r10d
incl %edx
addl $0x9, %r9d
cmpl $0x12, %r9d
ja 0x12b09
leal -0x1(%rdx), %r9d
cmpl %r8d, %r9d
cmovgel %edx, %r8d
incq %rax
cmpq %rax, %r12
jne 0x12afc
cmpl %esi, %r12d
adcl $0x0, %r8d
cmpl $0x64, %ecx
movq %r15, -0x58(%rbp)
movl %esi, -0x44(%rbp)
jae 0x12b5d
movsd 0xcced(%rip), %xmm0     # 0x1f848
jmp 0x12b71
movl %ecx, %eax
imulq $0x51eb851f, %rax, %rax # imm = 0x51EB851F
shrq $0x25, %rax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd %xmm0, -0x38(%rbp)
xorl %r15d, %r15d
movq %rdi, -0x60(%rbp)
movl %r8d, -0x48(%rbp)
movq (%rdi,%r15,8), %r14
movq %r14, %r9
shrq $0x20, %r9
movl %r14d, %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
movsd %xmm0, -0x30(%rbp)
movq %rbx, %rdi
leaq 0xd976(%rip), %rsi      # 0x2051c
leaq 0xd982(%rip), %rdx      # 0x2052f
movq -0x40(%rbp), %rcx
xorl %eax, %eax
callq 0x2280
movsd -0x30(%rbp), %xmm0
divsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
cvttsd2si %xmm0, %rax
cmpl $0x64, %eax
movl $0x64, %r13d
cmovbl %eax, %r13d
testl %eax, %eax
je 0x12bef
movl $0x2a, %edi
movq %rbx, %rsi
callq 0x2210
decl %r13d
jne 0x12bdd
movsd -0x30(%rbp), %xmm0
ucomisd 0xd3c4(%rip), %xmm0     # 0x1ffc0
jbe 0x12c27
divsd 0xd3ba(%rip), %xmm0     # 0x1ffc0
callq 0x2260
cvttsd2si %xmm0, %r13
testl %r13d, %r13d
je 0x12c27
movl $0x2b, %edi
movq %rbx, %rsi
callq 0x2210
decl %r13d
jne 0x12c15
movq %rbx, %rdi
leaq 0xd5f7(%rip), %rsi      # 0x20228
movl %r14d, %edx
xorl %eax, %eax
callq 0x2280
incq %r15
cmpq %r15, %r12
movq -0x60(%rbp), %rdi
movl -0x48(%rbp), %r8d
jne 0x12b81
cmpl -0x44(%rbp), %r12d
movq -0x58(%rbp), %r15
jae 0x12d32
movq -0x50(%rbp), %r10
leal -0x1(%r12), %eax
movl 0x4(%rdi,%rax,8), %r9d
movl %r12d, %eax
xorpd %xmm1, %xmm1
movl (%rdi,%rax,8), %ecx
xorps %xmm0, %xmm0
cvtsi2sd %rcx, %xmm0
addsd %xmm0, %xmm1
incq %rax
cmpq %rax, %r10
jne 0x12c72
decl %r8d
leaq 0xd8a6(%rip), %rsi      # 0x20539
leaq 0xd895(%rip), %rdx      # 0x2052f
movq %rbx, %rdi
movq -0x40(%rbp), %rcx
xorl %eax, %eax
movsd %xmm1, -0x30(%rbp)
callq 0x2280
movsd -0x30(%rbp), %xmm0
divsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
cvttsd2si %xmm0, %rax
cmpl $0x64, %eax
movl $0x64, %r14d
cmovbl %eax, %r14d
testl %eax, %eax
je 0x12ce4
movl $0x2a, %edi
movq %rbx, %rsi
callq 0x2210
decl %r14d
jne 0x12cd2
movsd -0x40(%rbp), %xmm0
ucomisd 0xd2cf(%rip), %xmm0     # 0x1ffc0
jbe 0x12d1c
divsd 0xd2c5(%rip), %xmm0     # 0x1ffc0
callq 0x2260
cvttsd2si %xmm0, %r14
testl %r14d, %r14d
je 0x12d1c
movl $0x2b, %edi
movq %rbx, %rsi
callq 0x2210
decl %r14d
jne 0x12d0a
cvttsd2si -0x30(%rbp), %edx
leaq 0xd500(%rip), %rsi      # 0x20228
movq %rbx, %rdi
xorl %eax, %eax
callq 0x2280
movq %r15, %rsp
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq