// File: /workspace/github_c_makefile_star2_O0/c-zhou[P]yahs/enzyme.c
// Function: calc_re_cuts_density1
double **calc_re_cuts_density1(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;
    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];
        b = div_ceil(seq.len, resolution);
        ds = (double *) calloc(b, 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) {
                    ds[(seg.a + (seg.y - 1) - (re.sites[a] - seg.x)) / resolution] += 1.;
                    ++a;
                }
            } else {
                while (a < re.n && re.sites[a] < e) {
                    ds[(seg.a + re.sites[a] - seg.x) / resolution] += 1.;
                    ++a;
                }
            }
        }
        for (j = 0; j < b - 1; ++j)
            ds[j] /= (double) resolution * re_cuts->density;
        ds[b - 1] /= ((double) seq.len - (double) (b - 1) * resolution) * re_cuts->density;
        
        for (j = 0; j < b; ++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] DENS1 [%u/%u] (%u):", __func__, i, n, b);
        for (j = 0; j < b; ++j)
            fprintf(stderr, " %.6f", ds[j]);
        fprintf(stderr, "\n");
#endif
    }

    return dens;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x29f7a
movq $0x0, -0x8(%rbp)
jmp 0x2a312
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, -0x40(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x30(%rbp), %eax
jae 0x2a30a
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rsi
movl -0x24(%rbp), %eax
imulq $0x58, %rax, %rax
addq %rax, %rsi
leaq -0xb0(%rbp), %rdi
movl $0x58, %edx
callq 0x22e0
movq -0xa8(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x2aa0
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, %edi
movl $0x8, %esi
callq 0x2290
movq %rax, -0x48(%rbp)
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x98(%rbp), %eax
jae 0x2a1cf
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rsi
movl -0x94(%rbp), %eax
addl -0x28(%rbp), %eax
movl %eax, %eax
imulq $0x30, %rax, %rax
addq %rax, %rsi
leaq -0xe0(%rbp), %rdi
movl $0x30, %edx
callq 0x22e0
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0xc8(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq %rcx, -0x58(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0x50(%rbp)
movl -0xc4(%rbp), %eax
addl -0xc0(%rbp), %eax
movl %eax, -0x34(%rbp)
movq -0x50(%rbp), %rdi
movl -0x54(%rbp), %esi
movl -0xc4(%rbp), %edx
callq 0x2a320
movl %eax, -0x38(%rbp)
movl -0xc8(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x2a12f
jmp 0x2a091
movl -0x38(%rbp), %ecx
xorl %eax, %eax
cmpl -0x54(%rbp), %ecx
movb %al, -0xe1(%rbp)
jae 0x2a0b7
movq -0x50(%rbp), %rax
movl -0x38(%rbp), %ecx
movl (%rax,%rcx,4), %eax
cmpl -0x34(%rbp), %eax
setb %al
movb %al, -0xe1(%rbp)
movb -0xe1(%rbp), %al
testb $0x1, %al
jne 0x2a0c3
jmp 0x2a12a
movq -0x48(%rbp), %rax
movq %rax, -0xf0(%rbp)
movq -0xd8(%rbp), %rax
movl -0xc0(%rbp), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
addq %rcx, %rax
movq -0x50(%rbp), %rcx
movl -0x38(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
subl -0xc4(%rbp), %ecx
movl %ecx, %ecx
subq %rcx, %rax
movl -0x14(%rbp), %ecx
xorl %edx, %edx
divq %rcx
movq %rax, %rcx
movq -0xf0(%rbp), %rax
movsd 0x74e6(%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 0x2a091
jmp 0x2a1bf
jmp 0x2a131
movl -0x38(%rbp), %ecx
xorl %eax, %eax
cmpl -0x54(%rbp), %ecx
movb %al, -0xf1(%rbp)
jae 0x2a157
movq -0x50(%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 0x2a163
jmp 0x2a1bd
movq -0x48(%rbp), %rax
movq %rax, -0x100(%rbp)
movq -0xd8(%rbp), %rax
movq -0x50(%rbp), %rcx
movl -0x38(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
addq %rcx, %rax
movl -0xc4(%rbp), %ecx
subq %rcx, %rax
movl -0x14(%rbp), %ecx
xorl %edx, %edx
divq %rcx
movq %rax, %rcx
movq -0x100(%rbp), %rax
movsd 0x7453(%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 0x2a131
jmp 0x2a1bf
jmp 0x2a1c1
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x29ff7
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
movl -0x2c(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jae 0x2a214
movl -0x14(%rbp), %eax
cvtsi2sd %rax, %xmm1
movq -0x10(%rbp), %rax
mulsd 0x8(%rax), %xmm1
movq -0x48(%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 0x2a1d6
movaps 0x6f85(%rip), %xmm1     # 0x311a0
movq -0xa8(%rbp), %xmm0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x6f81(%rip), %xmm1     # 0x311b0
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 -0x48(%rbp), %rax
movl -0x2c(%rbp), %ecx
subl $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
cmpl -0x2c(%rbp), %eax
jae 0x2a2ed
movq -0x48(%rbp), %rax
movl -0x28(%rbp), %ecx
movsd (%rax,%rcx,8), %xmm1
movsd 0xf763(%rip), %xmm0     # 0x39a18
ucomisd %xmm1, %xmm0
ja 0x2a2d1
movq -0x48(%rbp), %rax
movl -0x28(%rbp), %ecx
movsd (%rax,%rcx,8), %xmm0
ucomisd 0xf751(%rip), %xmm0     # 0x39a20
jbe 0x2a2e0
movq -0x48(%rbp), %rax
movl -0x28(%rbp), %ecx
xorps %xmm0, %xmm0
movsd %xmm0, (%rax,%rcx,8)
jmp 0x2a2e2
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x2a299
movq -0x48(%rbp), %rdx
movq -0x40(%rbp), %rax
movl -0x24(%rbp), %ecx
movq %rdx, (%rax,%rcx,8)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x29f9c
movq -0x40(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
nop