// File: sisong[P]ApkDiffPatch/src/diff/DiffData.cpp
// Function: getSamePairList(UnZipper*, UnZipper*, bool, int, int, std::vector<unsigned int, std::allocator<unsigned int>>&, std::vector<unsigned int, std::allocator<unsigned int>>&, std::vector<unsigned int, std::allocator<unsigned int>>&, std::vector<unsigned int, std::allocator<unsigned int>>&)
bool getSamePairList(UnZipper* newZip,UnZipper* oldZip,
                     bool newCompressedDataIsNormalized,
                     int zlibCompressLevel,int zlibCompressMemLevel,
                     std::vector<uint32_t>& out_samePairList,
                     std::vector<uint32_t>& out_newRefList,
                     std::vector<uint32_t>& out_newRefOtherCompressedList,
                     std::vector<uint32_t>& out_newRefCompressedSizeList){
    int oldFileCount=UnZipper_fileCount(oldZip);
    typedef std::multimap<uint32_t,int> TMap;
    TMap crcMap;
    for (int i=0; i<oldFileCount; ++i) {
        uint32_t crcOld=UnZipper_file_crc32(oldZip,i);
        crcMap.insert(TMap::value_type(crcOld,i));
    }
    
    int newFileCount=UnZipper_fileCount(newZip);
    for (int i=0; i<newFileCount; ++i) {
        ZipFilePos_t compressedSize=UnZipper_file_compressedSize(newZip,i);
        if (UnZipper_file_isReCompressedByApkV2Sign(newZip,i)){
            out_newRefOtherCompressedList.push_back(i);
            out_newRefCompressedSizeList.push_back(compressedSize);
        }else if ((0==UnZipper_file_uncompressedSize(newZip,i))
                  &&(!UnZipper_file_isCompressed(newZip,i))){ //empty entry
            check(0==compressedSize);
            //not need: out_newRefList.push_back(i);
        }else{
            bool findSame=false;
            int  oldSameIndex=-1;
            uint32_t crcNew=UnZipper_file_crc32(newZip,i);
            std::pair<TMap::const_iterator,TMap::const_iterator> range=crcMap.equal_range(crcNew);
            for (;range.first!=range.second;++range.first) {
                int oldIndex=range.first->second;
                if (zipFileData_isSame(newZip,i,oldZip,oldIndex)){
                    if (UnZipper_file_isReCompressedByApkV2Sign(oldZip,oldIndex))
                        continue;
                    if ((!UnZipper_file_isCompressed(oldZip,oldIndex))&&
                        UnZipper_file_isCompressed(newZip,i)) continue;
                    findSame=true;
                    oldSameIndex=oldIndex;
                    if (zipFile_name(newZip,i)==zipFile_name(oldZip,oldIndex)) break;
                }else{
                    printf("WARNING: crc32 equal but data not equal! file index: %d,%d\n",i,oldIndex);
                    hpatch_printPath_utf8(("   name: \""+zipFile_name(newZip,i)+"\"\n").c_str());
                    hpatch_printPath_utf8(("         \""+zipFile_name(oldZip,oldIndex)+"\"\n").c_str());
                }
            }
            if (findSame){
                out_samePairList.push_back(i);
                out_samePairList.push_back(oldSameIndex);
            }else{
                out_newRefList.push_back(i);
                if (UnZipper_file_isCompressed(newZip,i)){
                    if (newCompressedDataIsNormalized){
                        out_newRefCompressedSizeList.push_back(compressedSize);
                    }else{
                        std::vector<TByte> code;
                        check(getNormalizedCompressedCode(newZip,i,code,zlibCompressLevel,zlibCompressMemLevel));
                        out_newRefCompressedSizeList.push_back((uint32_t)code.size());
                    }
                }
            }
        }
    }
    return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x250, %rsp            # imm = 0x250
movb %dl, %al
movq 0x20(%rbp), %rdx
movq 0x18(%rbp), %rdx
movq 0x10(%rbp), %rdx
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
andb $0x1, %al
movb %al, -0x11(%rbp)
movl %ecx, -0x18(%rbp)
movl %r8d, -0x1c(%rbp)
movq %r9, -0x28(%rbp)
movq -0x10(%rbp), %rdi
callq 0x7ea90
movl %eax, -0x2c(%rbp)
leaq -0x60(%rbp), %rdi
callq 0xc070
movl $0x0, -0x64(%rbp)
movl -0x64(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0xa115
movq -0x10(%rbp), %rdi
movl -0x64(%rbp), %esi
callq 0x80540
movl %eax, -0x200(%rbp)
jmp 0xa0b9
movl -0x200(%rbp), %eax
movl %eax, -0x68(%rbp)
leaq -0x7c(%rbp), %rdi
leaq -0x68(%rbp), %rsi
leaq -0x64(%rbp), %rdx
callq 0xc0c0
jmp 0xa0d5
leaq -0x60(%rbp), %rdi
leaq -0x7c(%rbp), %rsi
callq 0xc090
movq %rax, -0x208(%rbp)
jmp 0xa0eb
movq -0x208(%rbp), %rax
movq %rax, -0x88(%rbp)
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0xa09d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0xa7e7
movq -0x8(%rbp), %rdi
callq 0x7ea90
movl %eax, -0x20c(%rbp)
jmp 0xa126
movl -0x20c(%rbp), %eax
movl %eax, -0x8c(%rbp)
movl $0x0, -0x90(%rbp)
movl -0x90(%rbp), %eax
cmpl -0x8c(%rbp), %eax
jge 0xa7d1
movq -0x8(%rbp), %rdi
movl -0x90(%rbp), %esi
callq 0x80520
movl %eax, -0x210(%rbp)
jmp 0xa165
movl -0x210(%rbp), %eax
movl %eax, -0x94(%rbp)
movq -0x8(%rbp), %rdi
movl -0x90(%rbp), %esi
callq 0x7f250
movb %al, -0x211(%rbp)
jmp 0xa188
movb -0x211(%rbp), %al
testb $0x1, %al
jne 0xa194
jmp 0xa1c9
movq 0x18(%rbp), %rdi
movl -0x90(%rbp), %eax
movl %eax, -0x98(%rbp)
leaq -0x98(%rbp), %rsi
callq 0xc0f0
jmp 0xa1b2
movq 0x20(%rbp), %rdi
leaq -0x94(%rbp), %rsi
callq 0xbf60
jmp 0xa1c4
jmp 0xa7bb
movq -0x8(%rbp), %rdi
movl -0x90(%rbp), %esi
callq 0x80480
movl %eax, -0x218(%rbp)
jmp 0xa1e0
movl -0x218(%rbp), %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0xa24d
movq -0x8(%rbp), %rdi
movl -0x90(%rbp), %esi
callq 0x7f2e0
movb %al, -0x219(%rbp)
jmp 0xa203
movb -0x219(%rbp), %al
testb $0x1, %al
jne 0xa24d
jmp 0xa20f
xorl %eax, %eax
cmpl -0x94(%rbp), %eax
je 0xa248
leaq 0xa362e(%rip), %rdi     # 0xad84e
xorl %eax, %eax
callq 0x4060
jmp 0xa229
leaq 0xa3040(%rip), %rdi     # 0xad270
leaq 0xa303f(%rip), %rsi     # 0xad276
movl $0x129, %edx            # imm = 0x129
leaq 0xa3625(%rip), %rcx     # 0xad868
callq 0x4270
jmp 0xa7b9
movb $0x0, -0x99(%rbp)
movl $0xffffffff, -0xa0(%rbp) # imm = 0xFFFFFFFF
movq -0x8(%rbp), %rdi
movl -0x90(%rbp), %esi
callq 0x80540
movl %eax, -0x220(%rbp)
jmp 0xa275
movl -0x220(%rbp), %eax
movl %eax, -0xa4(%rbp)
leaq -0x60(%rbp), %rdi
leaq -0xa4(%rbp), %rsi
callq 0xc120
movq %rdx, -0x230(%rbp)
movq %rax, -0x228(%rbp)
jmp 0xa2a1
movq -0x230(%rbp), %rax
movq -0x228(%rbp), %rcx
movq %rcx, -0xc8(%rbp)
movq %rax, -0xc0(%rbp)
leaq -0xb8(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0xc160
jmp 0xa2d2
jmp 0xa2d4
leaq -0xb8(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
addq $0x8, %rsi
callq 0xc1a0
testb $0x1, %al
jne 0xa2f4
jmp 0xa63d
leaq -0xb8(%rbp), %rdi
callq 0xc1d0
movl 0x4(%rax), %eax
movl %eax, -0xcc(%rbp)
movq -0x8(%rbp), %rdi
movl -0x90(%rbp), %esi
movq -0x10(%rbp), %rdx
movl -0xcc(%rbp), %ecx
callq 0x8a10
movb %al, -0x231(%rbp)
jmp 0xa32a
movb -0x231(%rbp), %al
testb $0x1, %al
jne 0xa339
jmp 0xa453
movq -0x10(%rbp), %rdi
movl -0xcc(%rbp), %esi
callq 0x7f250
movb %al, -0x232(%rbp)
jmp 0xa350
movb -0x232(%rbp), %al
testb $0x1, %al
jne 0xa35c
jmp 0xa361
jmp 0xa62c
movq -0x10(%rbp), %rdi
movl -0xcc(%rbp), %esi
callq 0x7f2e0
movb %al, -0x233(%rbp)
jmp 0xa378
movb -0x233(%rbp), %al
testb $0x1, %al
jne 0xa3ac
jmp 0xa384
movq -0x8(%rbp), %rdi
movl -0x90(%rbp), %esi
callq 0x7f2e0
movb %al, -0x234(%rbp)
jmp 0xa39b
movb -0x234(%rbp), %al
testb $0x1, %al
jne 0xa3a7
jmp 0xa3ac
jmp 0xa62c
movb $0x1, -0x99(%rbp)
movl -0xcc(%rbp), %eax
movl %eax, -0xa0(%rbp)
movq -0x8(%rbp), %rsi
movl -0x90(%rbp), %edx
leaq -0xf0(%rbp), %rdi
callq 0x9390
jmp 0xa3d7
movq -0x10(%rbp), %rsi
movl -0xcc(%rbp), %edx
leaq -0x110(%rbp), %rdi
callq 0x9390
jmp 0xa3ef
leaq -0xf0(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0xc1f0
movb %al, -0x235(%rbp)
leaq -0x110(%rbp), %rdi
callq 0x4260
leaq -0xf0(%rbp), %rdi
callq 0x4260
movb -0x235(%rbp), %al
testb $0x1, %al
jne 0xa42c
jmp 0xa44e
jmp 0xa63d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0xf0(%rbp), %rdi
callq 0x4260
jmp 0xa7e7
jmp 0xa62a
movl -0x90(%rbp), %esi
movl -0xcc(%rbp), %edx
leaq 0xa34a3(%rip), %rdi     # 0xad909
xorl %eax, %eax
callq 0x4060
jmp 0xa46f
movq -0x8(%rbp), %rsi
movl -0x90(%rbp), %edx
leaq -0x170(%rbp), %rdi
callq 0x9390
jmp 0xa487
leaq 0xa34b7(%rip), %rsi     # 0xad945
leaq -0x150(%rbp), %rdi
leaq -0x170(%rbp), %rdx
callq 0xc280
jmp 0xa4a3
leaq 0xa1d6f(%rip), %rdx     # 0xac219
leaq -0x130(%rbp), %rdi
leaq -0x150(%rbp), %rsi
callq 0x8670
jmp 0xa4bf
leaq -0x130(%rbp), %rdi
callq 0x4160
movq %rax, %rdi
callq 0x8cf20
jmp 0xa4d5
leaq -0x130(%rbp), %rdi
callq 0x4260
leaq -0x150(%rbp), %rdi
callq 0x4260
leaq -0x170(%rbp), %rdi
callq 0x4260
movq -0x10(%rbp), %rsi
movl -0xcc(%rbp), %edx
leaq -0x1d0(%rbp), %rdi
callq 0x9390
jmp 0xa511
leaq 0xa3438(%rip), %rsi     # 0xad950
leaq -0x1b0(%rbp), %rdi
leaq -0x1d0(%rbp), %rdx
callq 0xc280
jmp 0xa52d
leaq 0xa1ce5(%rip), %rdx     # 0xac219
leaq -0x190(%rbp), %rdi
leaq -0x1b0(%rbp), %rsi
callq 0x8670
jmp 0xa549
leaq -0x190(%rbp), %rdi
callq 0x4160
movq %rax, %rdi
callq 0x8cf20
jmp 0xa55f
leaq -0x190(%rbp), %rdi
callq 0x4260
leaq -0x1b0(%rbp), %rdi
callq 0x4260
leaq -0x1d0(%rbp), %rdi
callq 0x4260
jmp 0xa62a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0xa5c8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0xa5bc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x130(%rbp), %rdi
callq 0x4260
leaq -0x150(%rbp), %rdi
callq 0x4260
leaq -0x170(%rbp), %rdi
callq 0x4260
jmp 0xa7e7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0xa619
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0xa60d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x190(%rbp), %rdi
callq 0x4260
leaq -0x1b0(%rbp), %rdi
callq 0x4260
leaq -0x1d0(%rbp), %rdi
callq 0x4260
jmp 0xa7e7
jmp 0xa62c
leaq -0xb8(%rbp), %rdi
callq 0xc2d0
jmp 0xa2d4
testb $0x1, -0x99(%rbp)
je 0xa687
movq -0x28(%rbp), %rdi
movl -0x90(%rbp), %eax
movl %eax, -0x1d4(%rbp)
leaq -0x1d4(%rbp), %rsi
callq 0xc0f0
jmp 0xa664
movq -0x28(%rbp), %rdi
movl -0xa0(%rbp), %eax
movl %eax, -0x1d8(%rbp)
leaq -0x1d8(%rbp), %rsi
callq 0xc0f0
jmp 0xa682
jmp 0xa7b7
movq 0x10(%rbp), %rdi
movl -0x90(%rbp), %eax
movl %eax, -0x1dc(%rbp)
leaq -0x1dc(%rbp), %rsi
callq 0xc0f0
jmp 0xa6a5
movq -0x8(%rbp), %rdi
movl -0x90(%rbp), %esi
callq 0x7f2e0
movb %al, -0x236(%rbp)
jmp 0xa6bc
movb -0x236(%rbp), %al
testb $0x1, %al
jne 0xa6cb
jmp 0xa7b5
testb $0x1, -0x11(%rbp)
je 0xa6e8
movq 0x20(%rbp), %rdi
leaq -0x94(%rbp), %rsi
callq 0xbf60
jmp 0xa6e3
jmp 0xa7b3
leaq -0x1f8(%rbp), %rdi
movq %rdi, -0x240(%rbp)
callq 0xbe70
movq -0x240(%rbp), %rdx
movq -0x8(%rbp), %rdi
movl -0x90(%rbp), %esi
movl -0x18(%rbp), %ecx
movl -0x1c(%rbp), %r8d
callq 0x9bb0
movb %al, -0x237(%rbp)
jmp 0xa720
movb -0x237(%rbp), %al
testb $0x1, %al
jne 0xa775
jmp 0xa72c
leaq 0xa3228(%rip), %rdi     # 0xad95b
xorl %eax, %eax
callq 0x4060
jmp 0xa73c
leaq 0xa2b2d(%rip), %rdi     # 0xad270
leaq 0xa2b2c(%rip), %rsi     # 0xad276
movl $0x14a, %edx            # imm = 0x14A
leaq 0xa3112(%rip), %rcx     # 0xad868
callq 0x4270
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x1f8(%rbp), %rdi
callq 0xbb80
jmp 0xa7e7
movq 0x20(%rbp), %rax
movq %rax, -0x248(%rbp)
leaq -0x1f8(%rbp), %rdi
callq 0xbe90
movq -0x248(%rbp), %rdi
movl %eax, -0x1fc(%rbp)
leaq -0x1fc(%rbp), %rsi
callq 0xc0f0
jmp 0xa7a7
leaq -0x1f8(%rbp), %rdi
callq 0xbb80
jmp 0xa7b5
jmp 0xa7b7
jmp 0xa7b9
jmp 0xa7bb
jmp 0xa7bd
movl -0x90(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x90(%rbp)
jmp 0xa13c
leaq -0x60(%rbp), %rdi
callq 0xc300
movb $0x1, %al
andb $0x1, %al
addq $0x250, %rsp            # imm = 0x250
popq %rbp
retq
leaq -0x60(%rbp), %rdi
callq 0xc300
movq -0x70(%rbp), %rdi
callq 0x4680
nopl (%rax)