// File: /workspace/github_c_makefile_star2_O2/c-zhou[P]yahs/break.c
// Function: estimate_dist_thres_from_file
uint32_t estimate_dist_thres_from_file(const char *f, asm_dict_t *dict, double min_frac, uint32_t resolution, uint8_t mq)
{
    FILE *fp;
    uint32_t i, m, i0, i1, nb, *link_c;
    uint8_t buffer[BUFF_SIZE * 17];
    uint64_t max_len, p0, p1, pair_n, pair_c, intra_c, cum_c;
    int64_t magic_number;

    max_len = 0;
    for (i = 0; i < dict->n; ++i)
        if (dict->s[i].len > max_len)
            max_len = dict->s[i].len;
    nb = div_ceil(max_len, resolution);
    link_c = (uint32_t *) calloc(nb, sizeof(uint32_t));

    fp = fopen(f, "r");
    if (fp == NULL) {
        fprintf(stderr, "[E::%s] cannot open file %s for reading\n", __func__, f);
        exit(EXIT_FAILURE);
    }

    m = fread(&magic_number, sizeof(int64_t), 1, fp);
    if (m != 1) bin_fread_error();
    if (!is_valid_bin_header(magic_number)) {
        fprintf(stderr, "[E::%s] not a valid BIN file\n", __func__);
        exit(EXIT_FAILURE);
    }
    file_seek_skip_sdict(fp);
    m = fread(&pair_n, sizeof(uint64_t), 1, fp);
    if (m != 1) bin_fread_error();

    pair_c = intra_c = 0;
    while (pair_c < pair_n) {
        m = fread(buffer, sizeof(uint8_t), BUFF_SIZE * 17, fp);

        for (i = 0; i < m && pair_c < pair_n; i += 17, ++pair_c) {
            if (*(uint8_t *) (buffer + i + 16) < mq)
                continue;

            sd_coordinate_conversion(dict, *(uint32_t *) (buffer + i),     *(uint32_t *) (buffer + i + 4),  &i0, &p0, 0);
            sd_coordinate_conversion(dict, *(uint32_t *) (buffer + i + 8), *(uint32_t *) (buffer + i + 12), &i1, &p1, 0);

            if (i0 == i1 && i0 != UINT32_MAX) {
                ++link_c[labs((long) p0 - p1) / resolution];
                ++intra_c;
            }
        }
    }
    
    fclose(fp);
    
    i = 0;
    cum_c = 0;
    while (cum_c < intra_c * min_frac)
        cum_c += link_c[i++];
    free(link_c);

#ifdef DEBUG
    fprintf(stderr, "[DEBUG::%s] %lu read pairs processed, intra links: %lu \n", __func__, pair_c, intra_c);
#endif
    return i * resolution;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x11068, %rsp          # imm = 0x11068
movl %ecx, 0x14(%rsp)
movl %edx, %ebp
movsd %xmm0, 0x30(%rsp)
movq %rsi, %r15
movq %rdi, %rbx
movl (%rsi), %eax
imulq $0x58, %rax, %rax
xorl %ecx, %ecx
xorl %edi, %edi
cmpq %rcx, %rax
je 0x3643
movq 0x8(%r15), %rdx
movq 0x8(%rdx,%rcx), %rdx
cmpq %rdi, %rdx
cmovaq %rdx, %rdi
addq $0x58, %rcx
jmp 0x3628
movl %ebp, %esi
callq 0x28ff
movl %eax, %edi
pushq $0x4
popq %rsi
callq 0x2290
movq %rax, 0x8(%rsp)
leaq 0x1bcb1(%rip), %rsi     # 0x1f311
movq %rbx, %rdi
callq 0x23e0
testq %rax, %rax
je 0x3850
movq %rax, %r14
leaq 0x40(%rsp), %rdi
pushq $0x8
popq %rsi
pushq $0x1
popq %rdx
movq %rax, %rcx
callq 0x20f0
cmpl $0x1, %eax
je 0x3693
xorl %eax, %eax
callq 0x2986
movq 0x40(%rsp), %rdi
callq 0x2973
testl %eax, %eax
je 0x3874
movq %r14, %rdi
callq 0x11940
leaq 0x48(%rsp), %rdi
pushq $0x8
popq %rsi
pushq $0x1
popq %rdx
movq %r14, %rcx
callq 0x20f0
cmpl $0x1, %eax
je 0x36cc
xorl %eax, %eax
callq 0x2986
movq 0x48(%rsp), %rbx
movl %ebp, 0x10(%rsp)
movl %ebp, %eax
movq %rax, 0x38(%rsp)
xorl %r12d, %r12d
movq $0x0, 0x28(%rsp)
movq %r14, 0x20(%rsp)
cmpq %rbx, %r12
jae 0x37b7
movl $0x11000, %edx          # imm = 0x11000
leaq 0x60(%rsp), %rdi
pushq $0x1
popq %rsi
movq %r14, %rcx
callq 0x20f0
movq %rax, %r13
xorl %r14d, %r14d
cmpl %r13d, %r14d
jae 0x37ad
cmpq %rbx, %r12
jae 0x37ad
movl %r14d, %ebp
movl 0x14(%rsp), %eax
cmpb %al, 0x70(%rsp,%rbp)
jb 0x37a1
movl 0x60(%rsp,%rbp), %esi
movl 0x64(%rsp,%rbp), %edx
movq %r15, %rdi
leaq 0x1c(%rsp), %rcx
leaq 0x58(%rsp), %r8
xorl %r9d, %r9d
callq 0x100d2
movl 0x68(%rsp,%rbp), %esi
movl 0x6c(%rsp,%rbp), %edx
movq %r15, %rdi
leaq 0x18(%rsp), %rcx
leaq 0x50(%rsp), %r8
xorl %r9d, %r9d
callq 0x100d2
movl 0x1c(%rsp), %eax
cmpl $-0x1, %eax
je 0x37a1
cmpl 0x18(%rsp), %eax
jne 0x37a1
movq 0x58(%rsp), %rcx
subq 0x50(%rsp), %rcx
movq %rcx, %rax
negq %rax
cmovsq %rcx, %rax
xorl %edx, %edx
divq 0x38(%rsp)
movq 0x8(%rsp), %rcx
incl (%rcx,%rax,4)
incq 0x28(%rsp)
addl $0x11, %r14d
incq %r12
jmp 0x3711
movq 0x20(%rsp), %r14
jmp 0x36ed
movq %r14, %rdi
callq 0x2150
movsd 0x28(%rsp), %xmm1
unpcklps 0x1a9e4(%rip), %xmm1    # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x1a9ec(%rip), %xmm1    # 0x1e1c0
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x30(%rsp), %xmm0
xorl %ebx, %ebx
movq 0x1a9c0(%rip), %xmm1    # 0x1e1b0
movapd 0x1a9c8(%rip), %xmm2    # 0x1e1c0
xorl %eax, %eax
xorl %ecx, %ecx
movl 0x10(%rsp), %esi
movq 0x8(%rsp), %rdi
movq %rcx, %xmm3
punpckldq %xmm1, %xmm3    # xmm3 = xmm3[0],xmm1[0],xmm3[1],xmm1[1]
subpd %xmm2, %xmm3
movapd %xmm3, %xmm4
unpckhpd %xmm3, %xmm4            # xmm4 = xmm4[1],xmm3[1]
addsd %xmm3, %xmm4
ucomisd %xmm4, %xmm0
jbe 0x3832
movl %eax, %edx
incl %eax
movl (%rdi,%rdx,4), %edx
addq %rdx, %rcx
addl %esi, %ebx
jmp 0x3805
movq 0x8(%rsp), %rdi
callq 0x2060
movl %ebx, %eax
addq $0x11068, %rsp          # imm = 0x11068
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x247a1(%rip), %rax     # 0x27ff8
movq (%rax), %rdi
leaq 0x1a98f(%rip), %rsi     # 0x1e1f0
leaq 0x1a9b1(%rip), %rdx     # 0x1e219
movq %rbx, %rcx
xorl %eax, %eax
callq 0x22c0
jmp 0x3893
movq 0x2477d(%rip), %rax     # 0x27ff8
movq (%rax), %rdi
leaq 0x1a9b2(%rip), %rsi     # 0x1e237
leaq 0x1a98d(%rip), %rdx     # 0x1e219
xorl %eax, %eax
callq 0x22c0
pushq $0x1
popq %rdi
callq 0x24b0