// File: /workspace/github_c_makefile_star2_O3/lmcilroy[P]lzm/lzmencode.c
// Function: lzm_encode_fast
static unsigned int
lzm_encode_fast(
    const struct lzm_state * const state,
    const unsigned char * const buffer_in,
    const unsigned int size_in,
    unsigned char * const buffer_out,
    unsigned int * const size_out)
{
	const unsigned char * const end = buffer_in + size_in;
	const unsigned char * const match_end = end - 7;
	const unsigned char * const scan_end = match_end - 7;
	const unsigned char * const out_limit = buffer_out + *size_out;
	const unsigned char *lit_start = buffer_in;
	const unsigned char *curr_in = buffer_in;
	const unsigned char *next_curr;
	const unsigned char *last;
	unsigned char *curr_out = buffer_out;
	struct ht_entry *last_htp;
	unsigned long int token;
	unsigned long int next_token;
	unsigned int last_token;
	unsigned int len;
	unsigned int off;
	unsigned int misses = (1 << MISS_ORDER) + 1;
	unsigned int hashval;
	unsigned int next_hashval;

	lzm_reset(state, buffer_in);

	token = readmem64(curr_in);
	hashval = hash_fast(token);
	next_token = readmem64(curr_in + 1);
	next_hashval = hash_fast(next_token);
	last_htp = &state->last_ht[hashval];
	last_htp->index = curr_in - buffer_in;
	last_htp->token = token;
	curr_in++;

	while (likely(curr_in < scan_end)) {
		token = next_token;
		hashval = next_hashval;
		next_curr = curr_in + (misses >> MISS_ORDER);
		next_token = readmem64(next_curr);
		next_hashval = hash_fast(next_token);
		last_htp = &state->last_ht[hashval];
		last = last_htp->index + buffer_in;
		last_token = last_htp->token;
		last_htp->index = curr_in - buffer_in;
		last_htp->token = token;

		if ((unsigned int)token != last_token ||
		    (curr_in - last) & ~MAX_OFFSET_MASK) {
			misses++;
			curr_in = next_curr;
			continue;
		}
		misses = (1 << MISS_ORDER) + 1;

		len = MIN_MATCH;
		len += matchlen(curr_in + len, last + len, match_end);
		off = matchlen_rev(curr_in, last, lit_start, buffer_in);
		curr_in -= off;
		last -= off;
		len += off;

		curr_out = output_match(curr_out, lit_start,
		    curr_in - lit_start, curr_in - last, len, out_limit);
		if (unlikely(curr_out == NULL))
			return EOVERFLOW;

		curr_in += len;
		lit_start = curr_in;

		token = readmem64(curr_in - 2);
		hashval = hash_fast(token);
		next_token = readmem64(curr_in);
		next_hashval = hash_fast(next_token);
		last_htp = &state->last_ht[hashval];
		last_htp->index = curr_in - 2 - buffer_in;
		last_htp->token = token;
	}

	curr_out = output_literals(curr_out, lit_start, end - lit_start,
	    out_limit);
	if (curr_out == NULL)
		return EOVERFLOW;

	*size_out = curr_out - buffer_out;
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rcx, %r14
movq %rsi, %r15
movl %edx, %eax
movq %rax, 0x28(%rsp)
movq %r8, 0x30(%rsp)
movl (%r8), %eax
movq %rax, 0x18(%rsp)
cmpl $0x0, 0x14(%rdi)
movq (%rdi), %rax
je 0x1ac3
movl (%r15), %r8d
xorl %esi, %esi
andl $0x0, (%rax,%rsi,8)
movl %r8d, 0x4(%rax,%rsi,8)
incq %rsi
movl 0x14(%rdi), %r9d
cmpq %r9, %rsi
jb 0x1aae
addq %r14, 0x18(%rsp)
movabsq $-0x53a9a353cb000000, %r12 # imm = 0xAC565CAC35000000
movq (%r15), %rsi
movq 0x1(%r15), %r11
movq %rsi, %r8
imulq %r12, %r8
shrq $0x34, %r8
andl $0x0, (%rax,%r8,8)
movl %esi, 0x4(%rax,%r8,8)
movq %r14, 0x20(%rsp)
movq %r15, %rsi
cmpl $0x10, %edx
jb 0x1f20
movq 0x28(%rsp), %rcx
leaq (%r15,%rcx), %rdx
addq $-0x7, %rdx
movq %rdx, 0x40(%rsp)
leaq -0xe(%r15,%rcx), %rbp
leaq 0x1(%r15), %rbx
movq %r15, %rsi
movq 0x20(%rsp), %rcx
movq %rcx, 0x10(%rsp)
movq %rdi, (%rsp)
movq %rsi, 0x8(%rsp)
pushq $0x41
popq %rdx
movq %r11, %rcx
movq %r11, %r8
imulq %r12, %r8
shrq $0x34, %r8
movl %edx, %esi
shrl $0x6, %esi
movq (%rbx,%rsi), %r11
movl (%rax,%r8,8), %r13d
movl 0x4(%rax,%r8,8), %r9d
movl %ebx, %r10d
subl %r15d, %r10d
movl %r10d, (%rax,%r8,8)
movl %ecx, 0x4(%rax,%r8,8)
cmpl %ecx, %r9d
jne 0x1b7a
leaq (%r15,%r13), %r14
movq %rbx, %rcx
subq %r14, %rcx
cmpq $0xfffffff, %rcx        # imm = 0xFFFFFFF
jbe 0x1b89
addq %rsi, %rbx
incl %edx
cmpq %rbp, %rbx
jb 0x1b33
jmp 0x1f16
leaq 0x4(%rbx), %rdi
leaq 0x4(%r14), %rsi
movq 0x40(%rsp), %rdx
callq 0x4d64
xorl %r12d, %r12d
movq 0x8(%rsp), %rsi
cmpq %rsi, %rbx
je 0x1c3c
testl %r13d, %r13d
movq 0x10(%rsp), %r11
je 0x1cdc
movb -0x1(%rbx), %cl
cmpb -0x1(%r14), %cl
jne 0x1cdc
movl %ebx, %edx
subl %esi, %edx
movq %r14, %rcx
subq %rdx, %rcx
cmpq %r13, %rdx
cmovaeq %r15, %rcx
leaq 0x7(%rcx), %r8
movq %rbx, %r13
movq %r14, %rdi
cmpq %r14, %r8
jae 0x1bfc
movq -0x8(%rbx), %rdi
movq -0x8(%r14), %rdx
cmpq %rdx, %rdi
jne 0x1c6f
leaq -0x8(%rbx), %r13
leaq -0x8(%r14), %rdi
xorl %edx, %edx
leaq (%rdi,%rdx), %r9
cmpq %r8, %r9
jbe 0x1c46
movq -0x8(%r13,%rdx), %r10
movq -0x8(%rdi,%rdx), %r9
addq $-0x8, %rdx
cmpq %r9, %r10
je 0x1bfe
xorq %r10, %r9
bsrq %r9, %rcx
xorl $0x38, %ecx
shrl $0x3, %ecx
movl %ebx, %r12d
subl %r13d, %r12d
addl %ecx, %r12d
subl %edx, %r12d
addl $-0x8, %r12d
jmp 0x1cdc
movq 0x10(%rsp), %r11
jmp 0x1cdc
leaq 0x3(%rcx), %r8
cmpq %r8, %r9
jbe 0x1c80
movl -0x4(%r13,%rdx), %r9d
movl -0x4(%rdi,%rdx), %r8d
cmpl %r8d, %r9d
jne 0x1cc3
addq %rdx, %r13
addq $-0x4, %r13
leaq (%rdi,%rdx), %r9
addq $-0x4, %r9
jmp 0x1c83
xorq %rdi, %rdx
bsrq %rdx, %r12
xorl $0x38, %r12d
shrl $0x3, %r12d
jmp 0x1cdc
addq %rdx, %r13
leaq 0x1(%rcx), %rdx
cmpq %rdx, %r9
jbe 0x1ca6
leaq -0x2(%r13), %rdx
leaq -0x2(%r9), %rdi
movzwl -0x2(%r13), %r8d
cmpw -0x2(%r9), %r8w
cmoveq %rdx, %r13
cmoveq %rdi, %r9
cmpq %rcx, %r9
jbe 0x1cbb
leaq -0x1(%r13), %rcx
movb -0x1(%r13), %dl
cmpb -0x1(%r9), %dl
cmoveq %rcx, %r13
movl %ebx, %r12d
subl %r13d, %r12d
jmp 0x1cdc
xorl %r9d, %r8d
bsrl %r8d, %ecx
xorl $0x18, %ecx
shrl $0x3, %ecx
movl %ebx, %r12d
subl %r13d, %r12d
addl %ecx, %r12d
subl %edx, %r12d
movl %r12d, %ecx
subq %rcx, %rbx
movq %rbx, %r9
subq %rsi, %r9
movl %r9d, %r13d
leaq (%r11,%r13), %rdx
addq $0x17, %rdx
cmpq 0x18(%rsp), %rdx
ja 0x1f0e
negq %rcx
addl %ecx, %r14d
xorl %ecx, %ecx
movl %ebx, %edx
subl %r14d, %edx
sete %cl
orl %edx, %ecx
bsrl %ecx, %r8d
xorl $0x1f, %r8d
leaq 0x4a61(%rip), %rdi      # 0x6780
movl (%rdi,%r8,8), %ecx
shll %cl, %edx
orl 0x4(%rdi,%r8,8), %edx
movl %edx, 0x1(%r11)
leaq (%r11,%rcx), %r14
incq %r14
testl %r9d, %r9d
je 0x1d50
cmpl $0xe, %r9d
ja 0x1d55
shlb $0x4, %r9b
movb %r9b, (%r11)
movups (%rsi), %xmm0
movups %xmm0, (%r14)
jmp 0x1d8c
xorl %r9d, %r9d
jmp 0x1d8f
movb $-0x10, (%r11)
leal -0xf(%r9), %ecx
cmpl $0xfb, %ecx
movq %rax, 0x38(%rsp)
ja 0x1e4a
movb %cl, (%r14)
incq %r14
movq %r14, %rdi
movq %r13, %rdx
callq 0x11c0
movq 0x10(%rsp), %r11
movb (%r11), %r9b
movq 0x38(%rsp), %rax
addq %r13, %r14
leal 0x4(%rax), %ecx
addl %r12d, %ecx
addl %eax, %r12d
cmpl $0xf, %r12d
jae 0x1dbc
orb %r12b, %r9b
movb %r9b, (%r11)
testq %r14, %r14
movq (%rsp), %rdi
movabsq $-0x53a9a353cb000000, %r12 # imm = 0xAC565CAC35000000
jne 0x1de1
jmp 0x1f0e
orb $0xf, %r9b
movb %r9b, (%r11)
leal -0x13(%rcx), %eax
cmpl $0xfb, %eax
ja 0x1e25
movb %al, (%r14)
incq %r14
movq (%rsp), %rdi
movabsq $-0x53a9a353cb000000, %r12 # imm = 0xAC565CAC35000000
movl %ecx, %eax
leaq (%rbx,%rax), %rsi
leaq (%rbx,%rax), %rdx
addq $-0x2, %rdx
movq (%rdx), %r8
movq 0x2(%rdx), %r11
movq %r8, %rcx
imulq %r12, %rcx
shrq $0x34, %rcx
movq (%rdi), %rax
subl %r15d, %edx
movl %edx, (%rax,%rcx,8)
movl %r8d, 0x4(%rax,%rcx,8)
movq %r14, 0x10(%rsp)
movq %rsi, %rbx
cmpq %rbp, %rsi
jb 0x1b2b
jmp 0x1f20
cmpl $0x1fb, %eax            # imm = 0x1FB
movq (%rsp), %rdi
movabsq $-0x53a9a353cb000000, %r12 # imm = 0xAC565CAC35000000
ja 0x1e66
movb $-0x4, (%r14)
addb $0x4, %al
movb %al, 0x1(%r14)
addq $0x2, %r14
jmp 0x1de1
cmpl $0x1fb, %ecx            # imm = 0x1FB
ja 0x1e88
movb $-0x4, (%r14)
addb $0x4, %cl
movb %cl, 0x1(%r14)
addq $0x2, %r14
jmp 0x1d74
cmpl $0x100fc, %eax          # imm = 0x100FC
ja 0x1ead
movb $-0x3, (%r14)
addl $0xffffff03, %eax       # imm = 0xFFFFFF03
movw %ax, 0x1(%r14)
addq $0x3, %r14
movq (%rsp), %rdi
jmp 0x1de1
cmpl $0x100fc, %ecx          # imm = 0x100FC
ja 0x1ec8
movb $-0x3, (%r14)
addl $0xffffff03, %ecx       # imm = 0xFFFFFF03
movw %cx, 0x1(%r14)
addq $0x3, %r14
movq 0x8(%rsp), %rsi
jmp 0x1d74
cmpl $0x10000fd, %eax        # imm = 0x10000FD
ja 0x1ee5
movb $-0x2, (%r14)
leal -0x111(%rcx), %eax
movl %eax, 0x1(%r14)
addq $0x4, %r14
jmp 0x1e7f
cmpl $0x10000fd, %ecx        # imm = 0x10000FD
ja 0x1ef9
movb $-0x2, (%r14)
leal -0x10d(%r9), %eax
movl %eax, 0x1(%r14)
addq $0x4, %r14
jmp 0x1ea3
movb $-0x1, (%r14)
leal -0x112(%rcx), %eax
movl %eax, 0x1(%r14)
addq $0x5, %r14
jmp 0x1e7f
movb $-0x1, (%r14)
leal -0x10e(%r9), %eax
movl %eax, 0x1(%r14)
addq $0x5, %r14
jmp 0x1ea3
pushq $0x4b
popq %rbx
jmp 0x1fa4
movq 0x10(%rsp), %r14
movq 0x8(%rsp), %rsi
addq 0x28(%rsp), %r15
subq %rsi, %r15
movl %r15d, %r12d
leaq (%r14,%r12), %rax
addq $0x11, %rax
cmpq 0x18(%rsp), %rax
pushq $0x4b
popq %rbx
ja 0x1fa4
movl $0x1, 0x1(%r14)
leaq 0x2(%r14), %r13
xorl %ebx, %ebx
testl %r15d, %r15d
je 0x1f67
cmpl $0xe, %r15d
ja 0x1f6c
shlb $0x4, %r15b
movb %r15b, (%r14)
movups (%rsi), %xmm0
movups %xmm0, (%r13)
jmp 0x1f91
xorl %r15d, %r15d
jmp 0x1f94
movb $-0x10, (%r14)
leal -0xf(%r15), %eax
cmpl $0xfb, %eax
ja 0x1fb5
leaq 0x3(%r14), %r13
movb %al, 0x2(%r14)
movq %r13, %rdi
movq %r12, %rdx
callq 0x11c0
movb $-0x10, %r15b
addq %r12, %r13
movb %r15b, (%r14)
subl 0x20(%rsp), %r13d
movq 0x30(%rsp), %rax
movl %r13d, (%rax)
movl %ebx, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x1fb, %eax            # imm = 0x1FB
ja 0x1fcf
movb $-0x4, 0x2(%r14)
addb $0x4, %al
leaq 0x4(%r14), %r13
movb %al, 0x3(%r14)
xorl %ebx, %ebx
jmp 0x1f83
cmpl $0x100fc, %eax          # imm = 0x100FC
ja 0x1feb
movb $-0x3, 0x2(%r14)
addl $0xffffff03, %eax       # imm = 0xFFFFFF03
movw %ax, 0x3(%r14)
leaq 0x5(%r14), %r13
jmp 0x1fcb
cmpl $0x10000fd, %eax        # imm = 0x10000FD
ja 0x2008
movb $-0x2, 0x2(%r14)
leal -0x10d(%r15), %eax
movl %eax, 0x3(%r14)
leaq 0x6(%r14), %r13
jmp 0x1fcb
movb $-0x1, 0x2(%r14)
leal -0x10e(%r15), %eax
movl %eax, 0x3(%r14)
leaq 0x7(%r14), %r13
jmp 0x1fcb