// File: /workspace/github_cpp_makefile_star2_O1/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
cmpq $0x0, 0x228(%rdi)
jne 0x24af8
cmpb $0x1, 0x1b9(%rbx)
jne 0x24ad6
movb $0x0, 0x1b9(%rbx)
leaq 0x1d8(%rbx), %rax
jmp 0x24af1
cmpb $0x1, 0x1ba(%rbx)
jne 0x24f39
movb $0x0, 0x1ba(%rbx)
leaq 0x1f0(%rbx), %rax
movq %rax, 0x228(%rbx)
movq 0x228(%rbx), %rax
movups (%rax), %xmm0
movups %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 0x24b53
subq %rcx, %rdx
testb %sil, %sil
je 0x24b73
movq %rdx, %rdi
jmp 0x24b5b
testb %sil, %sil
je 0x24bba
movq %rax, %rdi
movl $0x1, %esi
callq 0x43897
movl %eax, %eax
addq %rax, 0x240(%rbx)
jmp 0x24c01
leaq 0xd(%rsp), %rax
leaq 0x18(%rsp), %rdi
movq %rax, (%rdi)
leaq 0x18(%rsp), %rsi
movl $0x1, %ecx
movl $0x1, %r8d
callq 0x437d8
testl %eax, %eax
jne 0x24be4
movl $0x10, %edi
callq 0x4190
movq %rax, %r14
leaq 0x35853(%rip), %rsi     # 0x5a400
movq %rax, %rdi
callq 0x4110
jmp 0x25001
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 0x437d8
testl %eax, %eax
je 0x25071
leaq 0x158(%rbx), %rdi
movq 0x160(%rbx), %rsi
movq 0x18(%rsp), %rcx
leaq 0xd(%rsp), %rdx
callq 0x9e84
movq %r15, 0x28(%rsp)
subq %r12, %r15
cmpb $0x1, 0x230(%rbx)
movq %r14, 0x30(%rsp)
movq %r12, 0x20(%rsp)
jne 0x24c48
movq %r15, %rdi
xorl %esi, %esi
callq 0x43897
movl %eax, %r12d
movq 0x220(%rbx), %rdi
xorl %esi, %esi
callq 0x43897
movl %eax, %ebp
addl %r12d, %ebp
addq 0x240(%rbx), %rbp
jmp 0x24ce2
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 0x437d8
testl %eax, %eax
je 0x25017
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 0x9e84
movq 0x220(%rbx), %rdx
movq %rbp, (%r13)
leaq 0x18(%rsp), %rsi
movq %r13, %rdi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x437d8
testl %eax, %eax
je 0x25035
movq 0x160(%rbx), %rsi
movq 0x18(%rsp), %rcx
leaq 0xd(%rsp), %rdx
movq %r12, %rdi
callq 0x9e84
movq 0x160(%rbx), %rbp
subq 0x158(%rbx), %rbp
leaq 0x210(%rbx), %r14
movq %rbp, 0x240(%rbx)
leaq 0x20(%rbx), %r12
movups (%r14), %xmm0
movups %xmm0, 0x68(%rbx)
movq 0x10(%r14), %rax
movq %rax, 0x78(%rbx)
movq %rax, 0x28(%rbx)
movq %rax, 0x48(%rbx)
movq $0x0, 0x50(%rbx)
leaq 0x170(%rbx), %r13
cmpb $0x1, 0x40(%rbx)
jne 0x24d2f
movq 0x28(%rbx), %rsi
movq %r13, %rdi
callq 0x1b4b0
jmp 0x24d3a
movq %r13, %rdi
movq %r12, %rsi
callq 0x1b5bc
addq %rbp, %rax
cmpq 0x118(%rbx), %rax
jbe 0x24e60
movq %r13, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x1b1a0
movq 0x30(%rsp), %rbp
addq %rbp, %rax
movq 0x118(%rbx), %rcx
shrq %rcx
cmpq %rcx, %rax
jae 0x24e74
cmpb $0x0, 0x1b9(%rbx)
jne 0x25053
cmpb $0x1, 0x1ba(%rbx)
je 0x25053
movw $0x101, 0x1b9(%rbx)     # imm = 0x101
movups (%r14), %xmm0
movups %xmm0, 0x1d8(%rbx)
movq 0x10(%r14), %rax
movq %rax, 0x1e8(%rbx)
movups (%r14), %xmm0
movups %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 0x244d8
cmpq $0x3, %r14
jbe 0x24fe5
movq 0x240(%rbx), %r14
cmpb $0x1, 0x40(%rbx)
jne 0x24e02
movq 0x28(%rbx), %rsi
movq %r13, %rdi
callq 0x1b4b0
jmp 0x24e0d
movq %r13, %rdi
movq %r12, %rsi
callq 0x1b5bc
addq %r14, %rax
cmpq 0x118(%rbx), %rax
ja 0x24dc7
movq %r15, 0x1e8(%rbx)
subq %r15, 0x200(%rbx)
addq %r15, 0x1f0(%rbx)
addq %r15, 0x1f8(%rbx)
movq %rbp, 0x240(%rbx)
cmpb $0x0, 0x230(%rbx)
jne 0x24e54
leaq 0x158(%rbx), %rdi
movq %rbp, %rsi
callq 0x9d84
incq 0x128(%rbx)
jmp 0x24f1d
cmpb $0x1, 0x40(%rbx)
jne 0x24ed2
movq 0x28(%rbx), %rsi
movq %r13, %rdi
callq 0x1b70a
jmp 0x24edd
movq %rbp, 0x240(%rbx)
cmpb $0x0, 0x230(%rbx)
jne 0x24e93
leaq 0x158(%rbx), %rdi
movq %rbp, %rsi
callq 0x9d84
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 0x25364
movq $0x0, 0x1a8(%rbx)
movq %rbx, %rdi
callq 0x25438
jmp 0x24f28
movq %r13, %rdi
movq %r12, %rsi
callq 0x1b858
movq 0x20(%rsp), %rax
cmpq %rax, 0x28(%rsp)
je 0x24ef7
addq %r15, 0x1b0(%rbx)
addq %r15, 0x1a8(%rbx)
movq 0x220(%rbx), %rax
movq 0x210(%rbx), %rcx
addq %rax, %rcx
movq %rcx, 0x148(%rbx)
addq 0x218(%rbx), %rax
movq %rax, 0x150(%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 0x24f92
leaq 0x1(%rdx), %rax
movq %rax, 0x208(%rbx)
leaq 0x210(%rbx), %rax
movq 0x10(%rsi), %rcx
cmpb $0x1, 0x20(%rsi)
jne 0x24fae
leaq (%rdx,%rdx,2), %rdx
movl (%rcx,%rdx,4), %esi
movq %rsi, 0x210(%rbx)
movl 0x4(%rcx,%rdx,4), %esi
movq %rsi, 0x218(%rbx)
movl 0x8(%rcx,%rdx,4), %ecx
movq %rcx, 0x220(%rbx)
jmp 0x24af1
cmpb $0x1, 0x1b8(%rbx)
jne 0x24fc7
movb $0x0, 0x1b8(%rbx)
leaq 0x1c0(%rbx), %rax
jmp 0x24af1
leaq (%rdx,%rdx,2), %rdx
movq 0x10(%rcx,%rdx,8), %rsi
movq %rsi, 0x10(%rax)
movups (%rcx,%rdx,8), %xmm0
movups %xmm0, (%rax)
jmp 0x24af1
cmpq $0x0, 0x240(%rbx)
je 0x24fde
movq %rbx, %rdi
callq 0x25264
jmp 0x24f28
xorl %eax, %eax
jmp 0x24f2a
movl $0x10, %edi
callq 0x4190
movq %rax, %r14
leaq 0x388a6(%rip), %rsi     # 0x5d89f
movq %rax, %rdi
callq 0x4110
movq 0x56fe0(%rip), %rsi     # 0x7bfe8
movq 0x56fa9(%rip), %rdx     # 0x7bfb8
movq %r14, %rdi
callq 0x4590
movl $0x10, %edi
callq 0x4190
movq %rax, %r14
leaq 0x353d5(%rip), %rsi     # 0x5a400
movq %rax, %rdi
callq 0x4110
jmp 0x25001
movl $0x10, %edi
callq 0x4190
movq %rax, %r14
leaq 0x353b7(%rip), %rsi     # 0x5a400
movq %rax, %rdi
callq 0x4110
jmp 0x25001
movl $0x10, %edi
callq 0x4190
movq %rax, %r14
leaq 0x38803(%rip), %rsi     # 0x5d86a
movq %rax, %rdi
callq 0x4110
jmp 0x25001
movl $0x10, %edi
callq 0x4190
movq %rax, %r14
leaq 0x3537b(%rip), %rsi     # 0x5a400
movq %rax, %rdi
callq 0x4110
jmp 0x25001
jmp 0x2509c
jmp 0x2509c
jmp 0x2509c
jmp 0x2509c
jmp 0x2509c
movq %rax, %rbx
movq %r14, %rdi
callq 0x4260
movq %rbx, %rdi
callq 0x45e0
nop