// File: sisong[P]ApkDiffPatch/HDiffPatch/file_for_patch.c
// Function: TFileStreamOutput_write_file
static hpatch_BOOL _TFileStreamOutput_write_file(const hpatch_TStreamOutput* stream,hpatch_StreamPos_t writeToPos,
                                                     const TByte* data,const TByte* data_end){
        size_t writeLen;
        hpatch_TFileStreamOutput* self=(hpatch_TFileStreamOutput*)stream->streamImport;
        assert(data<=data_end);
        assert(self->m_offset==0);
        writeLen=(size_t)(data_end-data);
        if (writeLen==0) return hpatch_TRUE;
        if ((writeLen>self->base.streamSize)
            ||(writeToPos>self->base.streamSize-writeLen)) _ferr_returnv(EFBIG);
        if (self->is_in_readModel){
            self->is_in_readModel=hpatch_FALSE;
            self->m_fpos=hpatch_kNullStreamPos;
        }
        if (writeToPos!=self->m_fpos){
            if (self->is_random_out){
                if (!_import_fileFlush(self->m_file)) _rw_ferr_return(); //for lseek64 safe
                if (!_import_fileSeek64To(self->m_file,writeToPos)) _rw_ferr_return();
                self->m_fpos=writeToPos;
            }else{
                _ferr_returnv(ERANGE); //must continue write at self->m_fpos
            }
        }
        if (!_import_fileWrite(self->m_file,data,data+writeLen)) _rw_ferr_return();
        self->m_fpos=writeToPos+writeLen;
        self->out_length=(self->out_length>=self->m_fpos)?self->out_length:self->m_fpos;
        return hpatch_TRUE;
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x20(%rbp), %rax
cmpq -0x28(%rbp), %rax
ja 0x8e4e2
jmp 0x8e501
leaq 0x277c9(%rip), %rdi     # 0xb5cb2
leaq 0x2742c(%rip), %rsi     # 0xb591c
movl $0x26a, %edx            # imm = 0x26A
leaq 0x277c5(%rip), %rcx     # 0xb5cc1
callq 0x4270
movq -0x38(%rbp), %rax
cmpq $0x0, 0x30(%rax)
jne 0x8e50e
jmp 0x8e52d
leaq 0x27826(%rip), %rdi     # 0xb5d3b
leaq 0x27400(%rip), %rsi     # 0xb591c
movl $0x26b, %edx            # imm = 0x26B
leaq 0x27799(%rip), %rcx     # 0xb5cc1
callq 0x4270
movq -0x28(%rbp), %rax
movq -0x20(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x8e54f
movl $0x1, -0x4(%rbp)
jmp 0x8e8d4
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rcx
cmpq 0x8(%rcx), %rax
ja 0x8e572
movq -0x18(%rbp), %rax
movq -0x38(%rbp), %rcx
movq 0x8(%rcx), %rcx
subq -0x30(%rbp), %rcx
cmpq %rcx, %rax
jbe 0x8e5e4
jmp 0x8e574
jmp 0x8e576
callq 0x4050
movl $0x1b, (%rax)
jmp 0x8e583
movq -0x38(%rbp), %rax
cmpl $0x1b, 0x38(%rax)
je 0x8e5d4
movq -0x38(%rbp), %rax
cmpl $0x0, 0x38(%rax)
jne 0x8e5a2
movq -0x38(%rbp), %rax
movl $0x1b, 0x38(%rax)
movq 0x57a27(%rip), %rax     # 0xe5fd0
movq (%rax), %rax
movq %rax, -0x50(%rbp)
movl $0x1b, %edi
callq 0x4100
movq -0x50(%rbp), %rdi
movq %rax, %rcx
leaq 0x1e757(%rip), %rsi     # 0xacd1f
movl $0x1b, %edx
movb $0x0, %al
callq 0x4520
jmp 0x8e5d6
jmp 0x8e5d8
movl $0x0, -0x4(%rbp)
jmp 0x8e8d4
movq -0x38(%rbp), %rax
cmpl $0x0, 0x40(%rax)
je 0x8e605
movq -0x38(%rbp), %rax
movl $0x0, 0x40(%rax)
movq -0x38(%rbp), %rax
movq $-0x1, 0x28(%rax)
movq -0x18(%rbp), %rax
movq -0x38(%rbp), %rcx
cmpq 0x28(%rcx), %rax
je 0x8e7d7
movq -0x38(%rbp), %rax
cmpl $0x0, 0x3c(%rax)
je 0x8e763
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x8eda0
cmpl $0x0, %eax
jne 0x8e6bb
movq -0x38(%rbp), %rax
movq $-0x1, 0x28(%rax)
callq 0x4050
movl (%rax), %eax
movl %eax, -0x3c(%rbp)
movq -0x38(%rbp), %rax
movl 0x38(%rax), %eax
cmpl -0x3c(%rbp), %eax
je 0x8e6ab
cmpl $0x0, -0x3c(%rbp)
je 0x8e6ab
movq -0x38(%rbp), %rax
cmpl $0x0, 0x38(%rax)
jne 0x8e677
movl -0x3c(%rbp), %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x38(%rax)
movq 0x57952(%rip), %rax     # 0xe5fd0
movq (%rax), %rax
movq %rax, -0x60(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0x54(%rbp)
movl -0x3c(%rbp), %edi
callq 0x4100
movq -0x60(%rbp), %rdi
movl -0x54(%rbp), %edx
movq %rax, %rcx
leaq 0x1e67b(%rip), %rsi     # 0xacd1f
movb $0x0, %al
callq 0x4520
jmp 0x8e6ad
jmp 0x8e6af
movl $0x0, -0x4(%rbp)
jmp 0x8e8d4
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x18(%rbp), %rsi
callq 0x8efe0
cmpl $0x0, %eax
jne 0x8e755
movq -0x38(%rbp), %rax
movq $-0x1, 0x28(%rax)
callq 0x4050
movl (%rax), %eax
movl %eax, -0x40(%rbp)
movq -0x38(%rbp), %rax
movl 0x38(%rax), %eax
cmpl -0x40(%rbp), %eax
je 0x8e745
cmpl $0x0, -0x40(%rbp)
je 0x8e745
movq -0x38(%rbp), %rax
cmpl $0x0, 0x38(%rax)
jne 0x8e711
movl -0x40(%rbp), %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x38(%rax)
movq 0x578b8(%rip), %rax     # 0xe5fd0
movq (%rax), %rax
movq %rax, -0x70(%rbp)
movl -0x40(%rbp), %eax
movl %eax, -0x64(%rbp)
movl -0x40(%rbp), %edi
callq 0x4100
movq -0x70(%rbp), %rdi
movl -0x64(%rbp), %edx
movq %rax, %rcx
leaq 0x1e5e1(%rip), %rsi     # 0xacd1f
movb $0x0, %al
callq 0x4520
jmp 0x8e747
jmp 0x8e749
movl $0x0, -0x4(%rbp)
jmp 0x8e8d4
movq -0x18(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x28(%rax)
jmp 0x8e7d5
jmp 0x8e765
jmp 0x8e767
callq 0x4050
movl $0x22, (%rax)
jmp 0x8e774
movq -0x38(%rbp), %rax
cmpl $0x22, 0x38(%rax)
je 0x8e7c5
movq -0x38(%rbp), %rax
cmpl $0x0, 0x38(%rax)
jne 0x8e793
movq -0x38(%rbp), %rax
movl $0x22, 0x38(%rax)
movq 0x57836(%rip), %rax     # 0xe5fd0
movq (%rax), %rax
movq %rax, -0x78(%rbp)
movl $0x22, %edi
callq 0x4100
movq -0x78(%rbp), %rdi
movq %rax, %rcx
leaq 0x1e566(%rip), %rsi     # 0xacd1f
movl $0x22, %edx
movb $0x0, %al
callq 0x4520
jmp 0x8e7c7
jmp 0x8e7c9
movl $0x0, -0x4(%rbp)
jmp 0x8e8d4
jmp 0x8e7d7
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x20(%rbp), %rsi
movq -0x20(%rbp), %rdx
addq -0x30(%rbp), %rdx
callq 0x8d990
cmpl $0x0, %eax
jne 0x8e87c
movq -0x38(%rbp), %rax
movq $-0x1, 0x28(%rax)
callq 0x4050
movl (%rax), %eax
movl %eax, -0x44(%rbp)
movq -0x38(%rbp), %rax
movl 0x38(%rax), %eax
cmpl -0x44(%rbp), %eax
je 0x8e86f
cmpl $0x0, -0x44(%rbp)
je 0x8e86f
movq -0x38(%rbp), %rax
cmpl $0x0, 0x38(%rax)
jne 0x8e835
movl -0x44(%rbp), %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x38(%rax)
movq 0x57794(%rip), %rax     # 0xe5fd0
movq (%rax), %rax
movq %rax, -0x88(%rbp)
movl -0x44(%rbp), %eax
movl %eax, -0x7c(%rbp)
movl -0x44(%rbp), %edi
callq 0x4100
movq -0x88(%rbp), %rdi
movl -0x7c(%rbp), %edx
movq %rax, %rcx
leaq 0x1e4b7(%rip), %rsi     # 0xacd1f
movb $0x0, %al
callq 0x4520
jmp 0x8e871
jmp 0x8e873
movl $0x0, -0x4(%rbp)
jmp 0x8e8d4
movq -0x18(%rbp), %rcx
addq -0x30(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x38(%rbp), %rax
movq 0x48(%rax), %rax
movq -0x38(%rbp), %rcx
cmpq 0x28(%rcx), %rax
jb 0x8e8af
movq -0x38(%rbp), %rax
movq 0x48(%rax), %rax
movq %rax, -0x90(%rbp)
jmp 0x8e8be
movq -0x38(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x48(%rax)
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x90, %rsp
popq %rbp
retq