// File: sisong[P]ApkDiffPatch/src/patch/Patcher.cpp
// Function: VirtualZipPatch(char const*, char const*, char const*, unsigned long, char const*, int, void*, void*)
TPatchResult VirtualZipPatch(const char* oldZipPath,const char* zipDiffPath,const char* outNewZipPath,
                             size_t maxUncompressMemory,const char* tempUncompressFileName,int threadNum,
                             IVirtualZip_in* virtual_in,IVirtualZip_out* virtual_out){
    hpatch_TFileStreamInput    oldZipStream;
    hpatch_TFileStreamInput    zipDiffStream;
    hpatch_TFileStreamOutput   outNewZipStream;
    TPatchResult    result=PATCH_SUCCESS;
    bool            _isInClear=false;
    
    hpatch_TFileStreamInput_init(&zipDiffStream);
    hpatch_TFileStreamInput_init(&oldZipStream);
    hpatch_TFileStreamOutput_init(&outNewZipStream);
    check(hpatch_TFileStreamInput_open(&oldZipStream,oldZipPath),PATCH_OPENREAD_ERROR);
    check(hpatch_TFileStreamInput_open(&zipDiffStream,zipDiffPath),PATCH_OPENREAD_ERROR);
    check(hpatch_TFileStreamOutput_open(&outNewZipStream,outNewZipPath,(hpatch_StreamPos_t)(-1)),PATCH_OPENWRITE_ERROR);
    hpatch_TFileStreamOutput_setRandomOut(&outNewZipStream,hpatch_TRUE);
    result=VirtualZipPatchWithStream(&oldZipStream.base,&zipDiffStream.base,&outNewZipStream.base,
                                     maxUncompressMemory,tempUncompressFileName,threadNum,virtual_in,virtual_out);
clear:
    _isInClear=true;
    check(hpatch_TFileStreamOutput_close(&outNewZipStream),PATCH_CLOSEFILE_ERROR);
    check(hpatch_TFileStreamInput_close(&oldZipStream),PATCH_CLOSEFILE_ERROR);
    check(hpatch_TFileStreamInput_close(&zipDiffStream),PATCH_CLOSEFILE_ERROR);
    return result;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movl %r9d, -0x2c(%rbp)
movl $0x0, -0x104(%rbp)
movb $0x0, -0x105(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0xa5c00
leaq -0x70(%rbp), %rdi
callq 0xa5c00
leaq -0x100(%rbp), %rdi
callq 0xa46a0
movq -0x8(%rbp), %rsi
leaq -0x70(%rbp), %rdi
callq 0x8da90
cmpl $0x0, %eax
jne 0xa44f0
leaq 0x1be26(%rip), %rdi     # 0xc02ec
movb $0x0, %al
callq 0x4060
cmpl $0x0, -0x104(%rbp)
jne 0xa44e0
movl $0x1, -0x104(%rbp)
testb $0x1, -0x105(%rbp)
jne 0xa44ee
jmp 0xa45cb
jmp 0xa44f0
movq -0x10(%rbp), %rsi
leaq -0xb0(%rbp), %rdi
callq 0x8da90
cmpl $0x0, %eax
jne 0xa4536
leaq 0x1be2e(%rip), %rdi     # 0xc033a
movb $0x0, %al
callq 0x4060
cmpl $0x0, -0x104(%rbp)
jne 0xa4526
movl $0x1, -0x104(%rbp)
testb $0x1, -0x105(%rbp)
jne 0xa4534
jmp 0xa45cb
jmp 0xa4536
movq -0x18(%rbp), %rsi
leaq -0x100(%rbp), %rdi
movq $-0x1, %rdx
callq 0x8e140
cmpl $0x0, %eax
jne 0xa4580
leaq 0x1be31(%rip), %rdi     # 0xc038a
movb $0x0, %al
callq 0x4060
cmpl $0x0, -0x104(%rbp)
jne 0xa4573
movl $0x2, -0x104(%rbp)
testb $0x1, -0x105(%rbp)
jne 0xa457e
jmp 0xa45cb
jmp 0xa4580
leaq -0x100(%rbp), %rdi
movl $0x1, %esi
callq 0xa5c30
leaq -0x70(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
leaq -0x100(%rbp), %rdx
movq -0x20(%rbp), %rcx
movq -0x28(%rbp), %r8
movl -0x2c(%rbp), %r9d
movq 0x10(%rbp), %r10
movq 0x18(%rbp), %rax
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
callq 0xa3800
movl %eax, -0x104(%rbp)
movb $0x1, -0x105(%rbp)
leaq -0x100(%rbp), %rdi
callq 0x8edd0
cmpl $0x0, %eax
jne 0xa4611
leaq 0x1be0f(%rip), %rdi     # 0xc03f9
movb $0x0, %al
callq 0x4060
cmpl $0x0, -0x104(%rbp)
jne 0xa4604
movl $0x3, -0x104(%rbp)
testb $0x1, -0x105(%rbp)
jne 0xa460f
jmp 0xa45cb
jmp 0xa4611
leaq -0x70(%rbp), %rdi
callq 0x8e030
cmpl $0x0, %eax
jne 0xa464d
leaq 0x1be1c(%rip), %rdi     # 0xc0442
movb $0x0, %al
callq 0x4060
cmpl $0x0, -0x104(%rbp)
jne 0xa4640
movl $0x3, -0x104(%rbp)
testb $0x1, -0x105(%rbp)
jne 0xa464b
jmp 0xa45cb
jmp 0xa464d
leaq -0xb0(%rbp), %rdi
callq 0x8e030
cmpl $0x0, %eax
jne 0xa468f
leaq 0x1be22(%rip), %rdi     # 0xc0487
movb $0x0, %al
callq 0x4060
cmpl $0x0, -0x104(%rbp)
jne 0xa467f
movl $0x3, -0x104(%rbp)
testb $0x1, -0x105(%rbp)
jne 0xa468d
jmp 0xa45cb
jmp 0xa468f
movl -0x104(%rbp), %eax
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
nop