// File: sisong[P]ApkDiffPatch/lzma/C/MtDec.c
// Function: MtDec_Read
const Byte *MtDec_Read(CMtDec *p, size_t *inLim)
{
  while (p->numFilledThreads != 0)
  {
    CMtDecThread *t = &p->threads[p->filledThreadStart];
    
    if (*inLim != 0)
    {
      {
        void *link = t->inBuf;
        void *next = ((CMtDecBufLink *)link)->next;
        ISzAlloc_Free(p->alloc, link);
        t->inBuf = next;
      }
      
      if (t->inDataSize == 0)
      {
        MtDecThread_FreeInBufs(t);
        if (--p->numFilledThreads == 0)
          break;
        if (++p->filledThreadStart == p->numStartedThreads)
          p->filledThreadStart = 0;
        t = &p->threads[p->filledThreadStart];
      }
    }
    
    {
      size_t lim = t->inDataSize_Start;
      if (lim != 0)
        t->inDataSize_Start = 0;
      else
      {
        UInt64 rem = t->inDataSize;
        lim = p->inBufSize;
        if (lim > rem)
          lim = (size_t)rem;
      }
      t->inDataSize -= lim;
      *inLim = lim;
      return (const Byte *)MTDEC__DATA_PTR_FROM_LINK(t->inBuf);
    }
  }

  {
    size_t crossSize = p->crossEnd - p->crossStart;
    if (crossSize != 0)
    {
      const Byte *data = MTDEC__DATA_PTR_FROM_LINK(p->crossBlock) + p->crossStart;
      *inLim = crossSize;
      p->crossStart = 0;
      p->crossEnd = 0;
      return data;
    }
    *inLim = 0;
    if (p->crossBlock)
    {
      ISzAlloc_Free(p->alloc, p->crossBlock);
      p->crossBlock = NULL;
    }
    return NULL;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0xac(%rax)
je 0x7991c
movq -0x10(%rbp), %rax
addq $0x108, %rax            # imm = 0x108
movq -0x10(%rbp), %rcx
movl 0xa8(%rcx), %ecx
imulq $0x110, %rcx, %rcx      # imm = 0x110
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
cmpq $0x0, (%rax)
je 0x7989d
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x20(%rcx), %rdi
movq -0x28(%rbp), %rsi
callq *%rax
movq -0x30(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x20(%rbp), %rax
cmpq $0x0, 0x20(%rax)
jne 0x7989b
movq -0x20(%rbp), %rdi
callq 0x79560
movq -0x10(%rbp), %rcx
movl 0xac(%rcx), %eax
addl $-0x1, %eax
movl %eax, 0xac(%rcx)
cmpl $0x0, %eax
jne 0x7984f
jmp 0x7991c
movq -0x10(%rbp), %rcx
movl 0xa8(%rcx), %eax
addl $0x1, %eax
movl %eax, 0xa8(%rcx)
movq -0x10(%rbp), %rcx
cmpl 0x70(%rcx), %eax
jne 0x79879
movq -0x10(%rbp), %rax
movl $0x0, 0xa8(%rax)
movq -0x10(%rbp), %rax
addq $0x108, %rax            # imm = 0x108
movq -0x10(%rbp), %rcx
movl 0xa8(%rcx), %ecx
imulq $0x110, %rcx, %rcx      # imm = 0x110
addq %rcx, %rax
movq %rax, -0x20(%rbp)
jmp 0x7989d
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x798be
movq -0x20(%rbp), %rax
movq $0x0, 0x18(%rax)
jmp 0x798e9
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
jbe 0x798e7
movq -0x40(%rbp), %rax
movq %rax, -0x38(%rbp)
jmp 0x798e9
movq -0x38(%rbp), %rdx
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rcx
subq %rdx, %rcx
movq %rcx, 0x20(%rax)
movq -0x38(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
addq $0x20, %rax
movq %rax, -0x8(%rbp)
jmp 0x799d3
movq -0x10(%rbp), %rax
movq 0x88(%rax), %rax
movq -0x10(%rbp), %rcx
subq 0x80(%rcx), %rax
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
je 0x7998b
movq -0x10(%rbp), %rax
movq 0x78(%rax), %rax
addq $0x20, %rax
movq -0x10(%rbp), %rcx
addq 0x80(%rcx), %rax
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
movq $0x0, 0x80(%rax)
movq -0x10(%rbp), %rax
movq $0x0, 0x88(%rax)
movq -0x50(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x799d3
movq -0x18(%rbp), %rax
movq $0x0, (%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x78(%rax)
je 0x799cb
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x20(%rcx), %rdi
movq -0x10(%rbp), %rcx
movq 0x78(%rcx), %rsi
callq *%rax
movq -0x10(%rbp), %rax
movq $0x0, 0x78(%rax)
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)