// File: /workspace/github_cpp_makefile_star2_O2/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
subq $0x28, %rsp
movq %rdi, %r12
movq 0x48(%rdi), %rax
movzwl 0x8(%rax), %eax
movb $0x1, 0x4(%rsp)
pushq $-0x4
popq %r8
xorl %r15d, %r15d
movb $0x1, %r14b
movb $0x1, 0x5(%rsp)
movq %rdi, 0x18(%rsp)
movq %rax, 0x8(%rsp)
cmpq %r15, %rax
je 0x38748
movq 0x50(%r12), %rbp
movq 0x58(%r12), %r13
movl (%r13,%r15,4), %ebx
cmpw $0x0, 0xa(%rbp,%rbx)
jne 0x3873c
movq %r8, 0x10(%rsp)
movq %r12, %rdi
movl %r15d, %esi
callq 0x3877f
testb %al, %al
je 0x386d9
movq 0x78(%r12), %rax
movq %r12, %rdi
movl (%rax,%r15,4), %r12d
testw $0xfff, %r12w           # imm = 0xFFF
jne 0x3876e
movq %rax, 0x20(%rsp)
movb %r14b, 0x7(%rsp)
testw $0x3000, %r12w          # imm = 0x3000
sete %r14b
testw $0xf000, %r12w          # imm = 0xF000
sete 0x6(%rsp)
movl %r15d, %esi
callq 0x37b6a
movzwl 0x1c(%rbp,%rbx), %ecx
movzwl 0x1e(%rbp,%rbx), %edx
leal (%rcx,%rdx), %esi
addl %eax, %esi
addl $0x1e, %esi
cmpl %r12d, %esi
jne 0x3876e
movb 0x7(%rsp), %sil
andb %r14b, %sil
movl %esi, %r14d
movb 0x6(%rsp), %sil
andb %sil, 0x4(%rsp)
testq %r15, %r15
je 0x386d4
movl -0x4(%r13,%r15,4), %esi
cmpw $0x0, 0xa(%rbp,%rsi)
movq 0x18(%rsp), %r12
movq 0x10(%rsp), %r8
je 0x386e5
movq 0x60(%r12), %rbp
addq %r8, %rbp
jmp 0x386ec
movq 0x18(%rsp), %r12
movq 0x8(%rsp), %rax
movq 0x10(%rsp), %r8
jmp 0x3873c
addq %rsi, %rbp
addq $0x18, %rbp
movq 0x20(%rsp), %rsi
movl -0x4(%rsi,%r15,4), %esi
addl (%rbp), %esi
cmpl %esi, %eax
jb 0x3876e
addl %edx, %ecx
addl $0x1e, %ecx
addl %esi, %ecx
negl %ecx
movl %ecx, %edx
movzwl %cx, %edi
andl $0xfff, %ecx            # imm = 0xFFF
addl %esi, %ecx
cmpl %eax, %ecx
sete %cl
andb %cl, 0x5(%rsp)
andl $0x3fff, %edx           # imm = 0x3FFF
addl %esi, %edx
cmpl %eax, %edx
sete %cl
andb %cl, %r14b
addl %esi, %edi
cmpl %eax, %edi
sete %al
andb %al, 0x4(%rsp)
movq 0x8(%rsp), %rax
incq %r15
addq $0x4, %r8
jmp 0x38603
movl $0x10000, %eax          # imm = 0x10000
testb $0x1, 0x4(%rsp)
jne 0x38770
movzbl 0x5(%rsp), %ecx
andl $0x1, %ecx
shll $0xc, %ecx
testb $0x1, %r14b
movl $0x4000, %eax           # imm = 0x4000
cmoveq %rcx, %rax
jmp 0x38770
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq