// File: sbingner[P]kerneldec/lzfse/src/lzfse_encode_base.c
// Function: lzfse_encode_v1_freq_table
static inline size_t
lzfse_encode_v1_freq_table(lzfse_compressed_block_header_v2 *out,
                           const lzfse_compressed_block_header_v1 *in) {
  uint32_t accum = 0;
  int accum_nbits = 0;
  const uint16_t *src = &(in->l_freq[0]); // first value of first table (struct
                                          // will not be modified, so this code
                                          // will remain valid)
  uint8_t *dst = &(out->freq[0]);
  for (int i = 0; i < LZFSE_ENCODE_L_SYMBOLS + LZFSE_ENCODE_M_SYMBOLS +
                          LZFSE_ENCODE_D_SYMBOLS + LZFSE_ENCODE_LITERAL_SYMBOLS;
       i++) {
    // Encode one value to accum
    int nbits = 0;
    uint32_t bits = lzfse_encode_v1_freq_value(src[i], &nbits);
    assert(bits < (1 << nbits));
    accum |= bits << accum_nbits;
    accum_nbits += nbits;

    // Store bytes from accum to output buffer
    while (accum_nbits >= 8) {
      *dst = (uint8_t)(accum & 0xff);
      accum >>= 8;
      accum_nbits -= 8;
      dst++;
    }
  }
  // Store final byte if needed
  if (accum_nbits > 0) {
    *dst = (uint8_t)(accum & 0xff);
    dst++;
  }

  // Return final size of out
  uint32_t header_size = (uint32_t)(dst - (uint8_t *)out);
  out->packed_fields[0] = 0;
  out->packed_fields[1] = 0;
  out->packed_fields[2] = setField(header_size, 0, 32);

  return header_size;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
movq -0x10(%rbp), %rax
addq $0x32, %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
addq $0x20, %rax
movq %rax, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
cmpl $0x168, -0x2c(%rbp)     # imm = 0x168
jge 0x741a
movl $0x0, -0x30(%rbp)
movq -0x20(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movzwl (%rax,%rcx,2), %edi
leaq -0x30(%rbp), %rsi
callq 0x7690
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
movl -0x30(%rbp), %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
cmpl %ecx, %eax
jae 0x739e
jmp 0x73bd
leaq 0x9283(%rip), %rdi      # 0x10628
leaq 0x9224(%rip), %rsi      # 0x105d0
movl $0x81, %edx
leaq 0x9284(%rip), %rcx      # 0x1063c
callq 0x3070
movl -0x34(%rbp), %eax
movl -0x18(%rbp), %ecx
shll %cl, %eax
orl -0x14(%rbp), %eax
movl %eax, -0x14(%rbp)
movl -0x30(%rbp), %eax
addl -0x18(%rbp), %eax
movl %eax, -0x18(%rbp)
cmpl $0x8, -0x18(%rbp)
jl 0x740a
movl -0x14(%rbp), %eax
andl $0xff, %eax
movb %al, %cl
movq -0x28(%rbp), %rax
movb %cl, (%rax)
movl -0x14(%rbp), %eax
shrl $0x8, %eax
movl %eax, -0x14(%rbp)
movl -0x18(%rbp), %eax
subl $0x8, %eax
movl %eax, -0x18(%rbp)
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x73d4
jmp 0x740c
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x735d
cmpl $0x0, -0x18(%rbp)
jle 0x743c
movl -0x14(%rbp), %eax
andl $0xff, %eax
movb %al, %cl
movq -0x28(%rbp), %rax
movb %cl, (%rax)
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq -0x8(%rbp), %rcx
subq %rcx, %rax
movl %eax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq $0x0, 0x8(%rax)
movq -0x8(%rbp), %rax
movq $0x0, 0x10(%rax)
movl -0x38(%rbp), %edi
xorl %esi, %esi
movl $0x20, %edx
callq 0x77b0
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x18(%rax)
movl -0x38(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)