// File: sisong[P]ApkDiffPatch/src/patch/OldStream.cpp
// Function: createRange(OldStream*, unsigned int const*, unsigned long, unsigned int const*, unsigned long)
bool _createRange(OldStream* self,const uint32_t* refList,size_t refCount,
                  const uint32_t* refNotDecompressList,size_t refNotDecompressCount){
    bool result=true;
    assert(self->_buf==0);
    const int fileCount=UnZipper_fileCount(self->_oldZip);
    size_t   rangIndex;
    uint32_t curSumSize=0;
    uint32_t curDecompressPos=0;
    size_t refi=0;
    size_t noti=0;
    
    self->_rangeCount= 1 + refCount + refNotDecompressCount;
    size_t _memSize=sizeof(uint32_t)*(self->_rangeCount*2+1)+self->_rangeCount*sizeof(unsigned char);
#if (_IS_NEED_VIRTUAL_ZIP)
    if (self->_vin)
        _memSize+=self->_rangeCount*sizeof(unsigned char);
#endif
    self->_buf=(unsigned char*)malloc(_memSize);
    check(self->_buf!=0);
    self->_rangeEndList=((uint32_t*)self->_buf)+1; //+1 for _rangeEndList[-1] safe
    self->_rangeFileOffsets=self->_rangeEndList+self->_rangeCount;
    self->_rangIsInDecBuf=(unsigned char*)(self->_rangeFileOffsets+self->_rangeCount);
#if (_IS_NEED_VIRTUAL_ZIP)
    if (self->_vin){
        self->_rangIsInVirtualBuf=self->_rangIsInDecBuf+self->_rangeCount;
        memset(self->_rangIsInVirtualBuf,0,self->_rangeCount);
    }
#endif
    curSumSize=(uint32_t)UnZipper_CESize(self->_oldZip);
    self->_rangeEndList[-1]=0;
    self->_rangeEndList[0]=curSumSize;
    self->_rangeFileOffsets[0]=0;
    self->_rangIsInDecBuf[0]=0;
    rangIndex=1;
    for (int fileIndex=0; fileIndex<fileCount; ++fileIndex) {
        if ((refi<refCount)&&((int)refList[refi]==fileIndex)){
            ZipFilePos_t rangeSize;
            bool         isCompressed;
#if (_IS_NEED_VIRTUAL_ZIP)
            if ((self->_vin)&&(self->_vin->entryDatas[fileIndex])){
                TZipEntryData* entryData=self->_vin->entryDatas[fileIndex];
                rangeSize=entryData->uncompressedSize;
                isCompressed=entryData->isCompressed;
                if (!isCompressed) self->_rangIsInVirtualBuf[rangIndex]=1;
            } else
#endif
            {
                rangeSize=UnZipper_file_uncompressedSize(self->_oldZip,fileIndex);
                isCompressed=UnZipper_file_isCompressed(self->_oldZip,fileIndex);
            }
            if (isCompressed){
                self->_rangIsInDecBuf[rangIndex]=1;
                self->_rangeFileOffsets[rangIndex]=curDecompressPos;
                curDecompressPos+=rangeSize;
            }else{
                self->_rangIsInDecBuf[rangIndex]=0;
#if (_IS_NEED_VIRTUAL_ZIP)
                if ((self->_vin)&&(self->_rangIsInVirtualBuf[rangIndex]))
                    self->_rangeFileOffsets[rangIndex]=fileIndex;
                else
#endif
                    self->_rangeFileOffsets[rangIndex]=UnZipper_fileData_offset(self->_oldZip,fileIndex);
            }
            curSumSize+=rangeSize;
            self->_rangeEndList[rangIndex]=curSumSize;
            ++refi;
            ++rangIndex;
        }
        if ((noti<refNotDecompressCount)&&((int)refNotDecompressList[noti]==fileIndex)){
            ZipFilePos_t rangeSize=UnZipper_file_compressedSize(self->_oldZip,fileIndex);
            self->_rangIsInDecBuf[rangIndex]=0;
            self->_rangeFileOffsets[rangIndex]=UnZipper_fileData_offset(self->_oldZip,fileIndex);
            curSumSize+=rangeSize;
            self->_rangeEndList[rangIndex]=curSumSize;
            ++noti;
            ++rangIndex;
        }
    }
    assert(rangIndex==self->_rangeCount);
    assert(curDecompressPos==self->_input_decompressedStream->streamSize);
    self->_curRangeIndex=0;
clear:
    return result;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movb $0x1, -0x29(%rbp)
movq -0x8(%rbp), %rax
cmpq $0x0, 0x60(%rax)
jne 0x7bf5d
jmp 0x7bf7c
leaq 0x370fc(%rip), %rdi     # 0xb3060
leaq 0x37103(%rip), %rsi     # 0xb306e
movl $0xd0, %edx
leaq 0x3710f(%rip), %rcx     # 0xb3086
callq 0x4270
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x7ea90
movl %eax, -0x30(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x50(%rbp)
movq -0x18(%rbp), %rcx
addq $0x1, %rcx
addq -0x28(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x50(%rax)
movq -0x8(%rbp), %rax
movq 0x50(%rax), %rax
shlq %rax
addq $0x1, %rax
shlq $0x2, %rax
movq -0x8(%rbp), %rcx
movq 0x50(%rcx), %rcx
shlq $0x0, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rdi
callq 0x44d0
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x60(%rax)
movq -0x8(%rbp), %rax
cmpq $0x0, 0x60(%rax)
jne 0x7c034
leaq 0x370cf(%rip), %rdi     # 0xb30d9
movb $0x0, %al
callq 0x4060
movb $0x0, -0x29(%rbp)
leaq 0x31254(%rip), %rdi     # 0xad270
leaq 0x3704b(%rip), %rsi     # 0xb306e
movl $0xdf, %edx
leaq 0x37057(%rip), %rcx     # 0xb3086
callq 0x4270
movq -0x8(%rbp), %rax
movq 0x60(%rax), %rcx
addq $0x4, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rcx
movq -0x8(%rbp), %rax
movq 0x50(%rax), %rax
shlq $0x2, %rax
addq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rcx
movq -0x8(%rbp), %rax
movq 0x50(%rax), %rax
shlq $0x2, %rax
addq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x48(%rax)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x7be40
movl %eax, -0x3c(%rbp)
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movl $0x0, -0x4(%rax)
movl -0x3c(%rbp), %ecx
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movl %ecx, (%rax)
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rax
movl $0x0, (%rax)
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
movb $0x0, (%rax)
movq $0x1, -0x38(%rbp)
movl $0x0, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
cmpl -0x30(%rbp), %eax
jge 0x7c26c
movq -0x48(%rbp), %rax
cmpq -0x18(%rbp), %rax
jae 0x7c1c7
movq -0x10(%rbp), %rax
movq -0x48(%rbp), %rcx
movl (%rax,%rcx,4), %eax
cmpl -0x5c(%rbp), %eax
jne 0x7c1c7
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
movl -0x5c(%rbp), %esi
callq 0x80480
movl %eax, -0x60(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
movl -0x5c(%rbp), %esi
callq 0x7f2e0
andb $0x1, %al
movb %al, -0x61(%rbp)
testb $0x1, -0x61(%rbp)
je 0x7c163
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
movq -0x38(%rbp), %rcx
movb $0x1, (%rax,%rcx)
movl -0x40(%rbp), %edx
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x38(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x60(%rbp), %eax
addl -0x40(%rbp), %eax
movl %eax, -0x40(%rbp)
jmp 0x7c194
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
movq -0x38(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
movl -0x5c(%rbp), %esi
callq 0x80620
movl %eax, %edx
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x38(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x60(%rbp), %eax
addl -0x3c(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %edx
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq -0x38(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x50(%rbp), %rax
cmpq -0x28(%rbp), %rax
jae 0x7c25c
movq -0x20(%rbp), %rax
movq -0x50(%rbp), %rcx
movl (%rax,%rcx,4), %eax
cmpl -0x5c(%rbp), %eax
jne 0x7c25c
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
movl -0x5c(%rbp), %esi
callq 0x80520
movl %eax, -0x68(%rbp)
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
movq -0x38(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
movl -0x5c(%rbp), %esi
callq 0x80620
movl %eax, %edx
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x38(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x68(%rbp), %eax
addl -0x3c(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %edx
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq -0x38(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x7c25e
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x7c0da
movq -0x38(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq 0x50(%rcx), %rax
jne 0x7c27c
jmp 0x7c29b
leaq 0x36e6c(%rip), %rdi     # 0xb30ef
leaq 0x36de4(%rip), %rsi     # 0xb306e
movl $0x11b, %edx            # imm = 0x11B
leaq 0x36df0(%rip), %rcx     # 0xb3086
callq 0x4270
movl -0x40(%rbp), %eax
movq -0x8(%rbp), %rcx
movq 0x10(%rcx), %rcx
cmpq 0x8(%rcx), %rax
jne 0x7c2ae
jmp 0x7c2cd
leaq 0x36e57(%rip), %rdi     # 0xb310c
leaq 0x36db2(%rip), %rsi     # 0xb306e
movl $0x11c, %edx            # imm = 0x11C
leaq 0x36dbe(%rip), %rcx     # 0xb3086
callq 0x4270
movq -0x8(%rbp), %rax
movl $0x0, 0x58(%rax)
movb -0x29(%rbp), %al
andb $0x1, %al
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)