// File: /workspace/github_cpp_makefile_star2_O1/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, %r12d
movl %edx, %ebx
movq %rsi, %r15
movq %rdi, %r14
callq 0x4023f
movq %r15, (%r14)
movb %bpl, 0x88(%r14)
xorl %eax, %eax
leaq 0x20(%rsp), %rsi
movl %eax, (%rsi)
movl %eax, 0x4(%rsp)
movq %r14, %rdi
callq 0x402aa
testb %al, %al
je 0x401c3
movl 0x20(%rsp), %eax
movq (%r14), %rdi
movq %rax, 0x8(%rsp)
leal 0x8(%rax), %esi
leaq 0x30(%rsp), %rcx
leaq 0x24(%rsp), %rdx
callq *0x10(%rdi)
testl %eax, %eax
je 0x401e2
movl %ebx, 0x18(%rsp)
movzwl 0x24(%rsp), %eax
movl %eax, 0x1c(%rsp)
movl 0x2c(%rsp), %r13d
movq (%r14), %rdi
leaq 0x8b(%r14), %r8
xorl %ebp, %ebp
leaq 0x4(%rsp), %rdx
movq %r13, %rsi
xorl %ecx, %ecx
callq 0x3f6d8
cmpq $0x0, 0xa0(%r14)
jne 0x40201
movl 0x4(%rsp), %r15d
movl %r15d, %ebx
subl $0x1000, %ebx           # imm = 0x1000
cmovbl %ebp, %ebx
subl %r15d, %r13d
movq %r13, 0x30(%rsp)
movq 0x8(%rsp), %rax
subl %r15d, %eax
movq %rax, 0x8(%rsp)
movl %r12d, 0x14(%rsp)
movzbl %r12b, %r13d
movq (%r14), %rax
movl 0x8(%rax), %esi
subl %ebx, %esi
movq %r14, %rdi
movl 0x1c(%rsp), %edx
callq 0x403bb
movq (%r14), %rdi
movq 0xa0(%r14), %rdx
movl %r15d, %eax
subl %ebx, %eax
addq %rdx, %rax
movq %rax, 0x98(%r14)
movq 0x30(%rsp), %rcx
addq %rax, %rcx
movq %rcx, 0x50(%r14)
addq 0x8(%rsp), %rax
movq %rax, 0x48(%r14)
movl 0xa8(%r14), %ecx
addq %rdx, %rcx
movl %ebx, %esi
callq *0x10(%rdi)
testl %eax, %eax
je 0x401a4
movq %r14, %rdi
movl %r13d, %esi
leaq 0x24(%rsp), %rdx
callq 0x404b5
movl 0x24(%rsp), %r12d
movl %r12d, %ecx
subl %ebx, %ecx
jae 0x40125
movq 0xa0(%r14), %rdi
movl %r12d, %eax
testq %rdi, %rdi
je 0x4015a
callq 0x43b0
movq $0x0, 0xa0(%r14)
movl $0x0, 0xa8(%r14)
movl %r12d, %eax
jmp 0x4015a
movl %ebx, %eax
je 0x4015a
subq %rcx, 0x98(%r14)
subq %rcx, 0x50(%r14)
subq %rcx, 0x48(%r14)
movl 0xa8(%r14), %edx
subl %ecx, %edx
movl %edx, 0xa8(%r14)
movq 0xa0(%r14), %rdi
leaq (%rdi,%rcx), %rsi
callq 0x4510
movl %ebx, %eax
subl $0x1, %ebp
setb %cl
cmpl %ebx, %r12d
jae 0x4016f
movl %eax, %ebx
testb %cl, %cl
jne 0x40081
cmpq $0x0, 0xa0(%r14)
je 0x40220
movl 0x18(%rsp), %eax
movb %al, 0x89(%r14)
movl 0x14(%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 0x19ea5(%rip), %rdi     # 0x5a050
leaq 0x200af(%rip), %rsi     # 0x60261
leaq 0x20197(%rip), %rcx     # 0x60350
movl $0x1f8, %edx            # imm = 0x1F8
callq 0x4200
leaq 0x19e86(%rip), %rdi     # 0x5a050
leaq 0x20090(%rip), %rsi     # 0x60261
leaq 0x20178(%rip), %rcx     # 0x60350
movl $0x1ea, %edx            # imm = 0x1EA
callq 0x4200
leaq 0x19e67(%rip), %rdi     # 0x5a050
leaq 0x20071(%rip), %rsi     # 0x60261
leaq 0x20b72(%rip), %rcx     # 0x60d69
movl $0x87, %edx
callq 0x4200
leaq 0x2019c(%rip), %rdi     # 0x603a4
leaq 0x20052(%rip), %rsi     # 0x60261
leaq 0x2013a(%rip), %rcx     # 0x60350
movl $0x1f1, %edx            # imm = 0x1F1
callq 0x4200
leaq 0x19e29(%rip), %rdi     # 0x5a050
leaq 0x20033(%rip), %rsi     # 0x60261
leaq 0x2011b(%rip), %rcx     # 0x60350
movl $0x20a, %edx            # imm = 0x20A
callq 0x4200