// File: sisong[P]ApkDiffPatch/lzma/C/LzmaEnc.c
// Function: LzmaEnc_Alloc
static SRes LzmaEnc_Alloc(CLzmaEnc *p, UInt32 keepWindowSize, ISzAllocPtr alloc, ISzAllocPtr allocBig)
{
  UInt32 beforeSize = kNumOpts;
  UInt32 dictSize;

  if (!RangeEnc_Alloc(&p->rc, alloc))
    return SZ_ERROR_MEM;

  #ifndef Z7_ST
  p->mtMode = (p->multiThread && !p->fastMode && (MFB.btMode != 0));
  #endif

  {
    const unsigned lclp = p->lc + p->lp;
    if (!p->litProbs || !p->saveState.litProbs || p->lclp != lclp)
    {
      LzmaEnc_FreeLits(p, alloc);
      p->litProbs =           (CLzmaProb *)ISzAlloc_Alloc(alloc, ((size_t)0x300 * sizeof(CLzmaProb)) << lclp);
      p->saveState.litProbs = (CLzmaProb *)ISzAlloc_Alloc(alloc, ((size_t)0x300 * sizeof(CLzmaProb)) << lclp);
      if (!p->litProbs || !p->saveState.litProbs)
      {
        LzmaEnc_FreeLits(p, alloc);
        return SZ_ERROR_MEM;
      }
      p->lclp = lclp;
    }
  }

  MFB.bigHash = (Byte)(p->dictSize > kBigHashDicLimit ? 1 : 0);


  dictSize = p->dictSize;
  if (dictSize == ((UInt32)2 << 30) ||
      dictSize == ((UInt32)3 << 30))
  {
    /* 21.03 : here we reduce the dictionary for 2 reasons:
       1) we don't want 32-bit back_distance matches in decoder for 2 GB dictionary.
       2) we want to elimate useless last MatchFinder_Normalize3() for corner cases,
          where data size is aligned for 1 GB: 5/6/8 GB.
          That reducing must be >= 1 for such corner cases. */
    dictSize -= 1;
  }

  if (beforeSize + dictSize < keepWindowSize)
    beforeSize = keepWindowSize - dictSize;

  /* in worst case we can look ahead for
        max(LZMA_MATCH_LEN_MAX, numFastBytes + 1 + numFastBytes) bytes.
     we send larger value for (keepAfter) to MantchFinder_Create():
        (numFastBytes + LZMA_MATCH_LEN_MAX + 1)
  */

  #ifndef Z7_ST
  if (p->mtMode)
  {
    RINOK(MatchFinderMt_Create(&p->matchFinderMt, dictSize, beforeSize,
        p->numFastBytes, LZMA_MATCH_LEN_MAX + 1 /* 18.04 */
        , allocBig))
    p->matchFinderObj = &p->matchFinderMt;
    MFB.bigHash = (Byte)(MFB.hashMask >= 0xFFFFFF ? 1 : 0);
    MatchFinderMt_CreateVTable(&p->matchFinderMt, &p->matchFinder);
  }
  else
  #endif
  {
    if (!MatchFinder_Create(&MFB, dictSize, beforeSize,
        p->numFastBytes, LZMA_MATCH_LEN_MAX + 1 /* 21.03 */
        , allocBig))
      return SZ_ERROR_MEM;
    p->matchFinderObj = &MFB;
    MatchFinder_CreateVTable(&MFB, &p->matchFinder);
  }
  
  return SZ_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movl $0x800, -0x2c(%rbp)     # imm = 0x800
movq -0x10(%rbp), %rdi
addq $0x70, %rdi
movq -0x20(%rbp), %rsi
callq 0x69ec0
cmpl $0x0, %eax
jne 0x69c20
movl $0x2, -0x4(%rbp)
jmp 0x69ea8
movq -0x10(%rbp), %rcx
xorl %eax, %eax
cmpl $0x0, 0xd8(%rcx)
movb %al, -0x39(%rbp)
je 0x69c58
movq -0x10(%rbp), %rcx
xorl %eax, %eax
cmpl $0x0, 0xcc(%rcx)
movb %al, -0x39(%rbp)
jne 0x69c58
movq -0x10(%rbp), %rax
movzbl 0x649(%rax), %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x39(%rbp)
movb -0x39(%rbp), %al
andb $0x1, %al
movzbl %al, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0xfc(%rax)
movq -0x10(%rbp), %rax
movl 0xbc(%rax), %eax
movq -0x10(%rbp), %rcx
addl 0xc0(%rcx), %eax
movl %eax, -0x34(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x68(%rax)
je 0x69cad
movq -0x10(%rbp), %rax
cmpq $0x0, 0x1f888(%rax)
je 0x69cad
movq -0x10(%rbp), %rax
movl 0xc8(%rax), %eax
cmpl -0x34(%rbp), %eax
je 0x69d42
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x69b40
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq -0x20(%rbp), %rdi
movl -0x34(%rbp), %ecx
movl $0x600, %esi            # imm = 0x600
shlq %cl, %rsi
callq *%rax
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x68(%rax)
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq -0x20(%rbp), %rdi
movl -0x34(%rbp), %ecx
movl $0x600, %esi            # imm = 0x600
shlq %cl, %rsi
callq *%rax
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x1f888(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x68(%rax)
je 0x69d1c
movq -0x10(%rbp), %rax
cmpq $0x0, 0x1f888(%rax)
jne 0x69d35
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x69b40
movl $0x2, -0x4(%rbp)
jmp 0x69ea8
movl -0x34(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0xc8(%rax)
movq -0x10(%rbp), %rax
movl 0xf4(%rax), %edx
xorl %eax, %eax
movl $0x1, %ecx
cmpl $0x1000000, %edx        # imm = 0x1000000
cmoval %ecx, %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, 0x64a(%rax)
movq -0x10(%rbp), %rax
movl 0xf4(%rax), %eax
movl %eax, -0x30(%rbp)
cmpl $0x80000000, -0x30(%rbp) # imm = 0x80000000
je 0x69d87
cmpl $0xc0000000, -0x30(%rbp) # imm = 0xC0000000
jne 0x69d90
movl -0x30(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x30(%rbp)
movl -0x2c(%rbp), %eax
addl -0x30(%rbp), %eax
cmpl -0x14(%rbp), %eax
jae 0x69da4
movl -0x14(%rbp), %eax
subl -0x30(%rbp), %eax
movl %eax, -0x2c(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0xfc(%rax)
je 0x69e42
movq -0x10(%rbp), %rdi
addq $0x100, %rdi            # imm = 0x100
movl -0x30(%rbp), %esi
movl -0x2c(%rbp), %edx
movq -0x10(%rbp), %rax
movl 0x48(%rax), %ecx
movq -0x28(%rbp), %r9
movl $0x112, %r8d            # imm = 0x112
callq 0x75690
movl %eax, -0x38(%rbp)
cmpl $0x0, -0x38(%rbp)
je 0x69df0
movl -0x38(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x69ea8
movq -0x10(%rbp), %rcx
addq $0x100, %rcx            # imm = 0x100
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
movl 0x660(%rax), %edx
xorl %eax, %eax
movl $0x1, %ecx
cmpl $0xffffff, %edx         # imm = 0xFFFFFF
cmovael %ecx, %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, 0x64a(%rax)
movq -0x10(%rbp), %rdi
addq $0x100, %rdi            # imm = 0x100
movq -0x10(%rbp), %rsi
addq $0x8, %rsi
callq 0x75a80
jmp 0x69ea1
movq -0x10(%rbp), %rdi
addq $0x628, %rdi            # imm = 0x628
movl -0x30(%rbp), %esi
movl -0x2c(%rbp), %edx
movq -0x10(%rbp), %rax
movl 0x48(%rax), %ecx
movq -0x28(%rbp), %r9
movl $0x112, %r8d            # imm = 0x112
callq 0x6f4b0
cmpl $0x0, %eax
jne 0x69e77
movl $0x2, -0x4(%rbp)
jmp 0x69ea8
movq -0x10(%rbp), %rcx
addq $0x628, %rcx            # imm = 0x628
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rdi
addq $0x628, %rdi            # imm = 0x628
movq -0x10(%rbp), %rsi
addq $0x8, %rsi
callq 0x71140
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)