// File: /workspace/github_cpp_makefile_star2_O3/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 0x3fe23
movq %r15, (%r14)
movb %bpl, 0x88(%r14)
xorl %eax, %eax
leaq 0x28(%rsp), %rsi
movl %eax, (%rsi)
movl %eax, 0xc(%rsp)
movq %r14, %rdi
callq 0x3fe8e
testb %al, %al
je 0x3fdc6
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 0x3fde5
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 0x3f264
cmpq $0x0, 0xa0(%r14)
jne 0x3fe04
movl 0xc(%rsp), %ecx
movl %ecx, %r15d
subl $0x1000, %r15d          # imm = 0x1000
cmovbl %ebx, %r15d
subl %ecx, %ebp
movq 0x10(%rsp), %rax
movl %ecx, 0x20(%rsp)
subl %ecx, %eax
movq %rax, 0x10(%rsp)
movb $0x1, %bl
movl %r13d, 0x18(%rsp)
movzbl %r13b, %r13d
movq (%r14), %rax
movl 0x8(%rax), %esi
subl %r15d, %esi
movq %r14, %rdi
movl 0x24(%rsp), %edx
callq 0x3ffa3
movq (%r14), %rdi
movq 0xa0(%r14), %rdx
movl 0x20(%rsp), %eax
subl %r15d, %eax
addq %rdx, %rax
movq %rax, 0x98(%r14)
movq %rbp, %r12
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 0x3fda7
movq %r14, %rdi
movl %r13d, %esi
leaq 0x2c(%rsp), %rdx
callq 0x4009d
movl 0x2c(%rsp), %ebp
movl %ebp, %eax
subl %r15d, %eax
jae 0x3fd45
movq 0xa0(%r14), %rdi
testq %rdi, %rdi
je 0x3fd12
callq 0x43b0
movq $0x0, 0xa0(%r14)
movl $0x0, 0xa8(%r14)
movl %ebp, %r15d
testb $0x1, %bl
movl $0x0, %ebx
movq %r12, %rbp
jne 0x3fc74
leaq 0x1a323(%rip), %rdi     # 0x5a050
leaq 0x205ad(%rip), %rsi     # 0x602e1
leaq 0x20695(%rip), %rcx     # 0x603d0
movl $0x20a, %edx            # imm = 0x20A
callq 0x4200
je 0x3fd76
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 0x4510
cmpq $0x0, 0xa0(%r14)
je 0x3fd26
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 0x1a2a2(%rip), %rdi     # 0x5a050
leaq 0x2052c(%rip), %rsi     # 0x602e1
leaq 0x20614(%rip), %rcx     # 0x603d0
movl $0x1f8, %edx            # imm = 0x1F8
callq 0x4200
leaq 0x1a283(%rip), %rdi     # 0x5a050
leaq 0x2050d(%rip), %rsi     # 0x602e1
leaq 0x205f5(%rip), %rcx     # 0x603d0
movl $0x1ea, %edx            # imm = 0x1EA
callq 0x4200
leaq 0x1a264(%rip), %rdi     # 0x5a050
leaq 0x204ee(%rip), %rsi     # 0x602e1
leaq 0x20fef(%rip), %rcx     # 0x60de9
movl $0x87, %edx
callq 0x4200
leaq 0x20619(%rip), %rdi     # 0x60424
leaq 0x204cf(%rip), %rsi     # 0x602e1
leaq 0x205b7(%rip), %rcx     # 0x603d0
movl $0x1f1, %edx            # imm = 0x1F1
callq 0x4200