// File: sisong[P]ApkDiffPatch/HDiffPatch/libHDiffPatch/HDiff/private_diff/limit_mem_diff/digest_matcher.cpp
// Function: hdiff_private::TDigestMatcher::TDigestMatcher(hpatch_TStreamInput const*, hpatch_TStreamInput const*, unsigned long, hdiff_TMTSets_s const&)
TDigestMatcher::TDigestMatcher(const hpatch_TStreamInput* oldData,const hpatch_TStreamInput* newData,
                               size_t kMatchBlockSize,const hdiff_TMTSets_s& mtsets)
:m_oldData(oldData),m_newData(newData),m_isUseLargeSorted(true),m_mtsets(mtsets),
m_newCacheSize(0),m_oldCacheSize(0),m_oldMinCacheSize(0),m_backupCacheSize(0),m_kMatchBlockSize(0){
    if (kMatchBlockSize>(oldData->streamSize+1)/2)
        kMatchBlockSize=(size_t)((oldData->streamSize+1)/2);
    if (kMatchBlockSize<kMatchBlockSize_min)
        kMatchBlockSize=kMatchBlockSize_min;
    if (oldData->streamSize<kMatchBlockSize) return;
    m_kMatchBlockSize=kMatchBlockSize;
    
    hpatch_StreamPos_t _blockCount=getBlockCount(m_kMatchBlockSize,m_oldData->streamSize);
    m_isUseLargeSorted=(_blockCount>=((hpatch_StreamPos_t)1<<32));
    const size_t blockCount=(size_t)_blockCount;
    if (blockCount!=_blockCount)
        throw std::runtime_error("TDataDigest() oldData->streamSize/MatchBlockSize too big error!");
    m_blocks.resize(blockCount);
    if (m_isUseLargeSorted)
        m_sorted_larger.resize(blockCount);
    else
        m_sorted_limit.resize(blockCount);
    
    m_backupCacheSize=getBackupSize(m_kMatchBlockSize);
    m_newCacheSize=upperCount(m_kMatchBlockSize*2+m_backupCacheSize,kBestReadSize)*kBestReadSize;
    m_oldCacheSize=upperCount(m_kMatchBlockSize+m_backupCacheSize,kBestReadSize)*kBestReadSize;
    m_oldMinCacheSize=upperCount(m_kMatchBlockSize+m_backupCacheSize,kMinReadSize)*kMinReadSize;
    assert(m_oldMinCacheSize<=m_oldCacheSize);
    m_mem.realloc((m_newCacheSize+m_oldCacheSize)*getSearchThreadNum());
    getDigests();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x58(%rbp)
movq -0x10(%rbp), %rax
movq %rax, (%rdi)
movq -0x18(%rbp), %rax
movq %rax, 0x8(%rdi)
addq $0x10, %rdi
movq %rdi, -0x60(%rbp)
callq 0x42340
movq -0x58(%rbp), %rdi
addq $0x28, %rdi
movq %rdi, -0x50(%rbp)
callq 0x42360
jmp 0x3e6d6
movq -0x58(%rbp), %rdi
addq $0x40, %rdi
movq %rdi, -0x78(%rbp)
callq 0xbf40
movq -0x58(%rbp), %rdi
addq $0x58, %rdi
movq %rdi, -0x70(%rbp)
callq 0x42340
movq -0x58(%rbp), %rdi
movb $0x1, 0x70(%rdi)
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rcx
movq %rcx, 0x88(%rdi)
movups (%rax), %xmm0
movups %xmm0, 0x78(%rdi)
addq $0x90, %rdi
movq %rdi, -0x68(%rbp)
xorl %eax, %eax
movl %eax, %esi
callq 0x29c00
jmp 0x3e72c
movq -0x58(%rbp), %rax
movq $0x0, 0xa8(%rax)
movq $0x0, 0xb0(%rax)
movq $0x0, 0xb8(%rax)
movq $0x0, 0xc0(%rax)
movq $0x0, 0xc8(%rax)
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x8(%rcx), %rcx
addq $0x1, %rcx
shrq %rcx
cmpq %rcx, %rax
jbe 0x3e7b6
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
addq $0x1, %rax
shrq %rax
movq %rax, -0x20(%rbp)
jmp 0x3e7b6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x3ea7b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x3ea60
cmpq $0x4, -0x20(%rbp)
jae 0x3e7c5
movq $0x4, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
cmpq -0x20(%rbp), %rax
jae 0x3e7d8
jmp 0x3ea4e
movq -0x58(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rax, 0xc8(%rcx)
movq (%rcx), %rax
movq 0xc8(%rcx), %rdi
movq 0x8(%rax), %rsi
callq 0x3ea90
movq %rax, -0x80(%rbp)
jmp 0x3e800
movq -0x58(%rbp), %rax
movq -0x80(%rbp), %rcx
movq %rcx, -0x40(%rbp)
movabsq $0x100000000, %rcx      # imm = 0x100000000
cmpq %rcx, -0x40(%rbp)
setae %cl
andb $0x1, %cl
movb %cl, 0x70(%rax)
movq -0x40(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
cmpq -0x40(%rbp), %rax
je 0x3e8a7
movl $0x10, %edi
callq 0x41e0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x88(%rbp)
leaq 0x71a79(%rip), %rsi     # 0xb02cc
callq 0x4140
jmp 0x3e85a
movq -0x88(%rbp), %rdi
movq 0xa7788(%rip), %rsi     # 0xe5ff0
movq 0xa7751(%rip), %rdx     # 0xe5fc0
callq 0x4630
jmp 0x3ea8d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x3ea57
movq -0x88(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
callq 0x42e0
jmp 0x3ea57
movq -0x58(%rbp), %rdi
addq $0x10, %rdi
movq -0x48(%rbp), %rsi
callq 0x42390
jmp 0x3e8ba
movq -0x58(%rbp), %rax
testb $0x1, 0x70(%rax)
je 0x3e8d9
movq -0x58(%rbp), %rdi
addq $0x58, %rdi
movq -0x48(%rbp), %rsi
callq 0x42390
jmp 0x3e8d7
jmp 0x3e8ee
movq -0x58(%rbp), %rdi
addq $0x40, %rdi
movq -0x48(%rbp), %rsi
callq 0x42420
jmp 0x3e8ec
jmp 0x3e8ee
movq -0x58(%rbp), %rax
movq 0xc8(%rax), %rdi
callq 0x3eac0
movq %rax, -0x90(%rbp)
jmp 0x3e907
movq -0x58(%rbp), %rcx
movq -0x90(%rbp), %rax
movq %rax, 0xc0(%rcx)
movq 0xc0(%rcx), %rax
movq 0xc8(%rcx), %rcx
leaq (%rax,%rcx,2), %rdi
movl $0x40000, %esi          # imm = 0x40000
callq 0x3eaf0
movq %rax, -0x98(%rbp)
jmp 0x3e93e
movq -0x58(%rbp), %rcx
movq -0x98(%rbp), %rax
shlq $0x12, %rax
movq %rax, 0xa8(%rcx)
movq 0xc0(%rcx), %rax
movq 0xc8(%rcx), %rdi
addq %rax, %rdi
movl $0x40000, %esi          # imm = 0x40000
callq 0x3eaf0
movq %rax, -0xa0(%rbp)
jmp 0x3e978
movq -0x58(%rbp), %rcx
movq -0xa0(%rbp), %rax
shlq $0x12, %rax
movq %rax, 0xb0(%rcx)
movq 0xc0(%rcx), %rax
movq 0xc8(%rcx), %rdi
addq %rax, %rdi
movl $0x1000, %esi           # imm = 0x1000
callq 0x3eaf0
movq %rax, -0xa8(%rbp)
jmp 0x3e9b2
movq -0x58(%rbp), %rcx
movq -0xa8(%rbp), %rax
shlq $0xc, %rax
movq %rax, 0xb8(%rcx)
movq 0xb8(%rcx), %rax
cmpq 0xb0(%rcx), %rax
ja 0x3e9da
jmp 0x3e9f9
leaq 0x7192b(%rip), %rdi     # 0xb030c
leaq 0x71946(%rip), %rsi     # 0xb032e
movl $0xc0, %edx
leaq 0x71988(%rip), %rcx     # 0xb037c
callq 0x4270
movq -0x58(%rbp), %rdi
movq %rdi, %rax
addq $0x90, %rax
movq %rax, -0xb0(%rbp)
movq 0xa8(%rdi), %rax
movq 0xb0(%rdi), %rcx
addq %rcx, %rax
movq %rax, -0xb8(%rbp)
callq 0x3e5e0
movq -0xb8(%rbp), %rsi
movq -0xb0(%rbp), %rdi
imulq %rax, %rsi
callq 0x301a0
jmp 0x3ea43
movq -0x58(%rbp), %rdi
callq 0x3eb20
jmp 0x3ea4e
addq $0xc0, %rsp
popq %rbp
retq
movq -0x68(%rbp), %rdi
callq 0x29ca0
movq -0x70(%rbp), %rdi
callq 0x422c0
movq -0x78(%rbp), %rdi
callq 0xc010
movq -0x50(%rbp), %rdi
callq 0x42320
movq -0x60(%rbp), %rdi
callq 0x422c0
movq -0x30(%rbp), %rdi
callq 0x4680
nopl (%rax)