// File: sisong[P]ApkDiffPatch/src/patch/Patcher.cpp
// Function: VirtualZipPatchWithStream(hpatch_TStreamInput const*, hpatch_TStreamInput const*, hpatch_TStreamOutput const*, unsigned long, char const*, int, void*, void*)
TPatchResult VirtualZipPatchWithStream(const hpatch_TStreamInput* oldZipStream,const hpatch_TStreamInput* zipDiffStream,
                                       const hpatch_TStreamOutput* outNewZipStream,size_t maxUncompressMemory,
                                       const char* tempUncompressFileName,int threadNum,
                                       IVirtualZip_in* _virtual_in,IVirtualZip_out* virtual_out){
#define HPATCH_CACHE_SIZE  (128*1024)
    UnZipper            oldZip;
    Zipper              out_newZip;
    ZipDiffData         zipDiffData;
    OldStream           oldStream;
    NewStream           newStream;
    hpatch_compressedDiffInfo   diffInfo;
    TByte*                      ref_cache=0;
    hpatch_TFileStreamOutput    io_refFile;
    hpatch_TStreamOutput        io_ref_cache;
    hpatch_TStreamInput*        input_ref=0;
    hpatch_TStreamOutput*       output_ref=0;
    TPatchResult    result=PATCH_SUCCESS;
    bool            _isInClear=false;
    bool            isUsedTempFile=false;
    TByte*          temp_cache =0;
    size_t          temp_cahe_size;
    ZipFilePos_t    decompressSumSize=0;
    hpatch_TDecompress* decompressPlugin=0;
    bool isSD=false;
    hpatch_singleCompressedDiffInfo sdiffInfo;

    UnZipper_init(&oldZip);
    Zipper_init(&out_newZip);
    ZipDiffData_init(&zipDiffData);
    OldStream_init(&oldStream);
    NewStream_init(&newStream);
    hpatch_TFileStreamOutput_init(&io_refFile);
    
#if (_IS_NEED_VIRTUAL_ZIP)
    VirtualZip_in*  virtual_in=0;
    VirtualZip_in   _virtual_in_;
    if (_virtual_in) { VirtualZip_in_init(&_virtual_in_); virtual_in=&_virtual_in_; }
#else
    assert(_virtual_in==0);
    assert(virtual_out==0);
#endif

#ifdef _CompressPlugin_lzma2
    if (decompressPlugin==0){
        if (ZipDiffData_isCanDecompress(zipDiffStream,&lzma2DecompressPlugin))
            decompressPlugin=&lzma2DecompressPlugin;
    }
#endif
#ifdef _CompressPlugin_lzma
    if (decompressPlugin==0){
        if (ZipDiffData_isCanDecompress(zipDiffStream,&lzmaDecompressPlugin))
            decompressPlugin=&lzmaDecompressPlugin;
    }
#endif
    if (decompressPlugin==0){
        decompressPlugin=&zlibDecompressPlugin;
        check(ZipDiffData_isCanDecompress(zipDiffStream,decompressPlugin),PATCH_COMPRESSTYPE_ERROR);
    }
    
    check(ZipDiffData_openRead(&zipDiffData,zipDiffStream,decompressPlugin),PATCH_ZIPDIFFINFO_ERROR);
    isSD=(zipDiffData.PatchModel==1);
    check(UnZipper_openStream(&oldZip,oldZipStream,zipDiffData.oldZipIsDataNormalized!=0,
                              zipDiffData.oldIsFileDataOffsetMatch!=0),PATCH_OPENREAD_ERROR);
    check(zipDiffData.oldZipCESize==UnZipper_CESize(&oldZip),PATCH_OLDDATA_ERROR);
#if (_IS_NEED_VIRTUAL_ZIP)
    if (virtual_in)
        check(VirtualZip_in_open(virtual_in,_virtual_in,&oldZip),PATCH_VIRTUAL_IN_BEGIN_ERROR);
#endif
    check(zipDiffData.oldCrc==OldStream_getOldCrc(&oldZip,zipDiffData.oldRefList,zipDiffData.oldRefCount
                                                  _VIRTUAL_IN(virtual_in)), PATCH_OLDDATA_ERROR);
    if (!isSD){
        check(getCompressedDiffInfo(&diffInfo,zipDiffData.hdiffzData),PATCH_HDIFFINFO_ERROR);
    }else{
        check(getSingleCompressedDiffInfo(&sdiffInfo,zipDiffData.hdiffzData,0),PATCH_SD_HDIFFINFO_ERROR);
        memset(&diffInfo,0,sizeof(diffInfo));
        diffInfo.newDataSize=sdiffInfo.newDataSize;
        diffInfo.oldDataSize=sdiffInfo.oldDataSize;
        diffInfo.compressedCount=(sdiffInfo.compressedSize>0)?1:0;
        memcpy(diffInfo.compressType,sdiffInfo.compressType,sizeof(diffInfo.compressType));
    }
    if (strlen(diffInfo.compressType) > 0)
        check(decompressPlugin->is_can_open(diffInfo.compressType),PATCH_COMPRESSTYPE_ERROR);
    
    decompressSumSize=OldStream_getDecompressSumSize(&oldZip,zipDiffData.oldRefList,zipDiffData.oldRefCount
                                                     _VIRTUAL_IN(virtual_in));
    
    isUsedTempFile=(decompressSumSize > maxUncompressMemory)&&(tempUncompressFileName!=0);
    if (isUsedTempFile){
        check(hpatch_TFileStreamOutput_open(&io_refFile,tempUncompressFileName,decompressSumSize),
              PATCH_OPENWRITE_ERROR);
        output_ref=&io_refFile.base;
        input_ref=(hpatch_TStreamInput*)&io_refFile.base;
    }else{
        ref_cache=(TByte*)malloc(decompressSumSize+1);//+1 not null
        check(ref_cache!=0, PATCH_MEM_ERROR);
        mem_as_hStreamOutput(&io_ref_cache,ref_cache,ref_cache+decompressSumSize);
        output_ref=&io_ref_cache;
        input_ref=(hpatch_TStreamInput*)&io_ref_cache;
    }
    
    check(OldStream_getDecompressData(&oldZip,zipDiffData.oldRefList,zipDiffData.oldRefCount,
                                      output_ref _VIRTUAL_IN(virtual_in)),PATCH_OLDDECOMPRESS_ERROR);
    check(OldStream_open(&oldStream,&oldZip,zipDiffData.oldRefList,zipDiffData.oldRefCount,
                         0,0,input_ref _VIRTUAL_IN(virtual_in)), PATCH_OLDSTREAM_ERROR);
    check(oldStream.stream->streamSize==diffInfo.oldDataSize,PATCH_OLDDATA_ERROR);
    
    check(Zipper_openStream(&out_newZip,outNewZipStream,(int)zipDiffData.newZipFileCount,(int)zipDiffData.newZipAlignSize,
                            (int)zipDiffData.newCompressLevel,(int)zipDiffData.newCompressMemLevel,
                            zipDiffData.normalizeSoPageAlign,zipDiffData.pageAlignCompatible,kPageAlign_inPatch),PATCH_OPENWRITE_ERROR);
    check(NewStream_open(&newStream,&out_newZip,&oldZip,  (size_t)diffInfo.newDataSize,
                         zipDiffData.newZipIsDataNormalized!=0,
                         zipDiffData.newZipCESize,zipDiffData.extraEdit,
                         zipDiffData.samePairList,zipDiffData.samePairCount,
                         zipDiffData.newRefOtherCompressedList,zipDiffData.newRefOtherCompressedCount,
                         (int)zipDiffData.newOtherCompressLevel,(int)zipDiffData.newOtherCompressMemLevel,
                         zipDiffData.newRefCompressedSizeList,zipDiffData.newRefCompressedSizeCount,
                         threadNum _VIRTUAL_IN(virtual_in) _VIRTUAL_OUT(virtual_out)),PATCH_NEWSTREAM_ERROR);
    
    temp_cahe_size=HPATCH_CACHE_SIZE+(isSD?sdiffInfo.stepMemSize:0);
    temp_cache =(TByte*)malloc(temp_cahe_size);
    check(temp_cache!=0,PATCH_MEM_ERROR);
    if (!isSD){
        check(patch_decompress_with_cache(newStream.stream,oldStream.stream,zipDiffData.hdiffzData,
                                          decompressPlugin,temp_cache,temp_cache+temp_cahe_size),PATCH_HPATCH_ERROR);
    }else{
        check(patch_single_compressed_diff(newStream.stream,oldStream.stream,zipDiffData.hdiffzData,
                                           sdiffInfo.diffDataPos,sdiffInfo.uncompressedSize,sdiffInfo.compressedSize,
                                           decompressPlugin,sdiffInfo.coverCount,sdiffInfo.stepMemSize,
                                           temp_cache,temp_cache+temp_cahe_size,0),PATCH_SD_HPATCH_ERROR);
    }
    check(newStream.isFinish,PATCH_ZIPPATCH_ERROR);
    
clear:
    _isInClear=true;
    check(Zipper_close(&out_newZip),PATCH_CLOSEFILE_ERROR);
    NewStream_close(&newStream);
    OldStream_close(&oldStream);
#if (_IS_NEED_VIRTUAL_ZIP)
    if (virtual_in) check(VirtualZip_in_close(virtual_in),PATCH_VIRTUAL_IN_END_ERROR);
#endif
    check(UnZipper_close(&oldZip),PATCH_CLOSEFILE_ERROR);
    ZipDiffData_close(&zipDiffData);
    check(hpatch_TFileStreamOutput_close(&io_refFile),PATCH_CLOSEFILE_ERROR);
    if (isUsedTempFile) hpatch_removeFile(tempUncompressFileName);
    if (temp_cache) free(temp_cache);
    if (ref_cache) free(ref_cache);
    return result;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x8d8, %rsp            # imm = 0x8D8
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x30(%rbp)
movq %rsi, -0x38(%rbp)
movq %rdx, -0x40(%rbp)
movq %rcx, -0x48(%rbp)
movq %r8, -0x50(%rbp)
movl %r9d, -0x54(%rbp)
movq $0x0, -0x6a0(%rbp)
movq $0x0, -0x718(%rbp)
movq $0x0, -0x720(%rbp)
movl $0x0, -0x724(%rbp)
movb $0x0, -0x725(%rbp)
movb $0x0, -0x726(%rbp)
movq $0x0, -0x730(%rbp)
movl $0x0, -0x73c(%rbp)
movq $0x0, -0x748(%rbp)
movb $0x0, -0x749(%rbp)
leaq -0x108(%rbp), %rdi
callq 0x7f360
leaq -0x268(%rbp), %rdi
callq 0x80ef0
leaq -0x398(%rbp), %rdi
callq 0x7c7c0
leaq -0x400(%rbp), %rdi
callq 0x7bec0
leaq -0x580(%rbp), %rdi
callq 0xa23f0
leaq -0x6f0(%rbp), %rdi
callq 0xa46a0
cmpq $0x0, 0x10(%rbp)
jne 0xa38e5
jmp 0xa3904
leaq 0x1be23(%rip), %rdi     # 0xbf70f
leaq 0x1be2b(%rip), %rsi     # 0xbf71e
movl $0x58, %edx
leaq 0x1be35(%rip), %rcx     # 0xbf734
callq 0x4270
cmpq $0x0, 0x18(%rbp)
jne 0xa390d
jmp 0xa392c
leaq 0x1beca(%rip), %rdi     # 0xbf7de
leaq 0x1be03(%rip), %rsi     # 0xbf71e
movl $0x59, %edx
leaq 0x1be0d(%rip), %rcx     # 0xbf734
callq 0x4270
cmpq $0x0, -0x748(%rbp)
jne 0xa395c
movq -0x38(%rbp), %rdi
leaq 0x42cb7(%rip), %rsi     # 0xe65f8
callq 0x7c830
testb $0x1, %al
jne 0xa394c
jmp 0xa395a
leaq 0x42ca5(%rip), %rax     # 0xe65f8
movq %rax, -0x748(%rbp)
jmp 0xa395c
cmpq $0x0, -0x748(%rbp)
jne 0xa398c
movq -0x38(%rbp), %rdi
leaq 0x42cb7(%rip), %rsi     # 0xe6628
callq 0x7c830
testb $0x1, %al
jne 0xa397c
jmp 0xa398a
leaq 0x42ca5(%rip), %rax     # 0xe6628
movq %rax, -0x748(%rbp)
jmp 0xa398c
cmpq $0x0, -0x748(%rbp)
jne 0xa39eb
leaq 0x42cbb(%rip), %rax     # 0xe6658
movq %rax, -0x748(%rbp)
movq -0x38(%rbp), %rdi
movq -0x748(%rbp), %rsi
callq 0x7c830
testb $0x1, %al
jne 0xa39e9
leaq 0x1be2e(%rip), %rdi     # 0xbf7ed
movb $0x0, %al
callq 0x4060
cmpl $0x0, -0x724(%rbp)
jne 0xa39d9
movl $0x7, -0x724(%rbp)
testb $0x1, -0x725(%rbp)
jne 0xa39e7
jmp 0xa42a9
jmp 0xa39e9
jmp 0xa39eb
movq -0x38(%rbp), %rsi
movq -0x748(%rbp), %rdx
leaq -0x398(%rbp), %rdi
callq 0x7cac0
testb $0x1, %al
jne 0xa3a37
leaq 0x1be37(%rip), %rdi     # 0xbf844
movb $0x0, %al
callq 0x4060
cmpl $0x0, -0x724(%rbp)
jne 0xa3a27
movl $0x9, -0x724(%rbp)
testb $0x1, -0x725(%rbp)
jne 0xa3a35
jmp 0xa42a9
jmp 0xa3a37
cmpq $0x1, -0x398(%rbp)
sete %al
andb $0x1, %al
movb %al, -0x749(%rbp)
movq -0x30(%rbp), %rsi
cmpq $0x0, -0x320(%rbp)
setne %cl
cmpq $0x0, -0x318(%rbp)
setne %al
movzbl %cl, %edx
andl $0x1, %edx
movzbl %al, %ecx
andl $0x1, %ecx
leaq -0x108(%rbp), %rdi
xorl %r8d, %r8d
callq 0x7f480
testb $0x1, %al
jne 0xa3ab4
leaq 0x1be16(%rip), %rdi     # 0xbf8a0
movb $0x0, %al
callq 0x4060
cmpl $0x0, -0x724(%rbp)
jne 0xa3aa4
movl $0x1, -0x724(%rbp)
testb $0x1, -0x725(%rbp)
jne 0xa3ab2
jmp 0xa42a9
jmp 0xa3ab4
movq -0x310(%rbp), %rax
movq %rax, -0x898(%rbp)
leaq -0x108(%rbp), %rdi
callq 0xa46d0
movq %rax, %rcx
movq -0x898(%rbp), %rax
cmpq %rcx, %rax
je 0xa3b0e
leaq 0x1be4c(%rip), %rdi     # 0xbf930
movb $0x0, %al
callq 0x4060
cmpl $0x0, -0x724(%rbp)
jne 0xa3afe
movl $0xa, -0x724(%rbp)
testb $0x1, -0x725(%rbp)
jne 0xa3b0c
jmp 0xa42a9
jmp 0xa3b0e
movl -0x2f8(%rbp), %eax
movl %eax, -0x89c(%rbp)
movq -0x308(%rbp), %rsi
movq -0x300(%rbp), %rdx
leaq -0x108(%rbp), %rdi
callq 0x7bd60
movl %eax, %ecx
movl -0x89c(%rbp), %eax
cmpl %ecx, %eax
je 0xa3b71
leaq 0x1be32(%rip), %rdi     # 0xbf979
movb $0x0, %al
callq 0x4060
cmpl $0x0, -0x724(%rbp)
jne 0xa3b61
movl $0xa, -0x724(%rbp)
testb $0x1, -0x725(%rbp)
jne 0xa3b6f
jmp 0xa42a9
jmp 0xa3b71
testb $0x1, -0x749(%rbp)
jne 0xa3bc8
movq -0x2e0(%rbp), %rsi
leaq -0x698(%rbp), %rdi
callq 0x87ed0
cmpl $0x0, %eax
jne 0xa3bc3
leaq 0x1be6e(%rip), %rdi     # 0xbfa07
movb $0x0, %al
callq 0x4060
cmpl $0x0, -0x724(%rbp)
jne 0xa3bb3
movl $0x6, -0x724(%rbp)
testb $0x1, -0x725(%rbp)
jne 0xa3bc1
jmp 0xa42a9
jmp 0xa3bc3
jmp 0xa3c7f
movq -0x2e0(%rbp), %rsi
leaq -0x890(%rbp), %rdi
xorl %eax, %eax
movl %eax, %edx
callq 0x89e00
cmpl $0x0, %eax
jne 0xa3c15
leaq 0x1be6c(%rip), %rdi     # 0xbfa57
movb $0x0, %al
callq 0x4060
cmpl $0x0, -0x724(%rbp)
jne 0xa3c05
movl $0x14, -0x724(%rbp)
testb $0x1, -0x725(%rbp)
jne 0xa3c13
jmp 0xa42a9
jmp 0xa3c15
leaq -0x698(%rbp), %rdi
xorl %esi, %esi
movl $0x118, %edx            # imm = 0x118
callq 0x4210
movq -0x890(%rbp), %rax
movq %rax, -0x698(%rbp)
movq -0x888(%rbp), %rax
movq %rax, -0x690(%rbp)
movq -0x878(%rbp), %rdx
xorl %eax, %eax
movl $0x1, %ecx
cmpq $0x0, %rdx
cmoval %ecx, %eax
movl %eax, -0x688(%rbp)
leaq -0x698(%rbp), %rdi
addq $0x14, %rdi
leaq -0x890(%rbp), %rsi
addq $0x38, %rsi
movl $0x104, %edx            # imm = 0x104
callq 0x4320
leaq -0x698(%rbp), %rdi
addq $0x14, %rdi
callq 0x4180
cmpq $0x0, %rax
jbe 0xa3ce4
movq -0x748(%rbp), %rax
movq (%rax), %rax
leaq -0x698(%rbp), %rdi
addq $0x14, %rdi
callq *%rax
cmpl $0x0, %eax
jne 0xa3ce2
leaq 0x1bdfb(%rip), %rdi     # 0xbfab3
movb $0x0, %al
callq 0x4060
cmpl $0x0, -0x724(%rbp)
jne 0xa3cd2
movl $0x7, -0x724(%rbp)
testb $0x1, -0x725(%rbp)
jne 0xa3ce0
jmp 0xa42a9
jmp 0xa3ce2
jmp 0xa3ce4
movq -0x308(%rbp), %rsi
movq -0x300(%rbp), %rdx
leaq -0x108(%rbp), %rdi
callq 0x7bc30
movl %eax, -0x73c(%rbp)
movl -0x73c(%rbp), %eax
movl %eax, %ecx
xorl %eax, %eax
cmpq -0x48(%rbp), %rcx
movb %al, -0x89d(%rbp)
jbe 0xa3d28
cmpq $0x0, -0x50(%rbp)
setne %al
movb %al, -0x89d(%rbp)
movb -0x89d(%rbp), %al
andb $0x1, %al
movb %al, -0x726(%rbp)
testb $0x1, -0x726(%rbp)
je 0xa3dae
movq -0x50(%rbp), %rsi
movl -0x73c(%rbp), %eax
movl %eax, %edx
leaq -0x6f0(%rbp), %rdi
callq 0x8e140
cmpl $0x0, %eax
jne 0xa3d8d
leaq 0x1bda0(%rip), %rdi     # 0xbfb03
movb $0x0, %al
callq 0x4060
cmpl $0x0, -0x724(%rbp)
jne 0xa3d7d
movl $0x2, -0x724(%rbp)
testb $0x1, -0x725(%rbp)
jne 0xa3d8b
jmp 0xa42a9
jmp 0xa3d8d
leaq -0x6f0(%rbp), %rax
movq %rax, -0x720(%rbp)
leaq -0x6f0(%rbp), %rax
movq %rax, -0x718(%rbp)
jmp 0xa3e41
movl -0x73c(%rbp), %eax
addl $0x1, %eax
movl %eax, %eax
movl %eax, %edi
callq 0x44d0
movq %rax, -0x6a0(%rbp)
cmpq $0x0, -0x6a0(%rbp)
jne 0xa3e02
leaq 0x1bd97(%rip), %rdi     # 0xbfb6f
movb $0x0, %al
callq 0x4060
cmpl $0x0, -0x724(%rbp)
jne 0xa3df2
movl $0x4, -0x724(%rbp)
testb $0x1, -0x725(%rbp)
jne 0xa3e00
jmp 0xa42a9
jmp 0xa3e02
movq -0x6a0(%rbp), %rsi
movq -0x6a0(%rbp), %rdx
movl -0x73c(%rbp), %eax
addq %rax, %rdx
leaq -0x710(%rbp), %rdi
callq 0x85c10
leaq -0x710(%rbp), %rax
movq %rax, -0x720(%rbp)
leaq -0x710(%rbp), %rax
movq %rax, -0x718(%rbp)
movq -0x308(%rbp), %rsi
movq -0x300(%rbp), %rdx
movq -0x720(%rbp), %rcx
leaq -0x108(%rbp), %rdi
callq 0x7bcb0
testb $0x1, %al
jne 0xa3e97
leaq 0x1bd21(%rip), %rdi     # 0xbfb8e
movb $0x0, %al
callq 0x4060
cmpl $0x0, -0x724(%rbp)
jne 0xa3e87
movl $0xb, -0x724(%rbp)
testb $0x1, -0x725(%rbp)
jne 0xa3e95
jmp 0xa42a9
jmp 0xa3e97
movq -0x308(%rbp), %rdx
movq -0x300(%rbp), %rcx
movq -0x718(%rbp), %rax
leaq -0x400(%rbp), %rdi
leaq -0x108(%rbp), %rsi
xorl %r8d, %r8d
movl %r8d, %r9d
movq %r9, %r8
movq %rax, (%rsp)
callq 0x7c2f0
testb $0x1, %al
jne 0xa3f01
leaq 0x1bd4b(%rip), %rdi     # 0xbfc22
movb $0x0, %al
callq 0x4060
cmpl $0x0, -0x724(%rbp)
jne 0xa3ef1
movl $0xc, -0x724(%rbp)
testb $0x1, -0x725(%rbp)
jne 0xa3eff
jmp 0xa42a9
jmp 0xa3f01
movq -0x400(%rbp), %rax
movq 0x8(%rax), %rax
cmpq -0x690(%rbp), %rax
je 0xa3f46
leaq 0x1bd97(%rip), %rdi     # 0xbfcb3
movb $0x0, %al
callq 0x4060
cmpl $0x0, -0x724(%rbp)
jne 0xa3f36
movl $0xa, -0x724(%rbp)
testb $0x1, -0x725(%rbp)
jne 0xa3f44
jmp 0xa42a9
jmp 0xa3f46
movq -0x40(%rbp), %rsi
movq -0x390(%rbp), %rax
movl %eax, %edx
movq -0x380(%rbp), %rax
movl %eax, %ecx
movq -0x378(%rbp), %rax
movl %eax, %r8d
movq -0x370(%rbp), %rax
movl %eax, %r9d
movq -0x2f0(%rbp), %r10
movb -0x2e8(%rbp), %al
leaq -0x268(%rbp), %rdi
xorl %r11d, %r11d
andb $0x1, %al
movq %r10, (%rsp)
movzbl %al, %eax
movl %eax, 0x8(%rsp)
movl $0x0, 0x10(%rsp)
callq 0x810b0
testb $0x1, %al
jne 0xa3fd6
leaq 0x1bd50(%rip), %rdi     # 0xbfcfc
movb $0x0, %al
callq 0x4060
cmpl $0x0, -0x724(%rbp)
jne 0xa3fc6
movl $0x2, -0x724(%rbp)
testb $0x1, -0x725(%rbp)
jne 0xa3fd4
jmp 0xa42a9
jmp 0xa3fd6
movq -0x698(%rbp), %rcx
cmpq $0x0, -0x388(%rbp)
setne %al
movq -0x358(%rbp), %r9
movq -0x2d8(%rbp), %rsi
movq -0x350(%rbp), %rdi
movq -0x348(%rbp), %r8
movq -0x340(%rbp), %r10
movq -0x338(%rbp), %r11
movq -0x368(%rbp), %rdx
movl %edx, %ebx
movq -0x360(%rbp), %rdx
movl %edx, %r14d
movq -0x330(%rbp), %r15
movq -0x328(%rbp), %r12
movl -0x54(%rbp), %r13d
movq %rsp, %rdx
movq %rdx, -0x8a8(%rbp)
movl %r13d, 0x48(%rdx)
movq %r12, 0x40(%rdx)
movq %r15, 0x38(%rdx)
movl %r14d, 0x30(%rdx)
movl %ebx, 0x28(%rdx)
movq %r11, 0x20(%rdx)
movq %r10, 0x18(%rdx)
movq %r8, 0x10(%rdx)
movq %rdi, 0x8(%rdx)
movq %rsi, (%rdx)
movzbl %al, %r8d
andl $0x1, %r8d
leaq -0x580(%rbp), %rdi
leaq -0x268(%rbp), %rsi
leaq -0x108(%rbp), %rdx
callq 0xa2480
testb $0x1, %al
jne 0xa40be
leaq 0x1bd8e(%rip), %rdi     # 0xbfe22
movb $0x0, %al
callq 0x4060
cmpl $0x0, -0x724(%rbp)
jne 0xa40ae
movl $0xd, -0x724(%rbp)
testb $0x1, -0x725(%rbp)
jne 0xa40bc
jmp 0xa42a9
jmp 0xa40be
testb $0x1, -0x749(%rbp)
je 0xa40d7
movq -0x860(%rbp), %rax
movq %rax, -0x8b0(%rbp)
jmp 0xa40e2
xorl %eax, %eax
movq %rax, -0x8b0(%rbp)
jmp 0xa40e2
movq -0x8b0(%rbp), %rax
addq $0x20000, %rax          # imm = 0x20000
movq %rax, -0x738(%rbp)
movq -0x738(%rbp), %rdi
callq 0x44d0
movq %rax, -0x730(%rbp)
cmpq $0x0, -0x730(%rbp)
jne 0xa4144
leaq 0x1bf21(%rip), %rdi     # 0xc003b
movb $0x0, %al
callq 0x4060
cmpl $0x0, -0x724(%rbp)
jne 0xa4134
movl $0x4, -0x724(%rbp)
testb $0x1, -0x725(%rbp)
jne 0xa4142
jmp 0xa42a9
jmp 0xa4144
testb $0x1, -0x749(%rbp)
jne 0xa41be
movq -0x580(%rbp), %rdi
movq -0x400(%rbp), %rsi
movq -0x2e0(%rbp), %rdx
movq -0x748(%rbp), %rcx
movq -0x730(%rbp), %r8
movq -0x730(%rbp), %r9
addq -0x738(%rbp), %r9
callq 0x88a70
cmpl $0x0, %eax
jne 0xa41b9
leaq 0x1becc(%rip), %rdi     # 0xc005b
movb $0x0, %al
callq 0x4060
cmpl $0x0, -0x724(%rbp)
jne 0xa41a9
movl $0x5, -0x724(%rbp)
testb $0x1, -0x725(%rbp)
jne 0xa41b7
jmp 0xa42a9
jmp 0xa41b9
jmp 0xa4270
movq -0x580(%rbp), %rdi
movq -0x400(%rbp), %rsi
movq -0x2e0(%rbp), %rdx
movq -0x870(%rbp), %rcx
movq -0x880(%rbp), %r8
movq -0x878(%rbp), %r9
movq -0x748(%rbp), %r14
movq -0x868(%rbp), %rbx
movq -0x860(%rbp), %r11
movq -0x730(%rbp), %r10
movq -0x730(%rbp), %rax
addq -0x738(%rbp), %rax
xorl %r15d, %r15d
movq %r14, (%rsp)
movq %rbx, 0x8(%rsp)
movq %r11, 0x10(%rsp)
movq %r10, 0x18(%rsp)
movq %rax, 0x20(%rsp)
movq $0x0, 0x28(%rsp)
callq 0x896c0
cmpl $0x0, %eax
jne 0xa426e
leaq 0x1beb6(%rip), %rdi     # 0xc00fd
movb $0x0, %al
callq 0x4060
cmpl $0x0, -0x724(%rbp)
jne 0xa4261
movl $0x15, -0x724(%rbp)
testb $0x1, -0x725(%rbp)
jne 0xa426c
jmp 0xa42a9
jmp 0xa426e
jmp 0xa4270
testb $0x1, -0x578(%rbp)
jne 0xa42a7
leaq 0x1bf9c(%rip), %rdi     # 0xc021c
movb $0x0, %al
callq 0x4060
cmpl $0x0, -0x724(%rbp)
jne 0xa429a
movl $0x8, -0x724(%rbp)
testb $0x1, -0x725(%rbp)
jne 0xa42a5
jmp 0xa42a9
jmp 0xa42a7
jmp 0xa42a9
movb $0x1, -0x725(%rbp)
leaq -0x268(%rbp), %rdi
callq 0x80f20
testb $0x1, %al
jne 0xa42ee
leaq 0x1bf7f(%rip), %rdi     # 0xc0246
movb $0x0, %al
callq 0x4060
cmpl $0x0, -0x724(%rbp)
jne 0xa42e1
movl $0x3, -0x724(%rbp)
testb $0x1, -0x725(%rbp)
jne 0xa42ec
jmp 0xa42a9
jmp 0xa42ee
leaq -0x580(%rbp), %rdi
callq 0xa2420
leaq -0x400(%rbp), %rdi
callq 0x7bef0
leaq -0x108(%rbp), %rdi
callq 0x7f390
testb $0x1, %al
jne 0xa4347
leaq 0x1bf5b(%rip), %rdi     # 0xc0278
movb $0x0, %al
callq 0x4060
cmpl $0x0, -0x724(%rbp)
jne 0xa4337
movl $0x3, -0x724(%rbp)
testb $0x1, -0x725(%rbp)
jne 0xa4345
jmp 0xa42a9
jmp 0xa4347
leaq -0x398(%rbp), %rdi
callq 0x7c7f0
leaq -0x6f0(%rbp), %rdi
callq 0x8edd0
cmpl $0x0, %eax
jne 0xa4395
leaq 0x1bf3d(%rip), %rdi     # 0xc02a8
movb $0x0, %al
callq 0x4060
cmpl $0x0, -0x724(%rbp)
jne 0xa4385
movl $0x3, -0x724(%rbp)
testb $0x1, -0x725(%rbp)
jne 0xa4393
jmp 0xa42a9
jmp 0xa4395
testb $0x1, -0x726(%rbp)
je 0xa43a7
movq -0x50(%rbp), %rdi
callq 0x8d4f0
cmpq $0x0, -0x730(%rbp)
je 0xa43bd
movq -0x730(%rbp), %rdi
callq 0x4460
cmpq $0x0, -0x6a0(%rbp)
je 0xa43d3
movq -0x6a0(%rbp), %rdi
callq 0x4460
movl -0x724(%rbp), %eax
addq $0x8d8, %rsp            # imm = 0x8D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax,%rax)