// File: /workspace/github_cpp_makefile_star2_O3/sisong[P]ApkDiffPatch/src/patch/Zipper.cpp
// Function: UnZipper_getHugePageAlign
size_t UnZipper_getHugePageAlign(const UnZipper* self,size_t baseZipAlignSize){
    bool isOld4k=true;
    bool is16k=true;
    bool is64k=true;
    int fCount=UnZipper_fileCount(self);
    for (int i=0; i<fCount; ++i) {
        if (UnZipper_file_isCompressed(self,i)) continue;
        if (!_file_getIsSoFileName(self,i)) continue;
        const ZipFilePos_t dataPos=UnZipper_fileData_offset(self,i);
        if (dataPos%(4*1024)!=0)  return 0; // not align
        if (dataPos%(16*1024)!=0) is16k=false;
        if (dataPos%(64*1024)!=0) is64k=false;
       // if (!_file_getIsPageAlignSoFile(self,i)) isOld4k=false;

        const ZipFilePos_t entryPos=UnZipper_fileEntry_offset_unsafe(self,i);
        const int headInfoLen=30+UnZipper_file_nameLen(self,i)+_file_extraFieldLen(self,i);
        const ZipFilePos_t dataPos_x=entryPos+headInfoLen;
        if (dataPos_x!=dataPos) return 0; // not normalized
    
        if (i==0) continue;
        const ZipFilePos_t lastEndPos=UnZipper_fileData_offset(self,i-1)+
                (UnZipper_file_isCompressed(self,i-1)?UnZipper_file_compressedSize(self,i-1):UnZipper_file_uncompressedSize(self,i-1));
        if (entryPos<lastEndPos) return 0; // not normalized
        const int skipLen_base=_getAlignSkipLen(lastEndPos+headInfoLen,baseZipAlignSize);

        if (lastEndPos+_getAlignSkipLen(lastEndPos+headInfoLen,4*1024)!=entryPos) isOld4k=false;
        if (lastEndPos+_getAlignSkipLen(lastEndPos+headInfoLen,16*1024)!=entryPos) is16k=false;
        if (lastEndPos+_getAlignSkipLen(lastEndPos+headInfoLen,64*1024)!=entryPos) is64k=false;
    }

    if (is64k)
        return 64*1024;
    else if (is16k)
        return 16*1024;
    else if (isOld4k)
        return 4*1024;
    else
        return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq 0x48(%rdi), %rax
movzwl 0x8(%rax), %ecx
testq %rcx, %rcx
je 0x411c8
movq 0x50(%rdi), %rdx
movq 0x58(%rdi), %r8
shll $0x2, %ecx
movb $0x1, %r13b
xorl %r11d, %r11d
movb $0x1, %r9b
movb $0x1, %al
movq %rdi, -0x8(%rsp)
movl (%r8,%r11), %r12d
cmpw $0x0, 0xa(%rdx,%r12)
jne 0x41197
addq %rdx, %r12
movzwl 0x1c(%r12), %ebx
cmpq $0x3, %rbx
jb 0x41197
movzwl 0x2b(%r12,%rbx), %r10d
xorl $0x732e, %r10d          # imm = 0x732E
movzbl 0x2d(%r12,%rbx), %ebp
xorl $0x6f, %ebp
orw %r10w, %bp
jne 0x41197
movq 0x78(%rdi), %r15
movl (%r15,%r11), %ebp
testl $0xfff, %ebp            # imm = 0xFFF
jne 0x411cf
movb %r13b, -0xa(%rsp)
testl $0x3000, %ebp           # imm = 0x3000
sete %r13b
testl $0xf000, %ebp           # imm = 0xF000
sete %r10b
movq 0x80(%rdi), %r14
testq %r14, %r14
je 0x410d2
movl (%r14,%r11), %r14d
movzwl 0x1e(%r12), %r12d
jmp 0x410e5
movzwl 0x1e(%r12), %r12d
movl %ebp, %r14d
subl %ebx, %r14d
subl %r12d, %r14d
addl $-0x1e, %r14d
leal (%rbx,%r12), %esi
addl %r14d, %esi
addl $0x1e, %esi
cmpl %ebp, %esi
jne 0x411cf
andb %r13b, %r9b
andb %r10b, %al
testq %r11, %r11
je 0x4112c
movb %al, -0x9(%rsp)
movl -0x4(%r8,%r11), %r10d
cmpw $0x0, 0xa(%rdx,%r10)
movb -0xa(%rsp), %r13b
je 0x41133
movq -0x8(%rsp), %rax
movq 0x60(%rax), %rsi
leaq (%rsi,%r11), %r10
addq $-0x4, %r10
jmp 0x4113a
movb -0xa(%rsp), %r13b
jmp 0x41192
addq %rdx, %r10
addq $0x18, %r10
movl -0x4(%r15,%r11), %ebp
addl (%r10), %ebp
cmpl %ebp, %r14d
jb 0x411cf
leal (%rbx,%r12), %esi
addl $0x1e, %esi
addl %ebp, %esi
negl %esi
movl %esi, %r10d
movzwl %si, %ebx
andl $0xfff, %esi            # imm = 0xFFF
addl %ebp, %esi
cmpl %r14d, %esi
sete %sil
andb %sil, %r13b
andl $0x3fff, %r10d          # imm = 0x3FFF
addl %ebp, %r10d
cmpl %r14d, %r10d
sete %sil
andb %sil, %r9b
addl %ebp, %ebx
cmpl %r14d, %ebx
sete %sil
movb -0x9(%rsp), %al
andb %sil, %al
movq -0x8(%rsp), %rdi
addq $0x4, %r11
cmpq %r11, %rcx
jne 0x41049
movzbl %r13b, %ecx
andl $0x1, %ecx
shll $0xc, %ecx
testb $0x1, %r9b
movl $0x4000, %edx           # imm = 0x4000
cmoveq %rcx, %rdx
testb $0x1, %al
movl $0x10000, %eax          # imm = 0x10000
cmoveq %rdx, %rax
jmp 0x411d1
movl $0x10000, %eax          # imm = 0x10000
jmp 0x411d1
xorl %eax, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq