// File: /workspace/github_cpp_makefile_star2_O3/sisong[P]ApkDiffPatch/src/patch/Zipper.cpp
// Function: write_fileHeaderInfo(Zipper*, int, UnZipper*, int, bool)
static bool _write_fileHeaderInfo(Zipper* self,int fileIndex,UnZipper* srcZip,int srcFileIndex,bool isFullInfo){
    const TByte* const headBuf=fileHeaderBuf(srcZip,srcFileIndex);
    bool isCompressed=UnZipper_file_isCompressed(srcZip,srcFileIndex);
    ZipFilePos_t compressedSize=self->_fileCompressedSizes[fileIndex];
    if (self->_isUpdateIsCompress){
        self->_isUpdateIsCompress=false;
        if (isCompressed!=self->_newIsCompress){
            isCompressed=self->_newIsCompress;
            if (!self->_newIsCompress)
                compressedSize=UnZipper_file_uncompressedSize(srcZip,srcFileIndex);
        }
    }
    const uint16_t fileNameLen=UnZipper_file_nameLen(srcZip,srcFileIndex);
    const TByte* const fileNameBuf=headBuf+46;
    const TByte* extraFieldBuf=fileNameBuf+fileNameLen;
    const uint16_t extraFieldLen=_file_extraFieldLen(srcZip,srcFileIndex);
    uint16_t extraFieldBufLen=extraFieldLen;
    if (self->_pageAlignState==kPageAlign_inNormalize){
        extraFieldBufLen=_extraFieldNormalize(self->_normalizeExtraFieldBuf,extraFieldBuf,extraFieldLen);
        extraFieldBuf=self->_normalizeExtraFieldBuf;
    }
    uint16_t extraFieldLen_for_align=extraFieldBufLen;
    const bool isNeedAlign=(!isFullInfo)&&(!isCompressed); //dir or 0 size file need align too, same AndroidSDK#zipalign
    size_t curAlignSize=self->_ZipAlignSize;
    bool   curPageAlignCompatible=(self->_pageAlignCompatible)&&(self->_pageAlignState==kPageAlign_inNormalize);
    bool   isOldPatchSo=false;    
    if (isNeedAlign){
        const size_t headInfoLen=30+fileNameLen;
        const int skipLen_base=_getAlignSkipLen(self->_curFilePos+headInfoLen+extraFieldLen_for_align,curAlignSize);
        int skipLen=skipLen_base;
        if ((self->_pageAlignState==kPageAlign_inPatch)&& //only in patch compatible with old(<1.8.0) page-align
              ((self->_normalizeSoPageAlign!=curAlignSize)&&(self->_normalizeSoPageAlign==kSoSmallPageAlignSize)
              &&(self->_pageAlignCompatible)&&_file_getIsSoFileName(srcZip,srcFileIndex))){
            bool _isOldSmallPageAlign=_file_getIsPageAlignSoFile(srcZip,srcFileIndex);
            if (_isOldSmallPageAlign){// got patch for old page-align
                curAlignSize=kSoSmallPageAlignSize;
                isOldPatchSo=true;
            }
        }else if ((self->_normalizeSoPageAlign)&&
             (self->_normalizeSoPageAlign!=curAlignSize)&&_file_getIsSoFileName(srcZip,srcFileIndex)){
            if (0!=(self->_normalizeSoPageAlign%curAlignSize)){//error
                LOG_ERR("ERROR: Normalize unsupport this AlignSize %d\n",(int)curAlignSize);
                return false;
            }
            curAlignSize=self->_normalizeSoPageAlign;
        }
        if (curAlignSize!=self->_ZipAlignSize){//update skipLen
            int skipSoLen=_getAlignSkipLen(self->_curFilePos+headInfoLen+extraFieldLen_for_align,curAlignSize);
            if (skipSoLen!=skipLen){
                skipLen=skipSoLen;
                ++self->_normalizeSoPageAlignCount;
            }
        }
        
        if (skipLen!=0){
            if (fileNameLen+1>hpatch_kPathMaxSize) return false;
            // 第一个entry只能扩展其extraField来对齐;
            if ( (fileIndex==0) || ((!isOldPatchSo)&&curPageAlignCompatible&&(skipLen!=skipLen_base)) ){
                assert(0<=(int)extraFieldLen_for_align+skipLen);
                check(kMaxExtraFieldLen>=(int)extraFieldLen_for_align+skipLen);
                extraFieldLen_for_align+=skipLen;
                if ((extraFieldLen_for_align!=extraFieldLen)&&(self->_pageAlignState==kPageAlign_inNormalize)){// print WARNING 
                    const int changedLen=extraFieldLen_for_align-extraFieldLen;
                    char fileName[hpatch_kPathMaxSize];
                    if (fileNameLen+1>hpatch_kPathMaxSize) return false;
                    memcpy(fileName,UnZipper_file_nameBegin(srcZip,srcFileIndex),fileNameLen);
                    fileName[fileNameLen]='\0';
                    printf("WARNING: \""); hpatch_printPath_utf8(fileName);
                    if (changedLen>=0)
                        printf("\" file's extraField adding %d bytes 0 for align!\n",changedLen);
                    else
                        printf("\" file's extraField deleted %d bytes 0 for align!\n",-changedLen);
                }
            }else{
                check(_writeAlignSkip(self,skipLen));//利用entry之间的空间对齐;
            }
        }
    }
    if (!isFullInfo){
        self->_fileEntryOffsets[fileIndex]=self->_curFilePos;
        if (self->_normalizeExtraFieldLens)
            self->_normalizeExtraFieldLens[fileIndex]=self->_pageAlignCompatible?extraFieldLen_for_align:extraFieldBufLen;
    }else{
        if (self->_normalizeExtraFieldLens)
            extraFieldLen_for_align=self->_normalizeExtraFieldLens[fileIndex];
    }

    check(_writeUInt32(self,isFullInfo?kCENTRALHEADERMAGIC:kLOCALHEADERMAGIC));
    if (isFullInfo)
        check(_write(self,headBuf+4,2));//创建时版本;
    check(_write(self,headBuf+6,4));//解开时需要的版本+标志;//其中 标志 中已经去掉了data descriptor标识;
    check(_writeUInt16(self,isCompressed?Z_DEFLATED:0));//压缩方法;
    check(_write(self,headBuf+12,4));//文件的最后修改时间+文件最后修改日期;
    if (self->_isUpdateCrc32){
        self->_isUpdateCrc32=false;
        check(_writeUInt32(self,self->_newCrc32));//更新CRC-32校验;
    }else{
        check(_write(self,headBuf+16,4));//CRC-32校验;
    }
    check(_writeUInt32(self,compressedSize));//压缩后大小;
    check(_write(self,headBuf+24,30-24));//压缩前大小--文件名称长度;
    check(_writeUInt16(self,extraFieldLen_for_align));//扩展字段长度;
    
    uint16_t fileCommentLen=0;//文件注释长度;
    if (isFullInfo){
        fileCommentLen=readUInt16(headBuf+32);
        check(_writeUInt16(self,fileCommentLen));
        check(_write(self,headBuf+34,42-34));//文件开始的分卷号--文件外部属性;
        check(_writeUInt32(self,self->_fileEntryOffsets[fileIndex]));//对应文件在文件中的偏移;
    }
    check(_write(self,fileNameBuf,fileNameLen));//文件名称
    check(_write(self,extraFieldBuf,
                ((extraFieldBufLen<extraFieldLen_for_align)?extraFieldBufLen:extraFieldLen_for_align)));//扩展字段;
    if (extraFieldLen_for_align>extraFieldBufLen) //对齐;
        check(_writeAlignSkip(self,extraFieldLen_for_align-extraFieldBufLen));
    
    if (fileCommentLen>0)
        check(_write(self,fileNameBuf+fileNameLen+extraFieldLen,fileCommentLen));//[+文件注释];
    if (isNeedAlign)
        assert_align(self->_curFilePos,curAlignSize);//对齐检查;
    return  true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1068, %rsp           # imm = 0x1068
movl %r8d, 0x14(%rsp)
movq %rdi, %rbx
movq 0x50(%rdx), %rax
movq %rdx, 0x50(%rsp)
movq 0x58(%rdx), %rdx
movslq %ecx, %rcx
movq %rcx, 0x48(%rsp)
movl (%rdx,%rcx,4), %ecx
leaq (%rax,%rcx), %rdx
cmpw $0x0, 0xa(%rax,%rcx)
setne %al
movq 0xb0(%rdi), %rcx
movslq %esi, %r8
movl (%rcx,%r8,4), %ecx
cmpb $0x1, 0x150(%rdi)
movq %r8, 0x28(%rsp)
movl %esi, 0x18(%rsp)
jne 0x41b7f
movb $0x0, 0x150(%rbx)
movb 0x151(%rbx), %dil
cmpb %al, %dil
jne 0x41cbd
movl %ecx, 0xc(%rsp)
movb %al, 0xa(%rsp)
movzwl 0x1c(%rdx), %eax
movq %rax, 0x38(%rsp)
addq %rdx, %rax
addq $0x2e, %rax
movq %rdx, 0x20(%rsp)
movzwl 0x1e(%rdx), %ebp
cmpl $0x1, 0x90(%rbx)
movl %ebp, %edx
movq %rax, 0x58(%rsp)
movq %rax, 0x40(%rsp)
movl %ebp, 0x34(%rsp)
jne 0x41c29
movq 0x80(%rbx), %rax
movq %rax, 0x40(%rsp)
xorl %edx, %edx
cmpw $0x4, %bp
jb 0x41c29
xorl %edx, %edx
movq 0x58(%rsp), %r14
movzwl 0x2(%r14), %eax
leal 0x4(%rax), %r12d
subl %r12d, %ebp
jb 0x41c1d
movzwl (%r14), %ecx
movl %r12d, %r13d
cmpl $0xd935, %ecx           # imm = 0xD935
je 0x41c15
orl %eax, %ecx
testw %cx, %cx
je 0x41c15
movslq %edx, %r15
movq 0x40(%rsp), %rax
leaq (%rax,%r15), %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x4290
addl %r15d, %r12d
movl %r12d, %edx
addq %r13, %r14
cmpl $0x3, %ebp
jg 0x41bd4
movq 0x80(%rbx), %rax
movq %rax, 0x40(%rsp)
movl 0x14(%rsp), %eax
movl %eax, %r14d
orb 0xa(%rsp), %r14b
movb 0x88(%rbx), %bpl
movb $0x1, %dil
cmpb $0x1, %bpl
jne 0x41c50
cmpl $0x1, 0x90(%rbx)
setne %dil
movq 0x68(%rbx), %r12
testb $0x1, %r14b
movl %edx, 0x10(%rsp)
movb %r14b, 0xb(%rsp)
je 0x41c75
movl %edx, %r14d
movq 0x20(%rsp), %r15
movq 0x28(%rsp), %rbp
jmp 0x41f2f
movl 0x58(%rbx), %r10d
movzwl %dx, %r8d
movq 0x38(%rsp), %rax
leaq (%rax,%r8), %r11
leaq (%r11,%r10), %rax
addq %r12, %rax
addq $0x1d, %rax
xorl %edx, %edx
divq %r12
movq %rdx, %rcx
notl %ecx
addl %r12d, %ecx
movl 0x90(%rbx), %r9d
movq 0x70(%rbx), %rsi
testl %r9d, %r9d
je 0x41cd0
movq 0x20(%rsp), %r15
movq 0x28(%rsp), %rbp
jmp 0x41d4b
testb %dil, %dil
movb %dil, 0xa(%rsp)
je 0x41d1b
movl %ecx, 0xc(%rsp)
jmp 0x41b87
movl $0x1000, %eax           # imm = 0x1000
cmpq %rax, %rsi
sete %dl
cmpq %rax, %r12
setne %al
andb %dl, %al
andb %bpl, %al
cmpb $0x1, %al
movq 0x20(%rsp), %r15
movq 0x28(%rsp), %rbp
jne 0x41d4b
movq 0x50(%rsp), %rdx
movq 0x50(%rdx), %rax
movq 0x58(%rdx), %rdx
movq 0x48(%rsp), %rsi
movl (%rdx,%rsi,4), %esi
movzwl 0x1c(%rax,%rsi), %edx
cmpq $0x3, %rdx
jae 0x41d27
movl $0x1000, %esi           # imm = 0x1000
jmp 0x41d4b
movl 0x18(%rdx), %eax
movl %eax, 0xc(%rsp)
jmp 0x41b87
addq %rsi, %rax
movzwl 0x2b(%rax,%rdx), %esi
xorl $0x732e, %esi           # imm = 0x732E
movzbl 0x2d(%rax,%rdx), %edx
xorl $0x6f, %edx
orw %si, %dx
movl $0x1000, %esi           # imm = 0x1000
je 0x421a2
testq %rsi, %rsi
sete %al
cmpq %r12, %rsi
sete %dl
orb %al, %dl
jne 0x41d81
movq 0x50(%rsp), %rdx
movq 0x50(%rdx), %rax
movq 0x58(%rdx), %rdx
movq 0x48(%rsp), %r14
movl (%rdx,%r14,4), %r14d
movzwl 0x1c(%rax,%r14), %edx
cmpq $0x3, %rdx
jae 0x41e5d
xorl %r13d, %r13d
movl %ecx, %r14d
testl %r14d, %r14d
je 0x41d9d
cmpl $0xfff, 0x38(%rsp)      # imm = 0xFFF
jbe 0x41da9
xorl %ebp, %ebp
jmp 0x4218e
movl 0x10(%rsp), %eax
movl %eax, %r14d
jmp 0x41f2f
cmpl $0x0, 0x18(%rsp)
je 0x41dc6
orb %dil, %r13b
testb $0x1, %r13b
jne 0x41e8d
cmpl %ecx, %r14d
je 0x41e8d
addl %r8d, %r14d
js 0x4220e
cmpl $0x10000, %r14d         # imm = 0x10000
jae 0x4222d
cmpl $0x1, %r9d
jne 0x41f2f
movq %rbp, %r13
movl 0x34(%rsp), %ebp
cmpl %ebp, %r14d
je 0x41f08
movq %r12, 0x18(%rsp)
movq 0x50(%rsp), %rcx
movq 0x50(%rcx), %rax
movq 0x58(%rcx), %rcx
movq 0x48(%rsp), %rdx
movl (%rcx,%rdx,4), %ecx
leaq 0x2e(%rax,%rcx), %rsi
leaq 0x60(%rsp), %r12
movq %r12, %rdi
movq 0x38(%rsp), %r15
movq %r15, %rdx
callq 0x4290
movb $0x0, 0x60(%rsp,%r15)
leaq 0x1f394(%rip), %rdi     # 0x611cb
xorl %eax, %eax
callq 0x4060
movq %r12, %rdi
callq 0x47654
movl %r14d, %esi
subl %ebp, %esi
js 0x41f12
leaq 0x1f37e(%rip), %rdi     # 0x611d6
jmp 0x41f1b
addq %r14, %rax
movzwl 0x2b(%rax,%rdx), %ebp
xorl $0x732e, %ebp           # imm = 0x732E
movzbl 0x2d(%rax,%rdx), %eax
xorl $0x6f, %eax
xorl %r13d, %r13d
orw %bp, %ax
je 0x41ecb
movl %ecx, %r14d
movq 0x20(%rsp), %r15
movq 0x28(%rsp), %rbp
jmp 0x41d87
movq %r12, 0x18(%rsp)
movslq %r14d, %r13
xorps %xmm0, %xmm0
leaq 0x60(%rsp), %r14
movaps %xmm0, (%r14)
cmpq $0x10, %r13
movl $0x10, %r12d
cmovbq %r13, %r12
movq %rbx, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x416ab
subq %r12, %r13
jne 0x41ea1
movl 0x10(%rsp), %eax
movl %eax, %r14d
jmp 0x41f2a
movq %rsi, %rax
xorl %edx, %edx
divq %r12
testq %rdx, %rdx
movq 0x20(%rsp), %r15
movq 0x28(%rsp), %rbp
je 0x421b2
movq 0x3a0db(%rip), %rax     # 0x7bfc8
movq (%rax), %rdi
leaq 0x1f23d(%rip), %rsi     # 0x61134
xorl %ebp, %ebp
movl %r12d, %edx
xorl %eax, %eax
callq 0x4450
jmp 0x4218e
movq 0x20(%rsp), %r15
movq %r13, %rbp
jmp 0x41f2f
negl %esi
leaq 0x1f2ed(%rip), %rdi     # 0x61208
xorl %eax, %eax
callq 0x4060
movq 0x20(%rsp), %r15
movq %r13, %rbp
movq 0x18(%rsp), %r12
cmpb $0x0, 0x14(%rsp)
je 0x41f4b
movq 0x78(%rbx), %rcx
movl $0x2014b50, %eax        # imm = 0x2014B50
testq %rcx, %rcx
je 0x41f79
movzwl (%rcx,%rbp,2), %r14d
jmp 0x41f79
movl 0x58(%rbx), %eax
movq 0xa8(%rbx), %rcx
movl %eax, (%rcx,%rbp,4)
movq 0x78(%rbx), %rcx
movl $0x4034b50, %eax        # imm = 0x4034B50
testq %rcx, %rcx
je 0x41f79
cmpb $0x0, 0x88(%rbx)
movl 0x10(%rsp), %edx
cmovnel %r14d, %edx
movw %dx, (%rcx,%rbp,2)
leaq 0x60(%rsp), %rsi
movw $0x4b50, (%rsi)         # imm = 0x4B50
movl %eax, %ecx
shrl $0x10, %ecx
movb %cl, 0x2(%rsi)
shrl $0x18, %eax
movb %al, 0x3(%rsi)
movl $0x4, %edx
movq %rbx, %rdi
callq 0x416ab
cmpb $0x0, 0x14(%rsp)
je 0x41fb6
leaq 0x4(%r15), %rsi
movl $0x2, %edx
movq %rbx, %rdi
callq 0x416ab
leaq 0x6(%r15), %rsi
movl $0x4, %edx
movq %rbx, %rdi
callq 0x416ab
movb 0xa(%rsp), %al
shlb $0x3, %al
leaq 0x60(%rsp), %rsi
movb %al, (%rsi)
movb $0x0, 0x1(%rsi)
movl $0x2, %edx
movq %rbx, %rdi
callq 0x416ab
leaq 0xc(%r15), %rsi
movl $0x4, %edx
movq %rbx, %rdi
callq 0x416ab
cmpb $0x1, 0x148(%rbx)
movq %r12, 0x18(%rsp)
jne 0x4201b
movb $0x0, 0x148(%rbx)
movl 0x14c(%rbx), %eax
leaq 0x60(%rsp), %rsi
movl %eax, (%rsi)
jmp 0x4201f
leaq 0x10(%r15), %rsi
movl $0x4, %edx
movq %rbx, %rdi
callq 0x416ab
leaq 0x2e(%r15), %r12
leaq 0x60(%rsp), %r13
movl 0xc(%rsp), %eax
movl %eax, (%r13)
movl $0x4, %edx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x416ab
leaq 0x18(%r15), %rsi
movl $0x6, %edx
movq %rbx, %rdi
callq 0x416ab
movw %r14w, (%r13)
leaq 0x60(%rsp), %rsi
movl $0x2, %edx
movq %rbx, %rdi
callq 0x416ab
cmpb $0x0, 0x14(%rsp)
je 0x420e3
movzbl 0x20(%r15), %eax
movzbl 0x21(%r15), %ebp
leaq 0x60(%rsp), %r13
movb %al, (%r13)
movb %bpl, 0x1(%r13)
shll $0x8, %ebp
orl %eax, %ebp
movl $0x2, %edx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x416ab
addq $0x22, %r15
movl $0x8, %edx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x416ab
movq 0xa8(%rbx), %rax
movq 0x28(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, (%r13)
leaq 0x60(%rsp), %rsi
movl $0x4, %edx
movq %rbx, %rdi
callq 0x416ab
jmp 0x420e5
xorl %ebp, %ebp
movq %rbx, %rdi
movq %r12, %rsi
movq 0x38(%rsp), %rdx
callq 0x416ab
movl 0x10(%rsp), %r15d
cmpw %r14w, %r15w
movl %r14d, %eax
cmovbl %r15d, %eax
movzwl %ax, %edx
movq %rbx, %rdi
movq 0x40(%rsp), %rsi
callq 0x416ab
cmpw %r15w, %r14w
jbe 0x42156
movzwl %r14w, %r12d
movzwl %r15w, %eax
xorps %xmm0, %xmm0
movaps %xmm0, 0x60(%rsp)
subq %rax, %r12
je 0x42156
leaq 0x60(%rsp), %r14
cmpq $0x10, %r12
movl $0x10, %r15d
cmovbq %r12, %r15
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x416ab
subq %r15, %r12
jne 0x42135
testw %bp, %bp
je 0x42172
movl 0x34(%rsp), %eax
movq 0x58(%rsp), %rsi
addq %rax, %rsi
movzwl %bp, %edx
movq %rbx, %rdi
callq 0x416ab
movb $0x1, %bpl
testb $0x1, 0xb(%rsp)
movq 0x18(%rsp), %rcx
jne 0x4218e
movl 0x58(%rbx), %eax
xorl %edx, %edx
divq %rcx
testq %rdx, %rdx
jne 0x421ef
movl %ebp, %eax
addq $0x1068, %rsp           # imm = 0x1068
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb 0x8(%rax), %al
movl %eax, %r13d
shrb $0x7, %r13b
testb %al, %al
cmovnsq %r12, %rsi
cmpq %r12, %rsi
je 0x41d84
leaq (%r10,%r11), %rax
addq $0x1d, %rax
addq %rsi, %rax
xorl %edx, %edx
divq %rsi
movq %rdx, %r14
notl %r14d
addl %esi, %r14d
cmpl %ecx, %r14d
jne 0x421e1
movq %rsi, %r12
jmp 0x41d84
incl 0x8c(%rbx)
movq %rsi, %r12
jmp 0x41d87
leaq 0x1f045(%rip), %rdi     # 0x6123b
leaq 0x1e0e4(%rip), %rsi     # 0x602e1
leaq 0x1ef86(%rip), %rcx     # 0x6118a
movl $0x4bb, %edx            # imm = 0x4BB
callq 0x4200
leaq 0x1ef4d(%rip), %rdi     # 0x61162
leaq 0x1e0c5(%rip), %rsi     # 0x602e1
leaq 0x1ef67(%rip), %rcx     # 0x6118a
movl $0x47e, %edx            # imm = 0x47E
callq 0x4200
leaq 0x17e1c(%rip), %rdi     # 0x5a050
leaq 0x1e0a6(%rip), %rsi     # 0x602e1
leaq 0x1ef48(%rip), %rcx     # 0x6118a
movl $0x47f, %edx            # imm = 0x47F
callq 0x4200