// File: sisong[P]ApkDiffPatch/src/patch/Zipper.cpp
// Function: Zipper_file_append_beginWith
bool Zipper_file_append_beginWith(Zipper* self,UnZipper* srcZip,int srcFileIndex,
                                  bool appendDataIsCompressed,size_t dataUncompressedSize,size_t dataCompressedSize,
                                  int curFileCompressLevel,int curFileCompressMemLevel){
    const bool dstFileIsCompressed=_zipper_curFile_isCompressed(self,srcZip,srcFileIndex);
    if (dstFileIsCompressed&&(!appendDataIsCompressed))
        checkCompressSet(curFileCompressLevel,curFileCompressMemLevel);
    if ((!dstFileIsCompressed)&&(appendDataIsCompressed)){
        assert(false);//now need input decompressed data;
        return false; // for example: UnZipper_fileData_decompressTo(Zipper_file_append_part_as_stream());
    }
    if (0==dataCompressedSize){
        check((!appendDataIsCompressed)||(dataUncompressedSize==0));
        if (dataUncompressedSize!=0)
            dataCompressedSize=UnZipper_file_compressedSize(srcZip,srcFileIndex);//temp value
    }
    Zipper_file_append_stream* append_state=&self->_append_stream;
    if (append_state->self!=0){
        assert(false);  //need call Zipper_file_append_end()
        return false;
    }
    
    int curFileIndex=self->_fileEntryCount;
    check(curFileIndex < self->_fileEntryMaxCount);
    self->_fileEntryCount=curFileIndex+1;
    self->_fileCompressedSizes[curFileIndex]=dstFileIsCompressed?(ZipFilePos_t)dataCompressedSize: //maybe temp value
                                            (ZipFilePos_t)dataUncompressedSize; //finally value
    check(_write_fileHeaderInfo(self,curFileIndex,srcZip,srcFileIndex,false));//out file info
    
    append_state->self=self;
    append_state->compressor=&TZipCompressor_zlib;
    append_state->inputPos=0;
    append_state->outputPos=0;
    append_state->curFileIndex=curFileIndex;
    append_state->streamImport=append_state;
    append_state->streamSize=appendDataIsCompressed?dataCompressedSize:dataUncompressedSize; //finally value
    append_state->write=Zipper_file_append_stream::_append_part_input;
    assert(append_state->compressHandle==0);
    assert(append_state->threadWork==0);
    if (dstFileIsCompressed&&(!appendDataIsCompressed)){//compress data
#if (_IS_USED_MULTITHREAD)
        if (isUsedMT(self)&&(dataCompressedSize>0)){
            self->_threadWorks->waitCanFastDispatchWork();
            append_state->threadWork=newThreadWork(dataUncompressedSize,dataCompressedSize,self->_curFilePos,
                                                   curFileCompressLevel,curFileCompressMemLevel);
            if ((append_state->threadWork)&&(!_writeSkip(self,dataCompressedSize)))
                return false;
            //else continue : this thread do compress
        }
#endif
        if (!append_state->threadWork){
            append_state->compressOutStream.streamImport=append_state;
            append_state->compressOutStream.streamSize=self->_fileCompressedSizes[curFileIndex];//not used
            append_state->compressOutStream.write=Zipper_file_append_stream::_append_part_output;
            append_state->compressHandle=append_state->compressor->openCompressHandle(append_state->compressor,dataUncompressedSize,
                                                                curFileCompressLevel,curFileCompressMemLevel,
                                                                &append_state->compressOutStream,self->_codeBuf,kBufSize);
            if (!append_state->compressHandle)
                return false;
        }
    }//else //copy data
    return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movb %cl, %al
movl 0x18(%rbp), %ecx
movl 0x10(%rbp), %ecx
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
andb $0x1, %al
movb %al, -0x1d(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
callq 0x827a0
andb $0x1, %al
movb %al, -0x31(%rbp)
testb $0x1, -0x31(%rbp)
je 0x82436
testb $0x1, -0x1d(%rbp)
jne 0x82436
xorl %eax, %eax
cmpl 0x10(%rbp), %eax
jg 0x823e6
cmpl $0x9, 0x10(%rbp)
jle 0x82405
leaq 0x2ae83(%rip), %rdi     # 0xad270
leaq 0x31596(%rip), %rsi     # 0xb398a
movl $0x532, %edx            # imm = 0x532
leaq 0x31cf9(%rip), %rcx     # 0xb40f9
callq 0x4270
movl $0x1, %eax
cmpl 0x18(%rbp), %eax
jg 0x82415
cmpl $0x9, 0x18(%rbp)
jle 0x82434
leaq 0x2ae54(%rip), %rdi     # 0xad270
leaq 0x31567(%rip), %rsi     # 0xb398a
movl $0x532, %edx            # imm = 0x532
leaq 0x31cca(%rip), %rcx     # 0xb40f9
callq 0x4270
jmp 0x82436
testb $0x1, -0x31(%rbp)
jne 0x82461
testb $0x1, -0x1d(%rbp)
je 0x82461
leaq 0x2ae27(%rip), %rdi     # 0xad270
leaq 0x3153a(%rip), %rsi     # 0xb398a
movl $0x534, %edx            # imm = 0x534
leaq 0x31c9d(%rip), %rcx     # 0xb40f9
callq 0x4270
xorl %eax, %eax
cmpq -0x30(%rbp), %rax
jne 0x824b0
testb $0x1, -0x1d(%rbp)
je 0x82495
cmpq $0x0, -0x28(%rbp)
je 0x82495
leaq 0x2adf3(%rip), %rdi     # 0xad270
leaq 0x31506(%rip), %rsi     # 0xb398a
movl $0x538, %edx            # imm = 0x538
leaq 0x31c69(%rip), %rcx     # 0xb40f9
callq 0x4270
cmpq $0x0, -0x28(%rbp)
je 0x824ae
movq -0x18(%rbp), %rdi
movl -0x1c(%rbp), %esi
callq 0x80520
movl %eax, %eax
movq %rax, -0x30(%rbp)
jmp 0x824b0
movq -0x10(%rbp), %rax
addq $0xc0, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq $0x0, 0x30(%rax)
je 0x824e8
leaq 0x2ada0(%rip), %rdi     # 0xad270
leaq 0x314b3(%rip), %rsi     # 0xb398a
movl $0x53e, %edx            # imm = 0x53E
leaq 0x31c16(%rip), %rcx     # 0xb40f9
callq 0x4270
movq -0x10(%rbp), %rax
movl 0x60(%rax), %eax
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x5c(%rcx), %eax
jl 0x8251d
leaq 0x2ad6b(%rip), %rdi     # 0xad270
leaq 0x3147e(%rip), %rsi     # 0xb398a
movl $0x543, %edx            # imm = 0x543
leaq 0x31be1(%rip), %rcx     # 0xb40f9
callq 0x4270
movl -0x44(%rbp), %ecx
addl $0x1, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x60(%rax)
testb $0x1, -0x31(%rbp)
je 0x82539
movq -0x30(%rbp), %rax
movl %eax, -0x48(%rbp)
jmp 0x82540
movq -0x28(%rbp), %rax
movl %eax, -0x48(%rbp)
movl -0x48(%rbp), %edx
movq -0x10(%rbp), %rax
movq 0xb0(%rax), %rax
movslq -0x44(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x10(%rbp), %rdi
movl -0x44(%rbp), %esi
movq -0x18(%rbp), %rdx
movl -0x1c(%rbp), %ecx
xorl %r8d, %r8d
callq 0x827f0
testb $0x1, %al
jne 0x8258e
leaq 0x2acfa(%rip), %rdi     # 0xad270
leaq 0x3140d(%rip), %rsi     # 0xb398a
movl $0x547, %edx            # imm = 0x547
leaq 0x31b70(%rip), %rcx     # 0xb40f9
callq 0x4270
movq -0x10(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x40(%rbp), %rax
leaq 0x640f3(%rip), %rcx     # 0xe6698
movq %rcx, 0x40(%rax)
movq -0x40(%rbp), %rax
movq $0x0, 0x20(%rax)
movq -0x40(%rbp), %rax
movq $0x0, 0x28(%rax)
movl -0x44(%rbp), %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x70(%rax)
movq -0x40(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, (%rax)
testb $0x1, -0x1d(%rbp)
je 0x825e6
movq -0x30(%rbp), %rax
movq %rax, -0x50(%rbp)
jmp 0x825ee
movq -0x28(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x40(%rbp), %rax
leaq -0x645(%rip), %rcx      # 0x81fc0
movq %rcx, 0x18(%rax)
movq -0x40(%rbp), %rax
cmpq $0x0, 0x48(%rax)
jne 0x82616
jmp 0x82635
leaq 0x31b39(%rip), %rdi     # 0xb4156
leaq 0x31366(%rip), %rsi     # 0xb398a
movl $0x551, %edx            # imm = 0x551
leaq 0x31ac9(%rip), %rcx     # 0xb40f9
callq 0x4270
movq -0x40(%rbp), %rax
cmpq $0x0, 0x38(%rax)
jne 0x82642
jmp 0x82661
leaq 0x31b2d(%rip), %rdi     # 0xb4176
leaq 0x3133a(%rip), %rsi     # 0xb398a
movl $0x552, %edx            # imm = 0x552
leaq 0x31a9d(%rip), %rcx     # 0xb40f9
callq 0x4270
testb $0x1, -0x31(%rbp)
je 0x82789
testb $0x1, -0x1d(%rbp)
jne 0x82789
movq -0x10(%rbp), %rax
cmpl $0x1, 0x154(%rax)
jle 0x826e8
cmpq $0x0, -0x30(%rbp)
jbe 0x826e8
movq -0x10(%rbp), %rax
movq 0x158(%rax), %rdi
callq 0x856a0
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x10(%rbp), %rax
movl 0x58(%rax), %eax
movl %eax, %edx
movl 0x10(%rbp), %ecx
movl 0x18(%rbp), %r8d
callq 0x80e40
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x40(%rbp), %rax
cmpq $0x0, 0x38(%rax)
je 0x826e6
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x83220
testb $0x1, %al
jne 0x826e6
movb $0x0, -0x1(%rbp)
jmp 0x8278d
jmp 0x826e8
movq -0x40(%rbp), %rax
cmpq $0x0, 0x38(%rax)
jne 0x82787
movq -0x40(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x50(%rax)
movq -0x10(%rbp), %rax
movq 0xb0(%rax), %rax
movslq -0x44(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, %ecx
movq -0x40(%rbp), %rax
movq %rcx, 0x58(%rax)
movq -0x40(%rbp), %rax
leaq -0x5da(%rip), %rcx      # 0x82150
movq %rcx, 0x68(%rax)
movq -0x40(%rbp), %rax
movq 0x40(%rax), %rax
movq 0x8(%rax), %rax
movq -0x40(%rbp), %rcx
movq 0x40(%rcx), %rdi
movq -0x28(%rbp), %rsi
movl 0x10(%rbp), %edx
movl 0x18(%rbp), %ecx
movq -0x40(%rbp), %r8
addq $0x50, %r8
movq -0x10(%rbp), %r9
movq 0xb8(%r9), %r9
movq $0x4000, (%rsp)         # imm = 0x4000
callq *%rax
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x48(%rax)
movq -0x40(%rbp), %rax
cmpq $0x0, 0x48(%rax)
jne 0x82785
movb $0x0, -0x1(%rbp)
jmp 0x8278d
jmp 0x82787
jmp 0x82789
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)