// File: /workspace/github_cpp_makefile_star2_O1/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 $0x1098, %rsp           # imm = 0x1098
movl %r8d, 0x1c(%rsp)
movq %rdi, %rbx
movq 0x50(%rdx), %rax
movq %rdx, 0x28(%rsp)
movq 0x58(%rdx), %rdi
movl %ecx, 0x30(%rsp)
movslq %ecx, %rdx
movq %rdx, 0x70(%rsp)
movl (%rdi,%rdx,4), %ecx
leaq (%rax,%rcx), %r14
movb 0xa(%rax,%rcx), %dl
orb 0xb(%rax,%rcx), %dl
setne %al
movq 0xb0(%rbx), %rcx
movl %esi, 0x60(%rsp)
movslq %esi, %rdx
movq %rdx, 0x40(%rsp)
movl (%rcx,%rdx,4), %ecx
cmpb $0x1, 0x150(%rbx)
jne 0x4201a
movb $0x0, 0x150(%rbx)
movb 0x151(%rbx), %dl
cmpb %al, %dl
jne 0x42211
movl %ecx, 0x18(%rsp)
movb %al, 0xe(%rsp)
movzbl 0x1c(%r14), %eax
movzbl 0x1d(%r14), %ecx
movl %ecx, 0x64(%rsp)
shll $0x8, %ecx
orq %rax, %rcx
movq %rcx, 0x48(%rsp)
leaq (%r14,%rcx), %rax
addq $0x2e, %rax
movzwl 0x1e(%r14), %ebp
cmpl $0x1, 0x90(%rbx)
movl %ebp, %esi
movq %rax, 0x78(%rsp)
movq %rbx, 0x50(%rsp)
movl %ebp, 0x34(%rsp)
movq %r14, 0x20(%rsp)
jne 0x420ee
movq 0x80(%rbx), %rax
movq %rax, 0x10(%rsp)
xorl %esi, %esi
movq 0x78(%rsp), %r14
cmpl $0x4, %ebp
jl 0x420de
movzwl 0x2(%r14), %eax
leal 0x4(%rax), %r12d
movl %ebp, %r15d
subl %r12d, %r15d
jge 0x42098
movl %ebp, %r15d
jmp 0x420d6
movzwl (%r14), %ecx
movl %r12d, %r13d
cmpl $0xd935, %ecx           # imm = 0xD935
je 0x420d3
orl %eax, %ecx
testw %cx, %cx
je 0x420d3
movslq %esi, %rsi
movq 0x10(%rsp), %rax
leaq (%rax,%rsi), %rdi
movq %rsi, %rbx
movq %r14, %rsi
movq %r13, %rdx
callq 0x4290
movq %rbx, %rsi
movq 0x50(%rsp), %rbx
addl %r12d, %esi
addq %r13, %r14
cmpl %r12d, %ebp
movl %r15d, %ebp
jge 0x4207d
movq 0x80(%rbx), %rax
movl 0x34(%rsp), %ebp
movq 0x20(%rsp), %r14
movq %rax, 0x88(%rsp)
movl 0x1c(%rsp), %eax
movl %eax, %r12d
orb 0xe(%rsp), %r12b
movb 0x88(%rbx), %cl
movb $0x1, %al
cmpb $0x1, %cl
jne 0x42119
cmpl $0x1, 0x90(%rbx)
setne %al
movq 0x68(%rbx), %r8
testb $0x1, %r12b
movq %rsi, 0x10(%rsp)
je 0x42130
movl %esi, %r15d
jmp 0x42430
movb %al, 0xf(%rsp)
movl 0x58(%rbx), %r9d
movl 0x90(%rbx), %edi
movzwl %si, %edx
movq 0x48(%rsp), %rax
movq %rdx, 0x80(%rsp)
leal (%rax,%rdx), %r10d
leaq (%r10,%r9), %rax
addq %r8, %rax
addq $0x1d, %rax
xorl %edx, %edx
divq %r8
movq %rdx, %r14
movl %edi, 0x5c(%rsp)
testl %edi, %edi
jne 0x421f3
movl $0x1000, %eax           # imm = 0x1000
cmpq %rax, 0x70(%rbx)
sete %dl
cmpq %rax, %r8
setne %al
andb %dl, %al
andb %cl, %al
cmpb $0x1, %al
jne 0x421f3
leaq 0x1ee2b(%rip), %rdx     # 0x60fbd
movq 0x28(%rsp), %rdi
movl 0x30(%rsp), %esi
movl $0x3, %ecx
movq %r8, %r15
movq %r9, %r13
movq %r10, 0x38(%rsp)
callq 0x3fbcb
movq 0x38(%rsp), %r10
movq %r13, %r9
movq %r15, %r8
movq 0x10(%rsp), %rsi
testb %al, %al
je 0x421f3
movq 0x28(%rsp), %rcx
movq 0x50(%rcx), %rax
movq 0x58(%rcx), %rcx
movq 0x70(%rsp), %rdx
movl (%rcx,%rdx,4), %ecx
movb 0x8(%rax,%rcx), %al
movl %eax, %ecx
shrb $0x7, %cl
testb %al, %al
movl $0x1000, %r13d          # imm = 0x1000
cmovnsq %r8, %r13
jmp 0x422b7
movq 0x70(%rbx), %r13
testq %r13, %r13
sete %al
cmpq %r8, %r13
sete %cl
orb %al, %cl
je 0x42222
xorl %ecx, %ecx
movq %r8, %r13
jmp 0x422b7
testb %dl, %dl
movb %dl, 0xe(%rsp)
je 0x42295
movl %ecx, 0x18(%rsp)
jmp 0x42022
movq %r10, 0x38(%rsp)
movq %r9, 0x68(%rsp)
movq %r8, %r15
leaq 0x1ed87(%rip), %rdx     # 0x60fbd
movq 0x28(%rsp), %rdi
movl 0x30(%rsp), %esi
movl $0x3, %ecx
callq 0x3fbcb
xorl %ecx, %ecx
testb %al, %al
je 0x422a2
movq %r13, %rax
xorl %edx, %edx
movq %r15, %r8
divq %r15
testq %rdx, %rdx
movq 0x10(%rsp), %rsi
movq 0x68(%rsp), %r9
movq 0x38(%rsp), %r10
je 0x422b7
movq 0x39d53(%rip), %rax     # 0x7bfc8
movq (%rax), %rdi
leaq 0x1ee35(%rip), %rsi     # 0x610b4
movl %r8d, %edx
xorl %eax, %eax
movq %r8, %r13
callq 0x4450
xorl %eax, %eax
movq 0x10(%rsp), %rsi
jmp 0x422fb
movl 0x18(%r14), %eax
movl %eax, 0x18(%rsp)
jmp 0x42022
movq %r15, %r8
movq %r15, %r13
movq 0x10(%rsp), %rsi
movq 0x68(%rsp), %r9
movq 0x38(%rsp), %r10
notl %r14d
addl %r8d, %r14d
movl %r14d, %r15d
cmpq %r8, %r13
je 0x422eb
leaq (%r10,%r9), %rax
addq $0x1d, %rax
addq %r13, %rax
xorl %edx, %edx
divq %r13
notl %edx
addl %r13d, %edx
movl %r14d, %r15d
cmpl %r14d, %edx
je 0x422eb
incl 0x8c(%rbx)
movl %edx, %r15d
movb $0x1, %al
testl %r15d, %r15d
je 0x422fb
cmpb $0xf, 0x64(%rsp)
jbe 0x42308
xorl %eax, %eax
movl %esi, %r15d
movq 0x20(%rsp), %r14
jmp 0x42425
cmpl $0x0, 0x60(%rsp)
je 0x42325
orb 0xf(%rsp), %cl
testb $0x1, %cl
jne 0x423bf
cmpl %r14d, %r15d
je 0x423bf
addl 0x80(%rsp), %r15d
js 0x426fd
cmpl $0x10000, %r15d         # imm = 0x10000
movq 0x20(%rsp), %r14
jge 0x4271c
cmpl $0x1, 0x5c(%rsp)
jne 0x42425
movzwl %r15w, %r14d
cmpl %ebp, %r14d
je 0x422fe
movb %r12b, 0xd(%rsp)
movq 0x28(%rsp), %rcx
movq 0x50(%rcx), %rax
movq 0x58(%rcx), %rcx
movq 0x70(%rsp), %rdx
movl (%rcx,%rdx,4), %ecx
leaq 0x2e(%rax,%rcx), %rsi
leaq 0x90(%rsp), %rdi
movq 0x48(%rsp), %r12
movq %r12, %rdx
callq 0x4290
movb $0x0, 0x90(%rsp,%r12)
leaq 0x1edae(%rip), %rdi     # 0x6114b
xorl %eax, %eax
callq 0x4060
leaq 0x90(%rsp), %rdi
callq 0x48304
subl %ebp, %r14d
js 0x42400
leaq 0x1ed99(%rip), %rdi     # 0x61156
jmp 0x4240a
movslq %r15d, %r15
xorps %xmm0, %xmm0
leaq 0x90(%rsp), %r14
movaps %xmm0, (%r14)
cmpq $0x10, %r15
movl $0x10, %ebp
cmovbq %r15, %rbp
movq %rbx, %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x41b5e
subq %rbp, %r15
jne 0x423d1
movq 0x10(%rsp), %rsi
movl %esi, %r15d
movq 0x20(%rsp), %r14
jmp 0x42423
negl %r14d
leaq 0x1ed7e(%rip), %rdi     # 0x61188
movl %r14d, %esi
xorl %eax, %eax
callq 0x4060
movb 0xd(%rsp), %r12b
movq 0x20(%rsp), %r14
movq 0x10(%rsp), %rsi
movb $0x1, %al
movq %r13, %r8
testb %al, %al
je 0x426e7
cmpb $0x0, 0x1c(%rsp)
movq %r8, 0x28(%rsp)
je 0x42456
movq 0x78(%rbx), %rcx
movl $0x2014b50, %eax        # imm = 0x2014B50
testq %rcx, %rcx
je 0x42487
movq 0x40(%rsp), %rdx
movzwl (%rcx,%rdx,2), %r15d
jmp 0x42487
movl 0x58(%rbx), %eax
movq 0xa8(%rbx), %rcx
movq 0x40(%rsp), %rdi
movl %eax, (%rcx,%rdi,4)
movq 0x78(%rbx), %rcx
movl $0x4034b50, %eax        # imm = 0x4034B50
testq %rcx, %rcx
je 0x42487
cmpb $0x0, 0x88(%rbx)
movl %esi, %edx
cmovnel %r15d, %edx
movw %dx, (%rcx,%rdi,2)
leaq 0x90(%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 0x41b5e
cmpb $0x0, 0x1c(%rsp)
je 0x424c7
leaq 0x4(%r14), %rsi
movl $0x2, %edx
movq %rbx, %rdi
callq 0x41b5e
leaq 0x6(%r14), %rsi
movl $0x4, %edx
movq %rbx, %rdi
callq 0x41b5e
movb 0xe(%rsp), %al
shlb $0x3, %al
leaq 0x90(%rsp), %rsi
movb %al, (%rsi)
movb $0x0, 0x1(%rsi)
movl $0x2, %edx
movq %rbx, %rdi
callq 0x41b5e
leaq 0xc(%r14), %rsi
movl $0x4, %edx
movq %rbx, %rdi
callq 0x41b5e
cmpb $0x1, 0x148(%rbx)
movb %r12b, 0xd(%rsp)
jne 0x42532
movb $0x0, 0x148(%rbx)
movl 0x14c(%rbx), %eax
leaq 0x90(%rsp), %rsi
movl %eax, (%rsi)
jmp 0x42536
leaq 0x10(%r14), %rsi
movl $0x4, %edx
movq %rbx, %rdi
callq 0x41b5e
movq %r14, %r12
addq $0x2e, %r14
leaq 0x90(%rsp), %r13
movl 0x18(%rsp), %eax
movl %eax, (%r13)
movl $0x4, %edx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x41b5e
leaq 0x18(%r12), %rsi
movl $0x6, %edx
movq %rbx, %rdi
callq 0x41b5e
movw %r15w, (%r13)
leaq 0x90(%rsp), %rsi
movl $0x2, %edx
movq %rbx, %rdi
callq 0x41b5e
cmpb $0x0, 0x1c(%rsp)
je 0x4260c
movzbl 0x20(%r12), %eax
movzbl 0x21(%r12), %ebp
leaq 0x90(%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 0x41b5e
addq $0x22, %r12
movl $0x8, %edx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x41b5e
movq 0xa8(%rbx), %rax
movq 0x40(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, (%r13)
leaq 0x90(%rsp), %rsi
movl $0x4, %edx
movq %rbx, %rdi
callq 0x41b5e
jmp 0x4260e
xorl %ebp, %ebp
movq %rbx, %rdi
movq %r14, %rsi
movq 0x48(%rsp), %rdx
callq 0x41b5e
movq 0x10(%rsp), %rbx
cmpw %r15w, %bx
movl %r15d, %eax
cmovbl %ebx, %eax
movzwl %ax, %edx
movq 0x50(%rsp), %rdi
movq 0x88(%rsp), %rsi
callq 0x41b5e
movq %rbx, %rax
movq 0x50(%rsp), %rbx
cmpw %ax, %r15w
jbe 0x42690
movzwl %r15w, %r12d
movzwl %ax, %eax
xorps %xmm0, %xmm0
movaps %xmm0, 0x90(%rsp)
subq %rax, %r12
je 0x42690
leaq 0x90(%rsp), %r14
cmpq $0x10, %r12
movl $0x10, %r15d
cmovbq %r12, %r15
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x41b5e
subq %r15, %r12
jne 0x4266f
testw %bp, %bp
movb 0xd(%rsp), %r14b
je 0x426b1
movl 0x34(%rsp), %eax
movq 0x78(%rsp), %rsi
addq %rax, %rsi
movzwl %bp, %edx
movq %rbx, %rdi
callq 0x41b5e
movb $0x1, %cl
testb $0x1, %r14b
jne 0x426e9
movl 0x58(%rbx), %eax
xorl %edx, %edx
divq 0x28(%rsp)
testq %rdx, %rdx
je 0x426e9
leaq 0x1eaec(%rip), %rdi     # 0x611bb
leaq 0x1db8b(%rip), %rsi     # 0x60261
leaq 0x1ea2d(%rip), %rcx     # 0x6110a
movl $0x4bb, %edx            # imm = 0x4BB
callq 0x4200
xorl %ecx, %ecx
movl %ecx, %eax
addq $0x1098, %rsp           # imm = 0x1098
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1e9de(%rip), %rdi     # 0x610e2
leaq 0x1db56(%rip), %rsi     # 0x60261
leaq 0x1e9f8(%rip), %rcx     # 0x6110a
movl $0x47e, %edx            # imm = 0x47E
callq 0x4200
leaq 0x1792d(%rip), %rdi     # 0x5a050
leaq 0x1db37(%rip), %rsi     # 0x60261
leaq 0x1e9d9(%rip), %rcx     # 0x6110a
movl $0x47f, %edx            # imm = 0x47F
callq 0x4200