// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x110a0, %rsp          # imm = 0x110A0
movb %cl, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movsd %xmm0, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movb %al, -0x1d(%rbp)
movq $0x0, -0x11058(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl (%rcx), %eax
jae 0x4776
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x2c(%rbp), %ecx
imulq $0x58, %rcx, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
cmpq -0x11058(%rbp), %rax
jbe 0x4769
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x2c(%rbp), %ecx
imulq $0x58, %rcx, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq %rax, -0x11058(%rbp)
jmp 0x476b
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x4722
movq -0x11058(%rbp), %rdi
movl -0x1c(%rbp), %esi
callq 0x2aa0
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, %edi
movl $0x4, %esi
callq 0x2290
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x2db6b(%rip), %rsi     # 0x32311
callq 0x23f0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x47e3
movq 0x3483b(%rip), %rax     # 0x38ff8
movq (%rax), %rdi
movq -0x8(%rbp), %rcx
leaq 0x2ca05(%rip), %rsi     # 0x311d0
leaq 0x2ca27(%rip), %rdx     # 0x311f9
movb $0x0, %al
callq 0x22c0
movl $0x1, %edi
callq 0x24c0
movq -0x28(%rbp), %rcx
leaq -0x11090(%rbp), %rdi
movl $0x8, %esi
movl $0x1, %edx
callq 0x20f0
movl %eax, -0x30(%rbp)
cmpl $0x1, -0x30(%rbp)
je 0x480d
movb $0x0, %al
callq 0x2c00
movq -0x11090(%rbp), %rdi
callq 0x2bc0
cmpl $0x0, %eax
jne 0x4847
movq 0x347d3(%rip), %rax     # 0x38ff8
movq (%rax), %rdi
leaq 0x2c9e8(%rip), %rsi     # 0x31217
leaq 0x2c9c3(%rip), %rdx     # 0x311f9
movb $0x0, %al
callq 0x22c0
movl $0x1, %edi
callq 0x24c0
movq -0x28(%rbp), %rdi
callq 0x1bac0
movq -0x28(%rbp), %rcx
leaq -0x11070(%rbp), %rdi
movl $0x8, %esi
movl $0x1, %edx
callq 0x20f0
movl %eax, -0x30(%rbp)
cmpl $0x1, -0x30(%rbp)
je 0x487a
movb $0x0, %al
callq 0x2c00
movq $0x0, -0x11080(%rbp)
movq $0x0, -0x11078(%rbp)
movq -0x11078(%rbp), %rax
cmpq -0x11070(%rbp), %rax
jae 0x49f1
leaq -0x11050(%rbp), %rdi
movq -0x28(%rbp), %rcx
movl $0x1, %esi
movl $0x11000, %edx          # imm = 0x11000
callq 0x20f0
movl %eax, -0x30(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %ecx
xorl %eax, %eax
cmpl -0x30(%rbp), %ecx
movb %al, -0x11091(%rbp)
jae 0x48ef
movq -0x11078(%rbp), %rax
cmpq -0x11070(%rbp), %rax
setb %al
movb %al, -0x11091(%rbp)
movb -0x11091(%rbp), %al
testb $0x1, %al
jne 0x48fe
jmp 0x49ec
movl -0x2c(%rbp), %eax
movzbl -0x11040(%rbp,%rax), %eax
movzbl -0x1d(%rbp), %ecx
cmpl %ecx, %eax
jge 0x4916
jmp 0x49cc
movq -0x10(%rbp), %rdi
movl -0x2c(%rbp), %eax
movl -0x11050(%rbp,%rax), %esi
movl -0x2c(%rbp), %eax
movl -0x1104c(%rbp,%rax), %edx
leaq -0x34(%rbp), %rcx
leaq -0x11060(%rbp), %r8
xorl %r9d, %r9d
callq 0x19980
movq -0x10(%rbp), %rdi
movl -0x2c(%rbp), %eax
movl -0x11048(%rbp,%rax), %esi
movl -0x2c(%rbp), %eax
movl -0x11044(%rbp,%rax), %edx
leaq -0x38(%rbp), %rcx
leaq -0x11068(%rbp), %r8
xorl %r9d, %r9d
callq 0x19980
movl -0x34(%rbp), %eax
cmpl -0x38(%rbp), %eax
jne 0x49ca
cmpl $-0x1, -0x34(%rbp)
je 0x49ca
movq -0x48(%rbp), %rax
movq %rax, -0x110a0(%rbp)
movq -0x11060(%rbp), %rax
subq -0x11068(%rbp), %rax
movq %rax, %rcx
negq %rcx
cmovnsq %rcx, %rax
movl -0x1c(%rbp), %ecx
cqto
idivq %rcx
movq %rax, %rcx
movq -0x110a0(%rbp), %rax
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
movq -0x11080(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x11080(%rbp)
jmp 0x49cc
movl -0x2c(%rbp), %eax
addl $0x11, %eax
movl %eax, -0x2c(%rbp)
movq -0x11078(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x11078(%rbp)
jmp 0x48c8
jmp 0x4890
movq -0x28(%rbp), %rdi
callq 0x2150
movl $0x0, -0x2c(%rbp)
movq $0x0, -0x11088(%rbp)
movq -0x11088(%rbp), %xmm1
movaps 0x2c785(%rip), %xmm3    # 0x311a0
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
movapd 0x2c789(%rip), %xmm2    # 0x311b0
subpd %xmm2, %xmm1
movaps %xmm1, %xmm0
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm0, %xmm1
movq -0x11080(%rbp), %xmm0
punpckldq %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
subpd %xmm2, %xmm0
movaps %xmm0, %xmm2
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm2, %xmm0
mulsd -0x18(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x4a80
movq -0x48(%rbp), %rax
movl -0x2c(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x2c(%rbp)
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
addq -0x11088(%rbp), %rax
movq %rax, -0x11088(%rbp)
jmp 0x4a0c
movq -0x48(%rbp), %rdi
callq 0x2050
movl -0x2c(%rbp), %eax
imull -0x1c(%rbp), %eax
addq $0x110a0, %rsp          # imm = 0x110A0
popq %rbp
retq
nopl (%rax)