// File: /workspace/github_cpp_makefile_star2_O3/sisong[P]ApkDiffPatch/src/patch/Zipper.cpp
// Function: UnZipper_searchApkV2Sign
bool UnZipper_searchApkV2Sign(const hpatch_TStreamInput* stream,hpatch_StreamPos_t centralDirectory_pos,
                              ZipFilePos_t* v2sign_topPos,ZipFilePos_t* out_blockSize,bool* out_isHaveV3Sign){
    *v2sign_topPos=(ZipFilePos_t)centralDirectory_pos; //default not found
    if (out_blockSize) *out_blockSize=0;
    //nodePos_begin=v2sign_topPos-8;
    //sumNodeSize=blockSize-8-APKSigningTagLen;
    
    //tag
    const size_t APKSigningTagLen=16;
    const char* APKSigningTag="APK Sig Block 42";
    if (APKSigningTagLen>centralDirectory_pos) return true; //not found
    ZipFilePos_t APKSigningBlockTagPos=(ZipFilePos_t)centralDirectory_pos-APKSigningTagLen;
    TByte buf[APKSigningTagLen];
    check(stream->read(stream,APKSigningBlockTagPos,buf,buf+APKSigningTagLen));
    if (0!=memcmp(buf,APKSigningTag,APKSigningTagLen)) return true;//not found
    //bottom size
    check(8<=APKSigningBlockTagPos);
    ZipFilePos_t blockSizeBottomPos=APKSigningBlockTagPos-8;
    check(stream->read(stream,blockSizeBottomPos,buf,buf+8));
    hpatch_StreamPos_t blockSize=readUInt64(buf);
    //top
    check(blockSize+8<=centralDirectory_pos);
    ZipFilePos_t blockTopSizePos=(ZipFilePos_t)centralDirectory_pos-(ZipFilePos_t)blockSize-8;
    check(stream->read(stream,blockTopSizePos,buf,buf+8));
    check(blockSize==readUInt64(buf)); //check top size
    
    *v2sign_topPos=blockTopSizePos;
    if (out_blockSize) *out_blockSize=(ZipFilePos_t)blockSize;
    if (out_isHaveV3Sign){
        const hpatch_uint32_t kV3SignID=0xf05368c0;
        ZipFilePos_t IDNodePos;
        ZipFilePos_t IDNodeSize;
        if (!_searchID_in_block(stream,blockTopSizePos+8,(ZipFilePos_t)blockSize-8-APKSigningTagLen,
                                kV3SignID,&IDNodePos,&IDNodeSize)) return false; //error
        *out_isHaveV3Sign=(IDNodeSize>0);
    }
    return true;//found
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rcx, %r12
movq %rdx, %r13
movq %rsi, %r14
movq %rdi, %r15
movl %r14d, (%rdx)
testq %rcx, %rcx
je 0x3f28e
movl $0x0, (%r12)
cmpq $0x10, %r14
jb 0x3f411
movq %r8, 0x28(%rsp)
leal -0x10(%r14), %ebp
leaq 0x20(%rsp), %rcx
leaq 0x10(%rsp), %rdx
movq %r15, %rdi
movq %rbp, %rsi
callq *0x10(%r15)
testl %eax, %eax
je 0x3f4bd
movdqa 0x10(%rsp), %xmm0
pcmpeqb 0x20ff5(%rip), %xmm0    # 0x602c0
pmovmskb %xmm0, %eax
cmpl $0xffff, %eax           # imm = 0xFFFF
jne 0x3f411
cmpl $0x7, %ebp
jbe 0x3f4dc
leal -0x18(%r14), %esi
leaq 0x18(%rsp), %rcx
leaq 0x10(%rsp), %rdx
movq %r15, %rdi
callq *0x10(%r15)
testl %eax, %eax
je 0x3f4fb
movl 0x10(%rsp), %ebx
movl 0x14(%rsp), %ebp
shlq $0x20, %rbp
leaq (%rbx,%rbp), %rax
addq $0x8, %rax
cmpq %r14, %rax
ja 0x3f51a
subl %ebx, %r14d
leal -0x8(%r14), %esi
leaq 0x10(%rsp), %rdx
movq %r15, %rdi
movq %rsi, 0x30(%rsp)
leaq 0x18(%rsp), %rcx
callq *0x10(%r15)
testl %eax, %eax
je 0x3f539
orq %rbx, %rbp
cmpq 0x10(%rsp), %rbp
jne 0x3f558
movq 0x30(%rsp), %rax
movl %eax, (%r13)
testq %r12, %r12
je 0x3f362
movl %ebx, (%r12)
cmpq $0x0, 0x28(%rsp)
je 0x3f411
addl $-0x18, %ebx
je 0x3f408
leaq 0xc(%rsp), %r13
leaq 0x8(%rsp), %rbp
cmpl $0xb, %ebx
jbe 0x3f422
movl %r14d, %esi
movq %r15, %rdi
movq %rbp, %rdx
leaq 0x10(%rsp), %rcx
callq *0x10(%r15)
testl %eax, %eax
je 0x3f460
movl 0x8(%rsp), %r12d
movl 0xc(%rsp), %eax
shlq $0x20, %rax
orq %r12, %rax
cmpq $0x3, %rax
jbe 0x3f49e
addq $0x8, %rax
movl %ebx, %ecx
cmpq %rcx, %rax
ja 0x3f47f
leal 0x8(%r14), %esi
movq %r15, %rdi
movq %rbp, %rdx
movq %r13, %rcx
callq *0x10(%r15)
testl %eax, %eax
je 0x3f441
cmpl $0xf05368c0, 0x8(%rsp)  # imm = 0xF05368C0
je 0x3f400
movl %r12d, %eax
addl $0x8, %eax
addl %r12d, %r14d
addl $0x8, %r14d
subl %eax, %ebx
jne 0x3f381
xorl %r12d, %r12d
testl %r12d, %r12d
setne %al
jmp 0x3f40a
xorl %eax, %eax
movq 0x28(%rsp), %rcx
movb %al, (%rcx)
movb $0x1, %al
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1ac27(%rip), %rdi     # 0x5a050
leaq 0x20eb1(%rip), %rsi     # 0x602e1
leaq 0x2185f(%rip), %rcx     # 0x60c96
movl $0x93, %edx
callq 0x4200
leaq 0x1ac08(%rip), %rdi     # 0x5a050
leaq 0x20e92(%rip), %rsi     # 0x602e1
leaq 0x21840(%rip), %rcx     # 0x60c96
movl $0x98, %edx
callq 0x4200
leaq 0x1abe9(%rip), %rdi     # 0x5a050
leaq 0x20e73(%rip), %rsi     # 0x602e1
leaq 0x21821(%rip), %rcx     # 0x60c96
movl $0x94, %edx
callq 0x4200
leaq 0x1abca(%rip), %rdi     # 0x5a050
leaq 0x20e54(%rip), %rsi     # 0x602e1
leaq 0x21802(%rip), %rcx     # 0x60c96
movl $0x97, %edx
callq 0x4200
leaq 0x1abab(%rip), %rdi     # 0x5a050
leaq 0x20e35(%rip), %rsi     # 0x602e1
leaq 0x217e3(%rip), %rcx     # 0x60c96
movl $0x96, %edx
callq 0x4200
leaq 0x1ab8c(%rip), %rdi     # 0x5a050
leaq 0x20e16(%rip), %rsi     # 0x602e1
leaq 0x20e24(%rip), %rcx     # 0x602f6
movl $0xb3, %edx
callq 0x4200
leaq 0x1ab6d(%rip), %rdi     # 0x5a050
leaq 0x20df7(%rip), %rsi     # 0x602e1
leaq 0x20e05(%rip), %rcx     # 0x602f6
movl $0xb6, %edx
callq 0x4200
leaq 0x1ab4e(%rip), %rdi     # 0x5a050
leaq 0x20dd8(%rip), %rsi     # 0x602e1
leaq 0x20de6(%rip), %rcx     # 0x602f6
movl $0xb8, %edx
callq 0x4200
leaq 0x1ab2f(%rip), %rdi     # 0x5a050
leaq 0x20db9(%rip), %rsi     # 0x602e1
leaq 0x20dc7(%rip), %rcx     # 0x602f6
movl $0xbb, %edx
callq 0x4200
leaq 0x1ab10(%rip), %rdi     # 0x5a050
leaq 0x20d9a(%rip), %rsi     # 0x602e1
leaq 0x20da8(%rip), %rcx     # 0x602f6
movl $0xbd, %edx
callq 0x4200
leaq 0x1aaf1(%rip), %rdi     # 0x5a050
leaq 0x20d7b(%rip), %rsi     # 0x602e1
leaq 0x20d89(%rip), %rcx     # 0x602f6
movl $0xbe, %edx
callq 0x4200