// File: sisong[P]ApkDiffPatch/HDiffPatch/libHDiffPatch/HPatchLite/hpatch_lite.c
// Function: hpatchi_inplace_open
hpi_BOOL hpatchi_inplace_open(hpi_TInputStreamHandle diff_data,hpi_TInputStream_read read_diff,
                              hpi_compressType* out_compress_type,hpi_pos_t* out_newSize,
                              hpi_pos_t* out_uncompressSize,hpi_size_t* out_extraSafeSize){
    #define kHPatchLite_inplaceCode     2
    hpi_size_t lenn=hpi_kInplaceHeadSize;
    hpi_size_t lenu,lene;
    hpi_byte   buf[(hpi_kInplaceHeadSize>sizeof(hpi_pos_t))?hpi_kInplaceHeadSize:sizeof(hpi_pos_t)];
    
    _CHECK(read_diff(diff_data,buf,&lenn));
    //HPatchLite type tag 2byte, version code(high 2bit)
    lenu=buf[3];
    _SAFE_CHECK((lenn==hpi_kInplaceHeadSize)&(buf[0]=='h')&(buf[1]=='I')&((lenu>>6)==kHPatchLite_inplaceCode));
    *out_compress_type=buf[2]; //compress type
    lenn=lenu&7; //newSize bytes(low 3bit)
    lenu=(lenu>>3)&7; //uncompressSize bytes(mid 3bit)
    lene=buf[4];

    _SAFE_CHECK((lenn<=sizeof(hpi_pos_t))&(lenu<=sizeof(hpi_pos_t))&(lene<=sizeof(hpi_size_t)));
    _CHECK(read_diff(diff_data,buf,&lenn));
    *out_newSize=_hpi_readSize(buf,lenn);
    _CHECK(read_diff(diff_data,buf,&lenu));
    *out_uncompressSize=_hpi_readSize(buf,lenu);
    _CHECK(read_diff(diff_data,buf,&lene));
    *out_extraSafeSize=(hpi_size_t)_hpi_readSize(buf,lene);
    return hpi_TRUE;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movl $0x5, -0x3c(%rbp)
movq -0x18(%rbp), %rax
movq -0x10(%rbp), %rdi
leaq -0x49(%rbp), %rsi
leaq -0x3c(%rbp), %rdx
callq *%rax
cmpl $0x0, %eax
jne 0x185aa
movl $0x0, -0x4(%rbp)
jmp 0x18716
movzbl -0x46(%rbp), %eax
movl %eax, -0x40(%rbp)
cmpl $0x5, -0x3c(%rbp)
sete %al
andb $0x1, %al
movzbl %al, %eax
movzbl -0x49(%rbp), %ecx
cmpl $0x68, %ecx
sete %cl
andb $0x1, %cl
movzbl %cl, %ecx
andl %ecx, %eax
movzbl -0x48(%rbp), %ecx
cmpl $0x49, %ecx
sete %cl
andb $0x1, %cl
movzbl %cl, %ecx
andl %ecx, %eax
movl -0x40(%rbp), %ecx
shrl $0x6, %ecx
cmpl $0x2, %ecx
sete %cl
andb $0x1, %cl
movzbl %cl, %ecx
andl %ecx, %eax
cmpl $0x0, %eax
jne 0x18606
movl $0x0, -0x4(%rbp)
jmp 0x18716
movzbl -0x47(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movl -0x40(%rbp), %eax
andl $0x7, %eax
movl %eax, -0x3c(%rbp)
movl -0x40(%rbp), %eax
shrl $0x3, %eax
andl $0x7, %eax
movl %eax, -0x40(%rbp)
movzbl -0x45(%rbp), %eax
movl %eax, -0x44(%rbp)
movl -0x3c(%rbp), %eax
cmpq $0x4, %rax
setbe %al
andb $0x1, %al
movzbl %al, %eax
movl -0x40(%rbp), %ecx
cmpq $0x4, %rcx
setbe %cl
andb $0x1, %cl
movzbl %cl, %ecx
andl %ecx, %eax
movl -0x44(%rbp), %ecx
cmpq $0x4, %rcx
setbe %cl
andb $0x1, %cl
movzbl %cl, %ecx
andl %ecx, %eax
cmpl $0x0, %eax
jne 0x18670
movl $0x0, -0x4(%rbp)
jmp 0x18716
movq -0x18(%rbp), %rax
movq -0x10(%rbp), %rdi
leaq -0x49(%rbp), %rsi
leaq -0x3c(%rbp), %rdx
callq *%rax
cmpl $0x0, %eax
jne 0x18693
movl $0x0, -0x4(%rbp)
jmp 0x18716
leaq -0x49(%rbp), %rdi
movl -0x3c(%rbp), %esi
callq 0x18070
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movq -0x18(%rbp), %rax
movq -0x10(%rbp), %rdi
leaq -0x49(%rbp), %rsi
leaq -0x40(%rbp), %rdx
callq *%rax
cmpl $0x0, %eax
jne 0x186c7
movl $0x0, -0x4(%rbp)
jmp 0x18716
leaq -0x49(%rbp), %rdi
movl -0x40(%rbp), %esi
callq 0x18070
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, (%rax)
movq -0x18(%rbp), %rax
movq -0x10(%rbp), %rdi
leaq -0x49(%rbp), %rsi
leaq -0x44(%rbp), %rdx
callq *%rax
cmpl $0x0, %eax
jne 0x186fb
movl $0x0, -0x4(%rbp)
jmp 0x18716
leaq -0x49(%rbp), %rdi
movl -0x44(%rbp), %esi
callq 0x18070
movl %eax, %ecx
movq -0x38(%rbp), %rax
movl %ecx, (%rax)
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nop