// File: /workspace/github_c_makefile_star2_O1/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 $0x68, %rsp
movq %rcx, 0x10(%rsp)
movq %rsi, %r15
movl %edx, %eax
movq %rax, 0x20(%rsp)
movq %r8, 0x38(%rsp)
movl (%r8), %eax
movq %rax, 0x18(%rsp)
cmpl $0x0, 0x14(%rdi)
je 0x1ac3
movl (%r15), %eax
movq (%rdi), %rcx
xorl %esi, %esi
andl $0x0, (%rcx,%rsi,8)
movl %eax, 0x4(%rcx,%rsi,8)
incq %rsi
movl 0x14(%rdi), %r8d
cmpq %r8, %rsi
jb 0x1aaf
movq 0x10(%rsp), %r8
addq %r8, 0x18(%rsp)
movabsq $-0x53a9a353cb000000, %rbp # imm = 0xAC565CAC35000000
movq (%r15), %rcx
movq 0x1(%r15), %rax
movq %rcx, %rsi
imulq %rbp, %rsi
shrq $0x34, %rsi
movq (%rdi), %r9
andl $0x0, (%r9,%rsi,8)
movl %ecx, 0x4(%r9,%rsi,8)
movq %r8, %r9
movq %r15, %rsi
cmpl $0x10, %edx
jb 0x1f22
movq 0x20(%rsp), %rcx
leaq (%r15,%rcx), %rdx
addq $-0x7, %rdx
movq %rdx, 0x58(%rsp)
leaq -0xe(%r15,%rcx), %r12
leaq 0x1(%r15), %rbx
movq %r15, %rsi
movq 0x10(%rsp), %r9
movq %rdi, 0x60(%rsp)
movq %rsi, (%rsp)
movq %r9, 0x8(%rsp)
movq (%rdi), %rcx
pushq $0x41
popq %rdx
movq %rax, %rdi
movq %rax, %r8
imulq %rbp, %r8
shrq $0x34, %r8
movl %edx, %esi
shrl $0x6, %esi
movq (%rbx,%rsi), %rax
movl (%rcx,%r8,8), %r13d
movl 0x4(%rcx,%r8,8), %r9d
movl %ebx, %r10d
subl %r15d, %r10d
movl %r10d, (%rcx,%r8,8)
movl %edi, 0x4(%rcx,%r8,8)
cmpl %edi, %r9d
jne 0x1b83
leaq (%r15,%r13), %r14
movq %rbx, %rdi
subq %r14, %rdi
cmpq $0xfffffff, %rdi        # imm = 0xFFFFFFF
jbe 0x1b92
addq %rsi, %rbx
incl %edx
cmpq %r12, %rbx
jb 0x1b3c
jmp 0x1f19
leaq 0x4(%rbx), %rdi
leaq 0x4(%r14), %rsi
movq 0x58(%rsp), %rdx
callq 0x4d8c
xorl %r11d, %r11d
movq (%rsp), %rsi
cmpq %rsi, %rbx
je 0x1cdb
testl %r13d, %r13d
je 0x1cdb
movb -0x1(%rbx), %cl
cmpb -0x1(%r14), %cl
jne 0x1cdb
movl %ebx, %edx
subl %esi, %edx
movq %r14, %rcx
subq %rdx, %rcx
cmpq %r13, %rdx
cmovaeq %r15, %rcx
leaq 0x7(%rcx), %r8
movq %rbx, %r11
movq %r14, %rdi
cmpq %r14, %r8
jae 0x1bff
movq -0x8(%rbx), %rdi
movq -0x8(%r14), %rdx
cmpq %rdx, %rdi
jne 0x1c6a
leaq -0x8(%rbx), %r11
leaq -0x8(%r14), %rdi
xorl %edx, %edx
leaq (%rdi,%rdx), %r9
cmpq %r8, %r9
jbe 0x1c41
movq -0x8(%r11,%rdx), %r10
movq -0x8(%rdi,%rdx), %r9
addq $-0x8, %rdx
cmpq %r9, %r10
je 0x1c01
xorq %r10, %r9
bsrq %r9, %rcx
xorl $0x38, %ecx
shrl $0x3, %ecx
movl %ebx, %edi
subl %r11d, %edi
movq %rdi, %r11
addl %ecx, %r11d
subl %edx, %r11d
addl $-0x8, %r11d
jmp 0x1cdb
leaq 0x3(%rcx), %r8
cmpq %r8, %r9
jbe 0x1c7b
movl -0x4(%r11,%rdx), %r9d
movl -0x4(%rdi,%rdx), %r8d
cmpl %r8d, %r9d
jne 0x1cc0
addq %rdx, %r11
addq $-0x4, %r11
leaq (%rdi,%rdx), %r9
addq $-0x4, %r9
jmp 0x1c7e
xorq %rdi, %rdx
bsrq %rdx, %r11
xorl $0x38, %r11d
shrl $0x3, %r11d
jmp 0x1cdb
addq %rdx, %r11
leaq 0x1(%rcx), %rdx
cmpq %rdx, %r9
jbe 0x1ca1
leaq -0x2(%r11), %rdx
leaq -0x2(%r9), %rdi
movzwl -0x2(%r11), %r8d
cmpw -0x2(%r9), %r8w
cmoveq %rdx, %r11
cmoveq %rdi, %r9
cmpq %rcx, %r9
jbe 0x1cb6
leaq -0x1(%r11), %rcx
movb -0x1(%r11), %dl
cmpb -0x1(%r9), %dl
cmoveq %rcx, %r11
movl %ebx, %ecx
subl %r11d, %ecx
movq %rcx, %r11
jmp 0x1cdb
xorl %r9d, %r8d
bsrl %r8d, %ecx
xorl $0x18, %ecx
shrl $0x3, %ecx
movl %ebx, %edi
subl %r11d, %edi
movq %rdi, %r11
addl %ecx, %r11d
subl %edx, %r11d
leal 0x4(%rax), %r10d
movl %r11d, %ecx
subq %rcx, %rbx
addl %r11d, %r10d
movq %rbx, %r9
subq %rsi, %r9
movl %r9d, %edi
movq 0x8(%rsp), %r13
leaq (%rdi,%r13), %rdx
addq $0x17, %rdx
cmpq 0x18(%rsp), %rdx
jbe 0x1d0d
xorl %r9d, %r9d
jmp 0x1df4
movq %rdi, 0x30(%rsp)
negq %rcx
addl %ecx, %r14d
xorl %ecx, %ecx
movl %ebx, %edx
subl %r14d, %edx
movb $0x0, (%r13)
sete %cl
orl %edx, %ecx
bsrl %ecx, %r8d
xorl $0x1f, %r8d
leaq 0x4a48(%rip), %rdi      # 0x6780
movl (%rdi,%r8,8), %ecx
shll %cl, %edx
orl 0x4(%rdi,%r8,8), %edx
movl %edx, 0x1(%r13)
leaq (%rcx,%r13), %rdx
incq %rdx
testl %r9d, %r9d
je 0x1dc5
cmpl $0xe, %r9d
ja 0x1d6e
shlb $0x4, %r9b
movb %r9b, (%r13)
movups (%rsi), %xmm0
movups %xmm0, (%rdx)
movq 0x30(%rsp), %r14
jmp 0x1dc2
movb $-0x10, (%r13)
leal -0xf(%r9), %ecx
cmpl $0xfb, %ecx
movq %rax, 0x50(%rsp)
movq %r10, 0x48(%rsp)
movq %r11, 0x40(%rsp)
ja 0x1e58
movb %cl, (%rdx)
incq %rdx
movq %rdx, 0x28(%rsp)
movq 0x28(%rsp), %rdi
movq 0x30(%rsp), %r14
movq %r14, %rdx
callq 0x11c0
movq 0x28(%rsp), %rdx
movq 0x50(%rsp), %rax
movq 0x48(%rsp), %r10
movq 0x40(%rsp), %r11
addq %r14, %rdx
addl %eax, %r11d
movb (%r13), %al
cmpl $0xe, %r11d
ja 0x1ddb
orb %r11b, %al
movb %al, (%r13)
jmp 0x1df1
orb $0xf, %al
movb %al, (%r13)
leal -0x13(%r10), %eax
cmpl $0xfb, %eax
ja 0x1e43
movb %al, (%rdx)
incq %rdx
movq %rdx, %r9
testq %r9, %r9
movq 0x60(%rsp), %rdi
je 0x1fc2
movl %r10d, %eax
leaq (%rbx,%rax), %rsi
leaq (%rbx,%rax), %rcx
addq $-0x2, %rcx
movq (%rcx), %rdx
movq 0x2(%rcx), %rax
movq %rdx, %r10
imulq %rbp, %r10
shrq $0x34, %r10
movq (%rdi), %r8
subl %r15d, %ecx
movl %ecx, (%r8,%r10,8)
movl %edx, 0x4(%r8,%r10,8)
movq %rsi, %rbx
cmpq %r12, %rsi
jb 0x1b2d
jmp 0x1f22
cmpl $0x1fb, %eax            # imm = 0x1FB
ja 0x1e72
movb $-0x4, (%rdx)
addb $0x4, %al
movb %al, 0x1(%rdx)
addq $0x2, %rdx
jmp 0x1df1
cmpl $0x1fb, %ecx            # imm = 0x1FB
ja 0x1e91
movb $-0x4, (%rdx)
addb $0x4, %cl
movb %cl, 0x1(%rdx)
addq $0x2, %rdx
jmp 0x1d97
movq %rdx, %r9
cmpl $0x100fc, %eax          # imm = 0x100FC
ja 0x1eb8
movb $-0x3, (%rdx)
addl $0xffffff03, %eax       # imm = 0xFFFFFF03
movw %ax, 0x1(%rdx)
addq $0x3, %r9
jmp 0x1df4
cmpl $0x100fc, %ecx          # imm = 0x100FC
ja 0x1ed5
movb $-0x3, (%rdx)
addl $0xffffff03, %ecx       # imm = 0xFFFFFF03
movw %cx, 0x1(%rdx)
addq $0x3, %rdx
movq 0x8(%rsp), %r13
movq (%rsp), %rsi
jmp 0x1d97
cmpl $0x10000fd, %eax        # imm = 0x10000FD
ja 0x1ef0
movb $-0x2, (%rdx)
leal -0x111(%r10), %eax
movl %eax, 0x1(%rdx)
addq $0x4, %r9
jmp 0x1df4
cmpl $0x10000fd, %ecx        # imm = 0x10000FD
ja 0x1f06
movb $-0x2, (%rdx)
leal -0x10d(%r9), %eax
movl %eax, 0x1(%rdx)
addq $0x4, %rdx
jmp 0x1eaa
movb $-0x1, (%rdx)
leal -0x112(%r10), %eax
movl %eax, 0x1(%rdx)
addq $0x5, %r9
jmp 0x1df4
movb $-0x1, (%rdx)
leal -0x10e(%r9), %eax
movl %eax, 0x1(%rdx)
addq $0x5, %rdx
jmp 0x1eaa
movq 0x8(%rsp), %r9
movq (%rsp), %rsi
addq 0x20(%rsp), %r15
subq %rsi, %r15
movl %r15d, %r14d
leaq (%r9,%r14), %rax
addq $0x11, %rax
cmpq 0x18(%rsp), %rax
jbe 0x1f41
xorl %r13d, %r13d
jmp 0x1f70
movb $0x0, (%r9)
movl $0x1, 0x1(%r9)
leaq 0x2(%r9), %r13
testl %r15d, %r15d
je 0x1f70
movq %r9, %rcx
cmpl $0xe, %r15d
ja 0x1f75
shlb $0x4, %r15b
movb %r15b, (%rcx)
movups (%rsi), %xmm0
movups %xmm0, (%r13)
jmp 0x1f99
pushq $0x4b
popq %rax
jmp 0x1f9f
movq %rcx, %r13
movb $-0x10, (%rcx)
leal -0xf(%r15), %eax
cmpl $0xfb, %eax
ja 0x1fc7
movb %al, 0x2(%r13)
addq $0x3, %r13
movq %r13, %rdi
movq %r14, %rdx
callq 0x11c0
pushq $0x4b
popq %rax
addq %r14, %r13
testq %r13, %r13
je 0x1fb3
subl 0x10(%rsp), %r13d
movq 0x38(%rsp), %rax
movl %r13d, (%rax)
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x4b
popq %rax
jmp 0x1fb3
cmpl $0x1fb, %eax            # imm = 0x1FB
ja 0x1fdf
movb $-0x4, 0x2(%r13)
addb $0x4, %al
movb %al, 0x3(%r13)
addq $0x4, %r13
jmp 0x1f8e
movq %rcx, %r13
cmpl $0x100fc, %eax          # imm = 0x100FC
ja 0x1ffc
movb $-0x3, 0x2(%rcx)
addl $0xffffff03, %eax       # imm = 0xFFFFFF03
movw %ax, 0x3(%rcx)
addq $0x5, %r13
jmp 0x1f8e
cmpl $0x10000fd, %eax        # imm = 0x10000FD
ja 0x201a
movb $-0x2, 0x2(%rcx)
leal -0x10d(%r15), %eax
movl %eax, 0x3(%rcx)
addq $0x6, %r13
jmp 0x1f8e
movb $-0x1, 0x2(%rcx)
leal -0x10e(%r15), %eax
movl %eax, 0x3(%rcx)
addq $0x7, %r13
jmp 0x1f8e