// File: /workspace/github_c_makefile_star2_O1/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, -0x38(%rbp)
cmpl $0x5, %esi
jb 0x1229c
movq %rcx, %rbx
movq %rsp, %r9
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
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, %r11
jne 0x11fc6
mulsd 0xb7f0(%rip), %xmm0     # 0x1d7d8
xorpd %xmm1, %xmm1
xorl %r14d, %r14d
movapd %xmm1, %xmm2
movl (%rax,%r14,4), %ecx
xorps %xmm1, %xmm1
cvtsi2sd %rcx, %xmm1
addsd %xmm2, %xmm1
ucomisd %xmm0, %xmm1
jae 0x12016
incq %r14
cmpq %r14, %r11
jne 0x11fef
xorl %r14d, %r14d
jmp 0x12019
incl %r14d
xorl %r12d, %r12d
movl %r14d, %r15d
movl $0x0, %ecx
testl %r14d, %r14d
je 0x1203f
xorl %edx, %edx
xorl %esi, %esi
movl (%rax,%rdx,4), %ecx
cmpl %ecx, %esi
cmoval %esi, %ecx
incq %rdx
movl %ecx, %esi
cmpq %rdx, %r15
jne 0x1202d
testl %r14d, %r14d
je 0x12090
xorl %eax, %eax
xorl %edx, %edx
movl 0x4(%rdi,%rax,8), %esi
xorl %r12d, %r12d
testl %esi, %esi
setle %r12b
movslq %esi, %r10
imulq $0x66666667, %r10, %rsi # imm = 0x66666667
movq %rsi, %r8
shrq $0x3f, %r8
sarq $0x22, %rsi
addl %r8d, %esi
incl %r12d
addl $0x9, %r10d
cmpl $0x12, %r10d
ja 0x12055
leal -0x1(%r12), %esi
cmpl %edx, %esi
cmovll %edx, %r12d
incq %rax
movl %r12d, %edx
cmpq %r15, %rax
jne 0x12048
cmpl %r11d, %r14d
adcl $0x0, %r12d
cmpl $0x64, %ecx
movq %r9, -0x58(%rbp)
movq %r11, -0x50(%rbp)
jae 0x120ae
movsd 0xb724(%rip), %xmm0     # 0x1d7d0
jmp 0x120c2
movl %ecx, %eax
imulq $0x51eb851f, %rax, %rax # imm = 0x51EB851F
shrq $0x25, %rax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd %xmm0, -0x40(%rbp)
movq %r14, -0x48(%rbp)
testl %r14d, %r14d
je 0x121b3
xorl %r13d, %r13d
movq %rdi, -0x68(%rbp)
movq %r15, -0x60(%rbp)
movq (%rdi,%r13,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 0xc388(%rip), %rsi      # 0x1e48c
leaq 0xc394(%rip), %rdx      # 0x1e49f
movq -0x38(%rbp), %rcx
movl %r12d, %r8d
xorl %eax, %eax
callq 0x2290
movsd -0x30(%rbp), %xmm0
divsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
cvttsd2si %xmm0, %rax
cmpl $0x64, %eax
movl $0x64, %r15d
cmovbl %eax, %r15d
testl %eax, %eax
je 0x12150
movl $0x2a, %edi
movq %rbx, %rsi
callq 0x2210
decl %r15d
jne 0x1213e
xorl %r15d, %r15d
movsd -0x30(%rbp), %xmm0
ucomisd 0xbdd0(%rip), %xmm0     # 0x1df30
jbe 0x12174
divsd 0xbdc6(%rip), %xmm0     # 0x1df30
callq 0x2270
cvttsd2si %xmm0, %r15
testl %r15d, %r15d
je 0x1218b
movl $0x2b, %edi
movq %rbx, %rsi
callq 0x2210
decl %r15d
jne 0x12179
movq %rbx, %rdi
leaq 0xc003(%rip), %rsi      # 0x1e198
movl %r14d, %edx
xorl %eax, %eax
callq 0x2290
incq %r13
movq -0x60(%rbp), %r15
cmpq %r15, %r13
movq -0x68(%rbp), %rdi
jne 0x120df
movq -0x50(%rbp), %rcx
movq -0x48(%rbp), %rax
cmpl %ecx, %eax
movq -0x58(%rbp), %r13
jae 0x12299
decl %eax
movl 0x4(%rdi,%rax,8), %r9d
xorpd %xmm1, %xmm1
movl (%rdi,%r15,8), %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
addsd %xmm0, %xmm1
incq %r15
cmpq %r15, %rcx
jne 0x121d2
decl %r12d
leaq 0xc2b5(%rip), %rsi      # 0x1e4a9
leaq 0xc2a4(%rip), %rdx      # 0x1e49f
xorl %r14d, %r14d
movq %rbx, %rdi
movq -0x38(%rbp), %rcx
movl %r12d, %r8d
xorl %eax, %eax
movsd %xmm1, -0x30(%rbp)
callq 0x2290
movsd -0x30(%rbp), %xmm0
divsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
cvttsd2si %xmm0, %rax
cmpl $0x64, %eax
movl $0x64, %r15d
cmovbl %eax, %r15d
testl %eax, %eax
je 0x1224b
movl $0x2a, %edi
movq %rbx, %rsi
callq 0x2210
decl %r15d
jne 0x12239
movsd -0x38(%rbp), %xmm0
ucomisd 0xbcd8(%rip), %xmm0     # 0x1df30
jbe 0x1226c
divsd 0xbcce(%rip), %xmm0     # 0x1df30
callq 0x2270
cvttsd2si %xmm0, %r14
testl %r14d, %r14d
je 0x12283
movl $0x2b, %edi
movq %rbx, %rsi
callq 0x2210
decl %r14d
jne 0x12271
cvttsd2si -0x30(%rbp), %edx
leaq 0xbf09(%rip), %rsi      # 0x1e198
movq %rbx, %rdi
xorl %eax, %eax
callq 0x2290
movq %r13, %rsp
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop