// File: chhylp123[P]hifiasm/gfa_ut.cpp
// Function: ul_dp0(bubble_type*, asg_t*, path_dp_t*, double)
int64_t ul_dp0(bubble_type* bub, asg_t *g, path_dp_t *dp, double pass_thres/**, uint64_t is_debug**/)
{
    if(dp->pat.n < 2 || dp->ref.n < 2) return -1;
    uint64_t i, j, d, w; int64_t sc0, sc1, sc2, sc, sc_i, sc_j;
    init_ul_dp(g, dp);
    // if(is_debug) {
    //     print_dp_matrix(dp);
    // }
    for (i = 1; i < dp->n; i++) {//pat
        for (j = 1; j < dp->m; j++) {//mat
            w = node_check(((uint32_t)dp->pat.a[i-1]), ((uint32_t)dp->ref.a[j-1]), 
                        dp->pat.a[i-1]>>32, dp->ref.a[j-1]>>32, 0.04, g->seq[((uint32_t)dp->pat.a[i-1])>>1].len);

            if(w) {
                // if(is_debug) fprintf(stderr, "\n[M::%s::] i::%lu, j::%lu, w::%lu\n", __func__, i, j, w);
                dp->m_score.a[ul_dp_idx(*dp, i, j)] = dp->m_score.a[ul_dp_idx(*dp, i-1, j-1)] + w;
                dp->m_dir.a[ul_dp_idx(*dp, i, j)] = e_mdp;
            } else {
                sc0 = dp->m_score.a[ul_dp_idx(*dp, i-1, j-1)] - 
                        (int64_t)(MIN(g->seq[((uint32_t)dp->pat.a[i-1])>>1].len, g->seq[((uint32_t)dp->ref.a[j-1])>>1].len));
                sc1 = dp->m_score.a[ul_dp_idx(*dp, i-1, j)] - (int64_t)(g->seq[((uint32_t)dp->ref.a[j-1])>>1].len);
                sc2 = dp->m_score.a[ul_dp_idx(*dp, i, j-1)] - (int64_t)(g->seq[((uint32_t)dp->pat.a[i-1])>>1].len);

                d = ue_mdp; sc = sc0;
                if(sc < sc1) {
                    sc = sc1; d = lref_dp;
                }
                if(sc < sc2) {
                    sc = sc2; d = lpat_dp;
                }
                dp->m_score.a[ul_dp_idx(*dp, i, j)] = sc;
                dp->m_dir.a[ul_dp_idx(*dp, i, j)] = d;
            }
        }
    }

    sc = 0; sc_i = sc_j = -1;
    for (j = 1, i = dp->n - 1; j < dp->m; j++) {
        if(sc_i < 0 || sc < dp->m_score.a[ul_dp_idx(*dp, i, j)]) {
            sc_i = i; sc_j = j; sc = dp->m_score.a[ul_dp_idx(*dp, i, j)];
        }
    }
    for (i = 1, j = dp->m - 1; i < dp->n; i++) {
        if(sc_i < 0 || sc < dp->m_score.a[ul_dp_idx(*dp, i, j)]) {
            sc_i = i; sc_j = j; sc = dp->m_score.a[ul_dp_idx(*dp, i, j)];
        }
    }

    // if(is_debug) {
    //     fprintf(stderr, "[M::%s::] sc_i::%ld, sc_j::%ld, sc::%ld\n", __func__, sc_i, sc_j, sc);
    //     // print_dp_matrix(dp);
    // }

    if (sc_i < 0 || sc_i == 1 || sc_j == 1) return 0;
    int64_t match_all = 0, unmatch_all = 0, het_match_all = 0, het_unmatch_all = 0, het_occ = 0;
    //pat_s = sc_i - 1; ref_s = ref_e = sc_j - 1;
    for(i = sc_i, j = sc_j; i > 0 && j > 0;) {
        d = dp->m_dir.a[ul_dp_idx(*dp, i, j)];
        //pat_s = i - 1; ref_s = j - 1;
        // if(is_debug) fprintf(stderr, "[M::%s::] i::%lu, j::%lu, dir::%lu\n", __func__, i, j, d);
        // if(pat_s == 0) continue;
        if(d == e_mdp) {
            // if(i != 1 || j != 1) {//skip (i == 1 && j == 1)
            match_all += g->seq[((uint32_t)dp->pat.a[i-1])>>1].len;
            if(!IF_HOM((((uint32_t)dp->pat.a[i-1])>>1), *bub)) {
                het_match_all += g->seq[((uint32_t)dp->pat.a[i-1])>>1].len;
                het_occ++;
            }
            i--; j--; 
            // if(is_debug) {
            //     fprintf(stderr, "[M::%s::] PAT::utg%.6dl(%c::len->%lu), REF::utg%.6dl(%c::len->%lu)\n", __func__, 
            //         ((((uint32_t)dp->pat.a[i])>>1))+1, "+-"[((uint32_t)dp->pat.a[i])&1], dp->pat.a[i]>>32,
            //         ((((uint32_t)dp->ref.a[j])>>1))+1, "+-"[((uint32_t)dp->ref.a[j])&1], dp->ref.a[j]>>32);
            // }
        }
        if(d == ue_mdp) {
            unmatch_all += g->seq[((uint32_t)dp->pat.a[i-1])>>1].len;
            if(!IF_HOM((((uint32_t)dp->pat.a[i-1])>>1), *bub)) {
                het_unmatch_all += g->seq[((uint32_t)dp->pat.a[i-1])>>1].len;
            }
            i--; j--;
        }
        if(d == lpat_dp) {
            j--;
        }
        if(d == lref_dp) {
            unmatch_all += g->seq[((uint32_t)dp->pat.a[i-1])>>1].len;
            if(!IF_HOM((((uint32_t)dp->pat.a[i-1])>>1), *bub)) {
                het_unmatch_all += g->seq[((uint32_t)dp->pat.a[i-1])>>1].len;
            }
            i--;
        }
    }
    // if(is_debug) {
    //     fprintf(stderr, "[M::%s::] het_occ::%ld, match_all::%ld, unmatch_all::%ld, het_match_all::%ld, het_unmatch_all::%ld\n", __func__, 
    //     het_occ, match_all, unmatch_all, het_match_all, het_unmatch_all);
    // }

    assert((j == 0) && (((uint32_t)dp->pat.a[i]) == ((uint32_t)dp->ref.a[j])));
    ///skip the beg node
    match_all -= g->seq[((uint32_t)dp->pat.a[i])>>1].len;
    if(!IF_HOM((((uint32_t)dp->pat.a[i])>>1), *bub)) {
        het_match_all -= g->seq[((uint32_t)dp->pat.a[i])>>1].len; het_occ--;
    }


    if(het_occ < 1 || match_all == 0 || het_match_all == 0) return -1;
    if(match_all <= (match_all + unmatch_all)*pass_thres) return -1;
    if(het_match_all <= (het_match_all + het_unmatch_all)*pass_thres) return -1;
    return (((double)het_match_all)/((double)(het_match_all + het_unmatch_all)))*
                            (((uint32_t)dp->pat_cor.a[i]) - (dp->pat_cor.a[i]>>32));
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movsd %xmm0, -0x28(%rbp)
movq -0x20(%rbp), %rax
cmpq $0x2, 0x18(%rax)
jb 0x324c81
movq -0x20(%rbp), %rax
cmpq $0x2, (%rax)
jae 0x324c8e
movq $-0x1, -0x8(%rbp)
jmp 0x3256ff
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x324680
movq $0x1, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq -0x20(%rbp), %rcx
cmpq 0x90(%rcx), %rax
jae 0x325066
movq $0x1, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x20(%rbp), %rcx
cmpq 0x98(%rcx), %rax
jae 0x325053
movq -0x20(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x30(%rbp), %rcx
subq $0x1, %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %edi
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x38(%rbp), %rcx
subq $0x1, %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %esi
movq -0x20(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x30(%rbp), %rcx
subq $0x1, %rcx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movl %eax, %edx
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x38(%rbp), %rcx
subq $0x1, %rcx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x20(%rbp), %r8
movq 0x28(%r8), %r8
movq -0x30(%rbp), %r9
subq $0x1, %r9
movq (%r8,%r9,8), %r8
shrl %r8d
movl %r8d, %r8d
movl (%rax,%r8,8), %r8d
andl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
movsd 0x5a2c6(%rip), %xmm0    # 0x37f030
callq 0x324a90
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
je 0x324df7
movq -0x20(%rbp), %rax
movq 0x88(%rax), %rax
movq -0x20(%rbp), %rcx
movq 0x98(%rcx), %rcx
movq -0x30(%rbp), %rdx
subq $0x1, %rdx
imulq %rdx, %rcx
movq -0x38(%rbp), %rdx
subq $0x1, %rdx
addq %rdx, %rcx
movq (%rax,%rcx,8), %rdx
addq -0x48(%rbp), %rdx
movq -0x20(%rbp), %rax
movq 0x88(%rax), %rax
movq -0x20(%rbp), %rcx
movq 0x98(%rcx), %rcx
imulq -0x30(%rbp), %rcx
addq -0x38(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x20(%rbp), %rax
movq 0x70(%rax), %rax
movq -0x20(%rbp), %rcx
movq 0x98(%rcx), %rcx
imulq -0x30(%rbp), %rcx
addq -0x38(%rbp), %rcx
movb $0x0, (%rax,%rcx)
jmp 0x325040
movq -0x20(%rbp), %rax
movq 0x88(%rax), %rax
movq -0x20(%rbp), %rcx
movq 0x98(%rcx), %rcx
movq -0x30(%rbp), %rdx
subq $0x1, %rdx
imulq %rdx, %rcx
movq -0x38(%rbp), %rdx
subq $0x1, %rdx
addq %rdx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0xa8(%rbp)
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x20(%rbp), %rcx
movq 0x28(%rcx), %rcx
movq -0x30(%rbp), %rdx
subq $0x1, %rdx
movq (%rcx,%rdx,8), %rcx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq -0x18(%rbp), %rcx
movq 0x20(%rcx), %rcx
movq -0x20(%rbp), %rdx
movq 0x10(%rdx), %rdx
movq -0x38(%rbp), %rsi
subq $0x1, %rsi
movq (%rdx,%rsi,8), %rdx
shrl %edx
movl %edx, %edx
movl (%rcx,%rdx,8), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl %ecx, %eax
jg 0x324eb4
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x20(%rbp), %rcx
movq 0x28(%rcx), %rcx
movq -0x30(%rbp), %rdx
subq $0x1, %rdx
movq (%rcx,%rdx,8), %rcx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, -0xac(%rbp)
jmp 0x324ee2
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x20(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq -0x38(%rbp), %rdx
subq $0x1, %rdx
movq (%rcx,%rdx,8), %rcx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, -0xac(%rbp)
movq -0xa8(%rbp), %rax
movl -0xac(%rbp), %ecx
movl %ecx, %ecx
subq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x20(%rbp), %rax
movq 0x88(%rax), %rax
movq -0x20(%rbp), %rcx
movq 0x98(%rcx), %rcx
movq -0x30(%rbp), %rdx
subq $0x1, %rdx
imulq %rdx, %rcx
addq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x18(%rbp), %rcx
movq 0x20(%rcx), %rcx
movq -0x20(%rbp), %rdx
movq 0x10(%rdx), %rdx
movq -0x38(%rbp), %rsi
subq $0x1, %rsi
movq (%rdx,%rsi,8), %rdx
shrl %edx
movl %edx, %edx
movl (%rcx,%rdx,8), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movl %ecx, %ecx
subq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x20(%rbp), %rax
movq 0x88(%rax), %rax
movq -0x20(%rbp), %rcx
movq 0x98(%rcx), %rcx
imulq -0x30(%rbp), %rcx
movq -0x38(%rbp), %rdx
subq $0x1, %rdx
addq %rdx, %rcx
movq (%rax,%rcx,8), %rax
movq -0x18(%rbp), %rcx
movq 0x20(%rcx), %rcx
movq -0x20(%rbp), %rdx
movq 0x28(%rdx), %rdx
movq -0x30(%rbp), %rsi
subq $0x1, %rsi
movq (%rdx,%rsi,8), %rdx
shrl %edx
movl %edx, %edx
movl (%rcx,%rdx,8), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movl %ecx, %ecx
subq %rcx, %rax
movq %rax, -0x60(%rbp)
movq $0x1, -0x40(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
cmpq -0x58(%rbp), %rax
jge 0x324fda
movq -0x58(%rbp), %rax
movq %rax, -0x68(%rbp)
movq $0x3, -0x40(%rbp)
movq -0x68(%rbp), %rax
cmpq -0x60(%rbp), %rax
jge 0x324ff4
movq -0x60(%rbp), %rax
movq %rax, -0x68(%rbp)
movq $0x2, -0x40(%rbp)
movq -0x68(%rbp), %rdx
movq -0x20(%rbp), %rax
movq 0x88(%rax), %rax
movq -0x20(%rbp), %rcx
movq 0x98(%rcx), %rcx
imulq -0x30(%rbp), %rcx
addq -0x38(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x40(%rbp), %rax
movb %al, %dl
movq -0x20(%rbp), %rax
movq 0x70(%rax), %rax
movq -0x20(%rbp), %rcx
movq 0x98(%rcx), %rcx
imulq -0x30(%rbp), %rcx
addq -0x38(%rbp), %rcx
movb %dl, (%rax,%rcx)
jmp 0x325042
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x324cc0
jmp 0x325055
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x324ca3
movq $0x0, -0x68(%rbp)
movq $-0x1, -0x78(%rbp)
movq $-0x1, -0x70(%rbp)
movq $0x1, -0x38(%rbp)
movq -0x20(%rbp), %rax
movq 0x90(%rax), %rax
subq $0x1, %rax
movq %rax, -0x30(%rbp)
movq -0x38(%rbp), %rax
movq -0x20(%rbp), %rcx
cmpq 0x98(%rcx), %rax
jae 0x325124
cmpq $0x0, -0x70(%rbp)
jl 0x3250da
movq -0x68(%rbp), %rax
movq -0x20(%rbp), %rcx
movq 0x88(%rcx), %rcx
movq -0x20(%rbp), %rdx
movq 0x98(%rdx), %rdx
imulq -0x30(%rbp), %rdx
addq -0x38(%rbp), %rdx
cmpq (%rcx,%rdx,8), %rax
jge 0x325111
movq -0x30(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x20(%rbp), %rax
movq 0x88(%rax), %rax
movq -0x20(%rbp), %rcx
movq 0x98(%rcx), %rcx
imulq -0x30(%rbp), %rcx
addq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x68(%rbp)
jmp 0x325113
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x325099
movq $0x1, -0x30(%rbp)
movq -0x20(%rbp), %rax
movq 0x98(%rax), %rax
subq $0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rax
movq -0x20(%rbp), %rcx
cmpq 0x90(%rcx), %rax
jae 0x3251ca
cmpq $0x0, -0x70(%rbp)
jl 0x325180
movq -0x68(%rbp), %rax
movq -0x20(%rbp), %rcx
movq 0x88(%rcx), %rcx
movq -0x20(%rbp), %rdx
movq 0x98(%rdx), %rdx
imulq -0x30(%rbp), %rdx
addq -0x38(%rbp), %rdx
cmpq (%rcx,%rdx,8), %rax
jge 0x3251b7
movq -0x30(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x20(%rbp), %rax
movq 0x88(%rax), %rax
movq -0x20(%rbp), %rcx
movq 0x98(%rcx), %rcx
imulq -0x30(%rbp), %rcx
addq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x68(%rbp)
jmp 0x3251b9
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x32513f
cmpq $0x0, -0x70(%rbp)
jl 0x3251df
cmpq $0x1, -0x70(%rbp)
je 0x3251df
cmpq $0x1, -0x78(%rbp)
jne 0x3251ec
movq $0x0, -0x8(%rbp)
jmp 0x3256ff
movq $0x0, -0x80(%rbp)
movq $0x0, -0x88(%rbp)
movq $0x0, -0x90(%rbp)
movq $0x0, -0x98(%rbp)
movq $0x0, -0xa0(%rbp)
movq -0x70(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x78(%rbp), %rax
movq %rax, -0x38(%rbp)
xorl %eax, %eax
cmpq $0x0, -0x30(%rbp)
movb %al, -0xad(%rbp)
jbe 0x32524d
cmpq $0x0, -0x38(%rbp)
seta %al
movb %al, -0xad(%rbp)
movb -0xad(%rbp), %al
testb $0x1, %al
jne 0x32525c
jmp 0x3254f3
movq -0x20(%rbp), %rax
movq 0x70(%rax), %rax
movq -0x20(%rbp), %rcx
movq 0x98(%rcx), %rcx
imulq -0x30(%rbp), %rcx
addq -0x38(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x325355
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x20(%rbp), %rcx
movq 0x28(%rcx), %rcx
movq -0x30(%rbp), %rdx
subq $0x1, %rdx
movq (%rcx,%rdx,8), %rcx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
addq -0x80(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq -0x20(%rbp), %rcx
movq 0x28(%rcx), %rcx
movq -0x30(%rbp), %rdx
subq $0x1, %rdx
movq (%rcx,%rdx,8), %rcx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
movq -0x10(%rbp), %rcx
movq 0x80(%rcx), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
ja 0x32533d
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x20(%rbp), %rcx
movq 0x28(%rcx), %rcx
movq -0x30(%rbp), %rdx
subq $0x1, %rdx
movq (%rcx,%rdx,8), %rcx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
addq -0x90(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0xa0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xa0(%rbp)
movq -0x30(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x30(%rbp)
movq -0x38(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x38(%rbp)
cmpq $0x1, -0x40(%rbp)
jne 0x32541e
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x20(%rbp), %rcx
movq 0x28(%rcx), %rcx
movq -0x30(%rbp), %rdx
subq $0x1, %rdx
movq (%rcx,%rdx,8), %rcx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
addq -0x88(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq -0x20(%rbp), %rcx
movq 0x28(%rcx), %rcx
movq -0x30(%rbp), %rdx
subq $0x1, %rdx
movq (%rcx,%rdx,8), %rcx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
movq -0x10(%rbp), %rcx
movq 0x80(%rcx), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
ja 0x325406
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x20(%rbp), %rcx
movq 0x28(%rcx), %rcx
movq -0x30(%rbp), %rdx
subq $0x1, %rdx
movq (%rcx,%rdx,8), %rcx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
addq -0x98(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x30(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x30(%rbp)
movq -0x38(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x38(%rbp)
cmpq $0x2, -0x40(%rbp)
jne 0x325431
movq -0x38(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x38(%rbp)
cmpq $0x3, -0x40(%rbp)
jne 0x3254ee
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x20(%rbp), %rcx
movq 0x28(%rcx), %rcx
movq -0x30(%rbp), %rdx
subq $0x1, %rdx
movq (%rcx,%rdx,8), %rcx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
addq -0x88(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq -0x20(%rbp), %rcx
movq 0x28(%rcx), %rcx
movq -0x30(%rbp), %rdx
subq $0x1, %rdx
movq (%rcx,%rdx,8), %rcx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
movq -0x10(%rbp), %rcx
movq 0x80(%rcx), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
ja 0x3254e2
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x20(%rbp), %rcx
movq 0x28(%rcx), %rcx
movq -0x30(%rbp), %rdx
subq $0x1, %rdx
movq (%rcx,%rdx,8), %rcx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
addq -0x98(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x30(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x325230
xorl %eax, %eax
cmpq $0x0, -0x38(%rbp)
movb %al, -0xae(%rbp)
jne 0x32552d
movq -0x20(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x20(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq -0x38(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
cmpl %ecx, %eax
sete %al
movb %al, -0xae(%rbp)
movb -0xae(%rbp), %al
testb $0x1, %al
jne 0x325539
jmp 0x32553b
jmp 0x32555a
leaq 0x716df(%rip), %rdi     # 0x396c21
leaq 0x70c70(%rip), %rsi     # 0x3961b9
movl $0xeb0, %edx            # imm = 0xEB0
leaq 0x7170f(%rip), %rcx     # 0x396c64
callq 0x2130
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x20(%rbp), %rcx
movq 0x28(%rcx), %rcx
movq -0x30(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %ecx
movq -0x80(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x80(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq -0x20(%rbp), %rcx
movq 0x28(%rcx), %rcx
movq -0x30(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
movq -0x10(%rbp), %rcx
movq 0x80(%rcx), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
ja 0x32560a
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x20(%rbp), %rcx
movq 0x28(%rcx), %rcx
movq -0x30(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %ecx
movq -0x90(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x90(%rbp)
movq -0xa0(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0xa0(%rbp)
cmpq $0x1, -0xa0(%rbp)
jl 0x325625
cmpq $0x0, -0x80(%rbp)
je 0x325625
cmpq $0x0, -0x90(%rbp)
jne 0x325632
movq $-0x1, -0x8(%rbp)
jmp 0x3256ff
cvtsi2sdq -0x80(%rbp), %xmm1
movq -0x80(%rbp), %rax
addq -0x88(%rbp), %rax
cvtsi2sd %rax, %xmm0
mulsd -0x28(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jb 0x325660
movq $-0x1, -0x8(%rbp)
jmp 0x3256ff
cvtsi2sdq -0x90(%rbp), %xmm1
movq -0x90(%rbp), %rax
addq -0x98(%rbp), %rax
cvtsi2sd %rax, %xmm0
mulsd -0x28(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jb 0x325691
movq $-0x1, -0x8(%rbp)
jmp 0x3256ff
movq -0x90(%rbp), %rax
cvtsi2sd %rax, %xmm0
movq -0x98(%rbp), %rcx
addq %rcx, %rax
cvtsi2sd %rax, %xmm1
divsd %xmm1, %xmm0
movq -0x20(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rcx
movl %ecx, %eax
movl %eax, %eax
shrq $0x20, %rcx
subq %rcx, %rax
movq %rax, %xmm1
movaps 0x5c939(%rip), %xmm2    # 0x382010
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x5c93d(%rip), %xmm2    # 0x382020
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xb0, %rsp
popq %rbp
retq
nopl (%rax)