// File: /workspace/github_cpp_makefile_star2_O2/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 $0x1088, %rsp           # imm = 0x1088
movl %r8d, 0x8(%rsp)
movq %rdi, %rbx
movq 0x50(%rdx), %rax
movq %rdx, 0x10(%rsp)
movq 0x58(%rdx), %rdi
movl %ecx, 0x20(%rsp)
movslq %ecx, %rdx
movq %rdx, 0x58(%rsp)
movl (%rdi,%rdx,4), %ecx
leaq (%rax,%rcx), %rbp
cmpw $0x0, 0xa(%rax,%rcx)
setne %al
movq 0xb0(%rbx), %rcx
movl %esi, 0x54(%rsp)
movslq %esi, %r12
movl (%rcx,%r12,4), %ecx
cmpb $0x1, 0x150(%rbx)
jne 0x39052
movb $0x0, 0x150(%rbx)
movb 0x151(%rbx), %r13b
cmpb %al, %r13b
jne 0x39207
movl %ecx, 0x1c(%rsp)
movl %eax, %r13d
movzwl 0x1c(%rbp), %eax
movq %rax, 0x48(%rsp)
addq %rbp, %rax
addq $0x2e, %rax
movzwl 0x1e(%rbp), %r15d
cmpl $0x1, 0x90(%rbx)
movl %r15d, %r14d
movq %rax, 0x60(%rsp)
movl %r15d, 0x3c(%rsp)
movq %rbx, 0x28(%rsp)
movq %r12, 0x40(%rsp)
movq %rbp, 0x30(%rsp)
movb %r13b, 0x7(%rsp)
jne 0x3910c
movq 0x80(%rbx), %r12
xorl %r14d, %r14d
movq 0x60(%rsp), %r13
cmpl $0x4, %r15d
jl 0x390f1
movzwl 0x2(%r13), %eax
leaq 0x4(%rax), %rbp
subl %ebp, %r15d
jb 0x390f1
movzwl (%r13), %ecx
orw %cx, %ax
setne %al
cmpw $0xd935, %cx            # imm = 0xD935
setne %cl
testb %al, %cl
je 0x390ec
movslq %r14d, %r14
leaq (%r12,%r14), %rdi
movl %ebp, %ebx
movq %r13, %rsi
movq %rbx, %rdx
callq 0x42c0
addl %ebp, %r14d
movq %rbx, %rbp
addq %rbp, %r13
jmp 0x390a7
movq 0x28(%rsp), %rbx
movq 0x80(%rbx), %rax
movq 0x40(%rsp), %r12
movq 0x30(%rsp), %rbp
movb 0x7(%rsp), %r13b
movq %rax, 0x78(%rsp)
movl 0x8(%rsp), %r15d
movl %r15d, %eax
orb %r13b, %al
movb 0x88(%rbx), %cl
movb $0x1, %dl
cmpb $0x1, %cl
jne 0x39133
cmpl $0x1, 0x90(%rbx)
setne %dl
movq 0x68(%rbx), %r8
testb $0x1, %al
movb %al, 0xf(%rsp)
je 0x39147
movl %r14d, %edx
jmp 0x393aa
movb %dl, 0xe(%rsp)
movl 0x58(%rbx), %esi
movzwl %r14w, %edx
movq 0x48(%rsp), %rax
movq %rdx, 0x70(%rsp)
leaq (%rax,%rdx), %rdi
leaq (%rdi,%rsi), %rax
addq %r8, %rax
addq $0x1d, %rax
xorl %edx, %edx
divq %r8
movq %rdx, %r13
notl %r13d
addl %r8d, %r13d
movl 0x90(%rbx), %edx
movq 0x70(%rbx), %rbp
movl %edx, 0x50(%rsp)
testl %edx, %edx
jne 0x391f3
movl $0x1000, %eax           # imm = 0x1000
cmpq %rax, %rbp
sete %dl
cmpq %rax, %r8
setne %al
andb %dl, %al
andb %cl, %al
cmpb $0x1, %al
jne 0x391f3
movq %rdi, %rbp
movq 0x10(%rsp), %rdi
movq %rsi, %rbx
movl 0x20(%rsp), %esi
movq %r8, %r15
callq 0x3877f
movq %rbp, %rdi
movq %rbx, %rsi
movq %r15, %r8
movl $0x1000, %ebp           # imm = 0x1000
testb %al, %al
je 0x391f3
movq 0x10(%rsp), %rcx
movq 0x50(%rcx), %rax
movq 0x58(%rcx), %rcx
movq 0x58(%rsp), %rdx
movl (%rcx,%rdx,4), %ecx
movb 0x8(%rax,%rcx), %al
movl %eax, %ecx
shrb $0x7, %cl
testb %al, %al
cmovnsq %r8, %rbp
jmp 0x39250
testq %rbp, %rbp
sete %al
cmpq %r8, %rbp
sete %cl
orb %al, %cl
je 0x39215
xorl %ecx, %ecx
jmp 0x39271
testb %r13b, %r13b
je 0x39276
movl %ecx, 0x1c(%rsp)
jmp 0x39059
movq %rdi, 0x68(%rsp)
movq %rsi, %rbx
movq %r8, %r15
movq 0x10(%rsp), %rdi
movl 0x20(%rsp), %esi
callq 0x3877f
xorl %ecx, %ecx
testb %al, %al
je 0x39282
movq %rbp, %rax
xorl %edx, %edx
movq %r15, %r8
divq %r15
testq %rdx, %rdx
movq %rbx, %rsi
movq 0x68(%rsp), %rdi
jne 0x395cd
cmpq %r8, %rbp
je 0x39271
leaq (%rsi,%rdi), %rax
addq $0x1d, %rax
addq %rbp, %rax
xorl %edx, %edx
divq %rbp
notl %edx
addl %ebp, %edx
cmpl %r13d, %edx
jne 0x3928a
movq %rbp, %r8
movl %r13d, %edx
jmp 0x39298
movl 0x18(%rbp), %eax
movl %eax, 0x1c(%rsp)
jmp 0x39059
movl %r13d, %edx
movq %r15, %r8
jmp 0x39298
movq 0x28(%rsp), %rax
incl 0x8c(%rax)
movq %rbp, %r8
testl %edx, %edx
movq 0x30(%rsp), %rbp
je 0x392b1
cmpw $0xfff, 0x48(%rsp)      # imm = 0xFFF
jbe 0x392be
xorl %ebp, %ebp
jmp 0x39577
movl %r14d, %edx
movq 0x28(%rsp), %rbx
jmp 0x393a0
cmpl $0x0, 0x54(%rsp)
je 0x392db
orb 0xe(%rsp), %cl
testb $0x1, %cl
jne 0x39387
cmpl %r13d, %edx
je 0x39387
addl 0x70(%rsp), %edx
js 0x3960b
cmpl $0x10000, %edx          # imm = 0x10000
jae 0x3962a
cmpl $0x1, 0x50(%rsp)
movq 0x28(%rsp), %rbx
movb 0x7(%rsp), %r13b
jne 0x39590
movl 0x3c(%rsp), %ebp
cmpl %ebp, %edx
je 0x3958b
movq %r8, 0x20(%rsp)
movq 0x10(%rsp), %rcx
movq 0x50(%rcx), %rax
movq 0x58(%rcx), %rcx
movq %rdx, %r15
movq 0x58(%rsp), %rdx
movl (%rcx,%rdx,4), %ecx
leaq 0x2e(%rax,%rcx), %rsi
leaq 0x80(%rsp), %r12
movq %r12, %rdi
movq 0x48(%rsp), %r13
movq %r13, %rdx
callq 0x42c0
movb $0x0, 0x80(%rsp,%r13)
leaq 0x1cf0f(%rip), %rdi     # 0x5626b
xorl %eax, %eax
callq 0x4060
movq %r12, %rdi
callq 0x3e2f4
movq %r15, 0x10(%rsp)
movl %r15d, %esi
subl %ebp, %esi
js 0x3959a
leaq 0x1cef4(%rip), %rdi     # 0x56276
jmp 0x395a3
movslq %edx, %rsi
movq 0x28(%rsp), %rbx
movq %rbx, %rdi
movq %r8, %r15
callq 0x3a2d5
movq %r15, %r8
movl %r14d, %edx
movl 0x8(%rsp), %r15d
movb 0x7(%rsp), %r13b
testb %r15b, %r15b
movq %r8, 0x20(%rsp)
je 0x393ce
movq 0x78(%rbx), %rax
movl $0x2014b50, %esi        # imm = 0x2014B50
testq %rax, %rax
je 0x39403
movzwl (%rax,%r12,2), %eax
movq %rax, 0x10(%rsp)
jmp 0x39408
movl 0x58(%rbx), %eax
movq 0xa8(%rbx), %rcx
movl %eax, (%rcx,%r12,4)
movq 0x78(%rbx), %rax
movl $0x4034b50, %esi        # imm = 0x4034B50
testq %rax, %rax
movq %rdx, 0x10(%rsp)
je 0x39408
cmpb $0x0, 0x88(%rbx)
movl %r14d, %ecx
cmovnel %edx, %ecx
movw %cx, (%rax,%r12,2)
jmp 0x39408
movq %rdx, 0x10(%rsp)
movq %rbx, %rdi
callq 0x39c1b
testb %r15b, %r15b
je 0x39424
leaq 0x4(%rbp), %rsi
pushq $0x2
popq %rdx
movq %rbx, %rdi
callq 0x38bc7
leaq 0x6(%rbp), %rsi
pushq $0x4
popq %r12
movq %rbx, %rdi
movq %r12, %rdx
callq 0x38bc7
movzbl %r13b, %esi
shll $0x3, %esi
movq %rbx, %rdi
callq 0x39c05
leaq 0xc(%rbp), %rsi
movq %rbx, %rdi
movq %r12, %rdx
callq 0x38bc7
cmpb $0x1, 0x148(%rbx)
jne 0x39475
movb $0x0, 0x148(%rbx)
movl 0x14c(%rbx), %esi
movq %rbx, %rdi
callq 0x39c1b
jmp 0x39484
leaq 0x10(%rbp), %rsi
pushq $0x4
popq %rdx
movq %rbx, %rdi
callq 0x38bc7
leaq 0x2e(%rbp), %r13
movq %rbx, %rdi
movl 0x1c(%rsp), %esi
callq 0x39c1b
leaq 0x18(%rbp), %rsi
pushq $0x6
popq %rdx
movq %rbx, %rdi
callq 0x38bc7
movzwl 0x10(%rsp), %r12d
movq %rbx, %rdi
movl %r12d, %esi
callq 0x39c05
testb %r15b, %r15b
je 0x394f6
movq %rbp, %r15
movzwl 0x20(%rbp), %ebp
movzwl %bp, %esi
movq %rbx, %rdi
callq 0x39c05
addq $0x22, %r15
pushq $0x8
popq %rdx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x38bc7
movq 0xa8(%rbx), %rax
movq 0x40(%rsp), %rcx
movl (%rax,%rcx,4), %esi
movq %rbx, %rdi
callq 0x39c1b
jmp 0x394f8
xorl %ebp, %ebp
movq %rbx, %rdi
movq %r13, %rsi
movq 0x48(%rsp), %rdx
callq 0x38bc7
movq 0x10(%rsp), %r15
cmpw %r15w, %r14w
movl %r15d, %eax
cmovbl %r14d, %eax
movzwl %ax, %edx
movq %rbx, %rdi
movq 0x78(%rsp), %rsi
callq 0x38bc7
cmpw %r14w, %r15w
jbe 0x39540
movzwl %r14w, %eax
subq %rax, %r12
movq %rbx, %rdi
movq %r12, %rsi
callq 0x3a2d5
testw %bp, %bp
movl 0x3c(%rsp), %eax
je 0x3955e
movl %eax, %eax
movq 0x60(%rsp), %rsi
addq %rax, %rsi
movzwl %bp, %edx
movq %rbx, %rdi
callq 0x38bc7
movb $0x1, %bpl
testb $0x1, 0xf(%rsp)
jne 0x39577
movl 0x58(%rbx), %eax
xorl %edx, %edx
divq 0x20(%rsp)
testq %rdx, %rdx
jne 0x395ec
movl %ebp, %eax
addq $0x1088, %rsp           # imm = 0x1088
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x30(%rsp), %rbp
movl 0x8(%rsp), %r15d
jmp 0x393aa
negl %esi
leaq 0x1cd05(%rip), %rdi     # 0x562a8
xorl %eax, %eax
callq 0x4060
movq 0x40(%rsp), %r12
movq 0x30(%rsp), %rbp
movl 0x8(%rsp), %r15d
movq 0x20(%rsp), %r8
movb 0x7(%rsp), %r13b
movq 0x10(%rsp), %rdx
jmp 0x393aa
movq 0x3b9f4(%rip), %rax     # 0x74fc8
movq (%rax), %rdi
leaq 0x1cbf6(%rip), %rsi     # 0x561d4
xorl %ebp, %ebp
movl %r8d, %edx
xorl %eax, %eax
callq 0x4480
jmp 0x39577
leaq 0x1cce8(%rip), %rdi     # 0x562db
leaq 0x1bd87(%rip), %rsi     # 0x55381
leaq 0x1cc29(%rip), %rcx     # 0x5622a
movl $0x4bb, %edx            # imm = 0x4BB
callq 0x4230
leaq 0x1cbf0(%rip), %rdi     # 0x56202
leaq 0x1bd68(%rip), %rsi     # 0x55381
leaq 0x1cc0a(%rip), %rcx     # 0x5622a
movl $0x47e, %edx            # imm = 0x47E
callq 0x4230
leaq 0x15a1f(%rip), %rdi     # 0x4f050
leaq 0x1bd49(%rip), %rsi     # 0x55381
leaq 0x1cbeb(%rip), %rcx     # 0x5622a
movl $0x47f, %edx            # imm = 0x47F
callq 0x4230