// File: /workspace/github_c_makefile_star2_O1/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 $0x11078, %rsp          # imm = 0x11078
movl %ecx, 0x20(%rsp)
movl %edx, %ebp
movq %rsi, %r15
movq %rdi, %rbx
movl (%rsi), %ecx
testq %rcx, %rcx
movsd %xmm0, 0x38(%rsp)
je 0x58f1
movq 0x8(%r15), %rax
imulq $0x58, %rcx, %rcx
xorl %edx, %edx
xorl %edi, %edi
movq 0x8(%rax,%rdx), %rsi
cmpq %rdi, %rsi
cmovaq %rsi, %rdi
addq $0x58, %rdx
cmpq %rdx, %rcx
jne 0x58da
jmp 0x58f3
xorl %edi, %edi
movl %ebp, %esi
callq 0x4bf1
movl %eax, %edi
movl $0x4, %esi
callq 0x2290
movq %rax, %r14
leaq 0x1caff(%rip), %rsi     # 0x2240f
movq %rbx, %rdi
callq 0x23e0
testq %rax, %rax
je 0x5b32
movq %rax, %r12
leaq 0x50(%rsp), %rdi
movl $0x8, %esi
movl $0x1, %edx
movq %rax, %rcx
callq 0x20f0
cmpl $0x1, %eax
je 0x5947
xorl %eax, %eax
callq 0x4c81
movq 0x50(%rsp), %rdi
callq 0x4c6e
testl %eax, %eax
je 0x5b3a
movq %r12, %rdi
callq 0x15804
leaq 0x58(%rsp), %rdi
movl $0x8, %esi
movl $0x1, %edx
movq %r12, %rcx
callq 0x20f0
cmpl $0x1, %eax
je 0x5984
xorl %eax, %eax
callq 0x4c81
movq 0x58(%rsp), %r13
xorpd %xmm1, %xmm1
testq %r13, %r13
je 0x5aaf
movq %r14, 0x18(%rsp)
movl %ebp, 0x4(%rsp)
movl %ebp, %eax
movq %rax, 0x48(%rsp)
movq $0x0, 0x10(%rsp)
xorl %r14d, %r14d
movq %r12, 0x40(%rsp)
movl $0x1, %esi
movl $0x11000, %edx          # imm = 0x11000
leaq 0x70(%rsp), %rdi
movq %r12, %rcx
callq 0x20f0
movq %rax, %rbx
testl %ebx, %ebx
je 0x5a77
movl $0x11, %r12d
leal -0x11(%r12), %ebp
movl 0x20(%rsp), %eax
cmpb %al, 0x80(%rsp,%rbp)
jb 0x5a62
movl 0x70(%rsp,%rbp), %esi
movl 0x74(%rsp,%rbp), %edx
movq %r15, %rdi
leaq 0xc(%rsp), %rcx
leaq 0x68(%rsp), %r8
xorl %r9d, %r9d
callq 0x13d50
movl 0x78(%rsp,%rbp), %esi
movl 0x7c(%rsp,%rbp), %edx
movq %r15, %rdi
leaq 0x8(%rsp), %rcx
leaq 0x60(%rsp), %r8
xorl %r9d, %r9d
callq 0x13d50
movl 0xc(%rsp), %eax
cmpl $-0x1, %eax
je 0x5a62
cmpl 0x8(%rsp), %eax
jne 0x5a62
movq 0x68(%rsp), %rcx
subq 0x60(%rsp), %rcx
movq %rcx, %rax
negq %rax
cmovsq %rcx, %rax
xorl %edx, %edx
divq 0x48(%rsp)
movq 0x18(%rsp), %rcx
incl (%rcx,%rax,4)
incq 0x10(%rsp)
incq %r14
cmpl %ebx, %r12d
jae 0x5a77
addl $0x11, %r12d
cmpq %r13, %r14
jb 0x59df
cmpq %r13, %r14
movq 0x40(%rsp), %r12
jb 0x59b7
movsd 0x10(%rsp), %xmm0
unpcklps 0x1b72e(%rip), %xmm0    # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x1b736(%rip), %xmm0    # 0x211d0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movl 0x4(%rsp), %ebp
movq 0x18(%rsp), %r14
movapd %xmm1, 0x20(%rsp)
movq %r12, %rdi
callq 0x2150
movapd 0x20(%rsp), %xmm4
mulsd 0x38(%rsp), %xmm4
xorl %ebx, %ebx
ucomisd 0x1b71d(%rip), %xmm4    # 0x211f0
jbe 0x5b13
xorl %eax, %eax
movq 0x1b6e1(%rip), %xmm0    # 0x211c0
movapd 0x1b6e9(%rip), %xmm1    # 0x211d0
xorl %ebx, %ebx
movl %ebx, %ecx
incl %ebx
movl (%r14,%rcx,4), %ecx
addq %rcx, %rax
movq %rax, %xmm2
punpckldq %xmm0, %xmm2    # xmm2 = xmm2[0],xmm0[0],xmm2[1],xmm0[1]
subpd %xmm1, %xmm2
movapd %xmm2, %xmm3
unpckhpd %xmm2, %xmm3            # xmm3 = xmm3[1],xmm2[1]
addsd %xmm2, %xmm3
ucomisd %xmm3, %xmm4
ja 0x5ae9
movq %r14, %rdi
callq 0x2060
imull %ebp, %ebx
movl %ebx, %eax
addq $0x11078, %rsp          # imm = 0x11078
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
callq 0x2746
callq 0x271e