// File: sisong[P]ApkDiffPatch/src/patch/Zipper.cpp
// Function: Zipper_openStream
bool Zipper_openStream(Zipper* self,const hpatch_TStreamOutput* zipStream,int fileEntryMaxCount,
                       int ZipAlignSize,int compressLevel,int compressMemLevel,
                       size_t normalizeSoPageAlign,bool pageAlignCompatible,TPageAlignState pageAlignState){
#if (_IS_NEED_FIXED_ZLIB_VERSION)
    check(0==strcmp(kNormalizedZlibVersion,zlibVersion()));//fixed zlib version
#endif
    if (ZipAlignSize<=0) ZipAlignSize=1;
    checkCompressSet(compressLevel,compressMemLevel);
    self->_ZipAlignSize=ZipAlignSize;
    self->_normalizeSoPageAlign=normalizeSoPageAlign;
    self->_pageAlignCompatible=pageAlignCompatible;
    self->_compressLevel=compressLevel;
    self->_compressMemLevel=compressMemLevel;
    self->_pageAlignState=pageAlignState;
    
    assert(self->_stream==0);
    self->_stream=zipStream;
    
    size_t memSize=kBufSize*2+sizeof(ZipFilePos_t)*(fileEntryMaxCount*2+1);
    if (self->_pageAlignState==kPageAlign_inNormalize)
        memSize+=sizeof(uint16_t)*fileEntryMaxCount + (kMaxExtraFieldLen+1);
    TByte* buf=(TByte*)malloc(memSize);
    self->_buf=buf;
    self->_codeBuf=buf+kBufSize;
    size_t alignBuf=_hpatch_align_upper((buf+kBufSize*2),sizeof(ZipFilePos_t));
    self->_fileEntryOffsets=(ZipFilePos_t*)alignBuf; alignBuf+=sizeof(ZipFilePos_t)*fileEntryMaxCount;
    self->_fileCompressedSizes=(ZipFilePos_t*)alignBuf; alignBuf+=sizeof(ZipFilePos_t)*fileEntryMaxCount;
    memset(self->_fileCompressedSizes,0,fileEntryMaxCount*sizeof(ZipFilePos_t));//set error len
    self->_normalizeExtraFieldLens=0;
    if (self->_pageAlignState==kPageAlign_inNormalize){
        self->_normalizeExtraFieldLens=(uint16_t*)alignBuf; alignBuf+=sizeof(uint16_t)*fileEntryMaxCount;
        self->_normalizeExtraFieldBuf=(TByte*)alignBuf;
    }
    self->_fileEntryCount=0;
    self->_fileEntryMaxCount=fileEntryMaxCount;
    self->_fileHeaderCount=0;
    self->_curFilePos=0;
    self->_centralDirectory_pos=0;
    
    return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movl 0x20(%rbp), %eax
movb 0x18(%rbp), %al
movq 0x10(%rbp), %r10
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movl %r8d, -0x1c(%rbp)
movl %r9d, -0x20(%rbp)
andb $0x1, %al
movb %al, -0x21(%rbp)
callq 0xa2300
movq %rax, %rsi
leaq 0x2bb03(%rip), %rdi     # 0xacbef
callq 0x44f0
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
je 0x81118
leaq 0x2c170(%rip), %rdi     # 0xad270
leaq 0x32883(%rip), %rsi     # 0xb398a
movl $0x38a, %edx            # imm = 0x38A
leaq 0x32cd7(%rip), %rcx     # 0xb3dea
callq 0x4270
cmpl $0x0, -0x18(%rbp)
jg 0x81125
movl $0x1, -0x18(%rbp)
xorl %eax, %eax
cmpl -0x1c(%rbp), %eax
jg 0x81132
cmpl $0x9, -0x1c(%rbp)
jle 0x81151
leaq 0x2c137(%rip), %rdi     # 0xad270
leaq 0x3284a(%rip), %rsi     # 0xb398a
movl $0x38d, %edx            # imm = 0x38D
leaq 0x32c9e(%rip), %rcx     # 0xb3dea
callq 0x4270
movl $0x1, %eax
cmpl -0x20(%rbp), %eax
jg 0x81161
cmpl $0x9, -0x20(%rbp)
jle 0x81180
leaq 0x2c108(%rip), %rdi     # 0xad270
leaq 0x3281b(%rip), %rsi     # 0xb398a
movl $0x38d, %edx            # imm = 0x38D
leaq 0x32c6f(%rip), %rcx     # 0xb3dea
callq 0x4270
movslq -0x18(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x68(%rax)
movq 0x10(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x70(%rax)
movb -0x21(%rbp), %cl
movq -0x8(%rbp), %rax
andb $0x1, %cl
movb %cl, 0x88(%rax)
movl -0x1c(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x94(%rax)
movl -0x20(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x98(%rax)
movl 0x20(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x90(%rax)
movq -0x8(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x811db
jmp 0x811fa
leaq 0x32c7a(%rip), %rdi     # 0xb3e5c
leaq 0x327a1(%rip), %rsi     # 0xb398a
movl $0x395, %edx            # imm = 0x395
leaq 0x32bf5(%rip), %rcx     # 0xb3dea
callq 0x4270
movq -0x10(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, (%rax)
movl -0x14(%rbp), %eax
shll %eax
addl $0x1, %eax
cltq
shlq $0x2, %rax
addq $0x8000, %rax           # imm = 0x8000
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x1, 0x90(%rax)
jne 0x8123f
movslq -0x14(%rbp), %rax
shlq %rax
addq $0x10000, %rax          # imm = 0x10000
addq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
callq 0x44d0
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x138(%rax)
movq -0x38(%rbp), %rcx
addq $0x4000, %rcx           # imm = 0x4000
movq -0x8(%rbp), %rax
movq %rcx, 0xb8(%rax)
movq -0x38(%rbp), %rax
addq $0x8000, %rax           # imm = 0x8000
addq $0x3, %rax
andq $-0x4, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0xa8(%rax)
movslq -0x14(%rbp), %rax
shlq $0x2, %rax
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0xb0(%rax)
movslq -0x14(%rbp), %rax
shlq $0x2, %rax
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rax
movq 0xb0(%rax), %rdi
movslq -0x14(%rbp), %rdx
shlq $0x2, %rdx
xorl %esi, %esi
callq 0x4210
movq -0x8(%rbp), %rax
movq $0x0, 0x78(%rax)
movq -0x8(%rbp), %rax
cmpl $0x1, 0x90(%rax)
jne 0x81322
movq -0x40(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x78(%rax)
movslq -0x14(%rbp), %rax
shlq %rax
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x80(%rax)
movq -0x8(%rbp), %rax
movl $0x0, 0x60(%rax)
movl -0x14(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x5c(%rax)
movq -0x8(%rbp), %rax
movl $0x0, 0x9c(%rax)
movq -0x8(%rbp), %rax
movl $0x0, 0x58(%rax)
movq -0x8(%rbp), %rax
movl $0x0, 0xa0(%rax)
movb $0x1, %al
andb $0x1, %al
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax,%rax)