// File: /workspace/github_c_makefile_star2_O2/lmcilroy[P]lzm/lzmencode.c
// Function: lzm_encode_high
static unsigned int
lzm_encode_high(
    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 - 3;
	const unsigned char * const out_limit = buffer_out + *size_out;
	const unsigned char *curr_in = buffer_in;
	const unsigned char *next_curr;
	const unsigned char *curr_o;
	const unsigned char *last;
	const unsigned char *last_o;
	const unsigned char *match_last;
	const unsigned char *match_curr;
	const unsigned char *next_last;
	unsigned char *curr_out = buffer_out;
	struct ht_entry *last_htp;
	unsigned int token;
	unsigned int next_token;
	unsigned int last_token;
	unsigned int len;
	unsigned int off;
	unsigned int val;
	unsigned int match_len;
	unsigned int match_val;
	unsigned int curr_chain;
	unsigned int index;
	unsigned int misses = (1 << MISS_ORDER) + 1;
	unsigned int hashval;
	unsigned int next_hashval;

	struct prev_match prev;

	lzm_reset(state, buffer_in);

	prev.lit_start = buffer_in;
	prev.start = 0;
	prev.last = 0;
	prev.length = 0;

	token = readmem32(curr_in);
	hashval = hash_high(token, state->hash_order);
	next_token = readmem32(curr_in + 1);
	next_hashval = hash_high(next_token, state->hash_order);
	last_htp = &state->last_ht[hashval];
	index = curr_in - buffer_in;
	state->chains[index & state->chain_mask] = *last_htp;
	last_htp->index = index;
	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 = readmem32(next_curr);
		next_hashval = hash_high(next_token, state->hash_order);
		last_htp = &state->last_ht[hashval];
		last = last_htp->index + buffer_in;
		last_token = last_htp->token;
		index = curr_in - buffer_in;
		state->chains[index & state->chain_mask] = *last_htp;
		last_htp->index = index;
		last_htp->token = token;

		match_val = 0;
		match_len = 0;
		match_last = NULL;
		curr_chain = 1;

		for (;;) {
			if ((curr_in - last) & ~MAX_OFFSET_MASK)
				break;

			if ((token == last_token) && (match_len == 0 ||
			    curr_in[match_len] == last[match_len])) {

				len = MIN_MATCH;
				len += matchlen(curr_in + len, last + len,
				    match_end);
				off = matchlen_rev(curr_in, last,
				    prev.lit_start, buffer_in);
				curr_o = curr_in - off;
				last_o = last - off;
				len += off;
				val = len - lzm_offset_cost(curr_o - last_o);

				if (val > match_val) {
					match_val = val;
					match_len = len;
					match_last = last_o;
					match_curr = curr_o;
					if ((curr_o + len) >= scan_end)
						break;
				}
			}

			if (curr_chain++ == MAX_CHAIN_LENGTH)
				break;

			index = last - buffer_in;
			last_htp = &state->chains[index & state->chain_mask];
			next_last = last_htp->index + buffer_in;
			last_token = last_htp->token;

			if (next_last >= last)
				break;

			last = next_last;
		}

		if (match_len == 0) {
			misses++;
			curr_in = next_curr;
			continue;
		}
		misses = (1 << MISS_ORDER) + 1;

		curr_out = output_match_merge(&prev, curr_out, match_curr,
		    match_last, match_len, out_limit);
		if (unlikely(curr_out == NULL))
			return EOVERFLOW;

		match_curr += match_len;
		if (match_curr >= scan_end)
			break;

		curr_in = next_curr;
		while (curr_in < match_curr) {
			token = next_token;
			hashval = next_hashval;
			next_curr = curr_in + (misses >> MISS_ORDER);
			next_token = readmem32(next_curr);
			next_hashval = hash_high(next_token,
			    state->hash_order);
			last_htp = &state->last_ht[hashval];
			index = curr_in - buffer_in;
			state->chains[index & state->chain_mask] = *last_htp;
			last_htp->index = index;
			last_htp->token = token;
			curr_in = next_curr;
		}
	}

	curr_out = output_match_final(&prev, curr_out, end, 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 $0xc8, %rsp
movq %rcx, %rbx
movq %rsi, %r14
movq %rdi, %r15
movl %edx, %eax
leaq (%rsi,%rax), %rcx
movq %rcx, 0x98(%rsp)
leaq -0x7(%rsi,%rax), %rcx
movq %rcx, 0xb8(%rsp)
leaq -0xa(%rsi,%rax), %rax
movq %rax, 0x40(%rsp)
movq %r8, 0x90(%rsp)
movl (%r8), %eax
addq %rbx, %rax
movq %rax, 0x38(%rsp)
callq 0x3a52
movq %r15, %r11
leaq 0x68(%rsp), %rax
movq %r14, (%rax)
xorps %xmm0, %xmm0
andl $0x0, 0x18(%rax)
movups %xmm0, 0x8(%rax)
movl (%r14), %eax
movl 0x1(%r14), %r13d
imull $0x9e3779b1, %eax, %edx # imm = 0x9E3779B1
xorl %ecx, %ecx
subb 0x10(%r15), %cl
shrl %cl, %edx
imull $0x9e3779b1, %r13d, %r8d # imm = 0x9E3779B1
shrl %cl, %r8d
movq (%r15), %rcx
movq 0x8(%r15), %rsi
movq (%rcx,%rdx,8), %rdi
movq %rdi, (%rsi)
andl $0x0, (%rcx,%rdx,8)
leaq 0x1(%r14), %rsi
movl %eax, 0x4(%rcx,%rdx,8)
movq %r14, %rax
negq %rax
movq %rax, 0xa0(%rsp)
xorl %edi, %edi
movl $0x0, 0x4(%rsp)
movq %r14, 0x48(%rsp)
movq %r14, 0x58(%rsp)
movl %r8d, %r14d
movq %rbx, 0x88(%rsp)
movq %rbx, 0x8(%rsp)
movq %rsi, %rbx
movq %r15, 0x28(%rsp)
movq %rax, %rsi
pushq $0x41
popq %rax
movl %eax, 0x10(%rsp)
movq %rdi, 0x60(%rsp)
cmpq 0x40(%rsp), %rbx
jae 0x36fc
movq %rbx, %r15
movl %r13d, %r8d
movl 0x10(%rsp), %ecx
movl %ecx, %r12d
shrl $0x6, %r12d
movl (%rbx,%r12), %ebx
movb 0x10(%r11), %dl
movq %rsi, %r13
movl %r14d, %esi
movq (%r11), %rdi
movq 0x8(%r11), %rcx
movl (%rdi,%rsi,8), %r14d
movl 0x4(%rdi,%rsi,8), %eax
movl %r8d, 0x14(%rsp)
movl %r15d, %r8d
movq 0x48(%rsp), %r11
subl %r11d, %r8d
movq 0x28(%rsp), %r9
movl 0x1c(%r9), %r9d
andl %r8d, %r9d
movq (%rdi,%rsi,8), %r10
movq %r10, (%rcx,%r9,8)
movq %r12, 0xa8(%rsp)
leaq (%r15,%r12), %rcx
movq %rcx, 0xb0(%rsp)
movl %ebx, 0x54(%rsp)
imull $0x9e3779b1, %ebx, %r9d # imm = 0x9E3779B1
xorl %ecx, %ecx
subb %dl, %cl
movq $0x0, 0x20(%rsp)
shrl %cl, %r9d
movl %r9d, 0x50(%rsp)
addq %r11, %r14
movq 0x28(%rsp), %r11
movl %r8d, (%rdi,%rsi,8)
movl 0x14(%rsp), %r8d
movl %r8d, 0x4(%rdi,%rsi,8)
movq 0x60(%rsp), %rdi
leaq 0x4(%r15), %rcx
movq %rcx, 0xc0(%rsp)
pushq $0x7f
popq %rbx
movq %r13, 0x18(%rsp)
xorl %r13d, %r13d
movl $0x0, 0x30(%rsp)
movq %r15, %rcx
subq %r14, %rcx
cmpq $0xfffffff, %rcx        # imm = 0xFFFFFFF
ja 0x35d1
cmpl %eax, %r8d
jne 0x35a3
testl %r13d, %r13d
je 0x350c
movl %r13d, %eax
movb (%r15,%rax), %cl
cmpb (%r14,%rax), %cl
jne 0x35a3
leaq 0x4(%r14), %rsi
movq 0xc0(%rsp), %rdi
movq 0xb8(%rsp), %rdx
callq 0x3a6f
movl %eax, %r12d
movq %r15, %rdi
movq %r14, %rsi
movq 0x58(%rsp), %rdx
movq 0x48(%rsp), %rcx
callq 0x3bc6
movl 0x14(%rsp), %r8d
movq 0x60(%rsp), %rdi
movq 0x28(%rsp), %r11
movl %eax, %ecx
movq %r15, %rsi
subq %rcx, %rsi
movq %r14, %rbp
subq %rcx, %rbp
addl %eax, %r12d
addl $0x4, %r12d
xorl %eax, %eax
movl %esi, %ecx
subl %ebp, %ecx
sete %al
orl %ecx, %eax
bsrl %eax, %ecx
xorl $0x1f, %ecx
movl %r12d, %eax
leaq 0x21c4(%rip), %rdx      # 0x5740
subl (%rdx,%rcx,8), %eax
cmpl 0x30(%rsp), %eax
jbe 0x35a3
movl %r12d, %ecx
addq %rsi, %rcx
movq %rbp, 0x20(%rsp)
movq %rsi, 0x18(%rsp)
movl %r12d, %r13d
movl %eax, 0x30(%rsp)
cmpq 0x40(%rsp), %rcx
jae 0x35de
subl $0x1, %ebx
jb 0x35d1
movl %r14d, %eax
movq 0x48(%rsp), %rsi
subl %esi, %eax
andl 0x1c(%r11), %eax
movq 0x8(%r11), %rcx
movl (%rcx,%rax,8), %edx
addq %rsi, %rdx
cmpq %r14, %rdx
jae 0x35d1
movl 0x4(%rcx,%rax,8), %eax
movq %rdx, %r14
jmp 0x34da
movq 0x20(%rsp), %rbp
movq 0x18(%rsp), %rsi
movl %r13d, %r12d
incl 0x10(%rsp)
testl %r12d, %r12d
movl 0x54(%rsp), %r13d
movq 0xb0(%rsp), %rbx
movl 0x50(%rsp), %r14d
je 0x340f
movl 0x4(%rsp), %eax
testl %eax, %eax
je 0x3618
movl %eax, %eax
addq %rdi, %rax
cmpq %rsi, %rax
jbe 0x362a
leaq 0x4(%rdi), %rax
cmpq %rsi, %rax
jbe 0x361f
movq 0x8(%rsp), %rax
jmp 0x364d
movl %esi, %eax
subl %edi, %eax
movl %eax, 0x80(%rsp)
leaq 0x68(%rsp), %rdi
movq %rsi, 0x30(%rsp)
movq 0x8(%rsp), %rsi
movq 0x38(%rsp), %rdx
callq 0x3d02
movq 0x30(%rsp), %rsi
movq 0x28(%rsp), %r11
movq %rsi, 0x70(%rsp)
movq %rbp, 0x78(%rsp)
movl %r12d, 0x80(%rsp)
testq %rax, %rax
je 0x376b
movq %rax, 0x8(%rsp)
movl %r12d, %eax
addq %rsi, %rax
cmpq 0x40(%rsp), %rax
jae 0x36ed
addl 0xa0(%rsp), %r15d
addl 0xa8(%rsp), %r15d
cmpq %rax, %rbx
jae 0x36d6
movl 0x1(%rbx), %edx
movq %rsi, %rbp
movl %r14d, %esi
imull $0x9e3779b1, %edx, %edi # imm = 0x9E3779B1
xorl %ecx, %ecx
subb 0x10(%r11), %cl
shrl %cl, %edi
incq %rbx
movq (%r11), %rcx
movq 0x8(%r11), %r8
movl 0x1c(%r11), %r9d
andl %r15d, %r9d
movq (%rcx,%rsi,8), %r10
movq %r10, (%r8,%r9,8)
movl %r15d, (%rcx,%rsi,8)
movl %r13d, 0x4(%rcx,%rsi,8)
movq %rbp, %rsi
incl %r15d
movl %edx, %r13d
movl %edi, %r14d
jmp 0x368a
movq 0x68(%rsp), %rcx
movq %rcx, 0x58(%rsp)
movq %rsi, %rdi
movl %r12d, 0x4(%rsp)
jmp 0x3400
movq 0x38(%rsp), %rbx
pushq $0x4b
popq %rbp
movq 0x8(%rsp), %rax
jmp 0x3710
cmpl $0x0, 0x4(%rsp)
movq 0x38(%rsp), %rbx
pushq $0x4b
popq %rbp
movq 0x8(%rsp), %rax
je 0x3725
leaq 0x68(%rsp), %rdi
movq %rax, %rsi
movq %rbx, %rdx
callq 0x3d02
testq %rax, %rax
je 0x3757
movq 0x68(%rsp), %rsi
movq 0x98(%rsp), %rdx
subl %esi, %edx
movq %rax, %rdi
movq %rbx, %rcx
callq 0x390b
testq %rax, %rax
je 0x3757
subl 0x88(%rsp), %eax
movq 0x90(%rsp), %rcx
movl %eax, (%rcx)
xorl %ebp, %ebp
movl %ebp, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x4b
popq %rbp
jmp 0x3757