// File: 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
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x18(%rbp), %rax
movzwl (%rax), %eax
movl %eax, -0x28(%rbp)
movq -0x20(%rbp), %rax
movl -0x28(%rbp), %ecx
xorl $0x7ff, %ecx            # imm = 0x7FF
shrl $0x4, %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
movl %eax, -0x24(%rbp)
movq -0x20(%rbp), %rax
movl -0x28(%rbp), %ecx
shrl $0x4, %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
movl %eax, -0x2c(%rbp)
movl -0x24(%rbp), %eax
movq -0x20(%rbp), %rcx
movq -0x18(%rbp), %rdx
movzwl 0x10(%rdx), %edx
sarl $0x4, %edx
movslq %edx, %rdx
addl (%rcx,%rdx,4), %eax
movl %eax, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0xc(%rbp), %eax
jae 0x6a8a2
movq -0x8(%rbp), %rax
addq $0x4, %rax
movl -0x34(%rbp), %ecx
imulq $0x440, %rcx, %rcx      # imm = 0x440
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movl -0x34(%rbp), %ecx
shll $0x4, %ecx
movl %ecx, %ecx
shlq %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rdi
movl -0x2c(%rbp), %esi
movq -0x40(%rbp), %rdx
movq -0x20(%rbp), %rcx
callq 0x6aa30
movq -0x48(%rbp), %rdi
addq $0x10, %rdi
movl -0x30(%rbp), %esi
movq -0x40(%rbp), %rdx
addq $0x20, %rdx
movq -0x20(%rbp), %rcx
callq 0x6aa30
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x6a830
movq -0x8(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x4c(%rbp)
cmpl $0x10, -0x4c(%rbp)
jbe 0x6aa1b
movq -0x18(%rbp), %rax
addq $0x200, %rax            # imm = 0x200
movq %rax, -0x58(%rbp)
movq -0x8(%rbp), %rax
addq $0x4, %rax
addq $0x40, %rax
movq %rax, -0x60(%rbp)
movl -0x4c(%rbp), %eax
subl $0xf, %eax
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
shrl %eax
movl %eax, -0x4c(%rbp)
movq -0x20(%rbp), %rax
movq -0x18(%rbp), %rcx
movzwl 0x10(%rcx), %ecx
xorl $0x7ff, %ecx            # imm = 0x7FF
sarl $0x4, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
addl -0x24(%rbp), %eax
movl %eax, -0x24(%rbp)
movl -0x4c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x4c(%rbp)
addl $0x80, %eax
movl %eax, -0x64(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x68(%rbp)
movl -0x64(%rbp), %eax
andl $0x1, %eax
movl %eax, -0x6c(%rbp)
movl -0x64(%rbp), %eax
shrl %eax
movl %eax, -0x64(%rbp)
movq -0x20(%rbp), %rax
movq -0x58(%rbp), %rcx
movl -0x64(%rbp), %edx
movzwl (%rcx,%rdx,2), %ecx
xorl %edx, %edx
subl -0x6c(%rbp), %edx
andl $0x7ff, %edx            # imm = 0x7FF
xorl %edx, %ecx
shrl $0x4, %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
addl -0x68(%rbp), %eax
movl %eax, -0x68(%rbp)
cmpl $0x2, -0x64(%rbp)
jae 0x6a91c
movq -0x58(%rbp), %rax
movl -0x4c(%rbp), %ecx
movzwl 0x100(%rax,%rcx,2), %eax
movl %eax, -0x70(%rbp)
movl -0x68(%rbp), %edx
movq -0x20(%rbp), %rax
movl -0x70(%rbp), %ecx
shrl $0x4, %ecx
movl %ecx, %ecx
addl (%rax,%rcx,4), %edx
movq -0x60(%rbp), %rax
movl -0x4c(%rbp), %ecx
shlq %rcx
movl %edx, (%rax,%rcx,4)
movl -0x68(%rbp), %edx
movq -0x20(%rbp), %rax
movl -0x70(%rbp), %ecx
xorl $0x7ff, %ecx            # imm = 0x7FF
shrl $0x4, %ecx
movl %ecx, %ecx
addl (%rax,%rcx,4), %edx
movq -0x60(%rbp), %rax
movl -0x4c(%rbp), %ecx
shlq %rcx
movl %edx, 0x4(%rax,%rcx,4)
cmpl $0x0, -0x4c(%rbp)
jne 0x6a905
movq -0x8(%rbp), %rax
movl (%rax), %eax
subl $0x10, %eax
movl %eax, %eax
shlq $0x2, %rax
movq %rax, -0x80(%rbp)
movl $0x1, -0x74(%rbp)
movl -0x74(%rbp), %eax
cmpl -0xc(%rbp), %eax
jae 0x6aa19
movq -0x8(%rbp), %rdi
addq $0x4, %rdi
movl -0x74(%rbp), %eax
imulq $0x440, %rax, %rax      # imm = 0x440
addq %rax, %rdi
addq $0x40, %rdi
movq -0x8(%rbp), %rsi
addq $0x4, %rsi
addq $0x40, %rsi
movq -0x80(%rbp), %rdx
callq 0x4320
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0x6a9d8
jmp 0x6aa1b
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)