// File: /workspace/github_cpp_makefile_star2_O1/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 0x36926
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 0x368ef
movl %r11d, %ecx
jmp 0x3692b
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 0x368bd
movl 0xf0(%rdi), %ebp
incl %ebp
movl %ebp, %ecx
shrl %ecx
leaq 0x1600(%rdi), %rax
movq %rax, -0x60(%rsp)
leaq 0x2580(%rdi), %rax
movq %rax, -0x70(%rsp)
leaq 0x1a00(%rdi), %rax
movq %rax, -0x68(%rsp)
leaq 0x1604(%rdi), %r9
leaq 0x25c0(%rdi), %r10
leaq 0x163c(%rdi), %r11
leaq -0x7(%rcx), %rbx
movl $0x1a14, %r14d          # imm = 0x1A14
xorl %r15d, %r15d
xorl %r13d, %r13d
movl %ebp, -0x74(%rsp)
movq %r14, -0x58(%rsp)
cmpl $0x2, %ebp
jb 0x36ae1
movq %r13, %rbp
shlq $0x7, %rbp
addq -0x70(%rsp), %rbp
xorl %esi, %esi
leal 0x20(%rsi), %r8d
movl %r8d, %edx
andl $-0x2, %edx
movzwl (%rbp,%rdx), %edx
testb $0x1, %sil
movl $0x7f0, %eax            # imm = 0x7F0
cmovel %r15d, %eax
xorl %edx, %eax
shrl $0x4, %eax
movl %r8d, %r12d
shrl $0x2, %r12d
movzwl (%rbp,%r12,2), %edx
testb $0x2, %sil
movl $0x7f0, %r14d           # imm = 0x7F0
cmovel %r15d, %r14d
xorl %edx, %r14d
shrl $0x4, %r14d
movl 0xb30(%rdi,%r14,4), %edx
addl 0xb30(%rdi,%rax,4), %edx
andl $-0x2, %r12d
movzwl (%rbp,%r12), %eax
testb $0x4, %sil
movl $0x7f0, %r14d           # imm = 0x7F0
cmovel %r15d, %r14d
xorl %eax, %r14d
shrl $0x4, %r14d
addl 0xb30(%rdi,%r14,4), %edx
shrl $0x4, %r8d
movzwl (%rbp,%r8,2), %eax
testb $0x8, %sil
movl $0x7f0, %r14d           # imm = 0x7F0
cmovel %r15d, %r14d
xorl %eax, %r14d
shrl $0x4, %r14d
addl 0xb30(%rdi,%r14,4), %edx
andl $-0x2, %r8d
movzwl (%rbp,%r8), %eax
testb $0x10, %sil
movl $0x7f0, %r8d            # imm = 0x7F0
cmovel %r15d, %r8d
xorl %eax, %r8d
shrl $0x4, %r8d
addl 0xb30(%rdi,%r8,4), %edx
movzwl (%r10,%rsi,2), %eax
shrl $0x2, %eax
andl $-0x4, %eax
movl 0xb30(%rdi,%rax), %r8d
addl %edx, %r8d
movl %r8d, -0x4(%r9,%rsi,8)
xorl $0x1fc, %eax            # imm = 0x1FC
addl 0xb30(%rdi,%rax), %edx
movl %edx, (%r9,%rsi,8)
incq %rsi
cmpq %rsi, %rcx
jne 0x369e3
movl -0x74(%rsp), %ebp
cmpl $0x10, %ebp
jb 0x36b05
movl $0x20, %edx
xorl %esi, %esi
addl %edx, -0x4(%r11,%rsi,8)
addl %edx, (%r11,%rsi,8)
addl $0x10, %edx
incq %rsi
cmpq %rsi, %rbx
jne 0x36af1
movq %r13, %rdx
shlq $0x8, %rdx
addq -0x60(%rsp), %rdx
movq %r13, %rax
shlq $0x9, %rax
movl (%rdx), %esi
movq -0x68(%rsp), %r8
movl %esi, (%r8,%rax)
movl 0x4(%rdx), %esi
movl %esi, 0x4(%r8,%rax)
movl 0x8(%rdx), %esi
movl %esi, 0x8(%r8,%rax)
movl 0xc(%rdx), %esi
movl %esi, 0xc(%r8,%rax)
movq -0x58(%rsp), %r14
leaq (%rdi,%r14), %rsi
xorl %r12d, %r12d
movzbl 0x3084(%rdi,%r12), %eax
movl (%rdx,%rax,4), %eax
movl -0x40(%rsp,%r12,4), %r8d
addl %eax, %r8d
movl %r8d, -0x4(%rsi,%r12,4)
addl -0x3c(%rsp,%r12,4), %eax
movl %eax, (%rsi,%r12,4)
leaq 0x2(%r12), %rax
addq $0x4, %r12
cmpq $0x7e, %r12
movq %rax, %r12
jb 0x36b47
incq %r13
movl $0x100, %eax            # imm = 0x100
addq %rax, %r9
subq $-0x80, %r10
addq %rax, %r11
addq $0x200, %r14            # imm = 0x200
cmpq $0x4, %r13
jne 0x369c7
addq $0x1b8, %rsp            # imm = 0x1B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq