// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rcx, %rbp
movq %rsi, %r15
movq %rdi, %r14
movq %rsi, (%rdi)
movq %rdx, 0x8(%rdi)
leaq 0x10(%rdi), %rbx
leaq 0x40(%rdi), %rax
movq %rax, (%rsp)
leaq 0x58(%rdi), %r12
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rdi)
movups %xmm0, 0x20(%rdi)
movups %xmm0, 0x30(%rdi)
movups %xmm0, 0x40(%rdi)
movups %xmm0, 0x50(%rdi)
movups %xmm0, 0x60(%rdi)
movb $0x1, 0x70(%rdi)
movups (%r8), %xmm0
movups %xmm0, 0x78(%rdi)
movq 0x10(%r8), %rax
movq %rax, 0x88(%rdi)
leaq 0x90(%rdi), %r13
movq %r13, %rdi
xorl %esi, %esi
callq 0x11e94
xorps %xmm0, %xmm0
movups %xmm0, 0xb8(%r14)
andq $0x0, 0xc8(%r14)
movups %xmm0, 0xa8(%r14)
movq 0x8(%r15), %rax
leaq 0x1(%rax), %rdx
shrq %rdx
cmpq %rbp, %rdx
cmovaeq %rbp, %rdx
cmpq $0x5, %rdx
pushq $0x4
popq %rcx
cmovaeq %rdx, %rcx
cmpq %rcx, %rax
jb 0x19a91
movq %rcx, 0xc8(%r14)
movq (%r14), %rax
movq 0x8(%rax), %rax
addq %rcx, %rax
decq %rax
xorl %edx, %edx
divq %rcx
movq %rax, %r15
shrq $0x20, %rax
setne 0x70(%r14)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x1b644
cmpb $0x1, 0x70(%r14)
jne 0x199fb
movq %r12, %rdi
movq %r15, %rsi
callq 0x1b644
jmp 0x19a07
movq (%rsp), %rdi
movq %r15, %rsi
callq 0x1b676
movq 0xc8(%r14), %rcx
cmpq $0x101, %rcx            # imm = 0x101
movl $0x100, %edx            # imm = 0x100
cmovaeq %rcx, %rdx
movq %rdx, 0xc0(%r14)
leaq (%rdx,%rcx,2), %rbp
movl $0x3ffff, %eax          # imm = 0x3FFFF
addq %rax, %rbp
movq $-0x40000, %rsi         # imm = 0xFFFC0000
andq %rsi, %rbp
movq %rbp, 0xa8(%r14)
addq %rcx, %rax
addq %rdx, %rax
andq %rsi, %rax
movq %rax, 0xb0(%r14)
addq %rdx, %rcx
addq $0xfff, %rcx            # imm = 0xFFF
andq $-0x1000, %rcx          # imm = 0xF000
movq %rcx, 0xb8(%r14)
cmpq %rax, %rcx
ja 0x19aa0
addq %rax, %rbp
movq %r14, %rdi
callq 0x198c0
imulq %rax, %rbp
movq %r13, %rdi
movq %rbp, %rsi
callq 0x139d4
movq %r14, %rdi
callq 0x19afc
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x382bb(%rip), %rdi     # 0x51d62
leaq 0x382d6(%rip), %rsi     # 0x51d84
leaq 0x3831d(%rip), %rcx     # 0x51dd2
movl $0xc0, %edx
callq 0x4230
movq %rax, %r15
jmp 0x19acf
movq %rax, %r15
movq %r13, %rdi
callq 0x13a5c
addq $0x28, %r14
movq %r12, %rdi
callq 0x1bdfc
movq (%rsp), %rdi
callq 0x90f0
movq %r14, %rdi
callq 0x18b58
movq %rbx, %rdi
callq 0x1bdfc
movq %r15, %rdi
callq 0x4600