// File: /workspace/github_cpp_makefile_star2_O1/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 $0x18, %rsp
movq %rdi, %rbx
movl 0x58(%rdi), %eax
movl %eax, 0xc(%rsp)
movl 0x5c(%rdi), %eax
movl %eax, 0x8(%rsp)
movq 0x10(%rdi), %rax
movl (%rsi), %ecx
movl 0x10(%rsi), %r15d
movl %ecx, %r12d
movq %rax, 0x10(%rsp)
subl %eax, %r12d
subl 0x8(%rsi), %ecx
movl %ecx, 0x4(%rsp)
cmpl $0x13c, %r12d           # imm = 0x13C
jb 0x4451
leaq 0x1d520(%rbx), %r14
leaq 0x1d538(%rbx), %r13
movl $0x13b, %ebp            # imm = 0x13B
movl 0x58(%rbx), %ecx
leal -0x2708(%rcx), %eax
cmpl $0xffffd8ef, %eax       # imm = 0xFFFFD8EF
jb 0x4572
movl 0x5c(%rbx), %eax
leal -0x9af6(%rax), %edx
cmpl $0xffff63bf, %edx       # imm = 0xFFFF63BF
jb 0x4572
leal 0x1(%rcx), %edx
movl %edx, 0x58(%rbx)
movl $0x13b, 0x60(%rbx,%rcx,4) # imm = 0x13B
movl $0x0, 0x9ca0(%rbx,%rcx,4)
movl $0x1, 0x138e0(%rbx,%rcx,4)
leaq (%r14,%rax), %rdi
movq (%rbx), %rsi
movq 0x10(%rbx), %rcx
leaq 0x14b(%rcx), %rdx
cmpq 0x8(%rbx), %rdx
jle 0x440c
addq %rcx, %rsi
movl $0x13b, %edx            # imm = 0x13B
callq 0x30c0
jmp 0x4436
addq %rsi, %rcx
addq $0x18, %rcx
movups -0x18(%rcx), %xmm0
movups %xmm0, (%rdi)
addq %r13, %rax
xorl %edx, %edx
movups -0x8(%rcx,%rdx), %xmm0
movups %xmm0, -0x8(%rax,%rdx)
addq $0x10, %rdx
cmpq $0x12b, %rdx            # imm = 0x12B
jb 0x441f
addl %ebp, 0x5c(%rbx)
addq $0x13b, 0x10(%rbx)      # imm = 0x13B
addl $0xfffffec5, %r12d      # imm = 0xFFFFFEC5
cmpl %ebp, %r12d
ja 0x4398
cmpl $0x938, %r15d           # imm = 0x938
jb 0x4545
leaq 0x1d520(%rbx), %r13
movl 0x58(%rbx), %eax
leal -0x2708(%rax), %ecx
cmpl $0xffffd8ef, %ecx       # imm = 0xFFFFD8EF
jb 0x4572
movl 0x5c(%rbx), %edi
leal (%r12,%rdi), %ecx
addl $0xffff63cf, %ecx       # imm = 0xFFFF63CF
cmpl $0xffff63bf, %ecx       # imm = 0xFFFF63BF
jb 0x4572
leal 0x1(%rax), %ecx
movl %ecx, 0x58(%rbx)
movl %r12d, 0x60(%rbx,%rax,4)
movl $0x937, 0x9ca0(%rbx,%rax,4) # imm = 0x937
movl 0x4(%rsp), %ecx
movl %ecx, 0x138e0(%rbx,%rax,4)
addq %r13, %rdi
movq (%rbx), %rax
movq 0x10(%rbx), %rcx
leaq (%rax,%rcx), %rsi
movl %r12d, %r14d
leaq (%r14,%rcx), %rdx
addq $0x10, %rdx
cmpq 0x8(%rbx), %rdx
jle 0x44e2
testl %r12d, %r12d
je 0x4519
movq %r14, %rdx
callq 0x30c0
jmp 0x4519
movups (%rsi), %xmm0
movups %xmm0, (%rdi)
cmpl $0x11, %r12d
jb 0x4519
leaq (%rdi,%r14), %rdx
addq $0x10, %rdi
addq %rcx, %rax
addq $0x18, %rax
xorl %ecx, %ecx
movups -0x8(%rax,%rcx), %xmm0
leaq (%rdi,%rcx), %rsi
addq $0x10, %rsi
movups %xmm0, -0x10(%rsi)
addq $0x10, %rcx
cmpq %rdx, %rsi
jb 0x44ff
addl %r12d, 0x5c(%rbx)
movq 0x10(%rbx), %rax
addq %r14, %rax
addq $0x937, %rax            # imm = 0x937
movq %rax, 0x10(%rbx)
addl $0xfffff6c9, %r15d      # imm = 0xFFFFF6C9
xorl %r12d, %r12d
cmpl $0x937, %r15d           # imm = 0x937
ja 0x4465
movl %r15d, %eax
orl %r12d, %eax
je 0x459d
movl 0x58(%rbx), %ecx
leal -0x2708(%rcx), %eax
cmpl $0xffffd8ef, %eax       # imm = 0xFFFFD8EF
jb 0x4572
movl 0x5c(%rbx), %eax
leal (%r12,%rax), %edx
addl $0xffff63cf, %edx       # imm = 0xFFFF63CF
cmpl $0xffff63bf, %edx       # imm = 0xFFFF63BF
jae 0x45a1
movl 0xc(%rsp), %eax
movl %eax, 0x58(%rbx)
movl 0x8(%rsp), %eax
movl %eax, 0x5c(%rbx)
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
movq 0x10(%rsp), %r15
movq %r15, 0x10(%rbx)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
jmp 0x458e
leal 0x1(%rcx), %edx
movl %edx, 0x58(%rbx)
movl %r12d, 0x60(%rbx,%rcx,4)
movl %r15d, 0x9ca0(%rbx,%rcx,4)
movl 0x4(%rsp), %edx
movl %edx, 0x138e0(%rbx,%rcx,4)
leaq 0x1d520(%rbx,%rax), %rdi
movq (%rbx), %rcx
movq 0x10(%rbx), %r8
leaq (%rcx,%r8), %rsi
movl %r12d, %edx
leaq (%rdx,%r8), %r9
addq $0x10, %r9
cmpq 0x8(%rbx), %r9
jle 0x45ef
testl %r12d, %r12d
je 0x462e
callq 0x30c0
jmp 0x462e
movups (%rsi), %xmm0
movups %xmm0, (%rdi)
cmpl $0x11, %r12d
jb 0x462e
addq %rbx, %rax
addq %rdx, %rax
addq $0x1d520, %rax          # imm = 0x1D520
addq $0x10, %rdi
addq %r8, %rcx
addq $0x18, %rcx
xorl %edx, %edx
movups -0x8(%rcx,%rdx), %xmm0
leaq (%rdi,%rdx), %rsi
addq $0x10, %rsi
movups %xmm0, -0x10(%rsi)
addq $0x10, %rdx
cmpq %rax, %rsi
jb 0x4614
addl %r12d, 0x5c(%rbx)
addl %r12d, %r15d
addq 0x10(%rbx), %r15
xorl %eax, %eax
jmp 0x458a