// File: 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
movq %rsp, %rbp
subq $0x290, %rsp            # imm = 0x290
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x1c548
movq -0x8(%rbp), %rsi
movq -0x30(%rbp), %rdx
leaq -0x170(%rbp), %rdi
callq 0x89e00
cmpl $0x0, %eax
jne 0x1c53d
movl $0x10, %edi
callq 0x41e0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x228(%rbp)
leaq 0x92acd(%rip), %rsi     # 0xaefc6
callq 0x4140
jmp 0x1c500
movq -0x228(%rbp), %rdi
movq 0xc9ae2(%rip), %rsi     # 0xe5ff0
movq 0xc9aab(%rip), %rdx     # 0xe5fc0
callq 0x4630
movq -0x228(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x178(%rbp)
movl %eax, -0x17c(%rbp)
callq 0x42e0
jmp 0x1c907
leaq -0x170(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
cmpq $0x0, 0x18(%rax)
seta %al
andb $0x1, %al
movb %al, -0x17d(%rbp)
testb $0x1, -0x17d(%rbp)
je 0x1c66d
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x30(%rbp), %rcx
movq -0x28(%rbp), %rdx
addq 0x20(%rdx), %rcx
addq %rcx, %rax
movq -0x8(%rbp), %rcx
cmpq 0x8(%rcx), %rax
je 0x1c5ec
movl $0x10, %edi
callq 0x41e0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x230(%rbp)
leaq 0x92a49(%rip), %rsi     # 0xaeff1
callq 0x4140
jmp 0x1c5af
movq -0x230(%rbp), %rdi
movq 0xc9a33(%rip), %rsi     # 0xe5ff0
movq 0xc99fc(%rip), %rdx     # 0xe5fc0
callq 0x4630
movq -0x230(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x178(%rbp)
movl %eax, -0x17c(%rbp)
callq 0x42e0
jmp 0x1c907
cmpq $0x0, -0x10(%rbp)
je 0x1c609
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq -0x28(%rbp), %rdi
addq $0x38, %rdi
callq *%rax
cmpl $0x0, %eax
jne 0x1c66b
movl $0x10, %edi
callq 0x41e0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x238(%rbp)
leaq 0x929fa(%rip), %rsi     # 0xaf021
callq 0x4140
jmp 0x1c62e
movq -0x238(%rbp), %rdi
movq 0xc99b4(%rip), %rsi     # 0xe5ff0
movq 0xc997d(%rip), %rdx     # 0xe5fc0
callq 0x4630
movq -0x238(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x178(%rbp)
movl %eax, -0x17c(%rbp)
callq 0x42e0
jmp 0x1c907
jmp 0x1c66d
movq -0x18(%rbp), %rsi
movq 0x10(%rbp), %rdx
leaq -0x1a8(%rbp), %rdi
callq 0x4f3c0
leaq -0x1c0(%rbp), %rdi
movq %rdi, -0x240(%rbp)
callq 0xbe70
movq -0x240(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq 0xc9eda(%rip), %rdx     # 0xe6580
callq 0x1c330
jmp 0x1c6ad
movq -0x28(%rbp), %rax
movq (%rax), %rsi
leaq -0x1c0(%rbp), %rdi
callq 0x1c920
jmp 0x1c6c2
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rsi
leaq -0x1c0(%rbp), %rdi
callq 0x1c920
jmp 0x1c6d8
movq -0x28(%rbp), %rax
movq 0x28(%rax), %rsi
leaq -0x1c0(%rbp), %rdi
callq 0x1c920
jmp 0x1c6ee
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rsi
leaq -0x1c0(%rbp), %rdi
callq 0x1c920
jmp 0x1c704
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rsi
leaq -0x1c0(%rbp), %rdi
callq 0x1c920
jmp 0x1c71a
leaq -0x1c0(%rbp), %rdi
movq %rdi, -0x250(%rbp)
callq 0xbb60
movq -0x250(%rbp), %rdi
movq %rax, -0x248(%rbp)
callq 0xbe90
movq -0x248(%rbp), %rsi
movq %rax, %rdx
leaq -0x1a8(%rbp), %rdi
callq 0x4f450
jmp 0x1c758
leaq -0x1c0(%rbp), %rdi
callq 0xbb80
movq -0x8(%rbp), %rax
movq %rax, -0x268(%rbp)
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rax
addq -0x30(%rbp), %rax
movq %rax, -0x260(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x258(%rbp)
testb $0x1, -0x17d(%rbp)
je 0x1c7a7
movq -0x10(%rbp), %rax
movq %rax, -0x270(%rbp)
jmp 0x1c7b2
xorl %eax, %eax
movq %rax, -0x270(%rbp)
jmp 0x1c7b2
movq -0x258(%rbp), %rcx
movq -0x260(%rbp), %rdx
movq -0x268(%rbp), %rsi
movq -0x270(%rbp), %r8
movq -0x28(%rbp), %rax
movq 0x10(%rax), %r9
leaq -0x210(%rbp), %rdi
callq 0x29e00
jmp 0x1c7e4
cmpq $0x0, -0x20(%rbp)
je 0x1c7fc
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x278(%rbp)
jmp 0x1c807
xorl %eax, %eax
movq %rax, -0x278(%rbp)
jmp 0x1c807
movq -0x278(%rbp), %rsi
leaq -0x1a8(%rbp), %rdi
callq 0x29eb0
movq %rdx, -0x288(%rbp)
movq %rax, -0x280(%rbp)
jmp 0x1c82a
movq -0x288(%rbp), %rax
movq -0x280(%rbp), %rcx
movq %rcx, -0x220(%rbp)
movq %rax, -0x218(%rbp)
movq -0x20(%rbp), %rdx
xorl %r8d, %r8d
movl %r8d, %r9d
leaq -0x1a8(%rbp), %rdi
leaq -0x210(%rbp), %rsi
leaq -0x220(%rbp), %rcx
callq 0x4fd10
jmp 0x1c86c
leaq -0x210(%rbp), %rdi
callq 0x29e80
leaq -0x1a8(%rbp), %rdi
callq 0x29f00
movq %rax, -0x290(%rbp)
jmp 0x1c88d
leaq -0x1a8(%rbp), %rdi
callq 0x4f430
movq -0x290(%rbp), %rax
addq $0x290, %rsp            # imm = 0x290
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x178(%rbp)
movl %eax, -0x17c(%rbp)
leaq -0x1c0(%rbp), %rdi
callq 0xbb80
jmp 0x1c8fb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x178(%rbp)
movl %eax, -0x17c(%rbp)
jmp 0x1c8fb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x178(%rbp)
movl %eax, -0x17c(%rbp)
leaq -0x210(%rbp), %rdi
callq 0x29e80
leaq -0x1a8(%rbp), %rdi
callq 0x4f430
movq -0x178(%rbp), %rdi
callq 0x4680
nopw %cs:(%rax,%rax)