// File: sisong[P]ApkDiffPatch/HDiffPatch/libHDiffPatch/HDiff/private_diff/compress_detect.cpp
// Function: hdiff_private::TCompressDetect::_cost_rle(unsigned char const*, unsigned long) const
size_t TCompressDetect::_cost_rle(const unsigned char* d,size_t n)const{
    //assert(kCacheSize*2^(kCompressDetectMaxBit-1)<2^32);
    const unsigned int kCompressDetectDivBit=12;
    const unsigned int kCompressDetectMaxBit=12;
    if (n==0) return 0;
    if (m_lastChar<0) return n;
    size_t        codeSize=0;
    unsigned char last=m_lastChar;
    for (size_t i=0;i<n;++i) {
        unsigned char cur=d[i];
        size_t rab=m_table->sum2char[last*256+cur];
        size_t ra =1+m_table->sum1char[last];
        last=cur;
        if ((rab<<(kCompressDetectMaxBit-1))>ra){
            if ((rab<<8)<ra) { rab<<=8; codeSize+=8; }
            if ((rab<<4)<ra) { rab<<=4; codeSize+=4; }
            if ((rab<<2)<ra) { rab<<=2; codeSize+=2; }
            if ((rab<<1)<ra) { codeSize+=1; }
            ++codeSize;
        }else{
            codeSize+=kCompressDetectMaxBit;
        }
    }
    return (codeSize+((kCompressDetectDivBit>>1)+1))/kCompressDetectDivBit;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x60(%rbp)
movl $0xc, -0x24(%rbp)
movl $0xc, -0x28(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x3db9a
movq $0x0, -0x8(%rbp)
jmp 0x3dd05
movq -0x60(%rbp), %rax
cmpl $0x0, 0x20(%rax)
jge 0x3dbb1
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x3dd05
movq -0x60(%rbp), %rax
movq $0x0, -0x30(%rbp)
movl 0x20(%rax), %eax
movb %al, -0x31(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x20(%rbp), %rax
jae 0x3dcef
movq -0x60(%rbp), %rax
movq -0x18(%rbp), %rcx
movq -0x40(%rbp), %rdx
movb (%rcx,%rdx), %cl
movb %cl, -0x41(%rbp)
movq 0x18(%rax), %rcx
movzbl -0x31(%rbp), %edx
shll $0x8, %edx
movzbl -0x41(%rbp), %esi
addl %esi, %edx
movslq %edx, %rdx
movl 0x404(%rcx,%rdx,4), %ecx
movq %rcx, -0x50(%rbp)
movq 0x18(%rax), %rax
movzbl -0x31(%rbp), %ecx
movl 0x4(%rax,%rcx,4), %eax
addl $0x1, %eax
movl %eax, %eax
movq %rax, -0x58(%rbp)
movb -0x41(%rbp), %al
movb %al, -0x31(%rbp)
movq -0x50(%rbp), %rax
shlq $0xb, %rax
cmpq -0x58(%rbp), %rax
jbe 0x3dcd0
movq -0x50(%rbp), %rax
shlq $0x8, %rax
cmpq -0x58(%rbp), %rax
jae 0x3dc5d
movq -0x50(%rbp), %rax
shlq $0x8, %rax
movq %rax, -0x50(%rbp)
movq -0x30(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x30(%rbp)
movq -0x50(%rbp), %rax
shlq $0x4, %rax
cmpq -0x58(%rbp), %rax
jae 0x3dc83
movq -0x50(%rbp), %rax
shlq $0x4, %rax
movq %rax, -0x50(%rbp)
movq -0x30(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x30(%rbp)
movq -0x50(%rbp), %rax
shlq $0x2, %rax
cmpq -0x58(%rbp), %rax
jae 0x3dca9
movq -0x50(%rbp), %rax
shlq $0x2, %rax
movq %rax, -0x50(%rbp)
movq -0x30(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x30(%rbp)
movq -0x50(%rbp), %rax
shlq %rax
cmpq -0x58(%rbp), %rax
jae 0x3dcc2
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x3dcdc
movq -0x30(%rbp), %rax
addq $0xc, %rax
movq %rax, -0x30(%rbp)
jmp 0x3dcde
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x3dbcb
movq -0x30(%rbp), %rax
addq $0x7, %rax
movl $0xc, %ecx
xorl %edx, %edx
divq %rcx
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
popq %rbp
retq
nopl (%rax,%rax)