// File: /workspace/github_cpp_makefile_star2_O2/sbingner[P]kerneldec/lzfse/src/lzfse_fse.c
// Function: fse_init_value_decoder_table
void fse_init_value_decoder_table(int nstates, int nsymbols,
                                  const uint16_t *__restrict freq,
                                  const uint8_t *__restrict symbol_vbits,
                                  const int32_t *__restrict symbol_vbase,
                                  fse_value_decoder_entry *__restrict t) {
  assert(nsymbols <= 256);
  assert(fse_check_freq(freq, nsymbols, nstates) == 0);

  int n_clz = __builtin_clz(nstates);
  for (int i = 0; i < nsymbols; i++) {
    int f = (int)freq[i];
    if (f == 0)
      continue; // skip this symbol, no occurrences

    int k =
        __builtin_clz(f) - n_clz; // shift needed to ensure N <= (F<<K) < 2*N
    int j0 = ((2 * nstates) >> k) - f;

    fse_value_decoder_entry ei = {0};
    ei.value_bits = symbol_vbits[i];
    ei.vbase = symbol_vbase[i];

    // Initialize all states S reached by this symbol: OFFSET <= S < OFFSET + F
    for (int j = 0; j < f; j++) {
      fse_value_decoder_entry e = ei;

      if (j < j0) {
        e.total_bits = (uint8_t)k + e.value_bits;
        e.delta = (int16_t)(((f + j) << k) - nstates);
      } else {
        e.total_bits = (uint8_t)(k - 1) + e.value_bits;
        e.delta = (int16_t)((j - j0) << (k - 1));
      }

      memcpy(t, &e, 8);
      t++;
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r8, 0x20(%rsp)
movq %rcx, 0x18(%rsp)
cmpl $0x101, %esi            # imm = 0x101
jge 0x72b3
movl %esi, %r10d
movl %esi, %eax
xorl %ecx, %ecx
xorl %esi, %esi
cmpq %rcx, %rax
je 0x71cc
movzwl (%rdx,%rcx,2), %r8d
addq %r8, %rsi
incq %rcx
jmp 0x71ba
movslq %edi, %rax
cmpq %rax, %rsi
ja 0x72cc
bsrl %edi, %eax
xorl $0x1f, %eax
movl %eax, 0xc(%rsp)
leal (%rdi,%rdi), %eax
movl %eax, 0x8(%rsp)
xorl %esi, %esi
testl %r10d, %r10d
cmovlel %esi, %r10d
movq %rdx, 0x10(%rsp)
cmpq %r10, %rsi
je 0x72a4
movzwl (%rdx,%rsi,2), %ebx
testl %ebx, %ebx
je 0x729c
movq %r10, %rdx
bsrl %ebx, %r10d
xorl $0x1f, %r10d
subl 0xc(%rsp), %r10d
movl 0x8(%rsp), %r15d
movl %r10d, %ecx
sarl %cl, %r15d
movq 0x18(%rsp), %rax
movb (%rax,%rsi), %r12b
movq 0x20(%rsp), %rax
movl (%rax,%rsi,4), %r13d
leal -0x1(%r10), %r11d
movl %ebx, %eax
negl %eax
movl %ebx, %r8d
subl %r15d, %r8d
subl %ebx, %r15d
movl %ebx, %ebp
xorl %ebx, %ebx
movl %eax, %ecx
addl %ebx, %ecx
je 0x7294
cmpl %r15d, %ebx
jge 0x726b
leal (%rbx,%rbp), %r14d
movl %r10d, %ecx
shll %cl, %r14d
subl %edi, %r14d
movl %r10d, %ecx
jmp 0x7278
leal (%r8,%rbx), %r14d
movl %r11d, %ecx
shll %cl, %r14d
movl %r11d, %ecx
addb %r12b, %cl
movb %cl, (%r9)
movb %r12b, 0x1(%r9)
movw %r14w, 0x2(%r9)
movl %r13d, 0x4(%r9)
addq $0x8, %r9
incq %rbx
jmp 0x724e
movq %rdx, %r10
movq 0x10(%rsp), %rdx
incq %rsi
jmp 0x71f7
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x26ab(%rip), %rdi      # 0x9965
leaq 0x26b4(%rip), %rsi      # 0x9975
leaq 0x273c(%rip), %rcx      # 0x9a04
pushq $0x72
jmp 0x72e3
leaq 0x2704(%rip), %rdi      # 0x99d7
leaq 0x269b(%rip), %rsi      # 0x9975
leaq 0x2723(%rip), %rcx      # 0x9a04
pushq $0x73
popq %rdx
callq 0x3070