// File: /workspace/github_cpp_makefile_star2_O3/sbingner[P]kerneldec/lzfse/src/lzvn_encode_base.c
// Function: lzvn_emit_match
static inline lzvn_offset lzvn_emit_match(lzvn_encoder_state *state,
                                          lzvn_match_info match) {
  size_t L = (size_t)(match.m_begin - state->src_literal); // literal count
  size_t M = (size_t)match.M;                              // match length
  size_t D = (size_t)match.D;                              // match distance
  size_t D_prev = (size_t)state->d_prev; // previously emitted match distance
  unsigned char *dst = emit(state->src + state->src_literal, state->dst,
                            state->dst_end, L, M, D, D_prev);
  // Check if DST is full
  if (dst >= state->dst_end) {
    return 0; // FULL
  }

  // Update state
  lzvn_offset dst_used = dst - state->dst;
  state->d_prev = match.D;
  state->dst = dst;
  state->src_literal = match.m_end;
  return dst_used;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq 0x60(%rsp), %r12
movq 0x70(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x28(%rdi), %r14
movq 0x30(%rdi), %r13
subq %r14, %r12
movq 0x78(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x70(%rdi), %rax
movq %rax, 0x10(%rsp)
addq (%rdi), %r14
movq %rdi, 0x8(%rsp)
movq 0x40(%rdi), %r15
cmpq $0x10, %r12
jb 0x6e65
movl $0x10f, %ebp            # imm = 0x10F
cmpq %rbp, %r12
movl $0x10f, %ebx            # imm = 0x10F
cmovbq %r12, %rbx
leaq (%rbx,%r13), %rax
addq $0xa, %rax
cmpq %r15, %rax
jae 0x6f7d
movl %ebx, %eax
shll $0x8, %eax
addl $0xfffff0e0, %eax       # imm = 0xFFFFF0E0
movw %ax, (%r13)
leaq 0x2(%r13), %rdi
subq %rbx, %r12
leaq -0x1(%rbx), %rdx
andq $-0x8, %rdx
addq $0x8, %rdx
movq %r14, %rsi
callq 0x30c0
addq %rbx, %r13
addq $0x2, %r13
addq %rbx, %r14
cmpq $0xf, %r12
ja 0x6e0e
cmpq $0x4, %r12
jb 0x6eaa
leaq (%r12,%r13), %rax
addq $0xa, %rax
cmpq %r15, %rax
jae 0x6f7d
movl %r12d, %eax
orb $-0x20, %al
leaq 0x1(%r13), %rdi
movb %al, (%r13)
leaq -0x1(%r12), %rdx
andq $-0x8, %rdx
addq $0x8, %rdx
movq %r14, %rsi
callq 0x30c0
addq %r12, %r13
incq %r13
addq %r12, %r14
xorl %r12d, %r12d
movl $0xa, %esi
subq %r12, %rsi
subq %r12, %rsi
movq 0x20(%rsp), %rdi
cmpq %rdi, %rsi
cmovaeq %rdi, %rsi
leaq 0x8(%r13), %rax
cmpq %r15, %rax
jae 0x6f7d
movq %rdi, %rax
subq %rsi, %rax
leaq -0x3(%rsi), %rdx
movl (%r14), %ecx
movq 0x18(%rsp), %r8
cmpq 0x10(%rsp), %r8
jne 0x6f14
movl %r12d, %edi
shll $0x6, %edi
testq %r12, %r12
leal (%rdi,%rdx,8), %edx
movl $0xf0, %edi
movl $0x6, %r8d
cmovel %edi, %r8d
cmovnel %edx, %esi
orl %r8d, %esi
movb %sil, (%r13)
incq %r13
jmp 0x6fd4
cmpq $0x5ff, %r8             # imm = 0x5FF
ja 0x6f3f
movl %r8d, %esi
shrl $0x8, %esi
movl %r12d, %edi
shll $0x6, %edi
orl %esi, %edi
leal (%rdi,%rdx,8), %edx
movb %dl, (%r13)
movb %r8b, 0x1(%r13)
addq $0x2, %r13
jmp 0x6fd4
cmpq $0x22, %rdi
ja 0x6fbb
cmpq $0x3fff, %r8            # imm = 0x3FFF
ja 0x6fbb
testq %rax, %rax
je 0x6fbb
addl $-0x3, %edi
movl %edi, %eax
shrl $0x2, %eax
leal (%rax,%r12,8), %eax
addb $-0x60, %al
movb %al, (%r13)
andl $0x3, %edi
leal (%rdi,%r8,4), %eax
movw %ax, 0x1(%r13)
movl %ecx, 0x3(%r13)
leaq (%r12,%r13), %r15
addq $0x3, %r15
movq 0x8(%rsp), %rdi
cmpq 0x40(%rdi), %r15
jae 0x6faa
leaq 0x60(%rsp), %rcx
movq %r15, %rax
subq 0x30(%rdi), %rax
movq 0x18(%rcx), %rdx
movq %rdx, 0x70(%rdi)
movq %r15, 0x30(%rdi)
movq 0x8(%rcx), %rcx
movq %rcx, 0x28(%rdi)
jmp 0x6fac
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %r12d, %esi
shll $0x6, %esi
leal (%rsi,%rdx,8), %edx
orb $0x7, %dl
movb %dl, (%r13)
movw %r8w, 0x1(%r13)
addq $0x3, %r13
movl %ecx, (%r13)
addq %r13, %r12
cmpq $0x10, %rax
jb 0x701d
movl $0x10f, %edx            # imm = 0x10F
movq 0x8(%rsp), %rdi
leaq 0x2(%r12), %rcx
cmpq %r15, %rcx
jae 0x6f82
cmpq %rdx, %rax
movl $0x10f, %esi            # imm = 0x10F
cmovbq %rax, %rsi
subq %rsi, %rax
shll $0x8, %esi
addl $0xfffff0f0, %esi       # imm = 0xFFFFF0F0
movw %si, (%r12)
movq %rcx, %r12
cmpq $0xf, %rax
ja 0x6feb
jmp 0x7025
movq %r12, %rcx
movq 0x8(%rsp), %rdi
testq %rax, %rax
je 0x7043
leaq 0x1(%rcx), %rdx
cmpq %r15, %rdx
jae 0x6f82
orb $-0x10, %al
movb %al, (%rcx)
movq %rdx, %r15
jmp 0x6f82
movq %rcx, %r15
jmp 0x6f82