// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1b8, %rsp            # imm = 0x1B8
andl $0x0, 0xe8(%rdi)
leaq 0x2780(%rdi), %rax
movabsq $0x2, %rdx
movl $0x1, %esi
movabsq $0x1, %r8
cmpq $0x40, %rdx
je 0x2e3cb
movzbl 0x3080(%rdi,%rdx), %r9d
movl %r9d, %ecx
shrl %ecx
decl %ecx
andl $0x1, %r9d
orl $0x2, %r9d
shll %cl, %r9d
leaq (%rax,%r9,4), %rbx
movl %esi, %r10d
shll %cl, %r10d
xorl %r11d, %r11d
testl %ecx, %ecx
je 0x2e38b
movl %edx, %ebp
movl %esi, %r14d
movl %ebp, %r15d
andl $0x1, %r15d
movl %r14d, %r12d
leal (%r15,%r14,2), %r14d
negl %r15d
shrl %ebp
movzwl (%rbx,%r12,2), %r12d
andl $0x7f0, %r15d           # imm = 0x7F0
xorl %r12d, %r15d
shrl $0x4, %r15d
addl 0xb30(%rdi,%r15,4), %r11d
decl %ecx
jne 0x2e354
movl %r14d, %ecx
jmp 0x2e38e
movq %r8, %rcx
addl %edx, %r9d
movzwl (%rbx,%rcx,2), %ecx
shrl $0x2, %ecx
andl $-0x4, %ecx
movl 0xb30(%rdi,%rcx), %ebx
addl %r11d, %ebx
movl %r9d, %r14d
movl %ebx, -0x50(%rsp,%r14,4)
xorl $0x1fc, %ecx            # imm = 0x1FC
addl 0xb30(%rdi,%rcx), %r11d
addl %r10d, %r9d
movl %r11d, -0x50(%rsp,%r9,4)
incq %rdx
jmp 0x2e319
movl 0xf0(%rdi), %eax
incl %eax
shrl %eax
leaq 0x1600(%rdi), %rcx
movq %rcx, -0x68(%rsp)
leaq 0x2580(%rdi), %rcx
movq %rcx, -0x70(%rsp)
leaq 0x1a00(%rdi), %rcx
movq %rcx, -0x78(%rsp)
leaq 0x1604(%rdi), %r8
leaq 0x25c0(%rdi), %r9
leaq 0x3084(%rdi), %r10
xorl %r11d, %r11d
movl $0x7f0, %ebp            # imm = 0x7F0
movq %rdi, %r15
xorl %r12d, %r12d
cmpq $0x4, %r12
je 0x2e5da
movq %r11, -0x58(%rsp)
movq %r12, %r13
shlq $0x8, %r13
addq -0x68(%rsp), %r13
movq %r12, -0x60(%rsp)
shlq $0x7, %r12
addq -0x70(%rsp), %r12
xorl %ebx, %ebx
cmpq %rbx, %rax
je 0x2e52a
movl %ebx, %ecx
andl $0x1, %ecx
negl %ecx
leal 0x20(%rbx), %r11d
movl %r11d, %edx
andl $-0x2, %edx
movzwl (%r12,%rdx), %edx
andl %ebp, %ecx
xorl %edx, %ecx
shrl $0x4, %ecx
movl %r11d, %esi
shrl $0x2, %esi
movzwl (%r12,%rsi,2), %edx
movl %ebx, %r14d
shll $0x1e, %r14d
sarl $0x1f, %r14d
andl %ebp, %r14d
xorl %edx, %r14d
shrl $0x4, %r14d
movl 0xb30(%rdi,%r14,4), %edx
addl 0xb30(%rdi,%rcx,4), %edx
andl $-0x2, %esi
movzwl (%r12,%rsi), %ecx
movl %ebx, %esi
shll $0x1d, %esi
sarl $0x1f, %esi
andl %ebp, %esi
xorl %ecx, %esi
shrl $0x4, %esi
addl 0xb30(%rdi,%rsi,4), %edx
shrl $0x4, %r11d
movzwl (%r12,%r11,2), %ecx
movl %ebx, %esi
shll $0x1c, %esi
sarl $0x1f, %esi
andl %ebp, %esi
xorl %ecx, %esi
shrl $0x4, %esi
addl 0xb30(%rdi,%rsi,4), %edx
andl $-0x2, %r11d
movzwl (%r12,%r11), %ecx
movl %ebx, %esi
shll $0x1b, %esi
sarl $0x1f, %esi
andl %ebp, %esi
xorl %ecx, %esi
shrl $0x4, %esi
addl 0xb30(%rdi,%rsi,4), %edx
movzwl (%r9,%rbx,2), %ecx
shrl $0x2, %ecx
andl $-0x4, %ecx
movl 0xb30(%rdi,%rcx), %esi
addl %edx, %esi
movl %esi, -0x4(%r8,%rbx,8)
xorl $0x1fc, %ecx            # imm = 0x1FC
addl 0xb30(%rdi,%rcx), %edx
movl %edx, (%r8,%rbx,8)
incq %rbx
jmp 0x2e447
movl $0x2c7, %ecx            # imm = 0x2C7
movl $0x20, %edx
movq -0x58(%rsp), %r11
movq -0x60(%rsp), %r12
leaq -0x2c0(%rcx), %rsi
cmpq %rax, %rsi
jae 0x2e56b
movq (%r15,%rcx,8), %xmm0
movd %edx, %xmm1
pshufd $0x50, %xmm1, %xmm1     # xmm1 = xmm1[0,0,1,1]
paddd %xmm0, %xmm1
movq %xmm1, (%r15,%rcx,8)
addl $0x10, %edx
incq %rcx
jmp 0x2e53e
movq %r12, %rcx
shlq $0x9, %rcx
movdqu (%r13), %xmm0
movq -0x78(%rsp), %rdx
movdqu %xmm0, (%rdx,%rcx)
leaq (%r10,%r11), %rcx
xorl %edx, %edx
leaq 0x4(%rdx), %rsi
cmpq $0x7f, %rsi
ja 0x2e5bc
movzbl (%r10,%rdx), %esi
movq -0x40(%rsp,%rdx,4), %xmm0
movd (%r13,%rsi,4), %xmm1
pshufd $0x50, %xmm1, %xmm1     # xmm1 = xmm1[0,0,1,1]
paddd %xmm0, %xmm1
movq %xmm1, -0x1674(%rcx,%rdx,4)
addq $0x2, %rdx
jmp 0x2e588
incq %r12
movl $0x100, %ecx            # imm = 0x100
addq %rcx, %r8
subq $-0x80, %r9
addq %rcx, %r15
addq $0x200, %r11            # imm = 0x200
jmp 0x2e41c
addq $0x1b8, %rsp            # imm = 0x1B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq