// File: /workspace/github_cpp_makefile_star2_O1/sisong[P]ApkDiffPatch/lzma/C/Lzma2Enc.c
// Function: Lzma2Enc_EncodeMt1
static SRes Lzma2Enc_EncodeMt1(
    CLzma2Enc *me,
    CLzma2EncInt *p,
    ISeqOutStreamPtr outStream,
    Byte *outBuf, size_t *outBufSize,
    ISeqInStreamPtr inStream,
    const Byte *inData, size_t inDataSize,
    int finished,
    ICompressProgressPtr progress)
{
  UInt64 unpackTotal = 0;
  UInt64 packTotal = 0;
  size_t outLim = 0;
  CLimitedSeqInStream limitedInStream;

  if (outBuf)
  {
    outLim = *outBufSize;
    *outBufSize = 0;
  }

  if (!p->enc)
  {
    p->propsAreSet = False;
    p->enc = LzmaEnc_Create(me->alloc);
    if (!p->enc)
      return SZ_ERROR_MEM;
  }

  limitedInStream.realStream = inStream;
  if (inStream)
  {
    limitedInStream.vt.Read = LimitedSeqInStream_Read;
  }
  
  if (!outBuf)
  {
    // outStream version works only in one thread. So we use CLzma2Enc::tempBufLzma
    if (!me->tempBufLzma)
    {
      me->tempBufLzma = (Byte *)ISzAlloc_Alloc(me->alloc, LZMA2_CHUNK_SIZE_COMPRESSED_MAX);
      if (!me->tempBufLzma)
        return SZ_ERROR_MEM;
    }
  }

  RINOK(Lzma2EncInt_InitStream(p, &me->props))

  for (;;)
  {
    SRes res = SZ_OK;
    SizeT inSizeCur = 0;

    Lzma2EncInt_InitBlock(p);
    
    LimitedSeqInStream_Init(&limitedInStream);
    limitedInStream.limit = me->props.blockSize;

    if (inStream)
    {
      UInt64 expected = (UInt64)(Int64)-1;
      // inStream version works only in one thread. So we use CLzma2Enc::expectedDataSize
      if (me->expectedDataSize != (UInt64)(Int64)-1
          && me->expectedDataSize >= unpackTotal)
        expected = me->expectedDataSize - unpackTotal;
      if (me->props.blockSize != LZMA2_ENC_PROPS_BLOCK_SIZE_SOLID
          && expected > me->props.blockSize)
        expected = (size_t)me->props.blockSize;

      LzmaEnc_SetDataSize(p->enc, expected);

      RINOK(LzmaEnc_PrepareForLzma2(p->enc,
          &limitedInStream.vt,
          LZMA2_KEEP_WINDOW_SIZE,
          me->alloc,
          me->allocBig))
    }
    else
    {
      inSizeCur = (SizeT)(inDataSize - (size_t)unpackTotal);
      if (me->props.blockSize != LZMA2_ENC_PROPS_BLOCK_SIZE_SOLID
          && inSizeCur > me->props.blockSize)
        inSizeCur = (SizeT)(size_t)me->props.blockSize;
    
      // LzmaEnc_SetDataSize(p->enc, inSizeCur);
      
      RINOK(LzmaEnc_MemPrepare(p->enc,
          inData + (size_t)unpackTotal, inSizeCur,
          LZMA2_KEEP_WINDOW_SIZE,
          me->alloc,
          me->allocBig))
    }

    for (;;)
    {
      size_t packSize = LZMA2_CHUNK_SIZE_COMPRESSED_MAX;
      if (outBuf)
        packSize = outLim - (size_t)packTotal;
      
      res = Lzma2EncInt_EncodeSubblock(p,
          outBuf ? outBuf + (size_t)packTotal : me->tempBufLzma, &packSize,
          outBuf ? NULL : outStream);
      
      if (res != SZ_OK)
        break;

      packTotal += packSize;
      if (outBuf)
        *outBufSize = (size_t)packTotal;
      
      res = Progress(progress, unpackTotal + p->srcPos, packTotal);
      if (res != SZ_OK)
        break;

      /*
      if (LzmaEnc_GetNumAvailableBytes(p->enc) == 0)
        break;
      */

      if (packSize == 0)
        break;
    }
    
    LzmaEnc_Finish(p->enc);
    
    unpackTotal += p->srcPos;
    
    RINOK(res)

    if (p->srcPos != (inStream ? limitedInStream.processed : inSizeCur))
      return SZ_ERROR_FAIL;
    
    if (inStream ? limitedInStream.finished : (unpackTotal == inDataSize))
    {
      if (finished)
      {
        if (outBuf)
        {
          const size_t destPos = *outBufSize;
          if (destPos >= outLim)
            return SZ_ERROR_OUTPUT_EOF;
          outBuf[destPos] = LZMA2_CONTROL_EOF; // 0
          *outBufSize = destPos + 1;
        }
        else
        {
          const Byte b = LZMA2_CONTROL_EOF; // 0;
          if (ISeqOutStream_Write(outStream, &b, 1) != 1)
            return SZ_ERROR_WRITE;
        }
      }
      return SZ_OK;
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %r9, 0x38(%rsp)
movq %r8, %rbx
movq %rcx, %r15
movq %rdx, 0x58(%rsp)
movq %rsi, %r13
movq %rdi, 0x8(%rsp)
testq %rcx, %rcx
je 0x32a2c
movq (%rbx), %rax
movq %rax, 0x40(%rsp)
movq $0x0, (%rbx)
jmp 0x32a35
movq $0x0, 0x40(%rsp)
cmpq $0x0, (%r13)
jne 0x32a5c
movb $0x0, 0x8(%r13)
movq 0x8(%rsp), %rax
movq 0x78(%rax), %rdi
callq 0x33628
movq %rax, (%r13)
testq %rax, %rax
je 0x3303f
movq 0x38(%rsp), %rax
movq %rax, 0x98(%rsp)
testq %rax, %rax
je 0x32a7d
leaq 0x5f7(%rip), %rax       # 0x3306c
movq %rax, 0x90(%rsp)
testq %r15, %r15
jne 0x32aab
movq 0x8(%rsp), %rax
cmpq $0x0, 0x70(%rax)
jne 0x32aab
movq 0x8(%rsp), %r14
movq 0x78(%r14), %rdi
movl $0x10010, %esi          # imm = 0x10010
callq *(%rdi)
movq %rax, 0x70(%r14)
testq %rax, %rax
je 0x3303f
cmpb $0x0, 0x8(%r13)
jne 0x32afb
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rsi
movq $0x5, 0x20(%rsp)
movq (%r13), %rdi
callq 0x334f0
movl %eax, %edx
testl %eax, %eax
jne 0x32af5
movq (%r13), %rdi
leaq 0x10(%rsp), %rsi
movl %edx, %ebp
leaq 0x20(%rsp), %rdx
callq 0x366a0
movl %ebp, %edx
testl %eax, %eax
cmovnel %eax, %edx
je 0x33058
xorl %eax, %eax
testb %al, %al
je 0x32afd
xorl %edx, %edx
testl %edx, %edx
jne 0x33044
movl $0x10000, %r14d         # imm = 0x10000
xorl %r12d, %r12d
movq $0x0, 0x28(%rsp)
movq %rbx, 0x68(%rsp)
movq %r15, 0x60(%rsp)
movq 0x8(%rsp), %rbx
movq %r12, 0x18(%rsp)
movl %edx, %r12d
xorl %eax, %eax
movq %rax, 0x10(%r13)
movw $0x101, 0xa(%r13)       # imm = 0x101
movq $-0x1, 0xa0(%rsp)
movq %rax, 0xa8(%rsp)
movl $0x0, 0xb0(%rsp)
movq 0x50(%rbx), %rax
movq %rax, 0xa0(%rsp)
cmpq $0x0, 0x38(%rsp)
je 0x32bdf
movq 0x68(%rbx), %rcx
movq %rcx, %rdx
subq 0x28(%rsp), %rdx
setb %sil
testb $0x1, %sil
movq $-0x1, %rsi
cmovneq %rsi, %rdx
cmpq $-0x1, %rcx
cmoveq %rcx, %rdx
cmpq %rax, %rdx
movq %rax, %rsi
cmovbq %rdx, %rsi
cmpq $-0x1, %rax
cmoveq %rdx, %rsi
movq (%r13), %rdi
callq 0x33620
movq (%r13), %rdi
movq 0x78(%rbx), %rcx
movq 0x80(%rbx), %r8
leaq 0x90(%rsp), %rsi
movl $0x200000, %edx         # imm = 0x200000
callq 0x337d6
xorl %ebp, %ebp
testl %eax, %eax
movl %r12d, %edx
cmovnel %eax, %edx
jne 0x32c35
jmp 0x32c3f
movq 0xf8(%rsp), %rcx
movq 0x28(%rsp), %rdx
subq %rdx, %rcx
cmpq %rax, %rcx
movq %rax, %rbp
cmovbq %rcx, %rbp
cmpq $-0x1, %rax
cmoveq %rcx, %rbp
movq (%r13), %rdi
movq 0xf0(%rsp), %rax
leaq (%rax,%rdx), %rsi
movq 0x78(%rbx), %r8
movq 0x80(%rbx), %r9
movq %rbp, %rdx
movl $0x200000, %ecx         # imm = 0x200000
callq 0x33a45
testl %eax, %eax
movl %r12d, %edx
cmovnel %eax, %edx
je 0x32c3f
xorl %ebp, %ebp
movq 0x18(%rsp), %r12
jmp 0x32fb1
movq 0x18(%rsp), %r12
movq %rbp, 0x78(%rsp)
movl %edx, 0x54(%rsp)
movq 0x40(%rsp), %rcx
subq %r12, %rcx
testq %r15, %r15
movl $0x10010, %eax          # imm = 0x10010
cmoveq %rax, %rcx
je 0x32c6c
leaq (%r15,%r12), %rbp
xorl %r15d, %r15d
jmp 0x32c7a
movq 0x8(%rsp), %rax
movq 0x70(%rax), %rbp
movq 0x58(%rsp), %r15
movq %rcx, 0x20(%rsp)
movl $0x200000, 0x10(%rsp)   # imm = 0x200000
cmpb $0x1, 0xb(%r13)
movl $0x6, %ebx
sbbq $0x0, %rbx
movq %rcx, %rax
subq %rbx, %rax
movq %r12, 0x18(%rsp)
jae 0x32cac
movl $0x7, %edx
jmp 0x32edb
movq %rcx, 0x48(%rsp)
movq %rax, 0x20(%rsp)
movq (%r13), %rdi
callq 0x3324a
movq (%r13), %rdi
movzbl 0xa(%r13), %esi
addq %rbp, %rbx
movq %rbx, %rdx
leaq 0x20(%rsp), %rcx
movl $0x10000, %r8d          # imm = 0x10000
leaq 0x10(%rsp), %r9
callq 0x33aa1
movl %eax, %edx
movl 0x10(%rsp), %eax
testq %rax, %rax
je 0x32edb
cmpl $0x7, %edx
je 0x32d4d
testl %edx, %edx
jne 0x32edb
movq 0x20(%rsp), %rcx
leaq 0x2(%rcx), %rdx
cmpq %rax, %rdx
setb %dl
cmpq $0x10001, %rcx          # imm = 0x10001
setb %sil
testb %dl, %sil
je 0x32d4d
cmpq $0x0, 0x10(%r13)
je 0x32e6a
cmpb $0x0, 0xa(%r13)
je 0x32e71
xorl %esi, %esi
cmpb $0x0, 0xb(%r13)
setne %sil
shll $0x5, %esi
addl $0xa0, %esi
jmp 0x32e76
movq %rbp, 0x70(%rsp)
xorl %r12d, %r12d
xorl %ebx, %ebx
movq 0x48(%rsp), %rsi
movq %r15, 0x80(%rsp)
movl 0x10(%rsp), %ebp
testl %ebp, %ebp
je 0x32e5d
cmpl %r14d, %ebp
cmovael %r14d, %ebp
movq %rsi, %rax
subq %rbx, %rax
leal 0x3(%rbp), %ecx
cmpq %rcx, %rax
jae 0x32d91
movl $0x7, %edx
xorl %ebp, %ebp
jmp 0x32e4f
movl %edx, 0x34(%rsp)
movq %r12, 0x88(%rsp)
cmpq $0x1, 0x10(%r13)
movb $0x2, %al
sbbb $0x0, %al
movq %r13, %r14
movq 0x70(%rsp), %rcx
leaq (%rcx,%rbx), %r13
addq $0x3, %r13
movb %al, -0x3(%r13)
leal -0x1(%rbp), %eax
movb %ah, 0x1(%rcx,%rbx)
movb %al, -0x1(%r13)
movq (%r14), %rdi
callq 0x33a8f
movl 0x10(%rsp), %r15d
subq %r15, %rax
movl %ebp, %r12d
movq %r13, %rdi
movq %r14, %r13
movq %rax, %rsi
movq %r12, %rdx
callq 0x4290
subl %ebp, %r15d
movl %r15d, 0x10(%rsp)
movq 0x80(%rsp), %r15
addq %r12, 0x10(%r14)
addq %r12, %rbx
addq $0x3, %rbx
movb $0x1, %bpl
testq %r15, %r15
je 0x32e2e
movq 0x88(%rsp), %r12
addq %rbx, %r12
movq %r15, %rdi
movq 0x70(%rsp), %rsi
movq %rbx, %rdx
callq *(%r15)
cmpq %rbx, %rax
jne 0x32e3d
xorl %ebx, %ebx
jmp 0x32e31
movq %rbx, %r12
movl $0x10000, %r14d         # imm = 0x10000
movl 0x34(%rsp), %edx
jmp 0x32e4a
movl $0x9, %edx
xorl %ebp, %ebp
movl $0x10000, %r14d         # imm = 0x10000
movq 0x48(%rsp), %rsi
testb %bpl, %bpl
jne 0x32d64
jmp 0x32ede
movq (%r13), %rdi
callq 0x3339d
xorl %edx, %edx
jmp 0x32ede
movl $0xe0, %esi
jmp 0x32e76
movl $0x80, %esi
leal -0x1(%rax), %edx
leal -0x1(%rcx), %ebx
movl %edx, %edi
shrl $0x10, %edi
andl $0x1f, %edi
orl %esi, %edi
movb %dil, (%rbp)
movb %dh, 0x1(%rbp)
movb %dl, 0x2(%rbp)
movb %bh, 0x3(%rbp)
movb %bl, 0x4(%rbp)
cmpb $0x0, 0xb(%r13)
je 0x32eac
movb 0x9(%r13), %dl
movb %dl, 0x5(%rbp)
movl $0x6, %r12d
jmp 0x32eb2
movl $0x5, %r12d
movw $0x0, 0xa(%r13)
addq %rcx, %r12
addq %rax, 0x10(%r13)
testq %r15, %r15
je 0x32e66
movq %r15, %rdi
movq %rbp, %rsi
movq %r12, %rdx
callq *(%r15)
cmpq %r12, %rax
je 0x32e66
movl $0x9, %edx
xorl %r12d, %r12d
testl %edx, %edx
je 0x32ef5
xorl %eax, %eax
movq 0x68(%rsp), %rbx
movq 0x60(%rsp), %r15
movq 0x18(%rsp), %r12
jmp 0x32f4d
movq %r12, %rax
movq 0x18(%rsp), %r12
movq %rax, %rbp
addq %rax, %r12
movq 0x60(%rsp), %r15
testq %r15, %r15
movq 0x68(%rsp), %rbx
je 0x32f15
movq %r12, (%rbx)
movq 0x108(%rsp), %rdi
testq %rdi, %rdi
je 0x32f3e
movq 0x10(%r13), %rsi
addq 0x28(%rsp), %rsi
movq %r12, %rdx
callq *(%rdi)
movl %eax, %edx
testl %eax, %eax
movl $0xa, %eax
cmovnel %eax, %edx
jmp 0x32f40
xorl %edx, %edx
testl %edx, %edx
sete %cl
testq %rbp, %rbp
setne %al
andb %cl, %al
testb %al, %al
jne 0x32c4d
movq (%r13), %rdi
movl %edx, %ebp
callq 0x33a79
movq 0x10(%r13), %rax
addq %rax, 0x28(%rsp)
testl %ebp, %ebp
movl 0x54(%rsp), %edx
cmovnel %ebp, %edx
jne 0x32faa
cmpq $0x0, 0x38(%rsp)
movq 0x78(%rsp), %rcx
je 0x32f89
movq 0xa8(%rsp), %rcx
cmpq %rcx, %rax
jne 0x32fa5
cmpq $0x0, 0x38(%rsp)
je 0x32fbf
cmpl $0x0, 0xb0(%rsp)
jne 0x32fd1
movb $0x1, %bpl
jmp 0x32fac
movl $0xb, %edx
xorl %ebp, %ebp
movq 0x8(%rsp), %rbx
testb %bpl, %bpl
jne 0x32b26
jmp 0x33044
movb $0x1, %bpl
movq 0x28(%rsp), %rax
cmpq 0xf8(%rsp), %rax
jne 0x32fac
cmpl $0x0, 0x100(%rsp)
je 0x33036
testq %r15, %r15
je 0x3300a
movq (%rbx), %rcx
movl $0x7, %eax
cmpq 0x40(%rsp), %rcx
jae 0x32ffd
movb $0x0, (%r15,%rcx)
leaq 0x1(%rcx), %rax
movq %rax, (%rbx)
movl %edx, %eax
cmpq 0x40(%rsp), %rcx
jb 0x33036
xorl %ebp, %ebp
movl %eax, %edx
jmp 0x32fac
movb $0x0, 0x20(%rsp)
movl %edx, %ebx
movl $0x1, %edx
movq 0x58(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq *(%rdi)
movl %ebx, %edx
cmpq $0x1, %rax
movl $0x9, %eax
cmovnel %eax, %edx
jne 0x32faa
xorl %ebp, %ebp
xorl %edx, %edx
jmp 0x32fac
movl $0x2, %edx
movl %edx, %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb 0x10(%rsp), %al
movb %al, 0x9(%r13)
movb $0x1, 0x8(%r13)
movb $0x1, %al
jmp 0x32af7