// File: /workspace/github_c_makefile_star2_O2/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 $0x48, %rsp
movq %rdx, -0x50(%rbp)
cmpl $0x5, %esi
jb 0xeff2
movq %rcx, %rbx
movq %rsp, -0x60(%rbp)
movl %esi, %r11d
movq %rsp, %rcx
leaq 0xf(,%r11,4), %rdx
andq $-0x10, %rdx
movq %rcx, %rax
subq %rdx, %rax
movq %rax, %rsp
negq %rdx
andl $0x0, 0x8(%rcx,%rdx)
andq $0x0, (%rax)
xorpd %xmm0, %xmm0
pushq $0x3
popq %rcx
cmpq %rcx, %r11
je 0xed64
movl (%rdi,%rcx,8), %edx
movl %edx, (%rax,%rcx,4)
cvtsi2sd %rdx, %xmm1
addsd %xmm1, %xmm0
incq %rcx
jmp 0xed4b
mulsd 0xaa6c(%rip), %xmm0     # 0x197d8
xorpd %xmm1, %xmm1
xorl %ecx, %ecx
xorl %edx, %edx
cmpq %rdx, %r11
je 0xed94
movl (%rax,%rdx,4), %esi
cvtsi2sd %rsi, %xmm2
addsd %xmm2, %xmm1
ucomisd %xmm0, %xmm1
jae 0xed90
incq %rdx
jmp 0xed74
incl %edx
movl %edx, %ecx
movl %ecx, %r15d
xorl %edx, %edx
xorl %ecx, %ecx
cmpq %rdx, %r15
je 0xedad
movl (%rax,%rdx,4), %esi
cmpl %esi, %ecx
cmovbel %esi, %ecx
incq %rdx
jmp 0xed9b
xorl %r10d, %r10d
pushq $0xa
popq %r14
xorl %r8d, %r8d
cmpq %r15, %r10
je 0xedf0
movl 0x4(%rdi,%r10,8), %esi
xorl %r9d, %r9d
testl %esi, %esi
setle %r9b
movl %esi, %eax
cltd
idivl %r14d
incl %r9d
addl $0x9, %esi
cmpl $0x12, %esi
movl %eax, %esi
ja 0xedca
leal -0x1(%r9), %eax
cmpl %r8d, %eax
cmovll %r8d, %r9d
incq %r10
movl %r9d, %r8d
jmp 0xedb7
cmpl %r11d, %r15d
adcl $0x0, %r8d
pushq $0x64
popq %rsi
cmpl $0x64, %ecx
movq %r11, -0x58(%rbp)
jae 0xee0d
movsd 0xa9c5(%rip), %xmm0     # 0x197d0
jmp 0xee17
movl %ecx, %eax
xorl %edx, %edx
divl %esi
cvtsi2sd %eax, %xmm0
movsd %xmm0, -0x38(%rbp)
pushq $0x2b
popq %r14
pushq $0x2a
popq %r13
xorl %eax, %eax
movq %rdi, -0x70(%rbp)
movq %r15, -0x68(%rbp)
movl %r8d, -0x44(%rbp)
cmpq %r15, %rax
je 0xef08
movq %rax, -0x40(%rbp)
movq (%rdi,%rax,8), %r15
movq %r15, %r9
shrq $0x20, %r9
movl %r15d, %eax
cvtsi2sd %rax, %xmm0
movsd %xmm0, -0x30(%rbp)
movq %rbx, %rdi
leaq 0xb673(%rip), %rsi      # 0x1a4d4
leaq 0xb67f(%rip), %rdx      # 0x1a4e7
movq -0x50(%rbp), %rcx
xorl %eax, %eax
callq 0x2280
movsd -0x30(%rbp), %xmm0
divsd -0x38(%rbp), %xmm0
cvttsd2si %xmm0, %r12
cmpl $0x64, %r12d
pushq $0x64
popq %rax
cmovael %eax, %r12d
movsd %xmm0, -0x30(%rbp)
subl $0x1, %r12d
jb 0xeeaa
movl %r13d, %edi
movq %rbx, %rsi
callq 0x2210
movsd -0x30(%rbp), %xmm0
jmp 0xee92
xorl %r12d, %r12d
ucomisd 0xb0cb(%rip), %xmm0     # 0x19f80
jbe 0xeed6
divsd 0xb0c1(%rip), %xmm0     # 0x19f80
callq 0x2260
cvttsd2si %xmm0, %r12
jmp 0xeed6
movl %r14d, %edi
movq %rbx, %rsi
callq 0x2210
subl $0x1, %r12d
jae 0xeecb
movq %rbx, %rdi
leaq 0xb2fa(%rip), %rsi      # 0x1a1e0
movl %r15d, %edx
xorl %eax, %eax
callq 0x2280
movq -0x40(%rbp), %rax
incq %rax
movq -0x70(%rbp), %rdi
movq -0x68(%rbp), %r15
movl -0x44(%rbp), %r8d
jmp 0xee32
movq -0x58(%rbp), %rcx
cmpl %ecx, %r15d
jae 0xefee
leal -0x1(%r15), %eax
movl 0x4(%rdi,%rax,8), %r9d
xorpd %xmm0, %xmm0
movsd %xmm0, -0x30(%rbp)
pushq $0x64
popq %r12
cmpq %rcx, %r15
jae 0xef4c
movl (%rdi,%r15,8), %eax
cvtsi2sd %rax, %xmm0
movsd -0x30(%rbp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, -0x30(%rbp)
incq %r15
jmp 0xef2b
decl %r8d
leaq 0xb59b(%rip), %rsi      # 0x1a4f1
leaq 0xb58a(%rip), %rdx      # 0x1a4e7
movq %rbx, %rdi
movq -0x50(%rbp), %rcx
xorl %eax, %eax
callq 0x2280
movsd -0x30(%rbp), %xmm0
divsd -0x38(%rbp), %xmm0
cvttsd2si %xmm0, %rax
cmpl $0x64, %eax
cmovbl %eax, %r12d
pushq $0x2a
popq %r14
movsd %xmm0, -0x40(%rbp)
subl $0x1, %r12d
jb 0xefa2
movl %r14d, %edi
movq %rbx, %rsi
callq 0x2210
movsd -0x40(%rbp), %xmm0
jmp 0xef8a
xorl %r15d, %r15d
ucomisd 0xafd3(%rip), %xmm0     # 0x19f80
jbe 0xefc1
divsd 0xafc9(%rip), %xmm0     # 0x19f80
callq 0x2260
cvttsd2si %xmm0, %r15
pushq $0x2b
popq %r14
subl $0x1, %r15d
jb 0xefd8
movl %r14d, %edi
movq %rbx, %rsi
callq 0x2210
jmp 0xefc5
cvttsd2si -0x30(%rbp), %edx
leaq 0xb1fc(%rip), %rsi      # 0x1a1e0
movq %rbx, %rdi
xorl %eax, %eax
callq 0x2280
movq -0x60(%rbp), %rsp
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq