// File: sisong[P]ApkDiffPatch/src/zip_patch.cpp
// Function: zippatch_cmd_line(int, char const**)
int zippatch_cmd_line(int argc, const char * argv[]) {
    const char* oldZipPath=0;
    const char* zipDiffPath=0;
    const char* outNewZipPath=0;
    size_t      maxUncompressMemory=0;
    const char* tempUncompressFileName=0;
    hpatch_BOOL isOutputVersion=_kNULL_VALUE;
    size_t      threadNum = _THREAD_NUMBER_NULL;
    #define kMax_arg_values_size 5
    const char * arg_values[kMax_arg_values_size]={0};
    int          arg_values_size=0;
    int         i;
    for (i=1; i<argc; ++i) {
        const char* op=argv[i];
        _options_check((op!=0)&&(strlen(op)>0),"?");
        if (op[0]!='-'){
            _options_check(arg_values_size<kMax_arg_values_size,"count");
            arg_values[arg_values_size]=op;
            ++arg_values_size;
            continue;
        }
        _options_check((op!=0)&&(op[0]=='-'),"?");
        switch (op[1]) {
            case 'v':{
                _options_check((isOutputVersion==_kNULL_VALUE)&&(op[2]=='\0'),"-v");
                isOutputVersion=hpatch_TRUE;
            } break;
#if (_IS_USED_MULTITHREAD)
            case 'p':{
                _options_check((threadNum==_THREAD_NUMBER_NULL)&&((op[2]=='-')),"-p-?");
                const char* pnum=op+3;
                _options_check(a_to_size(pnum,strlen(pnum),&threadNum),"-p-?");
                _options_check(threadNum>=_THREAD_NUMBER_MIN,"-p-?");
            } break;
#endif
            default: {
                _options_check(hpatch_FALSE,"-?");
            } break;
        }//swich
    }
    if (isOutputVersion==_kNULL_VALUE)
        isOutputVersion=hpatch_FALSE;
    if (isOutputVersion){
        printf("ApkDiffPatch::ZipPatch v" APKDIFFPATCH_VERSION_STRING "\n\n");
        if (arg_values_size==0)
            return 0; //ok
    }
    if (threadNum==_THREAD_NUMBER_NULL)
        threadNum=_THREAD_NUMBER_MIN;
    else if (threadNum>_THREAD_NUMBER_MAX)
        threadNum=_THREAD_NUMBER_MAX;
    
    if(arg_values_size==3){
        oldZipPath   =arg_values[0];
        zipDiffPath  =arg_values[1];
        outNewZipPath=arg_values[2];
    }else if(arg_values_size==5){
        oldZipPath   =arg_values[0];
        zipDiffPath  =arg_values[1];
        outNewZipPath=arg_values[2];
        _options_check(kmg_to_size(arg_values[3],strlen(arg_values[3]),
                                   &maxUncompressMemory),"maxUncompressMemory");
        tempUncompressFileName=arg_values[4];
        _options_check((tempUncompressFileName!=0)
                       &&(strlen(tempUncompressFileName)>0),"tempUncompressFileName");
    }else{
        _options_check(false,"count");
    }
    hpatch_printPath_utf8((std::string("oldZip   : \"")+oldZipPath+"\"\n").c_str());
    hpatch_printPath_utf8((std::string("zipDiff  : \"")+zipDiffPath+"\"\n").c_str());
    hpatch_printPath_utf8((std::string("outNewZip: \"")+outNewZipPath+"\"\n").c_str());
    if (tempUncompressFileName!=0){
        printf("maxUncompressMemory:%" PRSizeT "\n",maxUncompressMemory);
        hpatch_printPath_utf8((std::string("tempUncompressFileName:\"")+tempUncompressFileName+"\"\n").c_str());
    }
    
    double time0=clock_s();
    int exitCode=ZipPatch(oldZipPath,zipDiffPath,outNewZipPath,
                          maxUncompressMemory,tempUncompressFileName,(int)threadNum);
    double time1=clock_s();
    if (exitCode==PATCH_SUCCESS)
        printf("  zip file patch ok!\n");
    else
        printf("  zip file patch error!\n");
    printf("\nZipPatch time: %.3f s\n",(time1-time0));
    return exitCode;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x290, %rsp            # imm = 0x290
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movl $0xffffffff, -0x3c(%rbp) # imm = 0xFFFFFFFF
movq $0x0, -0x48(%rbp)
leaq -0x70(%rbp), %rdi
xorl %esi, %esi
movl $0x28, %edx
callq 0x3180
movl $0x0, -0x74(%rbp)
movl $0x1, -0x78(%rbp)
movl -0x78(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x343f4
movq -0x10(%rbp), %rax
movslq -0x78(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x80(%rbp)
cmpq $0x0, -0x80(%rbp)
je 0x34209
movq -0x80(%rbp), %rdi
callq 0x3100
cmpq $0x0, %rax
ja 0x34228
leaq 0xf888(%rip), %rdi      # 0x43a98
movb $0x0, %al
callq 0x3040
callq 0x34ac0
movl $0x1, -0x4(%rbp)
jmp 0x34aa2
movq -0x80(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
je 0x34274
cmpl $0x5, -0x74(%rbp)
jl 0x34259
leaq 0xf869(%rip), %rdi      # 0x43aaa
movb $0x0, %al
callq 0x3040
callq 0x34ac0
movl $0x1, -0x4(%rbp)
jmp 0x34aa2
movq -0x80(%rbp), %rcx
movslq -0x74(%rbp), %rax
movq %rcx, -0x70(%rbp,%rax,8)
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0x343e6
cmpq $0x0, -0x80(%rbp)
je 0x34287
movq -0x80(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
je 0x342a6
leaq 0xf80a(%rip), %rdi      # 0x43a98
movb $0x0, %al
callq 0x3040
callq 0x34ac0
movl $0x1, -0x4(%rbp)
jmp 0x34aa2
movq -0x80(%rbp), %rax
movsbl 0x1(%rax), %eax
movl %eax, -0x254(%rbp)
subl $0x70, %eax
je 0x3430a
jmp 0x342bb
movl -0x254(%rbp), %eax
subl $0x76, %eax
jne 0x343c5
jmp 0x342cc
cmpl $-0x1, -0x3c(%rbp)
jne 0x342df
movq -0x80(%rbp), %rax
movsbl 0x2(%rax), %eax
cmpl $0x0, %eax
je 0x342fe
leaq 0xf7da(%rip), %rdi      # 0x43ac0
movb $0x0, %al
callq 0x3040
callq 0x34ac0
movl $0x1, -0x4(%rbp)
jmp 0x34aa2
movl $0x1, -0x3c(%rbp)
jmp 0x343e4
cmpq $0x0, -0x48(%rbp)
jne 0x3431e
movq -0x80(%rbp), %rax
movsbl 0x2(%rax), %eax
cmpl $0x2d, %eax
je 0x3433d
leaq 0xf7ae(%rip), %rdi      # 0x43ad3
movb $0x0, %al
callq 0x3040
callq 0x34ac0
movl $0x1, -0x4(%rbp)
jmp 0x34aa2
movq -0x80(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rax
movq %rax, -0x260(%rbp)
movq -0x88(%rbp), %rdi
callq 0x3100
movq -0x260(%rbp), %rdi
movq %rax, %rsi
leaq -0x48(%rbp), %rdx
callq 0x34ae0
cmpl $0x0, %eax
jne 0x3439d
leaq 0xf74e(%rip), %rdi      # 0x43ad3
movb $0x0, %al
callq 0x3040
callq 0x34ac0
movl $0x1, -0x4(%rbp)
jmp 0x34aa2
cmpq $0x1, -0x48(%rbp)
jae 0x343c3
leaq 0xf728(%rip), %rdi      # 0x43ad3
movb $0x0, %al
callq 0x3040
callq 0x34ac0
movl $0x1, -0x4(%rbp)
jmp 0x34aa2
jmp 0x343e4
leaq 0xf71c(%rip), %rdi      # 0x43ae8
movb $0x0, %al
callq 0x3040
callq 0x34ac0
movl $0x1, -0x4(%rbp)
jmp 0x34aa2
jmp 0x343e6
movl -0x78(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x78(%rbp)
jmp 0x341d7
cmpl $-0x1, -0x3c(%rbp)
jne 0x34401
movl $0x0, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
je 0x34429
leaq 0xf6ed(%rip), %rdi      # 0x43afb
movb $0x0, %al
callq 0x3040
cmpl $0x0, -0x74(%rbp)
jne 0x34427
movl $0x0, -0x4(%rbp)
jmp 0x34aa2
jmp 0x34429
cmpq $0x0, -0x48(%rbp)
jne 0x3443a
movq $0x1, -0x48(%rbp)
jmp 0x3444e
cmpq $0x100, -0x48(%rbp)     # imm = 0x100
jbe 0x3444c
movq $0x100, -0x48(%rbp)     # imm = 0x100
jmp 0x3444e
cmpl $0x3, -0x74(%rbp)
jne 0x34471
movq -0x70(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x68(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0x28(%rbp)
jmp 0x3453e
cmpl $0x5, -0x74(%rbp)
jne 0x3451d
movq -0x70(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x68(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x268(%rbp)
movq -0x58(%rbp), %rdi
callq 0x3100
movq -0x268(%rbp), %rdi
movq %rax, %rsi
leaq -0x30(%rbp), %rdx
callq 0x34c40
cmpl $0x0, %eax
jne 0x344de
leaq 0xf655(%rip), %rdi      # 0x43b1b
movb $0x0, %al
callq 0x3040
callq 0x34ac0
movl $0x1, -0x4(%rbp)
jmp 0x34aa2
movq -0x50(%rbp), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x344fc
movq -0x38(%rbp), %rdi
callq 0x3100
cmpq $0x0, %rax
ja 0x3451b
leaq 0xf63c(%rip), %rdi      # 0x43b3f
movb $0x0, %al
callq 0x3040
callq 0x34ac0
movl $0x1, -0x4(%rbp)
jmp 0x34aa2
jmp 0x3453c
leaq 0xf586(%rip), %rdi      # 0x43aaa
movb $0x0, %al
callq 0x3040
callq 0x34ac0
movl $0x1, -0x4(%rbp)
jmp 0x34aa2
jmp 0x3453e
leaq -0xe9(%rbp), %rdi
movq %rdi, -0x270(%rbp)
callq 0x3460
movq -0x270(%rbp), %rdx
leaq 0xf607(%rip), %rsi      # 0x43b66
leaq -0xe8(%rbp), %rdi
callq 0x34e50
jmp 0x3456d
movq -0x18(%rbp), %rdx
leaq -0xc8(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
callq 0x34e00
jmp 0x34586
leaq 0xf5e6(%rip), %rdx      # 0x43b73
leaq -0xa8(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x34e00
jmp 0x345a2
leaq -0xa8(%rbp), %rdi
callq 0x30e0
movq %rax, %rdi
callq 0x14d10
jmp 0x345b8
leaq -0xa8(%rbp), %rdi
callq 0x31b0
leaq -0xc8(%rbp), %rdi
callq 0x31b0
leaq -0xe8(%rbp), %rdi
callq 0x31b0
leaq -0xe9(%rbp), %rdi
callq 0x32c0
leaq -0x161(%rbp), %rdi
movq %rdi, -0x278(%rbp)
callq 0x3460
movq -0x278(%rbp), %rdx
leaq 0xf56d(%rip), %rsi      # 0x43b76
leaq -0x160(%rbp), %rdi
callq 0x34e50
jmp 0x34617
movq -0x20(%rbp), %rdx
leaq -0x140(%rbp), %rdi
leaq -0x160(%rbp), %rsi
callq 0x34e00
jmp 0x34630
leaq 0xf53c(%rip), %rdx      # 0x43b73
leaq -0x120(%rbp), %rdi
leaq -0x140(%rbp), %rsi
callq 0x34e00
jmp 0x3464c
leaq -0x120(%rbp), %rdi
callq 0x30e0
movq %rax, %rdi
callq 0x14d10
jmp 0x34662
leaq -0x120(%rbp), %rdi
callq 0x31b0
leaq -0x140(%rbp), %rdi
callq 0x31b0
leaq -0x160(%rbp), %rdi
callq 0x31b0
leaq -0x161(%rbp), %rdi
callq 0x32c0
leaq -0x1c9(%rbp), %rdi
movq %rdi, -0x280(%rbp)
callq 0x3460
movq -0x280(%rbp), %rdx
leaq 0xf4d0(%rip), %rsi      # 0x43b83
leaq -0x1c8(%rbp), %rdi
callq 0x34e50
jmp 0x346c1
movq -0x28(%rbp), %rdx
leaq -0x1a8(%rbp), %rdi
leaq -0x1c8(%rbp), %rsi
callq 0x34e00
jmp 0x346da
leaq 0xf492(%rip), %rdx      # 0x43b73
leaq -0x188(%rbp), %rdi
leaq -0x1a8(%rbp), %rsi
callq 0x34e00
jmp 0x346f6
leaq -0x188(%rbp), %rdi
callq 0x30e0
movq %rax, %rdi
callq 0x14d10
jmp 0x3470c
leaq -0x188(%rbp), %rdi
callq 0x31b0
leaq -0x1a8(%rbp), %rdi
callq 0x31b0
leaq -0x1c8(%rbp), %rdi
callq 0x31b0
leaq -0x1c9(%rbp), %rdi
callq 0x32c0
cmpq $0x0, -0x38(%rbp)
je 0x34a14
movq -0x30(%rbp), %rsi
leaq 0xf43e(%rip), %rdi      # 0x43b90
xorl %eax, %eax
callq 0x3040
leaq -0x231(%rbp), %rdi
movq %rdi, -0x288(%rbp)
callq 0x3460
movq -0x288(%rbp), %rdx
leaq 0xf42f(%rip), %rsi      # 0x43ba9
leaq -0x230(%rbp), %rdi
callq 0x34e50
jmp 0x34788
movq -0x38(%rbp), %rdx
leaq -0x210(%rbp), %rdi
leaq -0x230(%rbp), %rsi
callq 0x34e00
jmp 0x347a1
leaq 0xf3cb(%rip), %rdx      # 0x43b73
leaq -0x1f0(%rbp), %rdi
leaq -0x210(%rbp), %rsi
callq 0x34e00
jmp 0x347bd
leaq -0x1f0(%rbp), %rdi
callq 0x30e0
movq %rax, %rdi
callq 0x14d10
jmp 0x347d3
leaq -0x1f0(%rbp), %rdi
callq 0x31b0
leaq -0x210(%rbp), %rdi
callq 0x31b0
leaq -0x230(%rbp), %rdi
callq 0x31b0
leaq -0x231(%rbp), %rdi
callq 0x32c0
jmp 0x34a14
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0x3487a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0x3486e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0x34862
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x31b0
leaq -0xc8(%rbp), %rdi
callq 0x31b0
leaq -0xe8(%rbp), %rdi
callq 0x31b0
leaq -0xe9(%rbp), %rdi
callq 0x32c0
jmp 0x34aae
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0x348fd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0x348f1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0x348e5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
leaq -0x120(%rbp), %rdi
callq 0x31b0
leaq -0x140(%rbp), %rdi
callq 0x31b0
leaq -0x160(%rbp), %rdi
callq 0x31b0
leaq -0x161(%rbp), %rdi
callq 0x32c0
jmp 0x34aae
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0x34980
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0x34974
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0x34968
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
leaq -0x188(%rbp), %rdi
callq 0x31b0
leaq -0x1a8(%rbp), %rdi
callq 0x31b0
leaq -0x1c8(%rbp), %rdi
callq 0x31b0
leaq -0x1c9(%rbp), %rdi
callq 0x32c0
jmp 0x34aae
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0x34a03
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0x349f7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0x349eb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
leaq -0x1f0(%rbp), %rdi
callq 0x31b0
leaq -0x210(%rbp), %rdi
callq 0x31b0
leaq -0x230(%rbp), %rdi
callq 0x31b0
leaq -0x231(%rbp), %rdi
callq 0x32c0
jmp 0x34aae
callq 0x34d70
movsd %xmm0, -0x240(%rbp)
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x30(%rbp), %rcx
movq -0x38(%rbp), %r8
movq -0x48(%rbp), %rax
movl %eax, %r9d
callq 0x2c660
movl %eax, -0x244(%rbp)
callq 0x34d70
movsd %xmm0, -0x250(%rbp)
cmpl $0x0, -0x244(%rbp)
jne 0x34a6d
leaq 0xf15e(%rip), %rdi      # 0x43bc2
movb $0x0, %al
callq 0x3040
jmp 0x34a7b
leaq 0xf164(%rip), %rdi      # 0x43bd8
movb $0x0, %al
callq 0x3040
movsd -0x250(%rbp), %xmm0
subsd -0x240(%rbp), %xmm0
leaq 0xf15f(%rip), %rdi      # 0x43bf1
movb $0x1, %al
callq 0x3040
movl -0x244(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x290, %rsp            # imm = 0x290
popq %rbp
retq
movq -0xf8(%rbp), %rdi
callq 0x3450
nopw (%rax,%rax)