// File: sisong[P]ApkDiffPatch/src/patch/NewStream.cpp
// Function: copy_same_file(NewStream*, unsigned int, unsigned int)
static bool _copy_same_file(NewStream* self,uint32_t newFileIndex,uint32_t oldFileIndex){
    bool oldIsCompress;
    uint32_t uncompressedSize,compressedSize,crc32;
#if (_IS_NEED_VIRTUAL_ZIP)
    TZipEntryData* entryData=0;
    if ((self->_vin)&&(self->_vin->entryDatas[oldFileIndex])){
        entryData=self->_vin->entryDatas[oldFileIndex];
        oldIsCompress=entryData->isCompressed;
        uncompressedSize=entryData->uncompressedSize;
        crc32=self->_vin->import->getCrc32(self->_vin->import,self->_oldZip,oldFileIndex,entryData);
        compressedSize=entryData->savedCompressedSize;
    }else
#endif
    {
        oldIsCompress=UnZipper_file_isCompressed(self->_oldZip,oldFileIndex);
        uncompressedSize=UnZipper_file_uncompressedSize(self->_oldZip,oldFileIndex);
        crc32=UnZipper_file_crc32(self->_oldZip,oldFileIndex);
        compressedSize=UnZipper_file_compressedSize(self->_oldZip,oldFileIndex);
    }
    
    check(UnZipper_file_uncompressedSize(&self->_newZipVCE,newFileIndex)==uncompressedSize);
    check(UnZipper_file_crc32(&self->_newZipVCE,newFileIndex)==crc32);
    bool newIsCompress=UnZipper_file_isCompressed(&self->_newZipVCE,newFileIndex);
    bool isNeedDecompress=self->_isAlwaysReCompress|((oldIsCompress)&(!newIsCompress));
    ZipFilePos_t newCompressedSize=UnZipper_file_compressedSize(&self->_newZipVCE,newFileIndex);
    if (newCompressedSize>0)
        compressedSize=newCompressedSize;
    _update_compressedSize(self,newFileIndex,newIsCompress?compressedSize:uncompressedSize);
    bool  appendDataIsCompressed=(!isNeedDecompress)&&oldIsCompress;
    
    bool is0FileSize=false; // in zip
#if (_IS_NEED_VIRTUAL_ZIP)
    TVirtualZip_out_type ty=kVirtualZip_out_void;
    if (self->_vout){
        ty=self->_vout->beginVirtualCopy(self->_vout,&self->_newZipVCE,newFileIndex,
                                         self->_oldZip,oldFileIndex);
        switch (ty) {
            case kVirtualZip_out_void: { //ok, do nothing
                assert(self->_vout->virtualStream==0); } break;
            case kVirtualZip_out_emptyFile_cast: { // set fileSize==0
                assert(self->_vout->virtualStream==0);
                _update_fileSize(self,newFileIndex,0,0);
                is0FileSize=true; } break;
            case kVirtualZip_out_emptyFile_uncompressed: { //set fileSize==0, need out and endVirtual
                assert(self->_vout->virtualStream!=0);
                _update_fileSize(self,newFileIndex,0,0);
                is0FileSize=true;
                isNeedDecompress=true; } break;
            default: { check(false); } break; //error, or unknow as error
        }
    }
#endif
    check(Zipper_file_append_begin(self->_out_newZip,&self->_newZipVCE,newFileIndex,
                                   appendDataIsCompressed,
                                   is0FileSize?0:uncompressedSize,is0FileSize?0:compressedSize));
    const hpatch_TStreamOutput* outStream=0;
#if (_IS_NEED_VIRTUAL_ZIP)
    switch (ty) {
        case kVirtualZip_out_void: { //copy to zip
            outStream=Zipper_file_append_part_as_stream(self->_out_newZip); } break;
        case kVirtualZip_out_emptyFile_cast: { } break; //nothing out
        case kVirtualZip_out_emptyFile_uncompressed: { //copy to virtualStream
            outStream=self->_vout->virtualStream; } break;
        default: { check(false); } break; //error, or unknow as error
    }
#else //copy to zip
    outStream=Zipper_file_append_part_as_stream(self->_out_newZip);
#endif
    if (outStream){
#if (_IS_NEED_VIRTUAL_ZIP)
        if (entryData){
            if (entryData->isCompressed){
                check(UnZipper_compressedData_decompressTo(self->_oldZip,entryData->dataStream,
                                                           0,entryData->dataStream->streamSize,
                                                           entryData->uncompressedSize,outStream,0));
            }else{
                check(UnZipper_dataStream_copyTo(self->_oldZip,entryData->dataStream,
                                                 0,entryData->dataStream->streamSize,outStream,0));
            }
        }else
#endif
        {
            if (isNeedDecompress){
                check(UnZipper_fileData_decompressTo(self->_oldZip,oldFileIndex,outStream));
            }else{
                check(UnZipper_fileData_copyTo(self->_oldZip,oldFileIndex,outStream));
            }
        }
    }
    
    check(Zipper_file_append_end(self->_out_newZip));
#if (_IS_NEED_VIRTUAL_ZIP)
    if ((self->_vout)&&(self->_vout->virtualStream))
        check(self->_vout->endVirtual(self->_vout));
#endif
    return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl -0x10(%rbp), %esi
callq 0x7f2e0
andb $0x1, %al
movb %al, -0x11(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl -0x10(%rbp), %esi
callq 0x80480
movl %eax, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl -0x10(%rbp), %esi
callq 0x80540
movl %eax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl -0x10(%rbp), %esi
callq 0x80520
movl %eax, -0x1c(%rbp)
movq -0x8(%rbp), %rdi
addq $0xd0, %rdi
movl -0xc(%rbp), %esi
callq 0x80480
cmpl -0x18(%rbp), %eax
je 0xa3258
leaq 0x1c0cf(%rip), %rdi     # 0xbf301
movb $0x0, %al
callq 0x4060
leaq 0xa030(%rip), %rdi      # 0xad270
leaq 0x1b979(%rip), %rsi     # 0xbebc0
movl $0x12a, %edx            # imm = 0x12A
leaq 0x1c107(%rip), %rcx     # 0xbf35a
callq 0x4270
movq -0x8(%rbp), %rdi
addq $0xd0, %rdi
movl -0xc(%rbp), %esi
callq 0x80540
cmpl -0x20(%rbp), %eax
je 0xa329d
leaq 0x1c119(%rip), %rdi     # 0xbf390
movb $0x0, %al
callq 0x4060
leaq 0x9feb(%rip), %rdi      # 0xad270
leaq 0x1b934(%rip), %rsi     # 0xbebc0
movl $0x12b, %edx            # imm = 0x12B
leaq 0x1c0c2(%rip), %rcx     # 0xbf35a
callq 0x4270
movq -0x8(%rbp), %rdi
addq $0xd0, %rdi
movl -0xc(%rbp), %esi
callq 0x7f2e0
andb $0x1, %al
movb %al, -0x21(%rbp)
movq -0x8(%rbp), %rax
movb 0xc8(%rax), %al
andb $0x1, %al
movzbl %al, %eax
movb -0x11(%rbp), %cl
andb $0x1, %cl
movzbl %cl, %ecx
movb -0x21(%rbp), %dl
xorb $-0x1, %dl
andb $0x1, %dl
movzbl %dl, %edx
andl %edx, %ecx
orl %ecx, %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movb %al, -0x22(%rbp)
movq -0x8(%rbp), %rdi
addq $0xd0, %rdi
movl -0xc(%rbp), %esi
callq 0x80520
movl %eax, -0x28(%rbp)
cmpl $0x0, -0x28(%rbp)
jbe 0xa330a
movl -0x28(%rbp), %eax
movl %eax, -0x1c(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x48(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x3c(%rbp)
testb $0x1, -0x21(%rbp)
je 0xa3326
movl -0x1c(%rbp), %eax
movl %eax, -0x4c(%rbp)
jmp 0xa332c
movl -0x18(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl -0x3c(%rbp), %esi
movq -0x48(%rbp), %rdi
movl -0x4c(%rbp), %edx
callq 0xa3510
xorl %eax, %eax
testb $0x1, -0x22(%rbp)
movb %al, -0x4d(%rbp)
jne 0xa334c
movb -0x11(%rbp), %al
movb %al, -0x4d(%rbp)
movb -0x4d(%rbp), %al
andb $0x1, %al
movb %al, -0x29(%rbp)
movb $0x0, -0x2a(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x68(%rbp)
movq -0x8(%rbp), %rax
addq $0xd0, %rax
movq %rax, -0x60(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x54(%rbp)
movb -0x29(%rbp), %al
movb %al, -0x4e(%rbp)
testb $0x1, -0x2a(%rbp)
je 0xa338b
xorl %eax, %eax
movl %eax, -0x6c(%rbp)
jmp 0xa3391
movl -0x18(%rbp), %eax
movl %eax, -0x6c(%rbp)
movl -0x6c(%rbp), %eax
movl %eax, %eax
movq %rax, -0x78(%rbp)
testb $0x1, -0x2a(%rbp)
je 0xa33a7
xorl %eax, %eax
movl %eax, -0x7c(%rbp)
jmp 0xa33ad
movl -0x1c(%rbp), %eax
movl %eax, -0x7c(%rbp)
movq -0x78(%rbp), %r8
movl -0x54(%rbp), %edx
movq -0x60(%rbp), %rsi
movq -0x68(%rbp), %rdi
movb -0x4e(%rbp), %al
movl -0x7c(%rbp), %ecx
movl %ecx, %ecx
movl %ecx, %r9d
movzbl %al, %ecx
andl $0x1, %ecx
callq 0x82320
testb $0x1, %al
jne 0xa3403
leaq 0x1bff6(%rip), %rdi     # 0xbf3d3
movb $0x0, %al
callq 0x4060
leaq 0x9e85(%rip), %rdi      # 0xad270
leaq 0x1b7ce(%rip), %rsi     # 0xbebc0
movl $0x14c, %edx            # imm = 0x14C
leaq 0x1bf5c(%rip), %rcx     # 0xbf35a
callq 0x4270
movq $0x0, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x83740
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0xa34c5
testb $0x1, -0x22(%rbp)
je 0xa3478
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl -0x10(%rbp), %esi
movq -0x38(%rbp), %rdx
xorl %eax, %eax
movl %eax, %ecx
callq 0x80d50
testb $0x1, %al
jne 0xa3476
leaq 0x1c02b(%rip), %rdi     # 0xbf47b
movb $0x0, %al
callq 0x4060
leaq 0x9e12(%rip), %rdi      # 0xad270
leaq 0x1b75b(%rip), %rsi     # 0xbebc0
movl $0x169, %edx            # imm = 0x169
leaq 0x1bee9(%rip), %rcx     # 0xbf35a
callq 0x4270
jmp 0xa34c3
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl -0x10(%rbp), %esi
movq -0x38(%rbp), %rdx
xorl %eax, %eax
movl %eax, %ecx
callq 0x806e0
testb $0x1, %al
jne 0xa34c1
leaq 0x1c02d(%rip), %rdi     # 0xbf4c8
movb $0x0, %al
callq 0x4060
leaq 0x9dc7(%rip), %rdi      # 0xad270
leaq 0x1b710(%rip), %rsi     # 0xbebc0
movl $0x16b, %edx            # imm = 0x16B
leaq 0x1be9e(%rip), %rcx     # 0xbf35a
callq 0x4270
jmp 0xa34c3
jmp 0xa34c5
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x83280
testb $0x1, %al
jne 0xa3503
leaq 0x1bb06(%rip), %rdi     # 0xbefe3
movb $0x0, %al
callq 0x4060
leaq 0x9d85(%rip), %rdi      # 0xad270
leaq 0x1b6ce(%rip), %rsi     # 0xbebc0
movl $0x170, %edx            # imm = 0x170
leaq 0x1be5c(%rip), %rcx     # 0xbf35a
callq 0x4270
movb $0x1, %al
andb $0x1, %al
addq $0x80, %rsp
popq %rbp
retq