// File: sisong[P]ApkDiffPatch/HDiffPatch/libHDiffPatch/HDiff/private_diff/compress_detect.cpp
// Function: unsigned long hdiff_private::_getRegionRleCost<true, true>(unsigned char const*, unsigned long, unsigned char const*, unsigned char*, unsigned long*)
size_t _getRegionRleCost(const unsigned char* d,size_t n,const unsigned char* sub,
                             unsigned char* out_nocompress,size_t* nocompressSize){
        size_t bufi=0;
        size_t i=0;
        size_t cost=0;
        while ((i<n)&&(d[i]==(is_sub_on?sub[i]:0)))
            ++i;
        while(i<n){
            unsigned char v=(is_sub_on?(unsigned char)(d[i]-sub[i]):d[i]);
            size_t i0=i; ++i;
            while ((i<n)&&(v==(is_sub_on?(unsigned char)(d[i]-sub[i]):d[i])))
                ++i;
            if ((v==0)|(v==255)){
                ++cost;
            }else{
                cost+=(i-i0<=1)?1:2;
                if (is_out_on)
                    out_nocompress[bufi++]=v;
            }
        }
        if (nocompressSize) *nocompressSize=bufi;
        return cost;
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x38(%rbp), %rcx
xorl %eax, %eax
cmpq -0x10(%rbp), %rcx
movb %al, -0x51(%rbp)
jae 0x3dfef
movq -0x8(%rbp), %rax
movq -0x38(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movq -0x18(%rbp), %rcx
movq -0x38(%rbp), %rdx
movzbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
sete %al
movb %al, -0x51(%rbp)
movb -0x51(%rbp), %al
testb $0x1, %al
jne 0x3dff8
jmp 0x3e006
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x3dfc0
jmp 0x3e008
movq -0x38(%rbp), %rax
cmpq -0x10(%rbp), %rax
jae 0x3e10e
movq -0x8(%rbp), %rax
movq -0x38(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movq -0x18(%rbp), %rcx
movq -0x38(%rbp), %rdx
movzbl (%rcx,%rdx), %ecx
subl %ecx, %eax
movb %al, -0x41(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rcx
xorl %eax, %eax
cmpq -0x10(%rbp), %rcx
movb %al, -0x52(%rbp)
jae 0x3e07f
movzbl -0x41(%rbp), %eax
movq -0x8(%rbp), %rcx
movq -0x38(%rbp), %rdx
movzbl (%rcx,%rdx), %ecx
movq -0x18(%rbp), %rdx
movq -0x38(%rbp), %rsi
movzbl (%rdx,%rsi), %edx
subl %edx, %ecx
movzbl %cl, %ecx
cmpl %ecx, %eax
sete %al
movb %al, -0x52(%rbp)
movb -0x52(%rbp), %al
testb $0x1, %al
jne 0x3e088
jmp 0x3e096
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x3e047
movzbl -0x41(%rbp), %eax
cmpl $0x0, %eax
sete %al
andb $0x1, %al
movzbl %al, %eax
movzbl -0x41(%rbp), %ecx
cmpl $0xff, %ecx
sete %cl
andb $0x1, %cl
movzbl %cl, %ecx
orl %ecx, %eax
cmpl $0x0, %eax
je 0x3e0cd
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x3e109
movq -0x38(%rbp), %rdx
subq -0x50(%rbp), %rdx
movl $0x2, %eax
movl $0x1, %ecx
cmpq $0x1, %rdx
cmovbel %ecx, %eax
cltq
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
movb -0x41(%rbp), %dl
movq -0x20(%rbp), %rax
movq -0x30(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x30(%rbp)
movb %dl, (%rax,%rcx)
jmp 0x3e008
cmpq $0x0, -0x28(%rbp)
je 0x3e120
movq -0x30(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movq -0x40(%rbp), %rax
popq %rbp
retq
nopw %cs:(%rax,%rax)