// File: /workspace/github_cpp_makefile_star2_O2/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 $0x18, %rsp
movq %rdi, %rbx
movq 0x228(%rdi), %r14
testq %r14, %r14
jne 0x1fbb1
cmpb $0x1, 0x1b9(%rbx)
jne 0x1fb46
movb $0x0, 0x1b9(%rbx)
leaq 0x1d8(%rbx), %r14
jmp 0x1fbaa
cmpb $0x1, 0x1ba(%rbx)
jne 0x1fb5f
movb $0x0, 0x1ba(%rbx)
leaq 0x1f0(%rbx), %r14
jmp 0x1fbaa
movq 0x110(%rbx), %rdi
movq 0x208(%rbx), %rsi
cmpq 0x18(%rdi), %rsi
jae 0x1fb8f
leaq 0x1(%rsi), %rax
movq %rax, 0x208(%rbx)
leaq 0x210(%rbx), %r14
movq %r14, %rdx
callq 0x21086
jmp 0x1fbaa
cmpb $0x1, 0x1b8(%rbx)
jne 0x1ff29
movb $0x0, 0x1b8(%rbx)
leaq 0x1c0(%rbx), %r14
movq %r14, 0x228(%rbx)
movups (%r14), %xmm0
movups %xmm0, 0x210(%rbx)
movq 0x10(%r14), %rax
movq %rax, 0x220(%rbx)
movq 0x240(%rbx), %r14
movq 0x210(%rbx), %rdx
movq 0x218(%rbx), %r13
movq 0x148(%rbx), %rcx
movq 0x150(%rbx), %r15
movq %rdx, %rax
movb 0x230(%rbx), %sil
subq %rcx, %rax
jae 0x1fc09
testb %sil, %sil
je 0x1fc24
subq %rdx, %rcx
pushq $0x1
popq %rsi
movq %rcx, %rdi
jmp 0x1fc14
testb %sil, %sil
je 0x1fc38
pushq $0x1
popq %rsi
movq %rax, %rdi
callq 0x3a58c
movl %eax, %eax
addq %rax, 0x240(%rbx)
jmp 0x1fc4c
leaq 0x158(%rbx), %rdi
subq %rdx, %rcx
pushq $0x1
popq %rdx
movq %rcx, %rsi
movl %edx, %ecx
jmp 0x1fc47
leaq 0x158(%rbx), %rdi
pushq $0x1
popq %rcx
movq %rax, %rsi
xorl %edx, %edx
callq 0x20242
movq %r14, 0x10(%rsp)
leaq 0x210(%rbx), %r14
movq %r13, 0x8(%rsp)
movq %r15, (%rsp)
subq %r15, %r13
cmpb $0x1, 0x230(%rbx)
jne 0x1fc96
movq %r13, %rdi
xorl %esi, %esi
callq 0x3a58c
movl %eax, %r15d
movq 0x220(%rbx), %rdi
xorl %esi, %esi
callq 0x3a58c
movl %eax, %ebp
addl %r15d, %ebp
addq 0x240(%rbx), %rbp
jmp 0x1fcc5
leaq 0x158(%rbx), %r15
movq %r15, %rdi
movq %r13, %rsi
callq 0x202d0
movq 0x220(%rbx), %rsi
movq %r15, %rdi
callq 0x202d0
movq 0x160(%rbx), %rbp
subq 0x158(%rbx), %rbp
movq %rbp, 0x240(%rbx)
movdqu (%r14), %xmm0
movdqu %xmm0, 0x68(%rbx)
movq 0x10(%r14), %rsi
movq %rsi, 0x78(%rbx)
movq %rsi, 0x28(%rbx)
movq %rsi, 0x48(%rbx)
andq $0x0, 0x50(%rbx)
leaq 0x20(%rbx), %r12
leaq 0x170(%rbx), %r15
cmpb $0x1, 0x40(%rbx)
jne 0x1fd06
movq %r15, %rdi
callq 0x1777a
jmp 0x1fd11
movq %r15, %rdi
movq %r12, %rsi
callq 0x177f4
addq %rbp, %rax
cmpq 0x118(%rbx), %rax
jbe 0x1fe4c
movq %r15, %rdi
callq 0x210ec
movq 0x10(%rsp), %rbp
addq %rbp, %rax
movq 0x118(%rbx), %rcx
shrq %rcx
cmpq %rcx, %rax
jae 0x1fe60
cmpb $0x0, 0x1b9(%rbx)
jne 0x1ff71
cmpb $0x1, 0x1ba(%rbx)
je 0x1ff71
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), %r13
leaq (,%r13,2), %r14
addq %r13, %r14
movq %r14, %r13
shrq $0x2, %r13
movq %r12, %rdi
movq %r13, %rsi
callq 0x1f63c
cmpq $0x3, %r14
jbe 0x1ff41
movq 0x240(%rbx), %r14
cmpb $0x1, 0x40(%rbx)
jne 0x1fdde
movq 0x28(%rbx), %rsi
movq %r15, %rdi
callq 0x1777a
jmp 0x1fde9
movq %r15, %rdi
movq %r12, %rsi
callq 0x177f4
addq %r14, %rax
cmpq 0x118(%rbx), %rax
ja 0x1fd9c
movq %r13, 0x1e8(%rbx)
subq %r13, 0x200(%rbx)
movdqu 0x1f0(%rbx), %xmm0
movq %r13, %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 0x1fe40
leaq 0x158(%rbx), %rdi
movq %rbp, %rsi
callq 0x843c
incq 0x128(%rbx)
jmp 0x1ff10
cmpb $0x1, 0x40(%rbx)
jne 0x1febb
movq 0x28(%rbx), %rsi
movq %r15, %rdi
callq 0x17914
jmp 0x1fec6
movq %rbp, 0x240(%rbx)
cmpb $0x0, 0x230(%rbx)
jne 0x1fe7f
leaq 0x158(%rbx), %rdi
movq %rbp, %rsi
callq 0x843c
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 0x202da
andq $0x0, 0x1a8(%rbx)
movq %rbx, %rdi
callq 0x203a6
jmp 0x1ff18
movq %r15, %rdi
movq %r12, %rsi
callq 0x179de
movq (%rsp), %rax
cmpq %rax, 0x8(%rsp)
je 0x1feef
movdqu 0x1a8(%rbx), %xmm0
movq %r13, %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)
andq $0x0, 0x228(%rbx)
movb $0x1, %al
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpq $0x0, 0x240(%rbx)
je 0x1ff3d
movq %rbx, %rdi
callq 0x20146
jmp 0x1ff18
xorl %eax, %eax
jmp 0x1ff1a
pushq $0x10
popq %rdi
callq 0x41c0
movq %rax, %rbx
leaq 0x32a5c(%rip), %rsi     # 0x529af
movq %rax, %rdi
callq 0x4120
movq 0x55086(%rip), %rsi     # 0x74fe8
movq 0x5504f(%rip), %rdx     # 0x74fb8
movq %rbx, %rdi
callq 0x45b0
pushq $0x10
popq %rdi
callq 0x41c0
movq %rax, %rbx
leaq 0x329f7(%rip), %rsi     # 0x5297a
movq %rax, %rdi
callq 0x4120
jmp 0x1ff5b
jmp 0x1ff8f
movq %rax, %r14
movq %rbx, %rdi
callq 0x4290
movq %r14, %rdi
callq 0x4600