// File: /workspace/github_cpp_makefile_star2_O3/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 $0x18, %rsp
movq %rcx, %r14
movq %rdx, %r15
movq %rdi, 0x10(%rsp)
movzwl (%rdx), %eax
shrl $0x2, %eax
andl $-0x4, %eax
movl %eax, %ecx
xorl $0x1fc, %ecx            # imm = 0x1FC
movl (%r14,%rcx), %ecx
movl %ecx, 0x4(%rsp)
movl %esi, (%rsp)
testl %esi, %esi
je 0x369ab
movl (%r14,%rax), %eax
movl %eax, 0xc(%rsp)
movzwl 0x10(%r15), %eax
shrl $0x4, %eax
movl (%r14,%rax,4), %eax
addl 0x4(%rsp), %eax
movl %eax, 0x8(%rsp)
movl (%rsp), %ebx
movq 0x10(%rsp), %rax
leaq 0x24(%rax), %rbp
shlq $0x4, %rbx
xorl %r13d, %r13d
leaq -0x20(%rbp), %rdx
movl %r13d, %r12d
andl $-0x10, %r12d
leaq (%r15,%r12,2), %rdi
movl 0xc(%rsp), %esi
movq %r14, %rcx
callq 0x36a9d
leaq (%r15,%r12,2), %rdi
addq $0x10, %rdi
movl 0x8(%rsp), %esi
movq %rbp, %rdx
movq %r14, %rcx
callq 0x36a9d
addq $0x10, %r13
addq $0x440, %rbp            # imm = 0x440
cmpq %r13, %rbx
jne 0x36969
movq 0x10(%rsp), %rbp
movl (%rbp), %r12d
cmpl $0x11, %r12d
jb 0x36a8e
leaq 0x44(%rbp), %r13
leal -0xf(%r12), %eax
shrl %eax
movzwl 0x10(%r15), %ecx
shrl $0x2, %ecx
andl $-0x4, %ecx
xorl $0x1fc, %ecx            # imm = 0x1FC
movl 0x4(%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 0x369eb
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 0x369e3
cmpl $0x2, (%rsp)
jb 0x36a8e
addl $-0x10, %r12d
shlq $0x2, %r12
movl (%rsp), %eax
addq $0x484, %rbp            # imm = 0x484
imulq $0x440, %rax, %rbx      # imm = 0x440
addq $-0x440, %rbx           # imm = 0xFBC0
xorl %r14d, %r14d
leaq (%r14,%rbp), %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x4290
addq $0x440, %r14            # imm = 0x440
cmpq %r14, %rbx
jne 0x36a73
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq