// File: sisong[P]ApkDiffPatch/lzma/C/LzmaEnc.c
// Function: FillDistancesPrices
Z7_NO_INLINE static void FillDistancesPrices(CLzmaEnc *p)
{
  // int y; for (y = 0; y < 100; y++) {

  UInt32 tempPrices[kNumFullDistances];
  unsigned i, lps;

  const CProbPrice *ProbPrices = p->ProbPrices;
  p->matchPriceCount = 0;

  for (i = kStartPosModelIndex / 2; i < kNumFullDistances / 2; i++)
  {
    unsigned posSlot = GetPosSlot1(i);
    unsigned footerBits = (posSlot >> 1) - 1;
    unsigned base = ((2 | (posSlot & 1)) << footerBits);
    const CLzmaProb *probs = p->posEncoders + (size_t)base * 2;
    // tempPrices[i] = RcTree_ReverseGetPrice(p->posEncoders + base, footerBits, i - base, p->ProbPrices);
    UInt32 price = 0;
    unsigned m = 1;
    unsigned sym = i;
    unsigned offset = (unsigned)1 << footerBits;
    base += i;
    
    if (footerBits)
    do
    {
      unsigned bit = sym & 1;
      sym >>= 1;
      price += GET_PRICEa(probs[m], bit);
      m = (m << 1) + bit;
    }
    while (--footerBits);

    {
      unsigned prob = probs[m];
      tempPrices[base         ] = price + GET_PRICEa_0(prob);
      tempPrices[base + offset] = price + GET_PRICEa_1(prob);
    }
  }

  for (lps = 0; lps < kNumLenToPosStates; lps++)
  {
    unsigned slot;
    unsigned distTableSize2 = (p->distTableSize + 1) >> 1;
    UInt32 *posSlotPrices = p->posSlotPrices[lps];
    const CLzmaProb *probs = p->posSlotEncoder[lps];
    
    for (slot = 0; slot < distTableSize2; slot++)
    {
      // posSlotPrices[slot] = RcTree_GetPrice(encoder, kNumPosSlotBits, slot, p->ProbPrices);
      UInt32 price;
      unsigned bit;
      unsigned sym = slot + (1 << (kNumPosSlotBits - 1));
      unsigned prob;
      bit = sym & 1; sym >>= 1; price  = GET_PRICEa(probs[sym], bit);
      bit = sym & 1; sym >>= 1; price += GET_PRICEa(probs[sym], bit);
      bit = sym & 1; sym >>= 1; price += GET_PRICEa(probs[sym], bit);
      bit = sym & 1; sym >>= 1; price += GET_PRICEa(probs[sym], bit);
      bit = sym & 1; sym >>= 1; price += GET_PRICEa(probs[sym], bit);
      prob = probs[(size_t)slot + (1 << (kNumPosSlotBits - 1))];
      posSlotPrices[(size_t)slot * 2    ] = price + GET_PRICEa_0(prob);
      posSlotPrices[(size_t)slot * 2 + 1] = price + GET_PRICEa_1(prob);
    }
    
    {
      UInt32 delta = ((UInt32)((kEndPosModelIndex / 2 - 1) - kNumAlignBits) << kNumBitPriceShiftBits);
      for (slot = kEndPosModelIndex / 2; slot < distTableSize2; slot++)
      {
        posSlotPrices[(size_t)slot * 2    ] += delta;
        posSlotPrices[(size_t)slot * 2 + 1] += delta;
        delta += ((UInt32)1 << kNumBitPriceShiftBits);
      }
    }

    {
      UInt32 *dp = p->distancesPrices[lps];
      
      dp[0] = posSlotPrices[0];
      dp[1] = posSlotPrices[1];
      dp[2] = posSlotPrices[2];
      dp[3] = posSlotPrices[3];

      for (i = 4; i < kNumFullDistances; i += 2)
      {
        UInt32 slotPrice = posSlotPrices[GetPosSlot1(i)];
        dp[i    ] = slotPrice + tempPrices[i];
        dp[i + 1] = slotPrice + tempPrices[i + 1];
      }
    }
  }
  // }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x210, %rsp            # imm = 0x210
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xb30, %rax            # imm = 0xB30
movq %rax, -0x220(%rbp)
movq -0x8(%rbp), %rax
movl $0x0, 0xe8(%rax)
movl $0x2, -0x214(%rbp)
cmpl $0x40, -0x214(%rbp)
jae 0x6a1ac
movq -0x8(%rbp), %rax
movl -0x214(%rbp), %ecx
movzbl 0x3080(%rax,%rcx), %eax
movl %eax, -0x224(%rbp)
movl -0x224(%rbp), %eax
shrl %eax
subl $0x1, %eax
movl %eax, -0x228(%rbp)
movl -0x224(%rbp), %eax
andl $0x1, %eax
orl $0x2, %eax
movl -0x228(%rbp), %ecx
shll %cl, %eax
movl %eax, -0x22c(%rbp)
movq -0x8(%rbp), %rax
addq $0x2780, %rax           # imm = 0x2780
movl -0x22c(%rbp), %ecx
shlq %rcx
shlq %rcx
addq %rcx, %rax
movq %rax, -0x238(%rbp)
movl $0x0, -0x23c(%rbp)
movl $0x1, -0x240(%rbp)
movl -0x214(%rbp), %eax
movl %eax, -0x244(%rbp)
movl -0x228(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, -0x248(%rbp)
movl -0x214(%rbp), %eax
addl -0x22c(%rbp), %eax
movl %eax, -0x22c(%rbp)
cmpl $0x0, -0x228(%rbp)
je 0x6a123
jmp 0x6a09c
movl -0x244(%rbp), %eax
andl $0x1, %eax
movl %eax, -0x24c(%rbp)
movl -0x244(%rbp), %eax
shrl %eax
movl %eax, -0x244(%rbp)
movq -0x220(%rbp), %rax
movq -0x238(%rbp), %rcx
movl -0x240(%rbp), %edx
movzwl (%rcx,%rdx,2), %ecx
xorl %edx, %edx
subl -0x24c(%rbp), %edx
andl $0x7ff, %edx            # imm = 0x7FF
xorl %edx, %ecx
shrl $0x4, %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
addl -0x23c(%rbp), %eax
movl %eax, -0x23c(%rbp)
movl -0x240(%rbp), %eax
shll %eax
addl -0x24c(%rbp), %eax
movl %eax, -0x240(%rbp)
movl -0x228(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x228(%rbp)
cmpl $0x0, %eax
jne 0x6a09c
jmp 0x6a123
movq -0x238(%rbp), %rax
movl -0x240(%rbp), %ecx
movzwl (%rax,%rcx,2), %eax
movl %eax, -0x250(%rbp)
movl -0x23c(%rbp), %ecx
movq -0x220(%rbp), %rax
movl -0x250(%rbp), %edx
shrl $0x4, %edx
movl %edx, %edx
addl (%rax,%rdx,4), %ecx
movl -0x22c(%rbp), %eax
movl %ecx, -0x210(%rbp,%rax,4)
movl -0x23c(%rbp), %ecx
movq -0x220(%rbp), %rax
movl -0x250(%rbp), %edx
xorl $0x7ff, %edx            # imm = 0x7FF
shrl $0x4, %edx
movl %edx, %edx
addl (%rax,%rdx,4), %ecx
movl -0x22c(%rbp), %eax
addl -0x248(%rbp), %eax
movl %eax, %eax
movl %ecx, -0x210(%rbp,%rax,4)
movl -0x214(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x214(%rbp)
jmp 0x69fd8
movl $0x0, -0x218(%rbp)
cmpl $0x4, -0x218(%rbp)
jae 0x6a623
movq -0x8(%rbp), %rax
movl 0xf0(%rax), %eax
addl $0x1, %eax
shrl %eax
movl %eax, -0x258(%rbp)
movq -0x8(%rbp), %rax
addq $0x1600, %rax           # imm = 0x1600
movl -0x218(%rbp), %ecx
shlq $0x8, %rcx
addq %rcx, %rax
movq %rax, -0x260(%rbp)
movq -0x8(%rbp), %rax
addq $0x2580, %rax           # imm = 0x2580
movl -0x218(%rbp), %ecx
shlq $0x7, %rcx
addq %rcx, %rax
movq %rax, -0x268(%rbp)
movl $0x0, -0x254(%rbp)
movl -0x254(%rbp), %eax
cmpl -0x258(%rbp), %eax
jae 0x6a485
movl -0x254(%rbp), %eax
addl $0x20, %eax
movl %eax, -0x274(%rbp)
movl -0x274(%rbp), %eax
andl $0x1, %eax
movl %eax, -0x270(%rbp)
movl -0x274(%rbp), %eax
shrl %eax
movl %eax, -0x274(%rbp)
movq -0x220(%rbp), %rax
movq -0x268(%rbp), %rcx
movl -0x274(%rbp), %edx
movzwl (%rcx,%rdx,2), %ecx
xorl %edx, %edx
subl -0x270(%rbp), %edx
andl $0x7ff, %edx            # imm = 0x7FF
xorl %edx, %ecx
shrl $0x4, %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
movl %eax, -0x26c(%rbp)
movl -0x274(%rbp), %eax
andl $0x1, %eax
movl %eax, -0x270(%rbp)
movl -0x274(%rbp), %eax
shrl %eax
movl %eax, -0x274(%rbp)
movq -0x220(%rbp), %rax
movq -0x268(%rbp), %rcx
movl -0x274(%rbp), %edx
movzwl (%rcx,%rdx,2), %ecx
xorl %edx, %edx
subl -0x270(%rbp), %edx
andl $0x7ff, %edx            # imm = 0x7FF
xorl %edx, %ecx
shrl $0x4, %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
addl -0x26c(%rbp), %eax
movl %eax, -0x26c(%rbp)
movl -0x274(%rbp), %eax
andl $0x1, %eax
movl %eax, -0x270(%rbp)
movl -0x274(%rbp), %eax
shrl %eax
movl %eax, -0x274(%rbp)
movq -0x220(%rbp), %rax
movq -0x268(%rbp), %rcx
movl -0x274(%rbp), %edx
movzwl (%rcx,%rdx,2), %ecx
xorl %edx, %edx
subl -0x270(%rbp), %edx
andl $0x7ff, %edx            # imm = 0x7FF
xorl %edx, %ecx
shrl $0x4, %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
addl -0x26c(%rbp), %eax
movl %eax, -0x26c(%rbp)
movl -0x274(%rbp), %eax
andl $0x1, %eax
movl %eax, -0x270(%rbp)
movl -0x274(%rbp), %eax
shrl %eax
movl %eax, -0x274(%rbp)
movq -0x220(%rbp), %rax
movq -0x268(%rbp), %rcx
movl -0x274(%rbp), %edx
movzwl (%rcx,%rdx,2), %ecx
xorl %edx, %edx
subl -0x270(%rbp), %edx
andl $0x7ff, %edx            # imm = 0x7FF
xorl %edx, %ecx
shrl $0x4, %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
addl -0x26c(%rbp), %eax
movl %eax, -0x26c(%rbp)
movl -0x274(%rbp), %eax
andl $0x1, %eax
movl %eax, -0x270(%rbp)
movl -0x274(%rbp), %eax
shrl %eax
movl %eax, -0x274(%rbp)
movq -0x220(%rbp), %rax
movq -0x268(%rbp), %rcx
movl -0x274(%rbp), %edx
movzwl (%rcx,%rdx,2), %ecx
xorl %edx, %edx
subl -0x270(%rbp), %edx
andl $0x7ff, %edx            # imm = 0x7FF
xorl %edx, %ecx
shrl $0x4, %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
addl -0x26c(%rbp), %eax
movl %eax, -0x26c(%rbp)
movq -0x268(%rbp), %rax
movl -0x254(%rbp), %ecx
movzwl 0x40(%rax,%rcx,2), %eax
movl %eax, -0x278(%rbp)
movl -0x26c(%rbp), %edx
movq -0x220(%rbp), %rax
movl -0x278(%rbp), %ecx
shrl $0x4, %ecx
movl %ecx, %ecx
addl (%rax,%rcx,4), %edx
movq -0x260(%rbp), %rax
movl -0x254(%rbp), %ecx
shlq %rcx
movl %edx, (%rax,%rcx,4)
movl -0x26c(%rbp), %edx
movq -0x220(%rbp), %rax
movl -0x278(%rbp), %ecx
xorl $0x7ff, %ecx            # imm = 0x7FF
shrl $0x4, %ecx
movl %ecx, %ecx
addl (%rax,%rcx,4), %edx
movq -0x260(%rbp), %rax
movl -0x254(%rbp), %ecx
shlq %rcx
movl %edx, 0x4(%rax,%rcx,4)
movl -0x254(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x254(%rbp)
jmp 0x6a21e
movl $0x20, -0x27c(%rbp)
movl $0x7, -0x254(%rbp)
movl -0x254(%rbp), %eax
cmpl -0x258(%rbp), %eax
jae 0x6a501
movl -0x27c(%rbp), %edx
movq -0x260(%rbp), %rax
movl -0x254(%rbp), %ecx
shlq %rcx
addl (%rax,%rcx,4), %edx
movl %edx, (%rax,%rcx,4)
movl -0x27c(%rbp), %edx
movq -0x260(%rbp), %rax
movl -0x254(%rbp), %ecx
shlq %rcx
addl 0x4(%rax,%rcx,4), %edx
movl %edx, 0x4(%rax,%rcx,4)
movl -0x27c(%rbp), %eax
addl $0x10, %eax
movl %eax, -0x27c(%rbp)
movl -0x254(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x254(%rbp)
jmp 0x6a499
movq -0x8(%rbp), %rax
addq $0x1a00, %rax           # imm = 0x1A00
movl -0x218(%rbp), %ecx
shlq $0x9, %rcx
addq %rcx, %rax
movq %rax, -0x288(%rbp)
movq -0x260(%rbp), %rax
movl (%rax), %ecx
movq -0x288(%rbp), %rax
movl %ecx, (%rax)
movq -0x260(%rbp), %rax
movl 0x4(%rax), %ecx
movq -0x288(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x260(%rbp), %rax
movl 0x8(%rax), %ecx
movq -0x288(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x260(%rbp), %rax
movl 0xc(%rax), %ecx
movq -0x288(%rbp), %rax
movl %ecx, 0xc(%rax)
movl $0x4, -0x214(%rbp)
cmpl $0x80, -0x214(%rbp)
jae 0x6a60d
movq -0x260(%rbp), %rax
movq -0x8(%rbp), %rcx
movl -0x214(%rbp), %edx
movzbl 0x3080(%rcx,%rdx), %ecx
movl (%rax,%rcx,4), %eax
movl %eax, -0x28c(%rbp)
movl -0x28c(%rbp), %edx
movl -0x214(%rbp), %eax
addl -0x210(%rbp,%rax,4), %edx
movq -0x288(%rbp), %rax
movl -0x214(%rbp), %ecx
movl %edx, (%rax,%rcx,4)
movl -0x28c(%rbp), %edx
movl -0x214(%rbp), %eax
addl $0x1, %eax
movl %eax, %eax
addl -0x210(%rbp,%rax,4), %edx
movq -0x288(%rbp), %rax
movl -0x214(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movl %edx, (%rax,%rcx,4)
movl -0x214(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x214(%rbp)
jmp 0x6a577
jmp 0x6a60f
movl -0x218(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x218(%rbp)
jmp 0x6a1b6
addq $0x210, %rsp            # imm = 0x210
popq %rbp
retq
nopl (%rax)