// File: chhylp123[P]hifiasm/ecovlp.cpp
// Function: extract_sub_cigar_cns(overlap_region*, long, long, long, long, long, rr_seq_t*, ul_ov_t*, cns_gfa*, asg32_v*, unsigned long, unsigned int)
uint32_t extract_sub_cigar_cns(overlap_region *z, int64_t s, int64_t e, int64_t iws, int64_t iwe, int64_t s_end, rr_seq_t *ssq, ul_ov_t *p, cns_gfa *cns, asg32_v* b32, uint64_t max_trace, uint32_t rid)
{
    // if(s == 10539 && e == 10760) {
        // fprintf(stderr, "\n>>>>>>iw::[%ld, %ld)\tw::[%ld, %ld)\tox::[%u, %u)<<<<<<\n", iws, iwe, s, e, z->x_pos_s, z->x_pos_e + 1);
    // }
    
    int64_t wk = ovlp_cur_wid(*p), xk = ovlp_cur_xoff(*p), yk = ovlp_cur_yoff(*p), ck = ovlp_cur_coff(*p), os, oe, ots, ote, ol, insert_pos = ((iws == iwe)? (0): (-1));
    bit_extz_t ez; int64_t bd = ovlp_bd(*p), s0, e0, ii[2], it[2]; uint64_t pe = (uint64_t)-1;
    s0 = ((int64_t)(z->w_list.a[wk].x_start)) + bd; 
    e0 = ((int64_t)(z->w_list.a[wk].x_end)) + 1 - bd;
    if(s < s0) s = s0; if(e > e0) e = e0;///exclude boundary
    if(s > e) return -1;///it is possible s == e
    os = MAX(s, s0); oe = MIN(e, e0);
    if(oe < os) return -1;///it is possible os == oe

    set_bit_extz_t(ez, (*z), wk);
    if(!ez.cigar.n) return -1;
    int64_t cn = ez.cigar.n; uint16_t op; int64_t ws, we, wts, wte, ovlp; char *tstr;
    if((ck < 0) || (ck > cn)) {//(*ck) == cn is allowed
        ck = 0; xk = ez.ts; yk = ez.ps;
    }

    while (ck > 0 && xk >= s) {///x -> t; y -> p; first insertion and then match/mismatch
        --ck;
        op = ez.cigar.a[ck]>>14;
        if(op!=2) xk -= (ez.cigar.a[ck]&(0x3fff));
        if(op!=3) yk -= (ez.cigar.a[ck]&(0x3fff)); 
    }

    if(s_end == 0 && s == iws) s_end = 0;
    else s_end = 1;

    // if(s_end == 0 || s != iws) {///do not conside the insertion before s
    //     while (ck < cn && xk < s) {
    //     }
    // }

    // if(s == 10539 && e == 10760) {
        // fprintf(stderr, "ck::%ld, cn::%ld, xk::%ld, yk::%ld\n", ck, cn, xk, yk);
    // }

    // char cm[4]; cm[0] = 'M'; cm[1] = 'S'; cm[2] = 'I'; cm[3] = 'D';  
    //some cigar will span s or e
    ii[0] = ii[1] = it[0] = it[1] = -1; 
    ssq->s = ssq->e = 0; ssq->n0 = e - s; 
    ssq->id = z->y_id; ssq->rev = z->y_pos_strand;
    if(ssq->n0 == 0) {ssq->n0 = ssq->n1;} 

    while (ck < cn && xk < e) {//[s, e)
        ws = xk; wts = yk;
        op = ez.cigar.a[ck]>>14; ol = (ez.cigar.a[ck]&(0x3fff));
        
        for (ck++; (ck < cn) && (op == (ez.cigar.a[ck]>>14)); ck++) {
            ol += (ez.cigar.a[ck]&(0x3fff));
        }
        ///op == 3: -> x; op == 2: -> y;
        if(op!=2) xk += ol;
        if(op!=3) yk += ol; 
        we = xk; wte = yk;

        // fprintf(stderr, "ck::%ld, cn::%ld, op::%u, ol::%ld\n", ck, cn, op, ol);

        os = MAX(s, ws); oe = MIN(e, we);
        ovlp = ((oe>os)? (oe-os):0);

        if(s == e) {///insertion in comparsion with the reference
            if(op != 0 || ws >= s || we <= e || e != iwe || s != iws) continue;///must be a match
        } else {
            if(op != 2) {
                if(!ovlp) continue;
            } else {///ws == we
                if(ws < s || ws >= e) continue;
            }
        }
        
        if((s_end == 0) && (op == 2) && (ws == s)) continue;///skip the insertion just before s
        
        

        if(op < 2) {
            ots = os - ws + wts; ote = oe - ws + wts;
        } else {///op == 2: more y; p == 3: more x
            ots = wts; ote = wte;
        } 



        if(ii[0] == -1) {
            ii[0] = os; it[0] = ots;
            // if(op < 2) {
            //     it[0] = os - ws + wts;
            // } else {///op == 2: more y; p == 3: more x
            //     it[0] = wts;
            // } 
        }

        ii[1] = oe; it[1] = ote;
        // if(op < 2) {
        //     it[1] = oe - ws + wts;
        // } else {///op == 2: more y; p == 3: more x
        //     it[1] = wte;
        // } 




        if(op != 2) ol = oe-os;

        tstr = NULL;
        if(op != 0) tstr = get_sub_seq(ssq, ots, ote);

        // if(s == 10539 && e == 10760) {
            // fprintf(stderr, "+0-%ld%c(%.*s)\tpe::%lu", ol, cm[op], tstr?((int)(ote - ots)):0, tstr, pe);
        // }
        // fprintf(stderr, ">q::[%ld, %ld)\n", ws, we);
        // fprintf(stderr, "%ld%c(%.*s)", ol, cm[op], tstr?((int)(ote - ots)):0, tstr);

        pe = append_cns_g(cns, tstr, ote - ots, os - iws, oe - iws, op, ol, pe, b32, max_trace, rid, insert_pos);

        // if(s == 10539 && e == 10760) {
            // fprintf(stderr, "+1-pe::%lu\n", pe);
        // }
    }

    while (ck < cn && xk <= e) {//[s, e)
        ws = xk; wts = yk;
        op = ez.cigar.a[ck]>>14; ol = (ez.cigar.a[ck]&(0x3fff));
        if(op != 2) break;

        for (ck++; (ck < cn) && (op == (ez.cigar.a[ck]>>14)); ck++) {
            ol += (ez.cigar.a[ck]&(0x3fff));
        }
        yk += ol;//yk += (ez.cigar.a[ck]&(0x3fff)); 
        we = xk; wte = yk;


        if(ws >= s && ws <= e) {
            ots = wts; ote = wte;
            if(ii[0] == -1) {
                ii[0] = ws; it[0] = ots;
            }
            ii[1] = we; it[1] = ote;
            

            tstr = NULL;
            if(op != 0) tstr = get_sub_seq(ssq, ots, ote);
            // if(s == 10539 && e == 10760) {
                // fprintf(stderr, "-0-%ld%c(%.*s)\tpe::%lu", ol, cm[op], tstr?((int)(ote - ots)):0, tstr, pe);
            // }
            // fprintf(stderr, "%ld%c(%.*s)", ol, cm[op], tstr?((int)(ote - ots)):0, tstr);

            pe = append_cns_g(cns, tstr, ote - ots, ws - iws, we - iws, op, ol, pe, b32, max_trace, rid, insert_pos);

            // if(s == 10539 && e == 10760) {
                // fprintf(stderr, "-1-pe::%lu\n", pe);
            // }
        }
    }

    // if(s == 10539 && e == 10760) {
        // fprintf(stderr, "\tx::[%ld, %ld)\ty::[%ld, %ld)\tiw::[%ld, %ld)\n", ii[0], ii[1], it[0], it[1], iws, iwe);
    // }

    // prt_cns_arc(cns, 0, __func__);
    // prt_cns_arc(cns, 1, __func__);
    if(ii[1] == -1) return -1;///it is possible when s == e and the cigar here is not a match

    uint64_t ae = 1;
    if((ii[1] == iwe)) {
        ae = 1;///end node
    } else {
        ae = ii[1] + cns->off - iws;
    }

    // if(s == 10539 && e == 10760) {
        // fprintf(stderr, "pe::%lu, ae::%lu, n_nodes::%u, ii[1]::%ld\n", pe, ae, (uint32_t)cns->n, ii[1]);
    // }

    if(pe == ((uint64_t)-1)) pe = 0;///start node

    ///if iws == iwe and the cigar is a match, pe will be equal to ae
    if(pe != ae) {
        if(!add_cns_arc(cns, pe, ae, 1, /**ae==1?1:0**/1)) {
            insert_cns_arc(cns, pe, ae, 1, /**ae==1?1:0**/1, rid); 
            insert_cns_arc(cns, ae, pe, 0, /**ae==1?1:0**/1, rid);
        } else {
            add_cns_arc(cns, ae, pe, 0, /**ae==1?1:0**/1);
        }
    }    


    // prt_cns_arc(cns, 0, __func__);
    // prt_cns_arc(cns, 1, __func__);


    // if(s == 10539 && e == 10760) {
    //     fprintf(stderr, "-end-pe::%lu, ae::%lu\n", pe, ae);
    // }

    ovlp_cur_xoff(*p) = xk; ovlp_cur_yoff(*p) = yk; ovlp_cur_coff(*p) = ck; ovlp_cur_ylen(*p) = 0;
    
    return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x258, %rsp            # imm = 0x258
movl 0x38(%rbp), %eax
movq 0x30(%rbp), %rax
movq 0x28(%rbp), %rax
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x28(%rbp)
movq %rsi, -0x30(%rbp)
movq %rdx, -0x38(%rbp)
movq %rcx, -0x40(%rbp)
movq %r8, -0x48(%rbp)
movq %r9, -0x50(%rbp)
movq 0x18(%rbp), %rax
movl (%rax), %eax
movq %rax, -0x58(%rbp)
movq 0x18(%rbp), %rax
movl 0x4(%rax), %eax
movq %rax, -0x60(%rbp)
movq 0x18(%rbp), %rax
movl 0x10(%rax), %eax
movq %rax, -0x68(%rbp)
movq 0x18(%rbp), %rax
movl 0x8(%rax), %eax
movq %rax, -0x70(%rbp)
movq -0x40(%rbp), %rdx
movq -0x48(%rbp), %rsi
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
xorl %ecx, %ecx
cmpq %rsi, %rdx
cmovel %ecx, %eax
cltq
movq %rax, -0xa0(%rbp)
movq 0x18(%rbp), %rax
movl 0x18(%rax), %eax
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
movl %eax, %eax
movq %rax, -0x180(%rbp)
movq $-0x1, -0x1b8(%rbp)
movq -0x28(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x58(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movslq (%rax), %rax
addq -0x180(%rbp), %rax
movq %rax, -0x188(%rbp)
movq -0x28(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x58(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movslq 0x4(%rax), %rax
addq $0x1, %rax
subq -0x180(%rbp), %rax
movq %rax, -0x190(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x188(%rbp), %rax
jge 0x24da2d
movq -0x188(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x190(%rbp), %rax
jle 0x24da45
movq -0x190(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x38(%rbp), %rax
jle 0x24da5b
movl $0xffffffff, -0x1c(%rbp) # imm = 0xFFFFFFFF
jmp 0x24e569
movq -0x30(%rbp), %rax
cmpq -0x188(%rbp), %rax
jl 0x24da75
movq -0x30(%rbp), %rax
movq %rax, -0x208(%rbp)
jmp 0x24da83
movq -0x188(%rbp), %rax
movq %rax, -0x208(%rbp)
movq -0x208(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x190(%rbp), %rax
jg 0x24daa8
movq -0x38(%rbp), %rax
movq %rax, -0x210(%rbp)
jmp 0x24dab6
movq -0x190(%rbp), %rax
movq %rax, -0x210(%rbp)
movq -0x210(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rax
cmpq -0x78(%rbp), %rax
jge 0x24dad7
movl $0xffffffff, -0x1c(%rbp) # imm = 0xFFFFFFFF
jmp 0x24e569
jmp 0x24dad9
movq -0x28(%rbp), %rax
movq 0x70(%rax), %rax
movq -0x28(%rbp), %rcx
movq 0x58(%rcx), %rcx
movq -0x58(%rbp), %rdx
shlq $0x5, %rdx
addq %rdx, %rcx
movl 0x18(%rcx), %ecx
shlq %rcx
addq %rcx, %rax
movq %rax, -0xc0(%rbp)
movq -0x28(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x58(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x1c(%rax), %eax
movq %rax, -0xc8(%rbp)
movq %rax, -0xd0(%rbp)
movq -0x28(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x58(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl (%rax), %eax
movl %eax, -0x15c(%rbp)
movq -0x28(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x58(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movl %eax, -0x158(%rbp)
movq -0x28(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x58(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, -0x168(%rbp)
movq -0x28(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x58(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
movl %eax, -0x164(%rbp)
movq -0x28(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x58(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movswl 0x14(%rax), %eax
movl %eax, -0x14c(%rbp)
movq -0x28(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x58(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movswl 0x14(%rax), %eax
movl %eax, -0x150(%rbp)
cmpq $0x0, -0xd0(%rbp)
jne 0x24dbe7
movl $0xffffffff, -0x1c(%rbp) # imm = 0xFFFFFFFF
jmp 0x24e569
movq -0xd0(%rbp), %rax
movq %rax, -0x1c0(%rbp)
cmpq $0x0, -0x70(%rbp)
jl 0x24dc09
movq -0x70(%rbp), %rax
cmpq -0x1c0(%rbp), %rax
jle 0x24dc27
movq $0x0, -0x70(%rbp)
movslq -0x15c(%rbp), %rax
movq %rax, -0x60(%rbp)
movslq -0x168(%rbp), %rax
movq %rax, -0x68(%rbp)
jmp 0x24dc29
xorl %eax, %eax
cmpq $0x0, -0x70(%rbp)
movb %al, -0x211(%rbp)
jle 0x24dc49
movq -0x60(%rbp), %rax
cmpq -0x30(%rbp), %rax
setge %al
movb %al, -0x211(%rbp)
movb -0x211(%rbp), %al
testb $0x1, %al
jne 0x24dc58
jmp 0x24dcde
movq -0x70(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x70(%rbp)
movq -0xc0(%rbp), %rax
movq -0x70(%rbp), %rcx
movzwl (%rax,%rcx,2), %eax
sarl $0xe, %eax
movw %ax, -0x1c2(%rbp)
movzwl -0x1c2(%rbp), %eax
cmpl $0x2, %eax
je 0x24dcab
movq -0xc0(%rbp), %rax
movq -0x70(%rbp), %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x3fff, %eax           # imm = 0x3FFF
movslq %eax, %rcx
movq -0x60(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x60(%rbp)
movzwl -0x1c2(%rbp), %eax
cmpl $0x3, %eax
je 0x24dcd9
movq -0xc0(%rbp), %rax
movq -0x70(%rbp), %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x3fff, %eax           # imm = 0x3FFF
movslq %eax, %rcx
movq -0x68(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x68(%rbp)
jmp 0x24dc29
cmpq $0x0, -0x50(%rbp)
jne 0x24dcf9
movq -0x30(%rbp), %rax
cmpq -0x40(%rbp), %rax
jne 0x24dcf9
movq $0x0, -0x50(%rbp)
jmp 0x24dd01
movq $0x1, -0x50(%rbp)
movq $-0x1, -0x1a8(%rbp)
movq $-0x1, -0x1b0(%rbp)
movq $-0x1, -0x198(%rbp)
movq $-0x1, -0x1a0(%rbp)
movq 0x10(%rbp), %rax
movq $0x0, 0x18(%rax)
movq 0x10(%rbp), %rax
movq $0x0, 0x10(%rax)
movq -0x38(%rbp), %rcx
subq -0x30(%rbp), %rcx
movq 0x10(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x28(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, %ecx
movq 0x10(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x28(%rbp), %rax
movl 0x1c(%rax), %eax
movl %eax, %ecx
movq 0x10(%rbp), %rax
movq %rcx, 0x38(%rax)
movq 0x10(%rbp), %rax
cmpq $0x0, 0x20(%rax)
jne 0x24dd92
movq 0x10(%rbp), %rax
movq 0x28(%rax), %rcx
movq 0x10(%rbp), %rax
movq %rcx, 0x20(%rax)
jmp 0x24dd94
movq -0x70(%rbp), %rcx
xorl %eax, %eax
cmpq -0x1c0(%rbp), %rcx
movb %al, -0x212(%rbp)
jge 0x24ddba
movq -0x60(%rbp), %rax
cmpq -0x38(%rbp), %rax
setl %al
movb %al, -0x212(%rbp)
movb -0x212(%rbp), %al
testb $0x1, %al
jne 0x24ddc9
jmp 0x24e198
movq -0x60(%rbp), %rax
movq %rax, -0x1d0(%rbp)
movq -0x68(%rbp), %rax
movq %rax, -0x1e0(%rbp)
movq -0xc0(%rbp), %rax
movq -0x70(%rbp), %rcx
movzwl (%rax,%rcx,2), %eax
sarl $0xe, %eax
movw %ax, -0x1c2(%rbp)
movq -0xc0(%rbp), %rax
movq -0x70(%rbp), %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x3fff, %eax           # imm = 0x3FFF
cltq
movq %rax, -0x98(%rbp)
movq -0x70(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rcx
xorl %eax, %eax
cmpq -0x1c0(%rbp), %rcx
movb %al, -0x213(%rbp)
jge 0x24de5a
movzwl -0x1c2(%rbp), %eax
movq -0xc0(%rbp), %rcx
movq -0x70(%rbp), %rdx
movzwl (%rcx,%rdx,2), %ecx
sarl $0xe, %ecx
cmpl %ecx, %eax
sete %al
movb %al, -0x213(%rbp)
movb -0x213(%rbp), %al
testb $0x1, %al
jne 0x24de66
jmp 0x24de98
movq -0xc0(%rbp), %rax
movq -0x70(%rbp), %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x3fff, %eax           # imm = 0x3FFF
cltq
addq -0x98(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x70(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x70(%rbp)
jmp 0x24de21
movzwl -0x1c2(%rbp), %eax
cmpl $0x2, %eax
je 0x24deb3
movq -0x98(%rbp), %rax
addq -0x60(%rbp), %rax
movq %rax, -0x60(%rbp)
movzwl -0x1c2(%rbp), %eax
cmpl $0x3, %eax
je 0x24dece
movq -0x98(%rbp), %rax
addq -0x68(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0x1d8(%rbp)
movq -0x68(%rbp), %rax
movq %rax, -0x1e8(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x1d0(%rbp), %rax
jl 0x24defe
movq -0x30(%rbp), %rax
movq %rax, -0x220(%rbp)
jmp 0x24df0c
movq -0x1d0(%rbp), %rax
movq %rax, -0x220(%rbp)
movq -0x220(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x1d8(%rbp), %rax
jg 0x24df31
movq -0x38(%rbp), %rax
movq %rax, -0x228(%rbp)
jmp 0x24df3f
movq -0x1d8(%rbp), %rax
movq %rax, -0x228(%rbp)
movq -0x228(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rax
cmpq -0x78(%rbp), %rax
jle 0x24df65
movq -0x80(%rbp), %rax
subq -0x78(%rbp), %rax
movq %rax, -0x230(%rbp)
jmp 0x24df70
xorl %eax, %eax
movq %rax, -0x230(%rbp)
jmp 0x24df70
movq -0x230(%rbp), %rax
movq %rax, -0x1f0(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x38(%rbp), %rax
jne 0x24dfc9
movzwl -0x1c2(%rbp), %eax
cmpl $0x0, %eax
jne 0x24dfc2
movq -0x1d0(%rbp), %rax
cmpq -0x30(%rbp), %rax
jge 0x24dfc2
movq -0x1d8(%rbp), %rax
cmpq -0x38(%rbp), %rax
jle 0x24dfc2
movq -0x38(%rbp), %rax
cmpq -0x48(%rbp), %rax
jne 0x24dfc2
movq -0x30(%rbp), %rax
cmpq -0x40(%rbp), %rax
je 0x24dfc7
jmp 0x24dd94
jmp 0x24e009
movzwl -0x1c2(%rbp), %eax
cmpl $0x2, %eax
je 0x24dfe6
cmpq $0x0, -0x1f0(%rbp)
jne 0x24dfe4
jmp 0x24dd94
jmp 0x24e007
movq -0x1d0(%rbp), %rax
cmpq -0x30(%rbp), %rax
jl 0x24e000
movq -0x1d0(%rbp), %rax
cmpq -0x38(%rbp), %rax
jl 0x24e005
jmp 0x24dd94
jmp 0x24e007
jmp 0x24e009
cmpq $0x0, -0x50(%rbp)
jne 0x24e02e
movzwl -0x1c2(%rbp), %eax
cmpl $0x2, %eax
jne 0x24e02e
movq -0x1d0(%rbp), %rax
cmpq -0x30(%rbp), %rax
jne 0x24e02e
jmp 0x24dd94
movzwl -0x1c2(%rbp), %eax
cmpl $0x2, %eax
jge 0x24e06e
movq -0x78(%rbp), %rax
subq -0x1d0(%rbp), %rax
addq -0x1e0(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x80(%rbp), %rax
subq -0x1d0(%rbp), %rax
addq -0x1e0(%rbp), %rax
movq %rax, -0x90(%rbp)
jmp 0x24e08a
movq -0x1e0(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x1e8(%rbp), %rax
movq %rax, -0x90(%rbp)
cmpq $-0x1, -0x1a0(%rbp)
jne 0x24e0ad
movq -0x78(%rbp), %rax
movq %rax, -0x1a0(%rbp)
movq -0x88(%rbp), %rax
movq %rax, -0x1b0(%rbp)
movq -0x80(%rbp), %rax
movq %rax, -0x198(%rbp)
movq -0x90(%rbp), %rax
movq %rax, -0x1a8(%rbp)
movzwl -0x1c2(%rbp), %eax
cmpl $0x2, %eax
je 0x24e0e1
movq -0x80(%rbp), %rax
subq -0x78(%rbp), %rax
movq %rax, -0x98(%rbp)
movq $0x0, -0x1f8(%rbp)
movzwl -0x1c2(%rbp), %eax
cmpl $0x0, %eax
je 0x24e116
movq 0x10(%rbp), %rdi
movq -0x88(%rbp), %rsi
movq -0x90(%rbp), %rdx
callq 0x24d750
movq %rax, -0x1f8(%rbp)
movq 0x20(%rbp), %rdi
movq -0x1f8(%rbp), %rsi
movq -0x90(%rbp), %rdx
subq -0x88(%rbp), %rdx
movq -0x78(%rbp), %rcx
subq -0x40(%rbp), %rcx
movq -0x80(%rbp), %r8
subq -0x40(%rbp), %r8
movzwl -0x1c2(%rbp), %eax
movl %eax, %r9d
movq -0x98(%rbp), %r15
movq -0x1b8(%rbp), %r14
movq 0x28(%rbp), %rbx
movq 0x30(%rbp), %r11
movl 0x38(%rbp), %r10d
movq -0xa0(%rbp), %rax
movq %r15, (%rsp)
movq %r14, 0x8(%rsp)
movq %rbx, 0x10(%rsp)
movq %r11, 0x18(%rsp)
movl %r10d, 0x20(%rsp)
movq %rax, 0x28(%rsp)
callq 0x24d5e0
movq %rax, -0x1b8(%rbp)
jmp 0x24dd94
jmp 0x24e19a
movq -0x70(%rbp), %rcx
xorl %eax, %eax
cmpq -0x1c0(%rbp), %rcx
movb %al, -0x231(%rbp)
jge 0x24e1c0
movq -0x60(%rbp), %rax
cmpq -0x38(%rbp), %rax
setle %al
movb %al, -0x231(%rbp)
movb -0x231(%rbp), %al
testb $0x1, %al
jne 0x24e1cf
jmp 0x24e411
movq -0x60(%rbp), %rax
movq %rax, -0x1d0(%rbp)
movq -0x68(%rbp), %rax
movq %rax, -0x1e0(%rbp)
movq -0xc0(%rbp), %rax
movq -0x70(%rbp), %rcx
movzwl (%rax,%rcx,2), %eax
sarl $0xe, %eax
movw %ax, -0x1c2(%rbp)
movq -0xc0(%rbp), %rax
movq -0x70(%rbp), %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x3fff, %eax           # imm = 0x3FFF
cltq
movq %rax, -0x98(%rbp)
movzwl -0x1c2(%rbp), %eax
cmpl $0x2, %eax
je 0x24e22c
jmp 0x24e411
movq -0x70(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rcx
xorl %eax, %eax
cmpq -0x1c0(%rbp), %rcx
movb %al, -0x232(%rbp)
jge 0x24e271
movzwl -0x1c2(%rbp), %eax
movq -0xc0(%rbp), %rcx
movq -0x70(%rbp), %rdx
movzwl (%rcx,%rdx,2), %ecx
sarl $0xe, %ecx
cmpl %ecx, %eax
sete %al
movb %al, -0x232(%rbp)
movb -0x232(%rbp), %al
testb $0x1, %al
jne 0x24e27d
jmp 0x24e2af
movq -0xc0(%rbp), %rax
movq -0x70(%rbp), %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x3fff, %eax           # imm = 0x3FFF
cltq
addq -0x98(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x70(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x70(%rbp)
jmp 0x24e238
movq -0x98(%rbp), %rax
addq -0x68(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0x1d8(%rbp)
movq -0x68(%rbp), %rax
movq %rax, -0x1e8(%rbp)
movq -0x1d0(%rbp), %rax
cmpq -0x30(%rbp), %rax
jl 0x24e40c
movq -0x1d0(%rbp), %rax
cmpq -0x38(%rbp), %rax
jg 0x24e40c
movq -0x1e0(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x1e8(%rbp), %rax
movq %rax, -0x90(%rbp)
cmpq $-0x1, -0x1a0(%rbp)
jne 0x24e338
movq -0x1d0(%rbp), %rax
movq %rax, -0x1a0(%rbp)
movq -0x88(%rbp), %rax
movq %rax, -0x1b0(%rbp)
movq -0x1d8(%rbp), %rax
movq %rax, -0x198(%rbp)
movq -0x90(%rbp), %rax
movq %rax, -0x1a8(%rbp)
movq $0x0, -0x1f8(%rbp)
movzwl -0x1c2(%rbp), %eax
cmpl $0x0, %eax
je 0x24e389
movq 0x10(%rbp), %rdi
movq -0x88(%rbp), %rsi
movq -0x90(%rbp), %rdx
callq 0x24d750
movq %rax, -0x1f8(%rbp)
movq 0x20(%rbp), %rdi
movq -0x1f8(%rbp), %rsi
movq -0x90(%rbp), %rdx
subq -0x88(%rbp), %rdx
movq -0x1d0(%rbp), %rcx
subq -0x40(%rbp), %rcx
movq -0x1d8(%rbp), %r8
subq -0x40(%rbp), %r8
movzwl -0x1c2(%rbp), %eax
movl %eax, %r9d
movq -0x98(%rbp), %r15
movq -0x1b8(%rbp), %r14
movq 0x28(%rbp), %rbx
movq 0x30(%rbp), %r11
movl 0x38(%rbp), %r10d
movq -0xa0(%rbp), %rax
movq %r15, (%rsp)
movq %r14, 0x8(%rsp)
movq %rbx, 0x10(%rsp)
movq %r11, 0x18(%rsp)
movl %r10d, 0x20(%rsp)
movq %rax, 0x28(%rsp)
callq 0x24d5e0
movq %rax, -0x1b8(%rbp)
jmp 0x24e19a
cmpq $-0x1, -0x198(%rbp)
jne 0x24e427
movl $0xffffffff, -0x1c(%rbp) # imm = 0xFFFFFFFF
jmp 0x24e569
movq $0x1, -0x200(%rbp)
movq -0x198(%rbp), %rax
cmpq -0x48(%rbp), %rax
jne 0x24e44c
movq $0x1, -0x200(%rbp)
jmp 0x24e468
movq -0x198(%rbp), %rax
movq 0x20(%rbp), %rcx
movl 0x20(%rcx), %ecx
addq %rcx, %rax
subq -0x40(%rbp), %rax
movq %rax, -0x200(%rbp)
cmpq $-0x1, -0x1b8(%rbp)
jne 0x24e47d
movq $0x0, -0x1b8(%rbp)
movq -0x1b8(%rbp), %rax
cmpq -0x200(%rbp), %rax
je 0x24e530
movq 0x20(%rbp), %rdi
movq -0x1b8(%rbp), %rax
movl %eax, %esi
movq -0x200(%rbp), %rax
movl %eax, %edx
movl $0x1, %r8d
movl %r8d, %ecx
callq 0x26cd20
cmpl $0x0, %eax
jne 0x24e50b
movq 0x20(%rbp), %rdi
movq -0x1b8(%rbp), %rax
movl %eax, %esi
movq -0x200(%rbp), %rax
movl %eax, %edx
movl 0x38(%rbp), %r9d
movl $0x1, %r8d
movl %r8d, %ecx
callq 0x26ca80
movq 0x20(%rbp), %rdi
movq -0x200(%rbp), %rax
movl %eax, %esi
movq -0x1b8(%rbp), %rax
movl %eax, %edx
movl 0x38(%rbp), %r9d
xorl %ecx, %ecx
movl $0x1, %r8d
callq 0x26ca80
jmp 0x24e52e
movq 0x20(%rbp), %rdi
movq -0x200(%rbp), %rax
movl %eax, %esi
movq -0x1b8(%rbp), %rax
movl %eax, %edx
xorl %ecx, %ecx
movl $0x1, %r8d
callq 0x26cd20
jmp 0x24e530
movq -0x60(%rbp), %rax
movl %eax, %ecx
movq 0x18(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x68(%rbp), %rax
movl %eax, %ecx
movq 0x18(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x70(%rbp), %rax
movl %eax, %ecx
movq 0x18(%rbp), %rax
movl %ecx, 0x8(%rax)
movq 0x18(%rbp), %rax
movl $0x0, 0x14(%rax)
movl $0x1, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
addq $0x258, %rsp            # imm = 0x258
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nopw (%rax,%rax)