// File: 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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movb $0x1, -0x19(%rbp)
movb $0x1, -0x1a(%rbp)
movb $0x1, -0x1b(%rbp)
movq -0x10(%rbp), %rdi
callq 0x7ea90
movl %eax, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0x819e3
movq -0x10(%rbp), %rdi
movl -0x24(%rbp), %esi
callq 0x7f2e0
testb $0x1, %al
jne 0x8180d
jmp 0x81812
jmp 0x819d5
movq -0x10(%rbp), %rdi
movl -0x24(%rbp), %esi
callq 0x81a30
testb $0x1, %al
jne 0x81827
jmp 0x819d5
movq -0x10(%rbp), %rdi
movl -0x24(%rbp), %esi
callq 0x80620
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %eax
andl $0xfff, %eax            # imm = 0xFFF
cmpl $0x0, %eax
je 0x81850
movq $0x0, -0x8(%rbp)
jmp 0x81a1b
movl -0x28(%rbp), %eax
andl $0x3fff, %eax           # imm = 0x3FFF
cmpl $0x0, %eax
je 0x81861
movb $0x0, -0x1a(%rbp)
movl -0x28(%rbp), %eax
andl $0xffff, %eax           # imm = 0xFFFF
cmpl $0x0, %eax
je 0x81872
movb $0x0, -0x1b(%rbp)
movq -0x10(%rbp), %rdi
movl -0x24(%rbp), %esi
callq 0x80640
movl %eax, -0x2c(%rbp)
movq -0x10(%rbp), %rdi
movl -0x24(%rbp), %esi
callq 0x7eae0
addl $0x1e, %eax
movl %eax, -0x40(%rbp)
movq -0x10(%rbp), %rdi
movl -0x24(%rbp), %esi
callq 0x81a60
movl %eax, %ecx
movl -0x40(%rbp), %eax
addl %ecx, %eax
movl %eax, -0x30(%rbp)
movl -0x2c(%rbp), %eax
addl -0x30(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x28(%rbp), %eax
je 0x818c7
movq $0x0, -0x8(%rbp)
jmp 0x81a1b
cmpl $0x0, -0x24(%rbp)
jne 0x818d2
jmp 0x819d5
movq -0x10(%rbp), %rdi
movl -0x24(%rbp), %esi
subl $0x1, %esi
callq 0x80620
movl %eax, -0x44(%rbp)
movq -0x10(%rbp), %rdi
movl -0x24(%rbp), %esi
subl $0x1, %esi
callq 0x7f2e0
testb $0x1, %al
jne 0x818f9
jmp 0x8190d
movq -0x10(%rbp), %rdi
movl -0x24(%rbp), %esi
subl $0x1, %esi
callq 0x80520
movl %eax, -0x48(%rbp)
jmp 0x8191f
movq -0x10(%rbp), %rdi
movl -0x24(%rbp), %esi
subl $0x1, %esi
callq 0x80480
movl %eax, -0x48(%rbp)
movl -0x44(%rbp), %eax
movl -0x48(%rbp), %ecx
addl %ecx, %eax
movl %eax, -0x38(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x38(%rbp), %eax
jae 0x8193f
movq $0x0, -0x8(%rbp)
jmp 0x81a1b
movl -0x38(%rbp), %eax
addl -0x30(%rbp), %eax
movl %eax, %eax
movl %eax, %edi
movq -0x18(%rbp), %rsi
callq 0x81aa0
movl %eax, -0x3c(%rbp)
movl -0x38(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl -0x38(%rbp), %eax
addl -0x30(%rbp), %eax
movl %eax, %eax
movl %eax, %edi
movl $0x1000, %esi           # imm = 0x1000
callq 0x81aa0
movl %eax, %ecx
movl -0x4c(%rbp), %eax
addl %ecx, %eax
cmpl -0x2c(%rbp), %eax
je 0x8197f
movb $0x0, -0x19(%rbp)
movl -0x38(%rbp), %eax
movl %eax, -0x50(%rbp)
movl -0x38(%rbp), %eax
addl -0x30(%rbp), %eax
movl %eax, %eax
movl %eax, %edi
movl $0x4000, %esi           # imm = 0x4000
callq 0x81aa0
movl %eax, %ecx
movl -0x50(%rbp), %eax
addl %ecx, %eax
cmpl -0x2c(%rbp), %eax
je 0x819a9
movb $0x0, -0x1a(%rbp)
movl -0x38(%rbp), %eax
movl %eax, -0x54(%rbp)
movl -0x38(%rbp), %eax
addl -0x30(%rbp), %eax
movl %eax, %eax
movl %eax, %edi
movl $0x10000, %esi          # imm = 0x10000
callq 0x81aa0
movl %eax, %ecx
movl -0x54(%rbp), %eax
addl %ecx, %eax
cmpl -0x2c(%rbp), %eax
je 0x819d3
movb $0x0, -0x1b(%rbp)
jmp 0x819d5
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x817ef
testb $0x1, -0x1b(%rbp)
je 0x819f3
movq $0x10000, -0x8(%rbp)    # imm = 0x10000
jmp 0x81a1b
testb $0x1, -0x1a(%rbp)
je 0x81a03
movq $0x4000, -0x8(%rbp)     # imm = 0x4000
jmp 0x81a1b
testb $0x1, -0x19(%rbp)
je 0x81a13
movq $0x1000, -0x8(%rbp)     # imm = 0x1000
jmp 0x81a1b
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)