// File: sisong[P]ApkDiffPatch/src/diff/OldRef.cpp
// Function: getOldRefList(UnZipper*, std::vector<unsigned int, std::allocator<unsigned int>> const&, std::vector<unsigned int, std::allocator<unsigned int>> const&, UnZipper*, std::vector<unsigned int, std::allocator<unsigned int>>&)
bool getOldRefList(UnZipper* newZip,const std::vector<uint32_t>& samePairList,
                   const std::vector<uint32_t>& newRefList,
                   UnZipper* oldZip,std::vector<uint32_t>& out_oldRefList){
    std::vector<uint32_t> oldSameList(samePairList.size()/2);
    for (size_t i=0; i<oldSameList.size(); ++i)
        oldSameList[i]=samePairList[i*2+1];
    std::sort(oldSameList.begin(),oldSameList.end());
    
    int oldZipFileCount=UnZipper_fileCount(oldZip);
    std::vector<uint32_t> decompressList;
    size_t iOldSame=0;
    for (int i=0; i<oldZipFileCount; ++i) {
        bool isInSame=false;
        while ((iOldSame<oldSameList.size())&&(i==(int)oldSameList[iOldSame])){
            isInSame=true;
            ++iOldSame;
        }
        if (UnZipper_file_uncompressedSize(oldZip,i)<=0)
            continue;
        if(!UnZipper_file_isCompressed(oldZip,i))
            out_oldRefList.push_back(i);//反正不用解压,不用判断其是否有参考意义了;
        else if (!isInSame) //跳过和newZip中相同的文件,但某些情况可能会使得结果变大;
            decompressList.push_back(i);
    }
    assert(iOldSame==oldSameList.size());
    //optimize: continue to reduce the decompressList?
    out_oldRefList.insert(out_oldRefList.end(),decompressList.begin(),decompressList.end());
    std::sort(out_oldRefList.begin(),out_oldRefList.end());
    return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x150, %rsp            # imm = 0x150
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq -0x10(%rbp), %rdi
callq 0xc360
shrq %rax
movq %rax, -0xf0(%rbp)
leaq -0x41(%rbp), %rdi
movq %rdi, -0xe8(%rbp)
callq 0xc9d0
movq -0xf0(%rbp), %rsi
movq -0xe8(%rbp), %rdx
leaq -0x40(%rbp), %rdi
callq 0x17980
jmp 0x175cb
leaq -0x41(%rbp), %rdi
callq 0x113d0
movq $0x0, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0xf8(%rbp)
leaq -0x40(%rbp), %rdi
callq 0xc360
movq %rax, %rcx
movq -0xf8(%rbp), %rax
cmpq %rcx, %rax
jae 0x17658
movq -0x10(%rbp), %rdi
movq -0x60(%rbp), %rsi
shlq %rsi
addq $0x1, %rsi
callq 0xca30
movl (%rax), %eax
movl %eax, -0xfc(%rbp)
movq -0x60(%rbp), %rsi
leaq -0x40(%rbp), %rdi
callq 0x179f0
movl -0xfc(%rbp), %ecx
movl %ecx, (%rax)
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
jmp 0x175dc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x41(%rbp), %rdi
callq 0x113d0
jmp 0x17976
leaq -0x40(%rbp), %rdi
movq %rdi, -0x108(%rbp)
callq 0x11720
movq -0x108(%rbp), %rdi
movq %rax, -0x68(%rbp)
callq 0x115b0
movq %rax, -0x70(%rbp)
movq -0x68(%rbp), %rdi
movq -0x70(%rbp), %rsi
callq 0x14af0
jmp 0x1768b
movq -0x20(%rbp), %rdi
callq 0x7ea90
movl %eax, -0x10c(%rbp)
jmp 0x1769c
movl -0x10c(%rbp), %eax
movl %eax, -0x74(%rbp)
leaq -0x90(%rbp), %rdi
callq 0xbf40
movq $0x0, -0x98(%rbp)
movl $0x0, -0x9c(%rbp)
movl -0x9c(%rbp), %eax
cmpl -0x74(%rbp), %eax
jge 0x17840
movb $0x0, -0x9d(%rbp)
movq -0x98(%rbp), %rax
movq %rax, -0x118(%rbp)
leaq -0x40(%rbp), %rdi
callq 0xc360
movq -0x118(%rbp), %rcx
movq %rax, %rdx
xorl %eax, %eax
cmpq %rdx, %rcx
movb %al, -0x10d(%rbp)
jae 0x1773a
movl -0x9c(%rbp), %eax
movl %eax, -0x11c(%rbp)
movq -0x98(%rbp), %rsi
leaq -0x40(%rbp), %rdi
callq 0x179f0
movq %rax, %rcx
movl -0x11c(%rbp), %eax
cmpl (%rcx), %eax
sete %al
movb %al, -0x10d(%rbp)
movb -0x10d(%rbp), %al
testb $0x1, %al
jne 0x17746
jmp 0x17775
movb $0x1, -0x9d(%rbp)
movq -0x98(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x98(%rbp)
jmp 0x176dc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x1796d
movq -0x20(%rbp), %rdi
movl -0x9c(%rbp), %esi
callq 0x80480
movl %eax, -0x120(%rbp)
jmp 0x1778c
movl -0x120(%rbp), %eax
cmpl $0x0, %eax
ja 0x177b9
jmp 0x1782c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x90(%rbp), %rdi
callq 0xc010
jmp 0x1796d
movq -0x20(%rbp), %rdi
movl -0x9c(%rbp), %esi
callq 0x7f2e0
movb %al, -0x121(%rbp)
jmp 0x177d0
movb -0x121(%rbp), %al
testb $0x1, %al
jne 0x177fc
jmp 0x177dc
movq -0x28(%rbp), %rdi
movl -0x9c(%rbp), %eax
movl %eax, -0xa4(%rbp)
leaq -0xa4(%rbp), %rsi
callq 0xc0f0
jmp 0x177fa
jmp 0x1782a
testb $0x1, -0x9d(%rbp)
jne 0x17828
movl -0x9c(%rbp), %eax
movl %eax, -0xa8(%rbp)
leaq -0x90(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0xc0f0
jmp 0x17826
jmp 0x17828
jmp 0x1782a
jmp 0x1782c
movl -0x9c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x9c(%rbp)
jmp 0x176c6
movq -0x98(%rbp), %rax
movq %rax, -0x130(%rbp)
leaq -0x40(%rbp), %rdi
callq 0xc360
movq %rax, %rcx
movq -0x130(%rbp), %rax
cmpq %rcx, %rax
jne 0x17868
jmp 0x17887
leaq 0x97027(%rip), %rdi     # 0xae896
leaq 0x9703d(%rip), %rsi     # 0xae8b3
movl $0x39, %edx
leaq 0x97045(%rip), %rcx     # 0xae8c7
callq 0x4270
movq -0x28(%rbp), %rdi
movq %rdi, -0x140(%rbp)
callq 0x115b0
movq %rax, -0xb8(%rbp)
leaq -0xb0(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x14ab0
leaq -0x90(%rbp), %rdi
movq %rdi, -0x148(%rbp)
callq 0x11720
movq -0x148(%rbp), %rdi
movq %rax, -0xc0(%rbp)
callq 0x115b0
movq -0x140(%rbp), %rdi
movq %rax, -0xc8(%rbp)
movq -0xb0(%rbp), %rsi
movq -0xc0(%rbp), %rdx
movq -0xc8(%rbp), %rcx
callq 0x14a00
movq %rax, -0x138(%rbp)
jmp 0x17908
movq -0x138(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq -0x28(%rbp), %rdi
callq 0x11720
movq %rax, -0xd8(%rbp)
movq -0x28(%rbp), %rdi
callq 0x115b0
movq %rax, -0xe0(%rbp)
movq -0xd8(%rbp), %rdi
movq -0xe0(%rbp), %rsi
callq 0x14af0
jmp 0x1794b
leaq -0x90(%rbp), %rdi
callq 0xc010
leaq -0x40(%rbp), %rdi
callq 0xc010
movb $0x1, %al
andb $0x1, %al
addq $0x150, %rsp            # imm = 0x150
popq %rbp
retq
leaq -0x40(%rbp), %rdi
callq 0xc010
movq -0x50(%rbp), %rdi
callq 0x4680
nop