// File: /workspace/github_cpp_makefile_star2_O3/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
movl $0x0, 0xe8(%rdi)
leaq 0x2780(%rdi), %rax
movl $0x2, %edx
movzbl 0x3080(%rdi,%rdx), %esi
movl %esi, %ecx
shrl %ecx
decl %ecx
andl $0x1, %esi
orl $0x2, %esi
shll %cl, %esi
leaq (%rax,%rsi,4), %r10
movl $0x1, %r8d
shll %cl, %r8d
xorl %r9d, %r9d
testl %ecx, %ecx
je 0x36595
movl $0x1, %r11d
movl %edx, %ebx
movl %ebx, %r14d
andl $0x1, %r14d
movl %r11d, %r15d
leal (%r14,%r11,2), %r11d
negl %r14d
shrl %ebx
movzwl (%r10,%r15,2), %ebp
andl $0x7f0, %r14d           # imm = 0x7F0
xorl %ebp, %r14d
shrl $0x4, %r14d
addl 0xb30(%rdi,%r14,4), %r9d
decl %ecx
jne 0x3655e
movl %r11d, %ecx
jmp 0x3659a
movl $0x1, %ecx
addl %edx, %esi
movzwl (%r10,%rcx,2), %ecx
shrl $0x2, %ecx
andl $-0x4, %ecx
movl 0xb30(%rdi,%rcx), %r10d
addl %r9d, %r10d
movl %esi, %r11d
movl %r10d, -0x50(%rsp,%r11,4)
xorl $0x1fc, %ecx            # imm = 0x1FC
addl 0xb30(%rdi,%rcx), %r9d
addl %r8d, %esi
movl %r9d, -0x50(%rsp,%rsi,4)
incq %rdx
cmpq $0x40, %rdx
jne 0x3652c
movl 0xf0(%rdi), %r15d
incl %r15d
movl %r15d, %ecx
shrl %ecx
leaq 0x1600(%rdi), %r12
leaq 0x2580(%rdi), %rax
movq %rax, -0x70(%rsp)
leaq 0x1a00(%rdi), %rax
movq %rax, -0x58(%rsp)
leaq 0x1604(%rdi), %r9
leaq 0x25c0(%rdi), %r10
leaq 0x1638(%rdi), %r11
leaq -0x7(%rcx), %rax
movq %rax, -0x78(%rsp)
leaq 0x3084(%rdi), %r14
xorl %ebx, %ebx
movl $0x7f0, %ebp            # imm = 0x7F0
xorl %esi, %esi
movl %r15d, -0x7c(%rsp)
movq %r12, -0x68(%rsp)
cmpl $0x2, %r15d
jb 0x3678c
movq %rbx, -0x60(%rsp)
movq %rsi, %r13
shlq $0x7, %r13
addq -0x70(%rsp), %r13
xorl %ebx, %ebx
movl %ebx, %edx
andl $0x1, %edx
negl %edx
leal 0x20(%rbx), %r15d
movl %r15d, %r8d
andl $-0x2, %r8d
movzwl (%r13,%r8), %r8d
andl %ebp, %edx
xorl %r8d, %edx
shrl $0x4, %edx
movl %r15d, %r12d
shrl $0x2, %r12d
movzwl (%r13,%r12,2), %r8d
movl %ebx, %eax
shll $0x1e, %eax
sarl $0x1f, %eax
andl %ebp, %eax
xorl %r8d, %eax
shrl $0x4, %eax
movl 0xb30(%rdi,%rax,4), %r8d
addl 0xb30(%rdi,%rdx,4), %r8d
andl $-0x2, %r12d
movzwl (%r13,%r12), %eax
movl %ebx, %edx
shll $0x1d, %edx
sarl $0x1f, %edx
andl %ebp, %edx
xorl %eax, %edx
shrl $0x4, %edx
addl 0xb30(%rdi,%rdx,4), %r8d
shrl $0x4, %r15d
movzwl (%r13,%r15,2), %eax
movl %ebx, %edx
shll $0x1c, %edx
sarl $0x1f, %edx
andl %ebp, %edx
xorl %eax, %edx
shrl $0x4, %edx
addl 0xb30(%rdi,%rdx,4), %r8d
andl $-0x2, %r15d
movzwl (%r13,%r15), %eax
movl %ebx, %edx
shll $0x1b, %edx
sarl $0x1f, %edx
andl %ebp, %edx
xorl %eax, %edx
shrl $0x4, %edx
addl 0xb30(%rdi,%rdx,4), %r8d
movzwl (%r10,%rbx,2), %eax
shrl $0x2, %eax
andl $-0x4, %eax
movl 0xb30(%rdi,%rax), %edx
addl %r8d, %edx
movl %edx, -0x4(%r9,%rbx,8)
xorl $0x1fc, %eax            # imm = 0x1FC
addl 0xb30(%rdi,%rax), %r8d
movl %r8d, (%r9,%rbx,8)
incq %rbx
cmpq %rbx, %rcx
jne 0x36660
movl -0x7c(%rsp), %r15d
cmpl $0x10, %r15d
movq -0x68(%rsp), %r12
movq -0x78(%rsp), %r8
movq -0x60(%rsp), %rbx
jb 0x3678c
movl $0x20, %eax
xorl %edx, %edx
movq (%r11,%rdx,8), %xmm0
movd %eax, %xmm1
pshufd $0x50, %xmm1, %xmm1     # xmm1 = xmm1[0,0,1,1]
paddd %xmm0, %xmm1
movq %xmm1, (%r11,%rdx,8)
addl $0x10, %eax
incq %rdx
cmpq %rdx, %r8
jne 0x36768
movq %rsi, %rax
shlq $0x8, %rax
movq %r12, %r13
addq %r12, %rax
movq %rsi, %rdx
shlq $0x9, %rdx
movups (%rax), %xmm0
movq -0x58(%rsp), %r8
movups %xmm0, (%r8,%rdx)
movq %rbx, %r12
leaq (%r14,%rbx), %rdx
xorl %r8d, %r8d
movzbl (%r14,%r8), %ebx
movq -0x40(%rsp,%r8,4), %xmm0
movd (%rax,%rbx,4), %xmm1
pshufd $0x50, %xmm1, %xmm1     # xmm1 = xmm1[0,0,1,1]
paddd %xmm0, %xmm1
movq %xmm1, -0x1674(%rdx,%r8,4)
leaq 0x2(%r8), %rbx
addq $0x4, %r8
cmpq $0x7e, %r8
movq %rbx, %r8
jb 0x367b7
incq %rsi
movl $0x100, %eax            # imm = 0x100
addq %rax, %r9
subq $-0x80, %r10
addq %rax, %r11
movq %r12, %rbx
addq $0x200, %rbx            # imm = 0x200
cmpq $0x4, %rsi
movq %r13, %r12
jne 0x36643
addq $0x1b8, %rsp            # imm = 0x1B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq