// File: /workspace/github_cpp_makefile_star2_O2/sisong[P]ApkDiffPatch/src/patch/Zipper.cpp
// Function: UnZipper_openStream
bool UnZipper_openStream(UnZipper* self,const hpatch_TStreamInput* zipFileStream,
                         bool isDataNormalized,bool isFileDataOffsetMatch,bool isSaved_fileEntryOffsets){
    check(_UnZipper_open_begin(self));
    self->stream=zipFileStream;
    self->_isSaved_fileEntryOffsets=isSaved_fileEntryOffsets;
    //_sreachVCE
    ZipFilePos_t endCentralDirectory_pos=0;
    ZipFilePos_t centralDirectory_pos=0;
    uint32_t     fileCount=0;
    ZipFilePos_t v2sign_topPos=0;
    check(_UnZipper_searchEndCentralDirectory(self,&endCentralDirectory_pos));
    check(_UnZipper_searchCentralDirectory(self,endCentralDirectory_pos,&centralDirectory_pos,&fileCount));
    check(UnZipper_searchApkV2Sign(self->stream,centralDirectory_pos,&v2sign_topPos,0,&self->_isHaveV3Sign));

    // now don't know fileDataEndPos value
    const ZipFilePos_t kNullSize=1024*4;
    ZipFilePos_t ripe_fileDataEndPos=(v2sign_topPos>kNullSize)?(v2sign_topPos-kNullSize):0;
    assert(self->_cache_fvce==0);
    for (int i=0; i<2; ++i){ //try 2 times
        check(_UnZipper_open_fvce(self,(ZipFilePos_t)self->stream->streamSize-ripe_fileDataEndPos,fileCount));
        self->_vce=self->_cache_fvce+(v2sign_topPos-ripe_fileDataEndPos);
        self->_centralDirectory=self->_vce+(centralDirectory_pos-v2sign_topPos);
        self->_endCentralDirectory=self->_vce+(endCentralDirectory_pos-v2sign_topPos);
        
        check(UnZipper_fileData_read(self,ripe_fileDataEndPos,self->_cache_fvce,self->_cache_fvce+self->_fvce_size));
        ZipFilePos_t fileDataEndPos;
        check(_UnZipper_vce_normalized(self,isFileDataOffsetMatch,&fileDataEndPos));
        if (fileDataEndPos>=ripe_fileDataEndPos){ //ok
            ZipFilePos_t nullSize=(fileDataEndPos-ripe_fileDataEndPos);
            if (nullSize>0){//need move data
                self->_vce-=nullSize;
                self->_centralDirectory-=nullSize;
                self->_endCentralDirectory-=nullSize;
                self->_fvce_size-=nullSize;
                memmove(self->_cache_fvce,self->_cache_fvce+nullSize,self->_fvce_size);
            }
            break;
        }else{ //continue
            _UnZipper_close_fvce(self);
            ripe_fileDataEndPos=fileDataEndPos;
        }
    }
    check(self->_cache_fvce!=0);
    self->_isDataNormalized=isDataNormalized;
    self->_isFileDataOffsetMatch=isFileDataOffsetMatch;
    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %r8d, %ebp
movl %ecx, %r13d
movl %edx, %ebx
movq %rsi, %r15
movq %rdi, %r14
callq 0x37407
movq %r15, (%r14)
movb %bpl, 0x88(%r14)
leaq 0x28(%rsp), %rsi
andl $0x0, (%rsi)
andl $0x0, 0xc(%rsp)
movq %r14, %rdi
callq 0x37472
testb %al, %al
je 0x3738b
movl 0x28(%rsp), %eax
movq (%r14), %rdi
movq %rax, 0x10(%rsp)
leal 0x8(%rax), %esi
leaq 0x38(%rsp), %rcx
leaq 0x2c(%rsp), %rdx
callq *0x10(%rdi)
testl %eax, %eax
je 0x373aa
movl %ebx, 0x1c(%rsp)
movzwl 0x2c(%rsp), %eax
movl %eax, 0x24(%rsp)
movl 0x34(%rsp), %ebp
movq (%r14), %rdi
leaq 0x8b(%r14), %r8
xorl %ebx, %ebx
leaq 0xc(%rsp), %rdx
movq %rbp, %rsi
xorl %ecx, %ecx
callq 0x3690c
cmpq $0x0, 0xa0(%r14)
jne 0x373c9
movl 0xc(%rsp), %r12d
movl %r12d, %r15d
subl $0x1000, %r15d          # imm = 0x1000
cmovbl %ebx, %r15d
subl %r12d, %ebp
movq 0x10(%rsp), %rax
subl %r12d, %eax
movq %rax, 0x10(%rsp)
pushq $0x2
popq %rbx
movl %r13d, 0x18(%rsp)
movzbl %r13b, %eax
movl %eax, 0x20(%rsp)
subl $0x1, %ebx
jb 0x37337
movq (%r14), %rax
movl 0x8(%rax), %esi
subl %r15d, %esi
movq %r14, %rdi
movl 0x24(%rsp), %edx
callq 0x37586
movq (%r14), %rdi
movq 0xa0(%r14), %rdx
movl %r12d, %eax
subl %r15d, %eax
addq %rdx, %rax
movq %rax, 0x98(%r14)
movq %rbp, %r13
leaq (%rax,%rbp), %rcx
movq %rcx, 0x50(%r14)
addq 0x10(%rsp), %rax
movq %rax, 0x48(%r14)
movl 0xa8(%r14), %ecx
addq %rdx, %rcx
movl %r15d, %esi
callq *0x10(%rdi)
testl %eax, %eax
je 0x3736c
movq %r14, %rdi
movl 0x20(%rsp), %esi
leaq 0x2c(%rsp), %rdx
callq 0x3767d
movl 0x2c(%rsp), %ebp
movl %ebp, %eax
subl %r15d, %eax
jae 0x37306
movq %r14, %rdi
callq 0x37174
movl %ebp, %r15d
movq %r13, %rbp
jmp 0x37273
je 0x37337
subq %rax, 0x98(%r14)
subq %rax, 0x50(%r14)
subq %rax, 0x48(%r14)
movl 0xa8(%r14), %edx
subl %eax, %edx
movl %edx, 0xa8(%r14)
movq 0xa0(%r14), %rdi
leaq (%rdi,%rax), %rsi
callq 0x4540
cmpq $0x0, 0xa0(%r14)
je 0x373e8
movl 0x1c(%rsp), %eax
movb %al, 0x89(%r14)
movl 0x18(%rsp), %eax
movb %al, 0x8a(%r14)
movb $0x1, %al
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x17cdd(%rip), %rdi     # 0x4f050
leaq 0x1e007(%rip), %rsi     # 0x55381
leaq 0x1e0ef(%rip), %rcx     # 0x55470
movl $0x1f8, %edx            # imm = 0x1F8
callq 0x4230
leaq 0x17cbe(%rip), %rdi     # 0x4f050
leaq 0x1dfe8(%rip), %rsi     # 0x55381
leaq 0x1e0d0(%rip), %rcx     # 0x55470
movl $0x1ea, %edx            # imm = 0x1EA
callq 0x4230
leaq 0x17c9f(%rip), %rdi     # 0x4f050
leaq 0x1dfc9(%rip), %rsi     # 0x55381
leaq 0x1eaca(%rip), %rcx     # 0x55e89
movl $0x87, %edx
callq 0x4230
leaq 0x1e0f4(%rip), %rdi     # 0x554c4
leaq 0x1dfaa(%rip), %rsi     # 0x55381
leaq 0x1e092(%rip), %rcx     # 0x55470
movl $0x1f1, %edx            # imm = 0x1F1
callq 0x4230
leaq 0x17c61(%rip), %rdi     # 0x4f050
leaq 0x1df8b(%rip), %rsi     # 0x55381
leaq 0x1e073(%rip), %rcx     # 0x55470
movl $0x20a, %edx            # imm = 0x20A
callq 0x4230