// File: sbingner[P]kerneldec/lzfse/src/lzfse_encode_base.c
// Function: lzfse_encode_v1_state
static inline void
lzfse_encode_v1_state(lzfse_compressed_block_header_v2 *out,
                      const lzfse_compressed_block_header_v1 *in) {
  out->magic = LZFSE_COMPRESSEDV2_BLOCK_MAGIC;
  out->n_raw_bytes = in->n_raw_bytes;

  // Literal state
  out->packed_fields[0] = setField(in->n_literals, 0, 20) |
              setField(in->n_literal_payload_bytes, 20, 20) |
              setField(in->n_matches, 40, 20) |
              setField(7 + in->literal_bits, 60, 3);
  out->packed_fields[1] = setField(in->literal_state[0], 0, 10) |
              setField(in->literal_state[1], 10, 10) |
              setField(in->literal_state[2], 20, 10) |
              setField(in->literal_state[3], 30, 10) |
              setField(in->n_lmd_payload_bytes, 40, 20) |
              setField(7 + in->lmd_bits, 60, 3);
  out->packed_fields[2] = out->packed_fields[2] // header_size already stored in v[2]
              | setField(in->l_state, 32, 10) | setField(in->m_state, 42, 10) |
              setField(in->d_state, 52, 10);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movl $0x32787662, (%rax)     # imm = 0x32787662
movq -0x10(%rbp), %rax
movl 0x4(%rax), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x10(%rbp), %rax
movl 0xc(%rax), %edi
xorl %esi, %esi
movl $0x14, %edx
callq 0x77b0
movq %rax, -0x68(%rbp)
movq -0x10(%rbp), %rax
movl 0x14(%rax), %edi
movl $0x14, %edx
movl %edx, %esi
callq 0x77b0
movq %rax, %rcx
movq -0x68(%rbp), %rax
orq %rcx, %rax
movq %rax, -0x60(%rbp)
movq -0x10(%rbp), %rax
movl 0x10(%rax), %edi
movl $0x28, %esi
movl $0x14, %edx
callq 0x77b0
movq %rax, %rcx
movq -0x60(%rbp), %rax
orq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rax
movl 0x1c(%rax), %edi
addl $0x7, %edi
movl $0x3c, %esi
movl $0x3, %edx
callq 0x77b0
movq -0x58(%rbp), %rcx
orq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rax
movzwl 0x20(%rax), %edi
xorl %esi, %esi
movl $0xa, %edx
callq 0x77b0
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rax
movzwl 0x22(%rax), %edi
movl $0xa, %edx
movl %edx, %esi
callq 0x77b0
movq %rax, %rcx
movq -0x50(%rbp), %rax
orq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movzwl 0x24(%rax), %edi
movl $0x14, %esi
movl $0xa, %edx
callq 0x77b0
movq %rax, %rcx
movq -0x48(%rbp), %rax
orq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movzwl 0x26(%rax), %edi
movl $0x1e, %esi
movl $0xa, %edx
callq 0x77b0
movq %rax, %rcx
movq -0x40(%rbp), %rax
orq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movl 0x18(%rax), %edi
movl $0x28, %esi
movl $0x14, %edx
callq 0x77b0
movq %rax, %rcx
movq -0x38(%rbp), %rax
orq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movl 0x28(%rax), %edi
addl $0x7, %edi
movl $0x3c, %esi
movl $0x3, %edx
callq 0x77b0
movq -0x30(%rbp), %rcx
orq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movzwl 0x2c(%rax), %edi
movl $0x20, %esi
movl $0xa, %edx
callq 0x77b0
movq %rax, %rcx
movq -0x28(%rbp), %rax
orq %rcx, %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movzwl 0x2e(%rax), %edi
movl $0x2a, %esi
movl $0xa, %edx
callq 0x77b0
movq %rax, %rcx
movq -0x20(%rbp), %rax
orq %rcx, %rax
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movzwl 0x30(%rax), %edi
movl $0x34, %esi
movl $0xa, %edx
callq 0x77b0
movq -0x18(%rbp), %rcx
orq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x18(%rax)
addq $0x70, %rsp
popq %rbp
retq
nop