// File: /workspace/github_cpp_makefile_star2_O2/sisong[P]ApkDiffPatch/lzma/C/LzmaEnc.c
// Function: LenPriceEnc_UpdateTables
Z7_FASTCALL LenPriceEnc_UpdateTables(
    CLenPriceEnc *p,
    unsigned numPosStates,
    const CLenEnc *enc,
    const CProbPrice *ProbPrices)
{
  UInt32 b;
 
  {
    unsigned prob = enc->low[0];
    UInt32 a, c;
    unsigned posState;
    b = GET_PRICEa_1(prob);
    a = GET_PRICEa_0(prob);
    c = b + GET_PRICEa_0(enc->low[kLenNumLowSymbols]);
    for (posState = 0; posState < numPosStates; posState++)
    {
      UInt32 *prices = p->prices[posState];
      const CLzmaProb *probs = enc->low + (posState << (1 + kLenNumLowBits));
      SetPrices_3(probs, a, prices, ProbPrices);
      SetPrices_3(probs + kLenNumLowSymbols, c, prices + kLenNumLowSymbols, ProbPrices);
    }
  }

  /*
  {
    unsigned i;
    UInt32 b;
    a = GET_PRICEa_0(enc->low[0]);
    for (i = 0; i < kLenNumLowSymbols; i++)
      p->prices2[i] = a;
    a = GET_PRICEa_1(enc->low[0]);
    b = a + GET_PRICEa_0(enc->low[kLenNumLowSymbols]);
    for (i = kLenNumLowSymbols; i < kLenNumLowSymbols * 2; i++)
      p->prices2[i] = b;
    a += GET_PRICEa_1(enc->low[kLenNumLowSymbols]);
  }
  */
 
  // p->counter = numSymbols;
  // p->counter = 64;

  {
    unsigned i = p->tableSize;
    
    if (i > kLenNumLowSymbols * 2)
    {
      const CLzmaProb *probs = enc->high;
      UInt32 *prices = p->prices[0] + kLenNumLowSymbols * 2;
      i -= kLenNumLowSymbols * 2 - 1;
      i >>= 1;
      b += GET_PRICEa_1(enc->low[kLenNumLowSymbols]);
      do
      {
        /*
        p->prices2[i] = a +
        // RcTree_GetPrice(enc->high, kLenNumHighBits, i - kLenNumLowSymbols * 2, ProbPrices);
        LitEnc_GetPrice(probs, i - kLenNumLowSymbols * 2, ProbPrices);
        */
        // UInt32 price = a + RcTree_GetPrice(probs, kLenNumHighBits - 1, sym, ProbPrices);
        unsigned sym = --i + (1 << (kLenNumHighBits - 1));
        UInt32 price = b;
        do
        {
          const unsigned bit = sym & 1;
          sym >>= 1;
          price += GET_PRICEa(probs[sym], bit);
        }
        while (sym >= 2);

        {
          const unsigned prob = probs[(size_t)i + (1 << (kLenNumHighBits - 1))];
          prices[(size_t)i * 2    ] = price + GET_PRICEa_0(prob);
          prices[(size_t)i * 2 + 1] = price + GET_PRICEa_1(prob);
        }
      }
      while (i);

      {
        unsigned posState;
        const size_t num = (p->tableSize - kLenNumLowSymbols * 2) * sizeof(p->prices[0][0]);
        for (posState = 1; posState < numPosStates; posState++)
          memcpy(p->prices[posState] + kLenNumLowSymbols * 2, p->prices[0] + kLenNumLowSymbols * 2, num);
      }
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rcx, %r14
movq %rdx, %r15
movzwl (%rdx), %eax
shrl $0x2, %eax
andl $-0x4, %eax
movl (%rcx,%rax), %ecx
movl %ecx, 0x1c(%rsp)
xorl $0x1fc, %eax            # imm = 0x1FC
movl (%r14,%rax), %ecx
movzwl 0x10(%rdx), %eax
shrl $0x4, %eax
movl (%r14,%rax,4), %eax
movl %ecx, 0x14(%rsp)
addl %ecx, %eax
movl %eax, 0x18(%rsp)
movl %esi, %ebx
movq %rbx, 0x20(%rsp)
shlq $0x4, %rbx
movq %rdi, 0x8(%rsp)
leaq 0x24(%rdi), %r13
xorl %r12d, %r12d
cmpq %r12, %rbx
je 0x2e76f
leaq -0x20(%r13), %rdx
movl %r12d, %ebp
andl $-0x10, %ebp
leaq (%r15,%rbp,2), %rdi
movl 0x1c(%rsp), %esi
movq %r14, %rcx
callq 0x2e860
leaq (%r15,%rbp,2), %rdi
addq $0x10, %rdi
movl 0x18(%rsp), %esi
movq %r13, %rdx
movq %r14, %rcx
callq 0x2e860
addq $0x10, %r12
addq $0x440, %r13            # imm = 0x440
jmp 0x2e72c
movq 0x8(%rsp), %rax
movl (%rax), %r12d
cmpl $0x11, %r12d
jb 0x2e851
movq 0x8(%rsp), %rax
leaq 0x44(%rax), %r13
leal -0xf(%r12), %eax
shrl %eax
movzwl 0x10(%r15), %ecx
shrl $0x2, %ecx
andl $-0x4, %ecx
xorl $0x1fc, %ecx            # imm = 0x1FC
movl 0x14(%rsp), %r9d
addl (%r14,%rcx), %r9d
leal 0x7f(%rax), %edx
movl %r9d, %ecx
movl %edx, %esi
movl %edx, %edi
andl $0x1, %edi
negl %edi
shrl %esi
movl %edx, %r8d
andl $-0x2, %r8d
movzwl 0x200(%r15,%r8), %r8d
andl $0x7f0, %edi            # imm = 0x7F0
xorl %r8d, %edi
shrl $0x4, %edi
addl (%r14,%rdi,4), %ecx
cmpl $0x3, %edx
movl %esi, %edx
ja 0x2e7b3
decl %eax
movzwl 0x300(%r15,%rax,2), %edx
shrl $0x2, %edx
andl $-0x4, %edx
movl (%r14,%rdx), %esi
addl %ecx, %esi
movl %esi, (%r13,%rax,8)
xorl $0x1fc, %edx            # imm = 0x1FC
addl (%r14,%rdx), %ecx
movl %ecx, 0x4(%r13,%rax,8)
testl %eax, %eax
jne 0x2e7ab
addl $-0x10, %r12d
shlq $0x2, %r12
addq $0x484, 0x8(%rsp)       # imm = 0x484
pushq $0x1
popq %rbx
cmpq 0x20(%rsp), %rbx
jae 0x2e851
movq 0x8(%rsp), %r14
movq %r14, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x42c0
incq %rbx
addq $0x440, %r14            # imm = 0x440
movq %r14, 0x8(%rsp)
jmp 0x2e826
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq