// File: chhylp123[P]hifiasm/hic.cpp
// Function: get_trans_rate_function_advance(ha_ug_index*, kvec_pe_hit*, hc_links*, bubble_type*, H_partition*, signed char*, mc_gg_status*, trans_idx*)
int get_trans_rate_function_advance(ha_ug_index* idx, kvec_pe_hit* hits, hc_links* link, bubble_type* bub, 
H_partition* hap, int8_t *s, mc_gg_status *sa, trans_idx* dis)
{
    kvec_t(uint64_t) buf;
    kv_init(buf);
    uint64_t beg, end, cnt[2];
    uint64_t k, i, t_d, r_idx, f_idx, med = (uint64_t)-1;
    uint32_t is_s;
    // int beg_status, end_status;

    buf.n = 0;
    for (k = 0; k < hits->a.n; ++k) 
    {
        beg = ((hits->a.a[k].s<<1)>>(64 - idx->uID_bits));
        end = ((hits->a.a[k].e<<1)>>(64 - idx->uID_bits));

        if(IF_HOM(beg, *bub)) continue;
        if(IF_HOM(end, *bub)) continue;
        if(is_hom_hit(hits->a.a[k])) continue;


        t_d = get_hic_distance(&(hits->a.a[k]), link, idx, NULL);
        if(t_d == (uint64_t)-1) continue;
        // if(beg == end)
        // {
        //     t_d = (t_d << 1);
        // }
        // else
        // {
        //     beg_status = (hap? get_phase_status(hap, beg):s[beg]);
        //     if(beg_status != 1 && beg_status != -1) continue;
        //     end_status = (hap? get_phase_status(hap, end):s[end]);
        //     if(end_status != 1 && end_status != -1) continue;
        //     if(beg_status != end_status)
        //     {
        //         t_d = (t_d << 1) + 1; 
        //     }
        //     else
        //     {
        //         t_d = (t_d << 1);
        //     }            
        // }
        is_s = is_same_phase(beg, end, hap, s, sa);
        if(is_s == (uint32_t)-1) continue;
        t_d = (t_d << 1) + 1 - is_s;

        kv_push(uint64_t, buf, t_d); 
    }

    ///might have bias, we may not use right linkage larger than trans rc linkage
    radix_sort_hc64(buf.a, buf.a+buf.n);

    for (k = 0, r_idx = f_idx = (uint64_t)-1; k < buf.n; k++)
    {
        if((buf.a[k]&1) == 0) r_idx = k;
        if((buf.a[k]&1) == 1) f_idx = k;
    }
    buf.n = MIN(r_idx, f_idx);

    
    trans_p_t* p = NULL;
    dis->n = 0;
    uint64_t bin_size = MIN(2250, buf.n>>8), m;
    if(bin_size == 0)
    {
        for (i = 8; i > 0; i--)
        {
            bin_size = buf.n>>i;
            if(bin_size > 0) break;
        }
        if(bin_size == 0) bin_size = buf.n;
    }
    i = 0;
    while (i < buf.n)
    {
        kv_pushp(trans_p_t, *dis, &p);
        p->beg = i;

        cnt[0] = cnt[1] = 0;
        k = MIN(i+bin_size, buf.n);
        for (; i < k; i++)
        {
            cnt[buf.a[i]&1]++;
        }
        p->end = i;
        p->cnt_0 = cnt[0];
        p->cnt_1 = cnt[1];
    }

    i = m = 0; med = (uint64_t)-1;
    while(i < dis->n)
    {
        if(dis->a[i].cnt_0 > 0 && dis->a[i].cnt_1 > 0)
        {
            dis->a[m] = dis->a[i];
            m++;
            i++;
            continue;
        }

        if(med == (uint64_t)-1) med = buf.a[dis->a[i].beg]>>1;
        k = i; cnt[0] = cnt[1] = 0;
        for (; i < dis->n; i++)
        {
            cnt[0] += dis->a[i].cnt_0;
            cnt[1] += dis->a[i].cnt_1;
            if(cnt[0] > 0 && cnt[1] > 0) break;
        }

        if(i < dis->n)
        {
            dis->a[m].cnt_0 = cnt[0];
            dis->a[m].cnt_1 = cnt[1];
            dis->a[m].beg = dis->a[k].beg;
            dis->a[m].end = dis->a[i].end;
            m++;
            i++;
            continue;
        }

        cnt[0] -= dis->a[k].cnt_0;
        cnt[1] -= dis->a[k].cnt_1;
        while (1)
        {
            cnt[0] += dis->a[k].cnt_0;
            cnt[1] += dis->a[k].cnt_1;
            if(cnt[0] > 0 && cnt[1] > 0) break;

            if(k == 0)
            {
                k = (uint64_t)-1;
                break;
            } 
            k--;
        }

        if(k != (uint64_t)-1)
        {
            dis->a[m].cnt_0 = cnt[0];
            dis->a[m].cnt_1 = cnt[1];
            dis->a[m].end = dis->a[i-1].end;
            continue;
        }
        m = 0;
        break;
    }
    dis->n = m;
    if(dis->n == 0)
    {
        kv_destroy(buf);
        return 0;
    } 

    for (i = 0; i < dis->n; i++)
    {
        dis->a[i].beg = buf.a[dis->a[i].beg]>>1;
        dis->a[i].end = (buf.a[dis->a[i].end-1]>>1);
    }

    for (i = 0; i < dis->n - 1; i++)
    {
        dis->a[i].end += ((dis->a[i+1].beg - dis->a[i].end)/2);
        dis->a[i+1].beg = dis->a[i].end;
    }

    // for (i = 0; i < dis->n; i++)
    // {
    //     if(i > 0 && dis->a[i].beg != dis->a[i-1].end) fprintf(stderr, "ERROR: dis->a[i].beg: %lu, dis->a[i-1].end: %lu\n", dis->a[i].beg, dis->a[i-1].end);
    //     fprintf(stderr, "beg: %lu, end: %lu, cnt_0: %lu, cnt_1: %lu, error_rate: %f\n", 
    //     dis->a[i].beg, dis->a[i].end, dis->a[i].cnt_0, dis->a[i].cnt_1, (double)(dis->a[i].cnt_1)/(double)(dis->a[i].cnt_1 + dis->a[i].cnt_0));
    // }
    
    LeastSquare_advance(dis, idx, med);
    // fprintf(stderr, "idx->a: %f, idx->b: %f, idx->frac: %f, med: %lu\n", 
    // (double)idx->a, (double)idx->b, (double)idx->frac, med);

    dis->max = dis->a[dis->n-1].end;


    
    if(idx->a < 0) idx->a = 0;
    if(idx->a == 0)
    {
        idx->b = MAX((((double)(dis->a[dis->n-1].cnt_1))/((double)(dis->a[dis->n-1].cnt_0 + dis->a[dis->n-1].cnt_1))), idx->b);
    }
    if(idx->b < 0 && get_trans(idx, dis->max) < 0)
    {
        idx->b = ((double)(dis->a[dis->n-1].cnt_1))/((double)(dis->a[dis->n-1].cnt_0 + dis->a[dis->n-1].cnt_1));
    } 

    // fprintf(stderr, "idx->a: %f, idx->b: %f, idx->frac: %f, med: %lu\n", 
    // (double)idx->a, (double)idx->b, (double)idx->frac, med);





    buf.n = 0;
    for (k = 0; k < hits->a.n; ++k) 
    {
        beg = ((hits->a.a[k].s<<1)>>(64 - idx->uID_bits));
        end = ((hits->a.a[k].e<<1)>>(64 - idx->uID_bits));

        if(IF_HOM(beg, *bub)) continue;
        if(IF_HOM(end, *bub)) continue;
        if(is_hom_hit(hits->a.a[k])) continue;
        if(beg == end) continue;

        t_d = get_hic_distance(&(hits->a.a[k]), link, idx, NULL);
        if(t_d == (uint64_t)-1) continue;
        kv_push(uint64_t, buf, t_d); 
    }

    ///might have bias, we may not use right linkage larger than trans rc linkage
    radix_sort_hc64(buf.a, buf.a+buf.n);
    if(buf.n == 0)
    {
        dis->med = 0;
    }
    else
    {
        dis->med = ((buf.n&1)?buf.a[buf.n>>1]:((buf.a[buf.n>>1]+buf.a[(buf.n>>1)-1])/2));
    }

    // fprintf(stderr, "dis->med: %lu\n", dis->med);
    
    kv_destroy(buf);
    return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x50(%rbp)
movq $0x0, -0x40(%rbp)
movq $-0x1, -0xa0(%rbp)
movq $0x0, -0x50(%rbp)
movq $0x0, -0x78(%rbp)
movq -0x78(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x1ea6ec
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x78(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rax
shlq %rax
movq -0x10(%rbp), %rdx
movl $0x40, %ecx
subq 0x18(%rdx), %rcx
shrq %cl, %rax
movq %rax, -0x58(%rbp)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x78(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
shlq %rax
movq -0x10(%rbp), %rdx
movl $0x40, %ecx
subq 0x18(%rdx), %rcx
shrq %cl, %rax
movq %rax, -0x60(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq -0x58(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movq -0x28(%rbp), %rcx
movq 0x80(%rcx), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
jbe 0x1ea5a1
jmp 0x1ea6db
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq -0x60(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movq -0x28(%rbp), %rcx
movq 0x80(%rcx), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
jbe 0x1ea5c8
jmp 0x1ea6db
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x78(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
cmpq $-0x1, 0x10(%rax)
jne 0x1ea5e7
jmp 0x1ea6db
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x78(%rbp), %rax
shlq $0x5, %rax
addq %rax, %rdi
movq -0x20(%rbp), %rsi
movq -0x10(%rbp), %rdx
xorl %eax, %eax
movl %eax, %ecx
callq 0x1db730
movq %rax, -0x88(%rbp)
cmpq $-0x1, -0x88(%rbp)
jne 0x1ea621
jmp 0x1ea6db
movq -0x58(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq -0x38(%rbp), %rcx
movq 0x10(%rbp), %r8
callq 0x1ea340
movl %eax, -0xa4(%rbp)
cmpl $-0x1, -0xa4(%rbp)
jne 0x1ea64e
jmp 0x1ea6db
movq -0x88(%rbp), %rax
shlq %rax
addq $0x1, %rax
movl -0xa4(%rbp), %ecx
subq %rcx, %rax
movq %rax, -0x88(%rbp)
movq -0x50(%rbp), %rax
cmpq -0x48(%rbp), %rax
jne 0x1ea6bb
cmpq $0x0, -0x48(%rbp)
je 0x1ea68d
movq -0x48(%rbp), %rax
shlq %rax
movq %rax, -0xe0(%rbp)
jmp 0x1ea69b
movl $0x2, %eax
movq %rax, -0xe0(%rbp)
jmp 0x1ea69b
movq -0xe0(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rdi
movq -0x48(%rbp), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, -0x40(%rbp)
movq -0x88(%rbp), %rdx
movq -0x40(%rbp), %rax
movq -0x50(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x50(%rbp)
movq %rdx, (%rax,%rcx,8)
jmp 0x1ea6db
movq -0x78(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x78(%rbp)
jmp 0x1ea50e
movq -0x40(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x50(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rsi
callq 0x1ba0f0
movq $0x0, -0x78(%rbp)
movq $-0x1, -0x98(%rbp)
movq $-0x1, -0x90(%rbp)
movq -0x78(%rbp), %rax
cmpq -0x50(%rbp), %rax
jae 0x1ea77e
movq -0x40(%rbp), %rax
movq -0x78(%rbp), %rcx
movq (%rax,%rcx,8), %rax
andq $0x1, %rax
cmpq $0x0, %rax
jne 0x1ea74d
movq -0x78(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x40(%rbp), %rax
movq -0x78(%rbp), %rcx
movq (%rax,%rcx,8), %rax
andq $0x1, %rax
cmpq $0x1, %rax
jne 0x1ea76e
movq -0x78(%rbp), %rax
movq %rax, -0x98(%rbp)
jmp 0x1ea770
movq -0x78(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x78(%rbp)
jmp 0x1ea722
movq -0x90(%rbp), %rax
cmpq -0x98(%rbp), %rax
ja 0x1ea79e
movq -0x90(%rbp), %rax
movq %rax, -0xe8(%rbp)
jmp 0x1ea7ac
movq -0x98(%rbp), %rax
movq %rax, -0xe8(%rbp)
movq -0xe8(%rbp), %rax
movq %rax, -0x50(%rbp)
movq $0x0, -0xb0(%rbp)
movq 0x18(%rbp), %rax
movq $0x0, 0x8(%rax)
movq -0x50(%rbp), %rcx
shrq $0x8, %rcx
movl $0x8ca, %eax            # imm = 0x8CA
cmpq %rcx, %rax
ja 0x1ea7ee
movl $0x8ca, %eax            # imm = 0x8CA
movq %rax, -0xf0(%rbp)
jmp 0x1ea7fd
movq -0x50(%rbp), %rax
shrq $0x8, %rax
movq %rax, -0xf0(%rbp)
movq -0xf0(%rbp), %rax
movq %rax, -0xb8(%rbp)
cmpq $0x0, -0xb8(%rbp)
jne 0x1ea869
movq $0x8, -0x80(%rbp)
cmpq $0x0, -0x80(%rbp)
jbe 0x1ea852
movq -0x50(%rbp), %rax
movq -0x80(%rbp), %rcx
shrq %cl, %rax
movq %rax, -0xb8(%rbp)
cmpq $0x0, -0xb8(%rbp)
jbe 0x1ea842
jmp 0x1ea852
jmp 0x1ea844
movq -0x80(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x80(%rbp)
jmp 0x1ea81d
cmpq $0x0, -0xb8(%rbp)
jne 0x1ea867
movq -0x50(%rbp), %rax
movq %rax, -0xb8(%rbp)
jmp 0x1ea869
movq $0x0, -0x80(%rbp)
movq -0x80(%rbp), %rax
cmpq -0x50(%rbp), %rax
jae 0x1ea9d7
jmp 0x1ea881
movq 0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x18(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jne 0x1ea8ee
movq 0x18(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x1ea8b2
movq 0x18(%rbp), %rax
movq 0x10(%rax), %rax
shlq %rax
movq %rax, -0xf8(%rbp)
jmp 0x1ea8c0
movl $0x2, %eax
movq %rax, -0xf8(%rbp)
jmp 0x1ea8c0
movq -0xf8(%rbp), %rcx
movq 0x18(%rbp), %rax
movq %rcx, 0x10(%rax)
movq 0x18(%rbp), %rax
movq (%rax), %rdi
movq 0x18(%rbp), %rax
imulq $0x28, 0x10(%rax), %rsi
callq 0x2360
movq %rax, %rcx
movq 0x18(%rbp), %rax
movq %rcx, (%rax)
movq 0x18(%rbp), %rax
movq (%rax), %rax
movq 0x18(%rbp), %rdx
movq 0x8(%rdx), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, 0x8(%rdx)
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0xb0(%rbp)
movq -0x80(%rbp), %rcx
movq -0xb0(%rbp), %rax
movq %rcx, (%rax)
movq $0x0, -0x68(%rbp)
movq $0x0, -0x70(%rbp)
movq -0x80(%rbp), %rax
addq -0xb8(%rbp), %rax
cmpq -0x50(%rbp), %rax
ja 0x1ea959
movq -0x80(%rbp), %rax
addq -0xb8(%rbp), %rax
movq %rax, -0x100(%rbp)
jmp 0x1ea964
movq -0x50(%rbp), %rax
movq %rax, -0x100(%rbp)
movq -0x100(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x80(%rbp), %rax
cmpq -0x78(%rbp), %rax
jae 0x1ea9a5
movq -0x40(%rbp), %rax
movq -0x80(%rbp), %rcx
movq (%rax,%rcx,8), %rax
andq $0x1, %rax
movq -0x70(%rbp,%rax,8), %rcx
addq $0x1, %rcx
movq %rcx, -0x70(%rbp,%rax,8)
movq -0x80(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x80(%rbp)
jmp 0x1ea96f
movq -0x80(%rbp), %rcx
movq -0xb0(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x70(%rbp), %rcx
movq -0xb0(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x68(%rbp), %rcx
movq -0xb0(%rbp), %rax
movq %rcx, 0x20(%rax)
jmp 0x1ea871
movq $0x0, -0xc0(%rbp)
movq $0x0, -0x80(%rbp)
movq $-0x1, -0xa0(%rbp)
movq -0x80(%rbp), %rax
movq 0x18(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jae 0x1ead00
movq 0x18(%rbp), %rax
movq (%rax), %rax
imulq $0x28, -0x80(%rbp), %rcx
addq %rcx, %rax
cmpq $0x0, 0x18(%rax)
jbe 0x1eaa81
movq 0x18(%rbp), %rax
movq (%rax), %rax
imulq $0x28, -0x80(%rbp), %rcx
addq %rcx, %rax
cmpq $0x0, 0x20(%rax)
jbe 0x1eaa81
movq 0x18(%rbp), %rax
movq (%rax), %rsi
imulq $0x28, -0x80(%rbp), %rax
addq %rax, %rsi
movq 0x18(%rbp), %rax
movq (%rax), %rdi
imulq $0x28, -0xc0(%rbp), %rax
addq %rax, %rdi
movl $0x28, %edx
callq 0x2180
movq -0xc0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xc0(%rbp)
movq -0x80(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x80(%rbp)
jmp 0x1ea9f5
cmpq $-0x1, -0xa0(%rbp)
jne 0x1eaaaf
movq -0x40(%rbp), %rax
movq 0x18(%rbp), %rcx
movq (%rcx), %rcx
imulq $0x28, -0x80(%rbp), %rdx
addq %rdx, %rcx
movq (%rcx), %rcx
movq (%rax,%rcx,8), %rax
shrq %rax
movq %rax, -0xa0(%rbp)
movq -0x80(%rbp), %rax
movq %rax, -0x78(%rbp)
movq $0x0, -0x68(%rbp)
movq $0x0, -0x70(%rbp)
movq -0x80(%rbp), %rax
movq 0x18(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jae 0x1eab2b
movq 0x18(%rbp), %rax
movq (%rax), %rax
imulq $0x28, -0x80(%rbp), %rcx
addq %rcx, %rax
movq 0x18(%rax), %rax
addq -0x70(%rbp), %rax
movq %rax, -0x70(%rbp)
movq 0x18(%rbp), %rax
movq (%rax), %rax
imulq $0x28, -0x80(%rbp), %rcx
addq %rcx, %rax
movq 0x20(%rax), %rax
addq -0x68(%rbp), %rax
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x70(%rbp)
jbe 0x1eab1b
cmpq $0x0, -0x68(%rbp)
jbe 0x1eab1b
jmp 0x1eab2b
jmp 0x1eab1d
movq -0x80(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x80(%rbp)
jmp 0x1eaac7
movq -0x80(%rbp), %rax
movq 0x18(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jae 0x1eabe4
movq -0x70(%rbp), %rcx
movq 0x18(%rbp), %rax
movq (%rax), %rax
imulq $0x28, -0xc0(%rbp), %rdx
addq %rdx, %rax
movq %rcx, 0x18(%rax)
movq -0x68(%rbp), %rcx
movq 0x18(%rbp), %rax
movq (%rax), %rax
imulq $0x28, -0xc0(%rbp), %rdx
addq %rdx, %rax
movq %rcx, 0x20(%rax)
movq 0x18(%rbp), %rax
movq (%rax), %rax
imulq $0x28, -0x78(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq 0x18(%rbp), %rax
movq (%rax), %rax
imulq $0x28, -0xc0(%rbp), %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movq 0x18(%rbp), %rax
movq (%rax), %rax
imulq $0x28, -0x80(%rbp), %rcx
addq %rcx, %rax
movq 0x8(%rax), %rcx
movq 0x18(%rbp), %rax
movq (%rax), %rax
imulq $0x28, -0xc0(%rbp), %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movq -0xc0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xc0(%rbp)
movq -0x80(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x80(%rbp)
jmp 0x1ea9f5
movq 0x18(%rbp), %rax
movq (%rax), %rax
imulq $0x28, -0x78(%rbp), %rcx
addq %rcx, %rax
movq 0x18(%rax), %rcx
movq -0x70(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x70(%rbp)
movq 0x18(%rbp), %rax
movq (%rax), %rax
imulq $0x28, -0x78(%rbp), %rcx
addq %rcx, %rax
movq 0x20(%rax), %rcx
movq -0x68(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x68(%rbp)
movq 0x18(%rbp), %rax
movq (%rax), %rax
imulq $0x28, -0x78(%rbp), %rcx
addq %rcx, %rax
movq 0x18(%rax), %rax
addq -0x70(%rbp), %rax
movq %rax, -0x70(%rbp)
movq 0x18(%rbp), %rax
movq (%rax), %rax
imulq $0x28, -0x78(%rbp), %rcx
addq %rcx, %rax
movq 0x20(%rax), %rax
addq -0x68(%rbp), %rax
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x70(%rbp)
jbe 0x1eac66
cmpq $0x0, -0x68(%rbp)
jbe 0x1eac66
jmp 0x1eac85
cmpq $0x0, -0x78(%rbp)
jne 0x1eac77
movq $-0x1, -0x78(%rbp)
jmp 0x1eac85
movq -0x78(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x78(%rbp)
jmp 0x1eac20
cmpq $-0x1, -0x78(%rbp)
je 0x1eacf5
movq -0x70(%rbp), %rcx
movq 0x18(%rbp), %rax
movq (%rax), %rax
imulq $0x28, -0xc0(%rbp), %rdx
addq %rdx, %rax
movq %rcx, 0x18(%rax)
movq -0x68(%rbp), %rcx
movq 0x18(%rbp), %rax
movq (%rax), %rax
imulq $0x28, -0xc0(%rbp), %rdx
addq %rdx, %rax
movq %rcx, 0x20(%rax)
movq 0x18(%rbp), %rax
movq (%rax), %rax
movq -0x80(%rbp), %rcx
subq $0x1, %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rcx
movq 0x18(%rbp), %rax
movq (%rax), %rax
imulq $0x28, -0xc0(%rbp), %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
jmp 0x1ea9f5
movq $0x0, -0xc0(%rbp)
movq -0xc0(%rbp), %rcx
movq 0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
movq 0x18(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x1ead2f
movq -0x40(%rbp), %rdi
callq 0x2210
movl $0x0, -0x4(%rbp)
jmp 0x1eb2d8
movq $0x0, -0x80(%rbp)
movq -0x80(%rbp), %rax
movq 0x18(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jae 0x1eadb7
movq -0x40(%rbp), %rax
movq 0x18(%rbp), %rcx
movq (%rcx), %rcx
imulq $0x28, -0x80(%rbp), %rdx
addq %rdx, %rcx
movq (%rcx), %rcx
movq (%rax,%rcx,8), %rcx
shrq %rcx
movq 0x18(%rbp), %rax
movq (%rax), %rax
imulq $0x28, -0x80(%rbp), %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movq -0x40(%rbp), %rax
movq 0x18(%rbp), %rcx
movq (%rcx), %rcx
imulq $0x28, -0x80(%rbp), %rdx
addq %rdx, %rcx
movq 0x8(%rcx), %rcx
subq $0x1, %rcx
movq (%rax,%rcx,8), %rcx
shrq %rcx
movq 0x18(%rbp), %rax
movq (%rax), %rax
imulq $0x28, -0x80(%rbp), %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movq -0x80(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x80(%rbp)
jmp 0x1ead37
movq $0x0, -0x80(%rbp)
movq -0x80(%rbp), %rax
movq 0x18(%rbp), %rcx
movq 0x8(%rcx), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
jae 0x1eae5b
movq 0x18(%rbp), %rax
movq (%rax), %rax
movq -0x80(%rbp), %rcx
addq $0x1, %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq 0x18(%rbp), %rax
movq (%rax), %rax
imulq $0x28, -0x80(%rbp), %rdx
addq %rdx, %rax
subq 0x8(%rax), %rcx
shrq %rcx
movq 0x18(%rbp), %rax
movq (%rax), %rax
imulq $0x28, -0x80(%rbp), %rdx
addq %rdx, %rax
addq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq 0x18(%rbp), %rax
movq (%rax), %rax
imulq $0x28, -0x80(%rbp), %rcx
addq %rcx, %rax
movq 0x8(%rax), %rcx
movq 0x18(%rbp), %rax
movq (%rax), %rax
movq -0x80(%rbp), %rdx
addq $0x1, %rdx
imulq $0x28, %rdx, %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movq -0x80(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x80(%rbp)
jmp 0x1eadbf
movq 0x18(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0xa0(%rbp), %rdx
callq 0x1dba90
movq 0x18(%rbp), %rax
movq (%rax), %rcx
movq 0x8(%rax), %rdx
leaq (%rdx,%rdx,4), %rdx
movq -0x20(%rcx,%rdx,8), %rcx
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rax
fldt 0x80(%rax)
fldz
fucompi %st(1), %st
fstp %st(0)
jbe 0x1eaea7
jmp 0x1eae9b
movq -0x10(%rbp), %rax
fldz
fstpt 0x80(%rax)
movq -0x10(%rbp), %rax
fldt 0x80(%rax)
fldz
fxch %st(1)
fucompi %st(1), %st
fstp %st(0)
jne 0x1eafdd
jp 0x1eafdd
jmp 0x1eaec7
movq 0x18(%rbp), %rax
movq (%rax), %rcx
movq 0x8(%rax), %rax
leaq (%rax,%rax,4), %rdx
movq -0x10(%rcx,%rdx,8), %rax
movq -0x8(%rcx,%rdx,8), %rcx
movq %rcx, %xmm0
movaps 0x197124(%rip), %xmm3   # 0x382010
punpckldq %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
movapd 0x197128(%rip), %xmm2   # 0x382020
subpd %xmm2, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
addq %rcx, %rax
movq %rax, %xmm1
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0xc8(%rbp)
fldl -0xc8(%rbp)
movq -0x10(%rbp), %rax
fldt 0x90(%rax)
fxch %st(1)
fucompi %st(1), %st
fstp %st(0)
jb 0x1eafbd
jmp 0x1eaf48
movq 0x18(%rbp), %rax
movq (%rax), %rcx
movq 0x8(%rax), %rax
leaq (%rax,%rax,4), %rdx
movq -0x10(%rcx,%rdx,8), %rax
movq -0x8(%rcx,%rdx,8), %rcx
movq %rcx, %xmm0
movaps 0x1970a3(%rip), %xmm3   # 0x382010
punpckldq %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
movapd 0x1970a7(%rip), %xmm2   # 0x382020
subpd %xmm2, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
addq %rcx, %rax
movq %rax, %xmm1
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0xd0(%rbp)
fldl -0xd0(%rbp)
fstpt -0x10c(%rbp)
jmp 0x1eafcd
movq -0x10(%rbp), %rax
fldt 0x90(%rax)
fstpt -0x10c(%rbp)
fldt -0x10c(%rbp)
movq -0x10(%rbp), %rax
fstpt 0x90(%rax)
movq -0x10(%rbp), %rax
fldt 0x90(%rax)
fldz
fucompi %st(1), %st
fstp %st(0)
jbe 0x1eb089
jmp 0x1eaff5
movq -0x10(%rbp), %rdi
movq 0x18(%rbp), %rax
movq 0x18(%rax), %rsi
callq 0x214d00
movaps %xmm0, %xmm1
xorps %xmm0, %xmm0
ucomisd %xmm1, %xmm0
jbe 0x1eb089
movq 0x18(%rbp), %rax
movq (%rax), %rcx
movq 0x8(%rax), %rax
leaq (%rax,%rax,4), %rdx
movq -0x10(%rcx,%rdx,8), %rax
movq -0x8(%rcx,%rdx,8), %rcx
movq %rcx, %xmm0
movaps 0x196fd9(%rip), %xmm3   # 0x382010
punpckldq %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
movapd 0x196fdd(%rip), %xmm2   # 0x382020
subpd %xmm2, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
addq %rcx, %rax
movq %rax, %xmm1
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0xd8(%rbp)
fldl -0xd8(%rbp)
movq -0x10(%rbp), %rax
fstpt 0x90(%rax)
movq $0x0, -0x50(%rbp)
movq $0x0, -0x78(%rbp)
movq -0x78(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x1eb23a
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x78(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rax
shlq %rax
movq -0x10(%rbp), %rdx
movl $0x40, %ecx
subq 0x18(%rdx), %rcx
shrq %cl, %rax
movq %rax, -0x58(%rbp)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x78(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
shlq %rax
movq -0x10(%rbp), %rdx
movl $0x40, %ecx
subq 0x18(%rdx), %rcx
shrq %cl, %rax
movq %rax, -0x60(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq -0x58(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movq -0x28(%rbp), %rcx
movq 0x80(%rcx), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
jbe 0x1eb12c
jmp 0x1eb229
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq -0x60(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movq -0x28(%rbp), %rcx
movq 0x80(%rcx), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
jbe 0x1eb153
jmp 0x1eb229
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x78(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
cmpq $-0x1, 0x10(%rax)
jne 0x1eb172
jmp 0x1eb229
movq -0x58(%rbp), %rax
cmpq -0x60(%rbp), %rax
jne 0x1eb181
jmp 0x1eb229
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x78(%rbp), %rax
shlq $0x5, %rax
addq %rax, %rdi
movq -0x20(%rbp), %rsi
movq -0x10(%rbp), %rdx
xorl %eax, %eax
movl %eax, %ecx
callq 0x1db730
movq %rax, -0x88(%rbp)
cmpq $-0x1, -0x88(%rbp)
jne 0x1eb1b8
jmp 0x1eb229
jmp 0x1eb1ba
movq -0x50(%rbp), %rax
cmpq -0x48(%rbp), %rax
jne 0x1eb209
cmpq $0x0, -0x48(%rbp)
je 0x1eb1db
movq -0x48(%rbp), %rax
shlq %rax
movq %rax, -0x118(%rbp)
jmp 0x1eb1e9
movl $0x2, %eax
movq %rax, -0x118(%rbp)
jmp 0x1eb1e9
movq -0x118(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rdi
movq -0x48(%rbp), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, -0x40(%rbp)
movq -0x88(%rbp), %rdx
movq -0x40(%rbp), %rax
movq -0x50(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x50(%rbp)
movq %rdx, (%rax,%rcx,8)
jmp 0x1eb229
movq -0x78(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x78(%rbp)
jmp 0x1eb099
movq -0x40(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x50(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rsi
callq 0x1ba0f0
cmpq $0x0, -0x50(%rbp)
jne 0x1eb267
movq 0x18(%rbp), %rax
movq $0x0, 0x20(%rax)
jmp 0x1eb2c8
movq -0x50(%rbp), %rax
andq $0x1, %rax
cmpq $0x0, %rax
je 0x1eb28d
movq -0x40(%rbp), %rax
movq -0x50(%rbp), %rcx
shrq %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x120(%rbp)
jmp 0x1eb2b9
movq -0x40(%rbp), %rax
movq -0x50(%rbp), %rcx
shrq %rcx
movq (%rax,%rcx,8), %rax
movq -0x40(%rbp), %rcx
movq -0x50(%rbp), %rdx
shrq %rdx
subq $0x1, %rdx
addq (%rcx,%rdx,8), %rax
shrq %rax
movq %rax, -0x120(%rbp)
movq -0x120(%rbp), %rcx
movq 0x18(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x40(%rbp), %rdi
callq 0x2210
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
nopw %cs:(%rax,%rax)