// File: sisong[P]ApkDiffPatch/src/patch/Zipper.cpp
// Function: UnZipper_vce_normalized(UnZipper*, bool, unsigned int*)
static bool _UnZipper_vce_normalized(UnZipper* self,bool isFileDataOffsetMatch,ZipFilePos_t* out_fileDataEndPos){
    assert(self->_endCentralDirectory!=0);
    writeUInt32_to(self->_endCentralDirectory+16,0);//normalized CentralDirectory的开始位置偏移;
    self->_isFileDataOffsetMatch=isFileDataOffsetMatch;
    bool test_isFileDataOffsetMatch=true;
    
    assert(self->_centralDirectory!=0);
    TByte* buf=self->_centralDirectory;
    const int fileCount=UnZipper_fileCount(self);
    size_t centralDirectory_size=_centralDirectory_size(self);
    ZipFilePos_t curOffset=0;
    memset(self->_dataDescriptors,kDataDescriptor_NO,fileCount);
    self->_dataDescriptorCount=0;
    *out_fileDataEndPos=0;
    for (int i=0; i<fileCount; ++i) {
        TByte* headBuf=buf+curOffset;
        check(kCENTRALHEADERMAGIC==readUInt32(headBuf));
        self->_fileHeaderOffsets[i]=curOffset;
        
        self->_fileCompressedSizes[i]=readUInt32(headBuf+20);
        writeUInt32_to(headBuf+20,0);//normalized 压缩大小占位;
        
        ZipFilePos_t fileEntryOffset=readUInt32(headBuf+42);
        if (self->_fileEntryOffsets)
            self->_fileEntryOffsets[i]=fileEntryOffset;
        writeUInt32_to(headBuf+42,0);//normalized 文件Entry开始位置偏移;
        ZipFilePos_t fastFileDataOffset=(fileEntryOffset+30+readUInt16(headBuf+28)+readUInt16(headBuf+30)); //fast
        if (isFileDataOffsetMatch){
            self->_fileDataOffsets[i]=fastFileDataOffset;
        }else{
            ZipFilePos_t fileDataOffset=_fileData_offset_read(self,fileEntryOffset);//seek&read;
            self->_fileDataOffsets[i]=fileDataOffset;
            test_isFileDataOffsetMatch&=(fileDataOffset==fastFileDataOffset);
        }
        ZipFilePos_t curFileDataEndPos=self->_fileDataOffsets[i]+self->_fileCompressedSizes[i];
        if (curFileDataEndPos>*out_fileDataEndPos)
            *out_fileDataEndPos=curFileDataEndPos;
        
        uint16_t fileTag=readUInt16(headBuf+8);//标志;
        if ((fileTag&(1<<3))!=0){//have descriptor?
            writeUInt16_to(headBuf+8,fileTag&(~(1<<3)));//normalized 标志中去掉data descriptor标识;
            const uint32_t crc=UnZipper_file_crc32(self,i);
            const ZipFilePos_t uncompressedSize=UnZipper_file_uncompressedSize(self,i);
            TByte buf[16];
            check(UnZipper_fileData_read(self,self->_fileDataOffsets[i]+self->_fileCompressedSizes[i],buf,buf+16));
            if ((readUInt32(buf)==crc)&&(readUInt32(buf+8)==uncompressedSize))
                self->_dataDescriptors[i]=kDataDescriptor_12;
            else if ((readUInt32(buf+4)==crc)&&(readUInt32(buf+12)==uncompressedSize))
                self->_dataDescriptors[i]=kDataDescriptor_16;
            else {
                //check(false);
                printf("WARNING: zip format error, unknow data descriptor!\n");
                self->_dataDescriptors[i]=kDataDescriptor_12;
            }
            ++self->_dataDescriptorCount;
        }
        
        int fileNameLen=UnZipper_file_nameLen(self,i);
        int extraFieldLen=readUInt16(headBuf+30);
        int fileCommentLen=readUInt16(headBuf+32);
        curOffset+= kMinFileHeaderSize + fileNameLen+extraFieldLen+fileCommentLen;
        check((size_t)curOffset <= centralDirectory_size);
    }
    
    //update
    self->_isFileDataOffsetMatch=test_isFileDataOffsetMatch;
    
    return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movb %sil, %al
movq %rdi, -0x8(%rbp)
andb $0x1, %al
movb %al, -0x9(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
cmpq $0x0, 0x48(%rax)
je 0x7fd28
jmp 0x7fd47
leaq 0x34866(%rip), %rdi     # 0xb4595
leaq 0x33c54(%rip), %rsi     # 0xb398a
movl $0x170, %edx            # imm = 0x170
leaq 0x34871(%rip), %rcx     # 0xb45b3
callq 0x4270
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rdi
addq $0x10, %rdi
xorl %esi, %esi
callq 0x84130
movb -0x9(%rbp), %cl
movq -0x8(%rbp), %rax
andb $0x1, %cl
movb %cl, 0x8a(%rax)
movb $0x1, -0x19(%rbp)
movq -0x8(%rbp), %rax
cmpq $0x0, 0x50(%rax)
je 0x7fd7b
jmp 0x7fd9a
leaq 0x34871(%rip), %rdi     # 0xb45f3
leaq 0x33c01(%rip), %rsi     # 0xb398a
movl $0x175, %edx            # imm = 0x175
leaq 0x3481e(%rip), %rcx     # 0xb45b3
callq 0x4270
movq -0x8(%rbp), %rax
movq 0x50(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
callq 0x7ea90
movl %eax, -0x2c(%rbp)
movq -0x8(%rbp), %rdi
callq 0x84180
cltq
movq %rax, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movq -0x8(%rbp), %rax
movq 0x68(%rax), %rdi
movslq -0x2c(%rbp), %rdx
xorl %esi, %esi
callq 0x4210
movq -0x8(%rbp), %rax
movl $0x0, 0x70(%rax)
movq -0x18(%rbp), %rax
movl $0x0, (%rax)
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0x80172
movq -0x28(%rbp), %rax
movl -0x3c(%rbp), %ecx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rdi
callq 0x804b0
movl %eax, %ecx
movl $0x2014b50, %eax        # imm = 0x2014B50
cmpl %ecx, %eax
je 0x7fe44
leaq 0x2d444(%rip), %rdi     # 0xad270
leaq 0x33b57(%rip), %rsi     # 0xb398a
movl $0x17f, %edx            # imm = 0x17F
leaq 0x34774(%rip), %rcx     # 0xb45b3
callq 0x4270
movl -0x3c(%rbp), %edx
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movslq -0x40(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x48(%rbp), %rdi
addq $0x14, %rdi
callq 0x804b0
movl %eax, %edx
movq -0x8(%rbp), %rax
movq 0x60(%rax), %rax
movslq -0x40(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x48(%rbp), %rdi
addq $0x14, %rdi
xorl %esi, %esi
callq 0x84130
movq -0x48(%rbp), %rdi
addq $0x2a, %rdi
callq 0x804b0
movl %eax, -0x4c(%rbp)
movq -0x8(%rbp), %rax
cmpq $0x0, 0x80(%rax)
je 0x7feb6
movl -0x4c(%rbp), %edx
movq -0x8(%rbp), %rax
movq 0x80(%rax), %rax
movslq -0x40(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x48(%rbp), %rdi
addq $0x2a, %rdi
xorl %esi, %esi
callq 0x84130
movl -0x4c(%rbp), %eax
addl $0x1e, %eax
movl %eax, -0x94(%rbp)
movq -0x48(%rbp), %rdi
addq $0x1c, %rdi
callq 0x7eac0
movw %ax, %cx
movl -0x94(%rbp), %eax
movzwl %cx, %ecx
addl %ecx, %eax
movl %eax, -0x90(%rbp)
movq -0x48(%rbp), %rdi
addq $0x1e, %rdi
callq 0x7eac0
movw %ax, %cx
movl -0x90(%rbp), %eax
movzwl %cx, %ecx
addl %ecx, %eax
movl %eax, -0x50(%rbp)
testb $0x1, -0x9(%rbp)
je 0x7ff2a
movl -0x50(%rbp), %edx
movq -0x8(%rbp), %rax
movq 0x78(%rax), %rax
movslq -0x40(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x7ff6e
movq -0x8(%rbp), %rdi
movl -0x4c(%rbp), %esi
callq 0x841b0
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %edx
movq -0x8(%rbp), %rax
movq 0x78(%rax), %rax
movslq -0x40(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x54(%rbp), %eax
cmpl -0x50(%rbp), %eax
sete %al
andb $0x1, %al
movzbl %al, %ecx
movb -0x19(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
andl %ecx, %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movb %al, -0x19(%rbp)
movq -0x8(%rbp), %rax
movq 0x78(%rax), %rax
movslq -0x40(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movq -0x8(%rbp), %rcx
movq 0x60(%rcx), %rcx
movslq -0x40(%rbp), %rdx
addl (%rcx,%rdx,4), %eax
movl %eax, -0x58(%rbp)
movl -0x58(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl (%rcx), %eax
jbe 0x7ffa3
movl -0x58(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movq -0x48(%rbp), %rdi
addq $0x8, %rdi
callq 0x7eac0
movw %ax, -0x5a(%rbp)
movzwl -0x5a(%rbp), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x800e1
movq -0x48(%rbp), %rdi
addq $0x8, %rdi
movzwl -0x5a(%rbp), %esi
andl $-0x9, %esi
callq 0x84240
movq -0x8(%rbp), %rdi
movl -0x40(%rbp), %esi
callq 0x80540
movl %eax, -0x60(%rbp)
movq -0x8(%rbp), %rdi
movl -0x40(%rbp), %esi
callq 0x80480
movl %eax, -0x64(%rbp)
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x78(%rax), %rax
movslq -0x40(%rbp), %rcx
movl (%rax,%rcx,4), %esi
movq -0x8(%rbp), %rax
movq 0x60(%rax), %rax
movslq -0x40(%rbp), %rcx
addl (%rax,%rcx,4), %esi
leaq -0x80(%rbp), %rdx
leaq -0x80(%rbp), %rcx
addq $0x10, %rcx
callq 0x7fcb0
testb $0x1, %al
jne 0x8004c
leaq 0x2d23c(%rip), %rdi     # 0xad270
leaq 0x3394f(%rip), %rsi     # 0xb398a
movl $0x19b, %edx            # imm = 0x19B
leaq 0x3456c(%rip), %rcx     # 0xb45b3
callq 0x4270
leaq -0x80(%rbp), %rdi
callq 0x804b0
cmpl -0x60(%rbp), %eax
jne 0x8007e
leaq -0x80(%rbp), %rdi
addq $0x8, %rdi
callq 0x804b0
cmpl -0x64(%rbp), %eax
jne 0x8007e
movq -0x8(%rbp), %rax
movq 0x68(%rax), %rax
movslq -0x40(%rbp), %rcx
movb $0x1, (%rax,%rcx)
jmp 0x800d4
leaq -0x80(%rbp), %rdi
addq $0x4, %rdi
callq 0x804b0
cmpl -0x60(%rbp), %eax
jne 0x800b4
leaq -0x80(%rbp), %rdi
addq $0xc, %rdi
callq 0x804b0
cmpl -0x64(%rbp), %eax
jne 0x800b4
movq -0x8(%rbp), %rax
movq 0x68(%rax), %rax
movslq -0x40(%rbp), %rcx
movb $0x2, (%rax,%rcx)
jmp 0x800d2
leaq 0x34553(%rip), %rdi     # 0xb460e
movb $0x0, %al
callq 0x4060
movq -0x8(%rbp), %rax
movq 0x68(%rax), %rax
movslq -0x40(%rbp), %rcx
movb $0x1, (%rax,%rcx)
jmp 0x800d4
movq -0x8(%rbp), %rax
movl 0x70(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x70(%rax)
movq -0x8(%rbp), %rdi
movl -0x40(%rbp), %esi
callq 0x7eae0
movl %eax, -0x84(%rbp)
movq -0x48(%rbp), %rdi
addq $0x1e, %rdi
callq 0x7eac0
movzwl %ax, %eax
movl %eax, -0x88(%rbp)
movq -0x48(%rbp), %rdi
addq $0x20, %rdi
callq 0x7eac0
movzwl %ax, %eax
movl %eax, -0x8c(%rbp)
movl -0x84(%rbp), %eax
addl $0x2e, %eax
addl -0x88(%rbp), %eax
addl -0x8c(%rbp), %eax
addl -0x3c(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpq -0x38(%rbp), %rax
jbe 0x80162
leaq 0x2d126(%rip), %rdi     # 0xad270
leaq 0x33839(%rip), %rsi     # 0xb398a
movl $0x1ac, %edx            # imm = 0x1AC
leaq 0x34456(%rip), %rcx     # 0xb45b3
callq 0x4270
jmp 0x80164
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x7fdf7
movb -0x19(%rbp), %cl
movq -0x8(%rbp), %rax
andb $0x1, %cl
movb %cl, 0x8a(%rax)
movb $0x1, %al
andb $0x1, %al
addq $0xa0, %rsp
popq %rbp
retq
nop