// File: sisong[P]ApkDiffPatch/lzma/C/LzmaEnc.c
// Function: Backward
static unsigned Backward(CLzmaEnc *p, unsigned cur)
{
  unsigned wr = cur + 1;
  p->optEnd = wr;

  for (;;)
  {
    UInt32 dist = p->opt[cur].dist;
    unsigned len = (unsigned)p->opt[cur].len;
    unsigned extra = (unsigned)p->opt[cur].extra;
    cur -= len;

    if (extra)
    {
      wr--;
      p->opt[wr].len = (UInt32)len;
      cur -= extra;
      len = extra;
      if (extra == 1)
      {
        p->opt[wr].dist = dist;
        dist = MARK_LIT;
      }
      else
      {
        p->opt[wr].dist = 0;
        len--;
        wr--;
        p->opt[wr].dist = MARK_LIT;
        p->opt[wr].len = 1;
      }
    }

    if (cur == 0)
    {
      p->backRes = dist;
      p->optCur = wr;
      return len;
    }
    
    wr--;
    p->opt[wr].dist = dist;
    p->opt[wr].len = (UInt32)len;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
movl -0x10(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x34(%rax)
movq -0x8(%rbp), %rax
addq $0xf888, %rax           # imm = 0xF888
movl -0xc(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
movl %eax, -0x14(%rbp)
movq -0x8(%rbp), %rax
addq $0xf888, %rax           # imm = 0xF888
movl -0xc(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, -0x18(%rbp)
movq -0x8(%rbp), %rax
addq $0xf888, %rax           # imm = 0xF888
movl -0xc(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movzwl 0x6(%rax), %eax
movl %eax, -0x1c(%rbp)
movl -0x18(%rbp), %ecx
movl -0xc(%rbp), %eax
subl %ecx, %eax
movl %eax, -0xc(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0x6e8c4
movl -0x10(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x10(%rbp)
movl -0x18(%rbp), %ecx
movq -0x8(%rbp), %rax
addq $0xf888, %rax           # imm = 0xF888
movl -0x10(%rbp), %edx
shlq $0x5, %rdx
addq %rdx, %rax
movl %ecx, 0x8(%rax)
movl -0x1c(%rbp), %ecx
movl -0xc(%rbp), %eax
subl %ecx, %eax
movl %eax, -0xc(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x18(%rbp)
cmpl $0x1, -0x1c(%rbp)
jne 0x6e85f
movl -0x14(%rbp), %ecx
movq -0x8(%rbp), %rax
addq $0xf888, %rax           # imm = 0xF888
movl -0x10(%rbp), %edx
shlq $0x5, %rdx
addq %rdx, %rax
movl %ecx, 0xc(%rax)
movl $0xffffffff, -0x14(%rbp) # imm = 0xFFFFFFFF
jmp 0x6e8c2
movq -0x8(%rbp), %rax
addq $0xf888, %rax           # imm = 0xF888
movl -0x10(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movl $0x0, 0xc(%rax)
movl -0x18(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x18(%rbp)
movl -0x10(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x10(%rbp)
movq -0x8(%rbp), %rax
addq $0xf888, %rax           # imm = 0xF888
movl -0x10(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movl $0xffffffff, 0xc(%rax)  # imm = 0xFFFFFFFF
movq -0x8(%rbp), %rax
addq $0xf888, %rax           # imm = 0xF888
movl -0x10(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movl $0x1, 0x8(%rax)
jmp 0x6e8c4
cmpl $0x0, -0xc(%rbp)
jne 0x6e8e6
movl -0x14(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0xb8(%rax)
movl -0x10(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x30(%rax)
movl -0x18(%rbp), %eax
popq %rbp
retq
movl -0x10(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x10(%rbp)
movl -0x14(%rbp), %ecx
movq -0x8(%rbp), %rax
addq $0xf888, %rax           # imm = 0xF888
movl -0x10(%rbp), %edx
shlq $0x5, %rdx
addq %rdx, %rax
movl %ecx, 0xc(%rax)
movl -0x18(%rbp), %ecx
movq -0x8(%rbp), %rax
addq $0xf888, %rax           # imm = 0xF888
movl -0x10(%rbp), %edx
shlq $0x5, %rdx
addq %rdx, %rax
movl %ecx, 0x8(%rax)
jmp 0x6e79e
nopl (%rax,%rax)