// File: /workspace/github_cpp_makefile_star2_O3/sisong[P]ApkDiffPatch/HDiffPatch/libHDiffPatch/HDiff/private_diff/limit_mem_diff/stream_serialize.cpp
// Function: hdiff_private::TStepStream::doStep()
bool TStepStream::doStep(){
    if (pCurCover==0){
        if (isHaveLeftCover)      { isHaveLeftCover=false;  pCurCover=&leftCover;  }
        else if (isHaveRightCover){ isHaveRightCover=false; pCurCover=&rightCover; }
        else if (cur_i<covers.coverCount()) { covers.covers(cur_i++,&cover); pCurCover=&cover; }
        else if (isHaveLastCover) { isHaveLastCover=false;  pCurCover=&lastCover;  }
        else if (step_bufCover_size>0){ _last_flush_step(); return true; }
        else { return false; } //end while
    }
    cover=*pCurCover;
    const size_t step_bufCover_backSize=step_bufCover_size;

    hpatch_StreamPos_t backNewLen=cover.newPos-lastNewEnd;
    if (cover.oldPos>=lastOldEnd){ //save inc_oldPos
        if (isInInit)
            step_bufCover_size+=hpatch_packUIntWithTag_size((hpatch_StreamPos_t)(cover.oldPos-lastOldEnd), 1);
        else 
            packUIntWithTag(step_bufCover,(hpatch_StreamPos_t)(cover.oldPos-lastOldEnd), 0, 1);
    }else{
        if (isInInit)
            step_bufCover_size+=hpatch_packUIntWithTag_size((hpatch_StreamPos_t)(lastOldEnd-cover.oldPos), 1);
        else
            packUIntWithTag(step_bufCover,(hpatch_StreamPos_t)(lastOldEnd-cover.oldPos), 1, 1);//sub safe
    }
    if (isInInit){
        step_bufCover_size+=hpatch_packUInt_size(backNewLen)+hpatch_packUInt_size(cover.length);
    }else{
        packUInt(step_bufCover,backNewLen); //save inc_newPos
        packUInt(step_bufCover,cover.length);
        step_bufCover_size=step_bufCover.size();
    }
    
    subDiff.resetCover(cover);
    const hpatch_StreamPos_t curMaxNeedSize = step_bufCover_size +
            (subDiff.isZeroSubDiff?step_bufRle.maxCodeSizeByZeroLen(subDiff.streamSize):step_bufRle.maxCodeSize(&subDiff));
    if (curMaxNeedSize<=patchStepMemSize){ //append
        if (subDiff.isZeroSubDiff)
            step_bufRle.appendByZeroLen(subDiff.streamSize);
        else
            step_bufRle.append(&subDiff);
        if (backNewLen>0){
            newDataDiffReadPos+=backNewLen;
            step_dataDiffSize+=backNewLen;
        }

        lastOldEnd=cover.oldPos+cover.length;//! +length
        lastNewEnd=cover.newPos+cover.length;
        pCurCover=0; // next 
        return true;
    }else{
        if (step_bufCover_backSize+step_bufRle.curCodeSize()>=(patchStepMemSize/2)){//flush step
            step_bufCover_size=step_bufCover_backSize;
            if (!isInInit) step_bufCover.resize(step_bufCover_backSize);
            
            step_dataDiff.reset(&newDataDiff,newDataDiffReadPos-step_dataDiffSize,newDataDiffReadPos);
            step_dataDiffSize=0;
            _flush_step_code();
            return true;  // pCurCover!
        }else{ //clip one cover to two cover
            check((!isHaveLeftCover)&&(!isHaveRightCover));
            isHaveLeftCover=true;
            isHaveRightCover=true;
            leftCover=cover;
            rightCover=cover;
            hpatch_StreamPos_t clen=cover.length;
            while (1) {
                clen=clen*3/4;
                subDiff.resetCoverLen(clen);
                check(clen>0); // stepMemSize error
                const hpatch_StreamPos_t _curMaxNeedSize = step_bufCover_size +
                    (subDiff.isZeroSubDiff?step_bufRle.maxCodeSizeByZeroLen(subDiff.streamSize):step_bufRle.maxCodeSize(&subDiff));
                if (_curMaxNeedSize<=patchStepMemSize)
                    break;
            }
            leftCover.length=clen;
            rightCover.length-=clen;
            rightCover.oldPos+=clen;
            rightCover.newPos+=clen;

            step_bufCover_size=step_bufCover_backSize;
            if (!isInInit) step_bufCover.resize(step_bufCover_backSize);
            ++curCoverCount;
            pCurCover=0;
            return true;  // leftCover
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %rbx
movq 0x228(%rdi), %rax
testq %rax, %rax
jne 0x247ec
cmpb $0x1, 0x1b9(%rbx)
jne 0x247ca
movb $0x0, 0x1b9(%rbx)
leaq 0x1d8(%rbx), %rax
jmp 0x247e5
cmpb $0x1, 0x1ba(%rbx)
jne 0x24c43
movb $0x0, 0x1ba(%rbx)
leaq 0x1f0(%rbx), %rax
movq %rax, 0x228(%rbx)
movdqu (%rax), %xmm0
movdqu %xmm0, 0x210(%rbx)
movq 0x10(%rax), %rax
movq %rax, 0x220(%rbx)
movq 0x240(%rbx), %r14
movq 0x210(%rbx), %rcx
movq 0x218(%rbx), %r15
movq 0x148(%rbx), %rdx
movq 0x150(%rbx), %r12
movq %rcx, %rax
movb 0x230(%rbx), %sil
subq %rdx, %rax
jae 0x24842
subq %rcx, %rdx
testb %sil, %sil
je 0x24862
movq %rdx, %rdi
jmp 0x2484a
testb %sil, %sil
je 0x248a9
movq %rax, %rdi
movl $0x1, %esi
callq 0x43313
movl %eax, %eax
addq %rax, 0x240(%rbx)
jmp 0x248f0
leaq 0xd(%rsp), %rax
leaq 0x18(%rsp), %rdi
movq %rax, (%rdi)
leaq 0x18(%rsp), %rsi
movl $0x1, %ecx
movl $0x1, %r8d
callq 0x43254
testl %eax, %eax
jne 0x248d3
movl $0x10, %edi
callq 0x4190
movq %rax, %r14
leaq 0x35b64(%rip), %rsi     # 0x5a400
movq %rax, %rdi
callq 0x4110
jmp 0x24d0d
leaq 0xd(%rsp), %rcx
leaq 0x18(%rsp), %rdi
movq %rcx, (%rdi)
leaq 0x18(%rsp), %rsi
movq %rax, %rdx
xorl %ecx, %ecx
movl $0x1, %r8d
callq 0x43254
testl %eax, %eax
je 0x24d7d
leaq 0x158(%rbx), %rdi
movq 0x160(%rbx), %rsi
movq 0x18(%rsp), %rcx
leaq 0xd(%rsp), %rdx
callq 0x9c50
movq %r15, 0x28(%rsp)
subq %r12, %r15
cmpb $0x1, 0x230(%rbx)
movq %r14, 0x30(%rsp)
movq %r12, 0x20(%rsp)
jne 0x24937
movq %r15, %rdi
xorl %esi, %esi
callq 0x43313
movl %eax, %r12d
movq 0x220(%rbx), %rdi
xorl %esi, %esi
callq 0x43313
movl %eax, %ebp
addl %r12d, %ebp
addq 0x240(%rbx), %rbp
jmp 0x249d1
leaq 0xd(%rsp), %rax
leaq 0x18(%rsp), %rdi
movq %rax, (%rdi)
leaq 0x18(%rsp), %rsi
movq %r15, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x43254
testl %eax, %eax
je 0x24d23
leaq 0x158(%rbx), %r12
movq 0x160(%rbx), %rsi
leaq 0x18(%rsp), %r13
movq (%r13), %rcx
leaq 0xd(%rsp), %rbp
movq %r12, %rdi
movq %rbp, %rdx
callq 0x9c50
movq 0x220(%rbx), %rdx
movq %rbp, (%r13)
leaq 0x18(%rsp), %rsi
movq %r13, %rdi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x43254
testl %eax, %eax
je 0x24d41
movq 0x160(%rbx), %rsi
movq 0x18(%rsp), %rcx
leaq 0xd(%rsp), %rdx
movq %r12, %rdi
callq 0x9c50
movq 0x160(%rbx), %rbp
subq 0x158(%rbx), %rbp
leaq 0x210(%rbx), %r14
movq %rbp, 0x240(%rbx)
leaq 0x20(%rbx), %r12
movdqu (%r14), %xmm0
movdqu %xmm0, 0x68(%rbx)
movq 0x10(%r14), %rsi
movq %rsi, 0x78(%rbx)
movq %rsi, 0x28(%rbx)
movq %rsi, 0x48(%rbx)
movq $0x0, 0x50(%rbx)
leaq 0x170(%rbx), %r13
cmpb $0x1, 0x40(%rbx)
jne 0x24a1c
movq %r13, %rdi
callq 0x1b1cc
jmp 0x24a27
movq %r13, %rdi
movq %r12, %rsi
callq 0x1b2d2
addq %rbp, %rax
cmpq 0x118(%rbx), %rax
jbe 0x24b5f
movq %r13, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x1aea2
movq 0x30(%rsp), %rbp
addq %rbp, %rax
movq 0x118(%rbx), %rcx
shrq %rcx
cmpq %rcx, %rax
jae 0x24b73
cmpb $0x0, 0x1b9(%rbx)
jne 0x24d5f
cmpb $0x1, 0x1ba(%rbx)
je 0x24d5f
movw $0x101, 0x1b9(%rbx)     # imm = 0x101
movups (%r14), %xmm0
movups %xmm0, 0x1d8(%rbx)
movq 0x10(%r14), %rax
movq %rax, 0x1e8(%rbx)
movdqu (%r14), %xmm0
movdqu %xmm0, 0x1f0(%rbx)
movq 0x10(%r14), %rax
movq %rax, 0x200(%rbx)
movq 0x220(%rbx), %r15
leaq (%r15,%r15,2), %r14
movq %r14, %r15
shrq $0x2, %r15
movq %r12, %rdi
movq %r15, %rsi
callq 0x241e2
cmpq $0x3, %r14
jbe 0x24cf1
movq 0x240(%rbx), %r14
cmpb $0x1, 0x40(%rbx)
jne 0x24af1
movq 0x28(%rbx), %rsi
movq %r13, %rdi
callq 0x1b1cc
jmp 0x24afc
movq %r13, %rdi
movq %r12, %rsi
callq 0x1b2d2
addq %r14, %rax
cmpq 0x118(%rbx), %rax
ja 0x24ab6
movq %r15, 0x1e8(%rbx)
subq %r15, 0x200(%rbx)
movdqu 0x1f0(%rbx), %xmm0
movq %r15, %xmm1
pshufd $0x44, %xmm1, %xmm1     # xmm1 = xmm1[0,1,0,1]
paddq %xmm0, %xmm1
movdqu %xmm1, 0x1f0(%rbx)
movq %rbp, 0x240(%rbx)
cmpb $0x0, 0x230(%rbx)
jne 0x24b53
leaq 0x158(%rbx), %rdi
movq %rbp, %rsi
callq 0x9b50
incq 0x128(%rbx)
jmp 0x24c27
cmpb $0x1, 0x40(%rbx)
jne 0x24bd1
movq 0x28(%rbx), %rsi
movq %r13, %rdi
callq 0x1b422
jmp 0x24bdc
movq %rbp, 0x240(%rbx)
cmpb $0x0, 0x230(%rbx)
jne 0x24b92
leaq 0x158(%rbx), %rdi
movq %rbp, %rsi
callq 0x9b50
leaq 0x260(%rbx), %rdi
leaq 0xa8(%rbx), %rsi
movq 0x1b0(%rbx), %rcx
movq %rcx, %rdx
subq 0x1a8(%rbx), %rdx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x25098
movq $0x0, 0x1a8(%rbx)
movq %rbx, %rdi
callq 0x2516c
jmp 0x24c32
movq %r13, %rdi
movq %r12, %rsi
callq 0x1b568
movq 0x20(%rsp), %rax
cmpq %rax, 0x28(%rsp)
je 0x24c06
movdqu 0x1a8(%rbx), %xmm0
movq %r15, %xmm1
pshufd $0x44, %xmm1, %xmm1     # xmm1 = xmm1[0,1,0,1]
paddq %xmm0, %xmm1
movdqu %xmm1, 0x1a8(%rbx)
movdqu 0x210(%rbx), %xmm0
movdqu 0x220(%rbx), %xmm1
pshufd $0x44, %xmm1, %xmm1     # xmm1 = xmm1[0,1,0,1]
paddq %xmm0, %xmm1
movdqu %xmm1, 0x148(%rbx)
movq $0x0, 0x228(%rbx)
movb $0x1, %al
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x110(%rbx), %rsi
movq 0x208(%rbx), %rdx
cmpq 0x18(%rsi), %rdx
jae 0x24c9c
leaq 0x1(%rdx), %rax
movq %rax, 0x208(%rbx)
leaq 0x210(%rbx), %rax
movq 0x10(%rsi), %rcx
cmpb $0x1, 0x20(%rsi)
jne 0x24cb8
leaq (%rdx,%rdx,2), %rdx
movq (%rcx,%rdx,4), %xmm0
pxor %xmm1, %xmm1
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movdqu %xmm0, 0x210(%rbx)
movl 0x8(%rcx,%rdx,4), %ecx
movq %rcx, 0x220(%rbx)
jmp 0x247e5
cmpb $0x1, 0x1b8(%rbx)
jne 0x24cd3
movb $0x0, 0x1b8(%rbx)
leaq 0x1c0(%rbx), %rax
jmp 0x247e5
leaq (%rdx,%rdx,2), %rdx
movq 0x10(%rcx,%rdx,8), %rsi
movq %rsi, 0x10(%rax)
movdqu (%rcx,%rdx,8), %xmm0
movdqu %xmm0, (%rax)
jmp 0x247e5
cmpq $0x0, 0x240(%rbx)
je 0x24cea
movq %rbx, %rdi
callq 0x24f98
jmp 0x24c32
xorl %eax, %eax
jmp 0x24c34
movl $0x10, %edi
callq 0x4190
movq %rax, %r14
leaq 0x38b8a(%rip), %rsi     # 0x5d88f
movq %rax, %rdi
callq 0x4110
movq 0x572d4(%rip), %rsi     # 0x7bfe8
movq 0x5729d(%rip), %rdx     # 0x7bfb8
movq %r14, %rdi
callq 0x4590
movl $0x10, %edi
callq 0x4190
movq %rax, %r14
leaq 0x356c9(%rip), %rsi     # 0x5a400
movq %rax, %rdi
callq 0x4110
jmp 0x24d0d
movl $0x10, %edi
callq 0x4190
movq %rax, %r14
leaq 0x356ab(%rip), %rsi     # 0x5a400
movq %rax, %rdi
callq 0x4110
jmp 0x24d0d
movl $0x10, %edi
callq 0x4190
movq %rax, %r14
leaq 0x38ae7(%rip), %rsi     # 0x5d85a
movq %rax, %rdi
callq 0x4110
jmp 0x24d0d
movl $0x10, %edi
callq 0x4190
movq %rax, %r14
leaq 0x3566f(%rip), %rsi     # 0x5a400
movq %rax, %rdi
callq 0x4110
jmp 0x24d0d
jmp 0x24da8
jmp 0x24da8
jmp 0x24da8
jmp 0x24da8
jmp 0x24da8
movq %rax, %rbx
movq %r14, %rdi
callq 0x4260
movq %rbx, %rdi
callq 0x45e0
nop