// File: sbingner[P]kerneldec/lzfse/src/lzfse_encode_base.c
// Function: lzfse_push_lmd
static inline int lzfse_push_lmd(lzfse_encoder_state *s, uint32_t L,
                                 uint32_t M, uint32_t D) {
  // Check if we have enough space to push the match (we add some margin to copy
  // literals faster here, and round final count later)
  if (s->n_matches + 1 + 8 > LZFSE_MATCHES_PER_BLOCK)
    return LZFSE_STATUS_DST_FULL; // state full
  if (s->n_literals + L + 16 > LZFSE_LITERALS_PER_BLOCK)
    return LZFSE_STATUS_DST_FULL; // state full

  // Store match
  uint32_t n = s->n_matches++;
  s->l_values[n] = L;
  s->m_values[n] = M;
  s->d_values[n] = D;

  // Store literals
  uint8_t *dst = s->literals + s->n_literals;
  const uint8_t *src = s->src + s->src_literal;
  uint8_t *dst_end = dst + L;
  if (s->src_literal + L + 16 > s->src_end) {
    // Careful at the end of SRC, we can't read 16 bytes
    if (L > 0)
      memcpy(dst, src, L);
  } else {
    copy16(dst, src);
    dst += 16;
    src += 16;
    while (dst < dst_end) {
      copy16(dst, src);
      dst += 16;
      src += 16;
    }
  }
  s->n_literals += L;

  // Update state
  s->src_literal += L + M;

  return LZFSE_STATUS_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movq %rdi, -0xd0(%rbp)
movl %esi, -0xd4(%rbp)
movl %edx, -0xd8(%rbp)
movl %ecx, -0xdc(%rbp)
movq -0xd0(%rbp), %rax
movl 0x58(%rax), %eax
addl $0x1, %eax
addl $0x8, %eax
cmpl $0x2710, %eax           # imm = 0x2710
jbe 0x6e9a
movl $0xfffffffe, -0xc4(%rbp) # imm = 0xFFFFFFFE
jmp 0x71b1
movq -0xd0(%rbp), %rax
movl 0x5c(%rax), %eax
addl -0xd4(%rbp), %eax
addl $0x10, %eax
cmpl $0x9c40, %eax           # imm = 0x9C40
jbe 0x6ec3
movl $0xfffffffe, -0xc4(%rbp) # imm = 0xFFFFFFFE
jmp 0x71b1
movq -0xd0(%rbp), %rcx
movl 0x58(%rcx), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, 0x58(%rcx)
movl %eax, -0xe0(%rbp)
movl -0xd4(%rbp), %edx
movq -0xd0(%rbp), %rax
movl -0xe0(%rbp), %ecx
movl %edx, 0x60(%rax,%rcx,4)
movl -0xd8(%rbp), %edx
movq -0xd0(%rbp), %rax
movl -0xe0(%rbp), %ecx
movl %edx, 0x9ca0(%rax,%rcx,4)
movl -0xdc(%rbp), %edx
movq -0xd0(%rbp), %rax
movl -0xe0(%rbp), %ecx
movl %edx, 0x138e0(%rax,%rcx,4)
movq -0xd0(%rbp), %rax
addq $0x1d520, %rax          # imm = 0x1D520
movq -0xd0(%rbp), %rcx
movl 0x5c(%rcx), %ecx
addq %rcx, %rax
movq %rax, -0xe8(%rbp)
movq -0xd0(%rbp), %rax
movq (%rax), %rax
movq -0xd0(%rbp), %rcx
addq 0x10(%rcx), %rax
movq %rax, -0xf0(%rbp)
movq -0xe8(%rbp), %rax
movl -0xd4(%rbp), %ecx
addq %rcx, %rax
movq %rax, -0xf8(%rbp)
movq -0xd0(%rbp), %rax
movq 0x10(%rax), %rax
movl -0xd4(%rbp), %ecx
addq %rcx, %rax
addq $0x10, %rax
movq -0xd0(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jle 0x6fc8
cmpl $0x0, -0xd4(%rbp)
jbe 0x6fc3
movq -0xe8(%rbp), %rdi
movq -0xf0(%rbp), %rsi
movl -0xd4(%rbp), %eax
movl %eax, %edx
callq 0x30c0
jmp 0x7175
movq -0xe8(%rbp), %rcx
movq -0xf0(%rbp), %rax
movq %rcx, -0x68(%rbp)
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x70(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x68(%rbp), %rcx
movq -0x78(%rbp), %rax
movq %rcx, -0x28(%rbp)
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
movq -0x30(%rbp), %rcx
movq %rcx, (%rax)
movq -0x68(%rbp), %rcx
addq $0x8, %rcx
movq -0x80(%rbp), %rax
movq %rcx, -0x38(%rbp)
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rax
movq -0x40(%rbp), %rcx
movq %rcx, (%rax)
movq -0xe8(%rbp), %rax
addq $0x10, %rax
movq %rax, -0xe8(%rbp)
movq -0xf0(%rbp), %rax
addq $0x10, %rax
movq %rax, -0xf0(%rbp)
movq -0xe8(%rbp), %rax
cmpq -0xf8(%rbp), %rax
jae 0x7173
movq -0xe8(%rbp), %rcx
movq -0xf0(%rbp), %rax
movq %rcx, -0xa8(%rbp)
movq %rax, -0xb0(%rbp)
movq -0xb0(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0xb0(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rax
movq (%rax), %rax
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0xa8(%rbp), %rcx
movq -0xb8(%rbp), %rax
movq %rcx, -0x8(%rbp)
movq %rax, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq -0x10(%rbp), %rcx
movq %rcx, (%rax)
movq -0xa8(%rbp), %rcx
addq $0x8, %rcx
movq -0xc0(%rbp), %rax
movq %rcx, -0x18(%rbp)
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq -0x20(%rbp), %rcx
movq %rcx, (%rax)
movq -0xe8(%rbp), %rax
addq $0x10, %rax
movq %rax, -0xe8(%rbp)
movq -0xf0(%rbp), %rax
addq $0x10, %rax
movq %rax, -0xf0(%rbp)
jmp 0x7076
jmp 0x7175
movl -0xd4(%rbp), %ecx
movq -0xd0(%rbp), %rax
addl 0x5c(%rax), %ecx
movl %ecx, 0x5c(%rax)
movl -0xd4(%rbp), %eax
addl -0xd8(%rbp), %eax
movl %eax, %eax
movl %eax, %ecx
movq -0xd0(%rbp), %rax
addq 0x10(%rax), %rcx
movq %rcx, 0x10(%rax)
movl $0x0, -0xc4(%rbp)
movl -0xc4(%rbp), %eax
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq