// File: /workspace/github_c_makefile_star2_O0/c-zhou[P]yahs/enzyme.c
// Function: calc_re_cuts_density2
double **calc_re_cuts_density2(re_cuts_t *re_cuts, uint32_t resolution, asm_dict_t *dict)
{
    if (!re_cuts)
        return 0;

    uint32_t i, j, b, n, e, a;
    uint64_t l, p;
    double **dens, *ds;
    re_t re;
    sd_aseq_t seq;
    sd_seg_t seg;
    n = dict->n;
    dens = (double **) malloc(n * sizeof(double *));
    for (i = 0; i < n; ++i) {
        seq = dict->s[i];
        l = div_ceil(seq.len, 2); // split sequence into two parts
        b = div_ceil(l, resolution);
        ds = (double *) calloc(b << 1, sizeof(double));
        for (j = 0; j < seq.n; ++j) {
            seg = dict->seg[seq.s + j];
            re = re_cuts->re[seg.c >> 1]; // get seq re cuts
            e = seg.x + seg.y; // seq end position, exclusive
            // binary search to get starting re cuts
            // first cutting site no smaller than seg.x
            // not many seq breaks - linear search might be faster on average?
            a = bin_search(re.sites, re.n, seg.x);
            if (seg.c & 1) {
                // reverse complement
                while (a < re.n && re.sites[a] < e) {
                    p = seg.a + (seg.y - 1) - (re.sites[a] - seg.x); // position on seq
                    if (p < l)
                        ds[p / resolution << 1] += 1.;
                    else
                        ds[(seq.len - p - 1) / resolution << 1 | 1] += 1.;
                    ++a;
                }
            } else {
                while (a < re.n && re.sites[a] < e) {
                    p = seg.a + re.sites[a] - seg.x; // position on seq
                    if (p < l)
                        ds[p / resolution << 1] += 1.;
                    else
                        ds[(seq.len - p - 1) / resolution << 1 | 1] += 1.;
                    ++a;
                }
            }
        }
        for (j = 0; j < (b - 1) << 1; ++j)
            ds[j] /= (double) resolution * re_cuts->density;
        ds[(b - 1) << 1] /= ((double) l - (double) (b - 1) * resolution) * re_cuts->density;
        ds[(b - 1) << 1 | 1] /= ((double) l - (double) (b - 1) * resolution) * re_cuts->density;
        
        for (j = 0; j < b << 1; ++j)
            if (ds[j] < MIN_RE_DENS || ds[j] > MAX_RE_DENS)
                 ds[j] = .0;

        dens[i] = ds;
#ifdef DEBUG_ENZ
        fprintf(stderr, "[DEBUG_ENZ::%s] DENS2 [%u/%u] (%u):", __func__, i, n, b);
        for (j = 0; j < b << 1; ++j)
            fprintf(stderr, " %.6f", ds[j]);
        fprintf(stderr, "\n");
#endif

    }

    return dens;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x2a3aa
movq $0x0, -0x8(%rbp)
jmp 0x2a879
movq -0x20(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
movl %eax, %edi
shlq $0x3, %rdi
callq 0x2340
movq %rax, -0x50(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x30(%rbp), %eax
jae 0x2a871
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rsi
movl -0x24(%rbp), %eax
imulq $0x58, %rax, %rax
addq %rax, %rsi
leaq -0xc0(%rbp), %rdi
movl $0x58, %edx
callq 0x22e0
movq -0xb8(%rbp), %rdi
movl $0x2, %esi
callq 0x2aa0
movl %eax, %eax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x2aa0
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
shll %eax
movl %eax, %eax
movl %eax, %edi
movl $0x8, %esi
callq 0x2290
movq %rax, -0x58(%rbp)
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0xa8(%rbp), %eax
jae 0x2a6d5
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rsi
movl -0xa4(%rbp), %eax
addl -0x28(%rbp), %eax
movl %eax, %eax
imulq $0x30, %rax, %rax
addq %rax, %rsi
leaq -0xf0(%rbp), %rdi
movl $0x30, %edx
callq 0x22e0
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0xd8(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq %rcx, -0x68(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0x60(%rbp)
movl -0xd4(%rbp), %eax
addl -0xd0(%rbp), %eax
movl %eax, -0x34(%rbp)
movq -0x60(%rbp), %rdi
movl -0x64(%rbp), %esi
movl -0xd4(%rbp), %edx
callq 0x2a320
movl %eax, -0x38(%rbp)
movl -0xd8(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x2a5d6
jmp 0x2a4d9
movl -0x38(%rbp), %ecx
xorl %eax, %eax
cmpl -0x64(%rbp), %ecx
movb %al, -0xf1(%rbp)
jae 0x2a4ff
movq -0x60(%rbp), %rax
movl -0x38(%rbp), %ecx
movl (%rax,%rcx,4), %eax
cmpl -0x34(%rbp), %eax
setb %al
movb %al, -0xf1(%rbp)
movb -0xf1(%rbp), %al
testb $0x1, %al
jne 0x2a50e
jmp 0x2a5d1
movq -0xe8(%rbp), %rax
movl -0xd0(%rbp), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
addq %rcx, %rax
movq -0x60(%rbp), %rcx
movl -0x38(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
subl -0xd4(%rbp), %ecx
movl %ecx, %ecx
subq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
cmpq -0x40(%rbp), %rax
jae 0x2a57e
movq -0x58(%rbp), %rax
movq %rax, -0x100(%rbp)
movq -0x48(%rbp), %rax
movl -0x14(%rbp), %ecx
xorl %edx, %edx
divq %rcx
movq %rax, %rcx
movq -0x100(%rbp), %rax
shlq %rcx
movsd 0x7086(%rip), %xmm0     # 0x315f8
addsd (%rax,%rcx,8), %xmm0
movsd %xmm0, (%rax,%rcx,8)
jmp 0x2a5c3
movq -0x58(%rbp), %rax
movq %rax, -0x108(%rbp)
movq -0xb8(%rbp), %rax
subq -0x48(%rbp), %rax
subq $0x1, %rax
movl -0x14(%rbp), %ecx
xorl %edx, %edx
divq %rcx
movq %rax, %rcx
movq -0x108(%rbp), %rax
shlq %rcx
orq $0x1, %rcx
movsd 0x703f(%rip), %xmm0     # 0x315f8
addsd (%rax,%rcx,8), %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x2a4d9
jmp 0x2a6c5
jmp 0x2a5d8
movl -0x38(%rbp), %ecx
xorl %eax, %eax
cmpl -0x64(%rbp), %ecx
movb %al, -0x109(%rbp)
jae 0x2a5fe
movq -0x60(%rbp), %rax
movl -0x38(%rbp), %ecx
movl (%rax,%rcx,4), %eax
cmpl -0x34(%rbp), %eax
setb %al
movb %al, -0x109(%rbp)
movb -0x109(%rbp), %al
testb $0x1, %al
jne 0x2a60d
jmp 0x2a6c3
movq -0xe8(%rbp), %rax
movq -0x60(%rbp), %rcx
movl -0x38(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
addq %rcx, %rax
movl -0xd4(%rbp), %ecx
subq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
cmpq -0x40(%rbp), %rax
jae 0x2a670
movq -0x58(%rbp), %rax
movq %rax, -0x118(%rbp)
movq -0x48(%rbp), %rax
movl -0x14(%rbp), %ecx
xorl %edx, %edx
divq %rcx
movq %rax, %rcx
movq -0x118(%rbp), %rax
shlq %rcx
movsd 0x6f94(%rip), %xmm0     # 0x315f8
addsd (%rax,%rcx,8), %xmm0
movsd %xmm0, (%rax,%rcx,8)
jmp 0x2a6b5
movq -0x58(%rbp), %rax
movq %rax, -0x120(%rbp)
movq -0xb8(%rbp), %rax
subq -0x48(%rbp), %rax
subq $0x1, %rax
movl -0x14(%rbp), %ecx
xorl %edx, %edx
divq %rcx
movq %rax, %rcx
movq -0x120(%rbp), %rax
shlq %rcx
orq $0x1, %rcx
movsd 0x6f4d(%rip), %xmm0     # 0x315f8
addsd (%rax,%rcx,8), %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x2a5d8
jmp 0x2a6c5
jmp 0x2a6c7
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x2a43f
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
movl -0x2c(%rbp), %ecx
subl $0x1, %ecx
shll %ecx
cmpl %ecx, %eax
jae 0x2a71c
movl -0x14(%rbp), %eax
cvtsi2sd %rax, %xmm1
movq -0x10(%rbp), %rax
mulsd 0x8(%rax), %xmm1
movq -0x58(%rbp), %rax
movl -0x28(%rbp), %ecx
movsd (%rax,%rcx,8), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x2a6dc
movq -0x40(%rbp), %xmm3
movaps 0x6a78(%rip), %xmm2     # 0x311a0
punpckldq %xmm2, %xmm3    # xmm3 = xmm3[0],xmm2[0],xmm3[1],xmm2[1]
movapd 0x6a7c(%rip), %xmm1     # 0x311b0
subpd %xmm1, %xmm3
movaps %xmm3, %xmm0
unpckhpd %xmm3, %xmm3            # xmm3 = xmm3[1,1]
addsd %xmm0, %xmm3
movl -0x2c(%rbp), %edx
movl %edx, %eax
decl %eax
cvtsi2sd %rax, %xmm0
movl -0x14(%rbp), %eax
cvtsi2sd %rax, %xmm4
mulsd %xmm4, %xmm0
subsd %xmm0, %xmm3
movq -0x10(%rbp), %rax
movsd 0x8(%rax), %xmm0
mulsd %xmm0, %xmm3
movq -0x58(%rbp), %rax
movl %edx, %ecx
leal -0x2(%rcx,%rcx), %ecx
movsd (%rax,%rcx,8), %xmm0
divsd %xmm3, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movq -0x40(%rbp), %xmm0
punpckldq %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movl -0x2c(%rbp), %eax
decl %eax
cvtsi2sd %rax, %xmm1
movl -0x14(%rbp), %eax
cvtsi2sd %rax, %xmm2
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movq -0x10(%rbp), %rax
mulsd 0x8(%rax), %xmm1
movq -0x58(%rbp), %rax
movl -0x2c(%rbp), %ecx
subl $0x1, %ecx
shll %ecx
orl $0x1, %ecx
movl %ecx, %ecx
movsd (%rax,%rcx,8), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
movl -0x2c(%rbp), %ecx
shll %ecx
cmpl %ecx, %eax
jae 0x2a854
movq -0x58(%rbp), %rax
movl -0x28(%rbp), %ecx
movsd (%rax,%rcx,8), %xmm1
movsd 0xf1fc(%rip), %xmm0     # 0x39a18
ucomisd %xmm1, %xmm0
ja 0x2a838
movq -0x58(%rbp), %rax
movl -0x28(%rbp), %ecx
movsd (%rax,%rcx,8), %xmm0
ucomisd 0xf1ea(%rip), %xmm0     # 0x39a20
jbe 0x2a847
movq -0x58(%rbp), %rax
movl -0x28(%rbp), %ecx
xorps %xmm0, %xmm0
movsd %xmm0, (%rax,%rcx,8)
jmp 0x2a849
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x2a7fc
movq -0x58(%rbp), %rdx
movq -0x50(%rbp), %rax
movl -0x24(%rbp), %ecx
movq %rdx, (%rax,%rcx,8)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x2a3cc
movq -0x50(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
nopw %cs:(%rax,%rax)