// File: /workspace/github_cpp_makefile_star2_O2/sisong[P]ApkDiffPatch/HDiffPatch/libHDiffPatch/HDiff/diff.cpp
// Function: resave_single_compressed_diff(hpatch_TStreamInput const*, hpatch_TDecompress*, hpatch_TStreamOutput const*, hdiff_TCompress const*, hpatch_singleCompressedDiffInfo const*, unsigned long long, unsigned long long)
hpatch_StreamPos_t
     resave_single_compressed_diff(const hpatch_TStreamInput*  in_diff,
                                   hpatch_TDecompress*         decompressPlugin,
                                   const hpatch_TStreamOutput* out_diff,
                                   const hdiff_TCompress*      compressPlugin,
                                   const hpatch_singleCompressedDiffInfo* diffInfo,
                                   hpatch_StreamPos_t          in_diff_curPos,
                                   hpatch_StreamPos_t          out_diff_curPos){
    hpatch_singleCompressedDiffInfo _diffInfo;
    if (diffInfo==0){
        checki(getSingleCompressedDiffInfo(&_diffInfo,in_diff,in_diff_curPos),
               "getSingleCompressedDiffInfo() return fail!");
        diffInfo=&_diffInfo;
    }
    const bool isCompressed=(diffInfo->compressedSize>0);
    if (isCompressed){ //check
        checki(diffInfo->compressedSize+(in_diff_curPos+diffInfo->diffDataPos)==in_diff->streamSize,
               "resave_single_compressed_diff() diffInfo error!");
        checki((decompressPlugin!=0)&&(decompressPlugin->is_can_open(diffInfo->compressType)),
               "resave_single_compressed_diff() decompressPlugin error!");
    }

    TDiffStream outDiff(out_diff,out_diff_curPos);
    {//type & head
        std::vector<TByte> outBuf;
        _outType(outBuf, compressPlugin,kHDiffSFVersionType);
        packUInt(outBuf, diffInfo->newDataSize);
        packUInt(outBuf, diffInfo->oldDataSize);
        packUInt(outBuf, diffInfo->coverCount);
        packUInt(outBuf, diffInfo->stepMemSize);
        packUInt(outBuf, diffInfo->uncompressedSize);
        outDiff.pushBack(outBuf.data(),outBuf.size());
        //no compressedSize
    }
    {//save single stream data
        TStreamClip clip(in_diff,diffInfo->diffDataPos+in_diff_curPos,in_diff->streamSize,
                         isCompressed?decompressPlugin:0,diffInfo->uncompressedSize);
        TPlaceholder compressedSize_pos=outDiff.packUInt_pos(compressPlugin?diffInfo->uncompressedSize:0);
        outDiff.pushStream(&clip,compressPlugin,compressedSize_pos);
    }
    return outDiff.getWritedPos();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1d8, %rsp            # imm = 0x1D8
movq %r9, %r15
movq %rcx, 0x8(%rsp)
movq %rdx, %rbp
movq %rsi, %r12
movq %rdi, %r13
testq %r8, %r8
je 0xe189
movq %r8, %r14
leaq 0x38(%r8), %rdi
jmp 0xe1af
leaq 0x98(%rsp), %r14
movq %r14, %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x3d4d6
testl %eax, %eax
je 0xe347
leaq 0xd0(%rsp), %rdi
movq 0x18(%r14), %rbx
testq %rbx, %rbx
je 0xe1df
leaq (%rbx,%r15), %rax
addq 0x20(%r14), %rax
cmpq 0x8(%r13), %rax
jne 0xe32b
testq %r12, %r12
je 0xe30f
callq *(%r12)
testl %eax, %eax
je 0xe30f
movq 0x210(%rsp), %rdx
leaq 0x60(%rsp), %rdi
movq %rbp, %rsi
callq 0x20594
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %rdi
movaps %xmm0, (%rdi)
andq $0x0, 0x10(%rdi)
leaq 0x432ef(%rip), %rdx     # 0x514fa
movq 0x8(%rsp), %rbp
movq %rbp, %rsi
callq 0xe07a
movq (%r14), %rsi
leaq 0x10(%rsp), %rdi
callq 0xe3bb
movq 0x8(%r14), %rsi
leaq 0x10(%rsp), %rdi
callq 0xe3bb
movq 0x28(%r14), %rsi
leaq 0x10(%rsp), %rdi
callq 0xe3bb
movq 0x30(%r14), %rsi
leaq 0x10(%rsp), %rdi
callq 0xe3bb
movq 0x10(%r14), %rsi
leaq 0x10(%rsp), %rdi
callq 0xe3bb
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
subq %rsi, %rdx
leaq 0x60(%rsp), %rdi
callq 0x205e2
leaq 0x10(%rsp), %rdi
callq 0x8b88
addq 0x20(%r14), %r15
testq %rbx, %rbx
movq 0x8(%r13), %rcx
cmoveq %rbx, %r12
movq 0x10(%r14), %r9
leaq 0x10(%rsp), %rdi
movq %r13, %rsi
movq %r15, %rdx
movq %r12, %r8
callq 0x11ea4
testq %rbp, %rbp
je 0xe2af
movq 0x10(%r14), %rsi
jmp 0xe2b1
xorl %esi, %esi
leaq 0x60(%rsp), %rdi
callq 0x11ece
leaq 0x88(%rsp), %rcx
movq %rax, (%rcx)
movq %rdx, 0x8(%rcx)
leaq 0x60(%rsp), %rdi
leaq 0x10(%rsp), %rsi
movq %rbp, %rdx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x20a6c
leaq 0x10(%rsp), %rdi
callq 0x11ebe
leaq 0x60(%rsp), %rdi
movq 0x8(%rdi), %rbx
callq 0x205d8
movq %rbx, %rax
addq $0x1d8, %rsp            # imm = 0x1D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x10
popq %rdi
callq 0x41c0
movq %rax, %r14
leaq 0x428b5(%rip), %rsi     # 0x50bd6
movq %rax, %rdi
callq 0x4120
jmp 0xe361
pushq $0x10
popq %rdi
callq 0x41c0
movq %rax, %r14
leaq 0x42869(%rip), %rsi     # 0x50ba6
movq %rax, %rdi
callq 0x4120
jmp 0xe361
pushq $0x10
popq %rdi
callq 0x41c0
movq %rax, %r14
leaq 0x42822(%rip), %rsi     # 0x50b7b
movq %rax, %rdi
callq 0x4120
movq 0x66c80(%rip), %rsi     # 0x74fe8
movq 0x66c49(%rip), %rdx     # 0x74fb8
movq %r14, %rdi
callq 0x45b0
jmp 0xe37b
jmp 0xe37b
movq %rax, %rbx
movq %r14, %rdi
callq 0x4290
jmp 0xe3b3
movq %rax, %rbx
jmp 0xe3a9
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x11ebe
jmp 0xe3a9
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x8b88
leaq 0x60(%rsp), %rdi
callq 0x205d8
movq %rbx, %rdi
callq 0x4600