// File: /workspace/github_cpp_makefile_star2_O3/sbingner[P]kerneldec/lzfse/src/lzfse_encode_base.c
// Function: lzfse_push_match
static int lzfse_push_match(lzfse_encoder_state *s, const lzfse_match *match) {
  // Save the initial n_matches, n_literals, src_literal
  uint32_t n_matches0 = s->n_matches;
  uint32_t n_literals0 = s->n_literals;
  lzfse_offset src_literals0 = s->src_literal;

  // L,M,D
  uint32_t L = (uint32_t)(match->pos - s->src_literal); // literal count
  uint32_t M = match->length;                           // match length
  uint32_t D = (uint32_t)(match->pos - match->ref);     // match distance
  int ok = 1;

  // Split L if too large
  while (L > LZFSE_ENCODE_MAX_L_VALUE) {
    if (lzfse_push_lmd(s, LZFSE_ENCODE_MAX_L_VALUE, 0, 1) != 0) {
      ok = 0;
      goto END;
    } // take D=1 because most frequent, but not actually used
    L -= LZFSE_ENCODE_MAX_L_VALUE;
  }

  // Split if M too large
  while (M > LZFSE_ENCODE_MAX_M_VALUE) {
    if (lzfse_push_lmd(s, L, LZFSE_ENCODE_MAX_M_VALUE, D) != 0) {
      ok = 0;
      goto END;
    }
    L = 0;
    M -= LZFSE_ENCODE_MAX_M_VALUE;
  }

  // L,M in range
  if (L > 0 || M > 0) {
    if (lzfse_push_lmd(s, L, M, D) != 0) {
      ok = 0;
      goto END;
    }
    L = M = 0;
    (void)L;
    (void)M; // dead stores
  }

END:
  if (!ok) {
    // Revert state
    s->n_matches = n_matches0;
    s->n_literals = n_literals0;
    s->src_literal = src_literals0;

    return LZFSE_STATUS_DST_FULL; // state tables full
  }

  return LZFSE_STATUS_OK; // OK
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
movl 0x58(%rdi), %eax
movl %eax, 0x14(%rsp)
movl 0x5c(%rdi), %ecx
movq 0x10(%rdi), %r13
movl (%rsi), %eax
movl 0x10(%rsi), %r15d
movl %eax, %ebp
subl %r13d, %ebp
subl 0x8(%rsi), %eax
movl %eax, 0xc(%rsp)
cmpl $0x13c, %ebp            # imm = 0x13C
movq %r13, 0x18(%rsp)
movl %ecx, 0x10(%rsp)
jb 0x4351
leaq 0x1d520(%rbx), %r14
leaq 0x1d538(%rbx), %rax
movq %rax, 0x20(%rsp)
movl $0x13b, %r8d            # imm = 0x13B
movl %ecx, %r12d
movl 0x58(%rbx), %eax
leal -0x2708(%rax), %ecx
cmpl $0xffffd8ef, %ecx       # imm = 0xFFFFD8EF
jb 0x4479
leal -0x9af6(%r12), %ecx
cmpl $0xffff63bf, %ecx       # imm = 0xFFFF63BF
jb 0x4479
leal 0x1(%rax), %ecx
movl %ecx, 0x58(%rbx)
movl $0x13b, 0x60(%rbx,%rax,4) # imm = 0x13B
movl $0x0, 0x9ca0(%rbx,%rax,4)
movl $0x1, 0x138e0(%rbx,%rax,4)
movl %r12d, %eax
leaq (%r14,%rax), %rdi
movq (%rbx), %rsi
leaq 0x14b(%r13), %rcx
cmpq 0x8(%rbx), %rcx
jle 0x42f9
addq %r13, %rsi
movl $0x13b, %edx            # imm = 0x13B
callq 0x30c0
movl $0x13b, %r8d            # imm = 0x13B
jmp 0x432e
leaq (%rsi,%r13), %rcx
addq $0x18, %rcx
movups -0x18(%rcx), %xmm0
movups %xmm0, (%rdi)
addq 0x20(%rsp), %rax
xorl %edx, %edx
movups -0x8(%rcx,%rdx), %xmm0
movups %xmm0, -0x8(%rax,%rdx)
addq $0x10, %rdx
cmpq $0x12b, %rdx            # imm = 0x12B
jb 0x430f
movl 0x5c(%rbx), %r12d
movq 0x10(%rbx), %r13
addl %r8d, %r12d
movl %r12d, 0x5c(%rbx)
addq $0x13b, %r13            # imm = 0x13B
movq %r13, 0x10(%rbx)
addl $0xfffffec5, %ebp       # imm = 0xFFFFFEC5
cmpl %r8d, %ebp
ja 0x4280
jmp 0x4354
movl %ecx, %r12d
cmpl $0x938, %r15d           # imm = 0x938
jb 0x444f
leaq 0x1d520(%rbx), %r8
movl 0x58(%rbx), %eax
leal -0x2708(%rax), %ecx
cmpl $0xffffd8ef, %ecx       # imm = 0xFFFFD8EF
jb 0x4479
leal (%r12,%rbp), %ecx
addl $0xffff63cf, %ecx       # imm = 0xFFFF63CF
cmpl $0xffff63bf, %ecx       # imm = 0xFFFF63BF
jb 0x4479
leal 0x1(%rax), %ecx
movl %ecx, 0x58(%rbx)
movl %ebp, 0x60(%rbx,%rax,4)
movl $0x937, 0x9ca0(%rbx,%rax,4) # imm = 0x937
movl 0xc(%rsp), %ecx
movl %ecx, 0x138e0(%rbx,%rax,4)
movl %r12d, %edi
addq %r8, %rdi
movq (%rbx), %rax
leaq (%rax,%r13), %rsi
movl %ebp, %r14d
leaq (%r14,%r13), %rcx
addq $0x10, %rcx
cmpq 0x8(%rbx), %rcx
jle 0x43e5
testl %ebp, %ebp
je 0x441b
movq %r14, %rdx
movq %r8, %r12
callq 0x30c0
movq %r12, %r8
jmp 0x441b
movups (%rsi), %xmm0
movups %xmm0, (%rdi)
cmpl $0x11, %ebp
jb 0x441b
leaq (%rdi,%r14), %rcx
addq $0x10, %rdi
addq %r13, %rax
addq $0x18, %rax
xorl %edx, %edx
movups -0x8(%rax,%rdx), %xmm0
leaq (%rdi,%rdx), %rsi
addq $0x10, %rsi
movups %xmm0, -0x10(%rsi)
addq $0x10, %rdx
cmpq %rcx, %rsi
jb 0x4401
movl %ebp, %r12d
addl 0x5c(%rbx), %r12d
movl %r12d, 0x5c(%rbx)
movq 0x10(%rbx), %rax
leaq (%r14,%rax), %r13
addq $0x937, %r13            # imm = 0x937
movq %r13, 0x10(%rbx)
addl $0xfffff6c9, %r15d      # imm = 0xFFFFF6C9
xorl %ebp, %ebp
cmpl $0x937, %r15d           # imm = 0x937
ja 0x4368
movl %r15d, %eax
orl %ebp, %eax
je 0x44a4
movl 0x58(%rbx), %eax
leal -0x2708(%rax), %ecx
cmpl $0xffffd8ef, %ecx       # imm = 0xFFFFD8EF
jb 0x4479
leal (%r12,%rbp), %ecx
addl $0xffff63cf, %ecx       # imm = 0xFFFF63CF
cmpl $0xffff63bf, %ecx       # imm = 0xFFFF63BF
jae 0x44a8
movl 0x14(%rsp), %eax
movl %eax, 0x58(%rbx)
movl 0x10(%rsp), %eax
movl %eax, 0x5c(%rbx)
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
movq 0x18(%rsp), %r15
movq %r15, 0x10(%rbx)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
jmp 0x4495
leal 0x1(%rax), %ecx
movl %ecx, 0x58(%rbx)
movl %ebp, 0x60(%rbx,%rax,4)
movl %r15d, 0x9ca0(%rbx,%rax,4)
movl 0xc(%rsp), %ecx
movl %ecx, 0x138e0(%rbx,%rax,4)
movl %r12d, %ecx
leaq 0x1d520(%rbx,%rcx), %rdi
movq (%rbx), %rax
leaq (%rax,%r13), %rsi
movl %ebp, %edx
leaq (%rdx,%r13), %r8
addq $0x10, %r8
cmpq 0x8(%rbx), %r8
jle 0x44f2
testl %ebp, %ebp
je 0x4531
callq 0x30c0
jmp 0x4531
movups (%rsi), %xmm0
movups %xmm0, (%rdi)
cmpl $0x11, %ebp
jb 0x4531
addq %rbx, %rcx
addq %rdx, %rcx
addq $0x1d520, %rcx          # imm = 0x1D520
addq $0x10, %rdi
addq %r13, %rax
addq $0x18, %rax
xorl %edx, %edx
movups -0x8(%rax,%rdx), %xmm0
leaq (%rdi,%rdx), %rsi
addq $0x10, %rsi
movups %xmm0, -0x10(%rsi)
addq $0x10, %rdx
cmpq %rcx, %rsi
jb 0x4517
addl %ebp, 0x5c(%rbx)
addl %ebp, %r15d
addq 0x10(%rbx), %r15
xorl %eax, %eax
jmp 0x4491