// File: /workspace/github_c_makefile_star2_O3/ebiggers[P]xpack/lib/xpack_compress.c
// Function: find_longest_repeat_offset_match
static u32
find_longest_repeat_offset_match(const u8 * const in_next,
				 const u32 max_len,
				 const u32 recent_offsets[],
				 unsigned *rep_max_idx_ret)
{
#if MIN_MATCH_LEN == 2
#  define load_initial  load_u16_unaligned
#elif MIN_MATCH_LEN == 3
#  define load_initial	load_u24_unaligned
#elif MIN_MATCH_LEN == 4
#  define load_initial	load_u32_unaligned
#else
#  error "unsupported MIN_MATCH_LEN"
#endif
	const u32 next_bytes = load_initial(in_next);
	const u8 *matchptr;
	u32 rep_len;
	u32 rep_max_len;
	unsigned rep_max_idx;

	STATIC_ASSERT(NUM_REPS >= 1 && NUM_REPS <= 4);

	matchptr = in_next - recent_offsets[0];
	if (load_initial(matchptr) == next_bytes)
		rep_max_len = lz_extend(in_next, matchptr, MIN_MATCH_LEN, max_len);
	else
		rep_max_len = 0;
	rep_max_idx = 0;

#if NUM_REPS >= 2
	matchptr = in_next - recent_offsets[1];
	if (load_initial(matchptr) == next_bytes) {
		rep_len = lz_extend(in_next, matchptr, MIN_MATCH_LEN, max_len);
		if (rep_len > rep_max_len) {
			rep_max_len = rep_len;
			rep_max_idx = 1;
		}
	}
#endif

#if NUM_REPS >= 3
	matchptr = in_next - recent_offsets[2];
	if (load_initial(matchptr) == next_bytes) {
		rep_len = lz_extend(in_next, matchptr, MIN_MATCH_LEN, max_len);
		if (rep_len > rep_max_len) {
			rep_max_len = rep_len;
			rep_max_idx = 2;
		}
	}
#endif

#if NUM_REPS >= 4
	matchptr = in_next - recent_offsets[3];
	if (load_initial(matchptr) == next_bytes) {
		rep_len = lz_extend(in_next, matchptr, MIN_MATCH_LEN, max_len);
		if (rep_len > rep_max_len) {
			rep_max_len = rep_len;
			rep_max_idx = 3;
		}
	}
#endif

	*rep_max_idx_ret = rep_max_idx;
	return rep_max_len;
}

// Assembly:
pushq %r14
pushq %rbx
movzwl (%rdi), %r9d
movl (%rdx), %r11d
movq %r11, %r10
negq %r10
xorl %r8d, %r8d
movl $0x0, %eax
cmpw %r9w, (%rdi,%r10)
jne 0x5001
movq %rdi, %r10
subq %r11, %r10
leal -0x22(%rsi), %eax
cmpl $-0x21, %eax
ja 0x5213
movq 0x2(%r10), %rax
movq 0x2(%rdi), %r11
cmpq %r11, %rax
jne 0x4fd2
movq 0xa(%r10), %rax
movq 0xa(%rdi), %r11
cmpq %r11, %rax
jne 0x4fdc
movq 0x12(%r10), %rax
movq 0x12(%rdi), %r11
cmpq %r11, %rax
jne 0x4fe6
movq 0x1a(%r10), %rbx
movq 0x1a(%rdi), %r11
movl $0x22, %eax
cmpq %r11, %rbx
jne 0x4ff0
leal 0x8(%rax), %ebx
cmpl %esi, %ebx
ja 0x5194
movl %eax, %eax
movq (%r10,%rax), %r14
movq (%rdi,%rax), %r11
movl %ebx, %eax
cmpq %r11, %r14
je 0x4fae
xorq %r14, %r11
addl $-0x8, %ebx
jmp 0x4ff8
xorq %rax, %r11
movl $0x2, %ebx
jmp 0x4ff8
xorq %rax, %r11
movl $0xa, %ebx
jmp 0x4ff8
xorq %rax, %r11
movl $0x12, %ebx
jmp 0x4ff8
xorq %rbx, %r11
movl $0x1a, %ebx
bsfq %r11, %rax
shrl $0x3, %eax
addl %ebx, %eax
movl 0x4(%rdx), %r11d
movq %rdi, %r10
subq %r11, %r10
cmpw %r9w, (%r10)
jne 0x50c3
leal -0x22(%rsi), %r8d
cmpl $-0x21, %r8d
ja 0x521d
movq 0x2(%r10), %r11
movq 0x2(%rdi), %r8
cmpq %r8, %r11
jne 0x5084
movq 0xa(%r10), %r11
movq 0xa(%rdi), %r8
cmpq %r8, %r11
jne 0x508e
movq 0x12(%r10), %r11
movq 0x12(%rdi), %r8
cmpq %r8, %r11
jne 0x5098
movq 0x1a(%r10), %rbx
movq 0x1a(%rdi), %r8
movl $0x22, %r11d
cmpq %r8, %rbx
jne 0x50a2
leal 0x8(%r11), %ebx
cmpl %esi, %ebx
ja 0x51bd
movl %r11d, %r8d
movq (%r10,%r8), %r14
movq (%rdi,%r8), %r8
movl %ebx, %r11d
cmpq %r8, %r14
je 0x505d
xorq %r14, %r8
addl $-0x8, %ebx
jmp 0x50aa
xorq %r11, %r8
movl $0x2, %ebx
jmp 0x50aa
xorq %r11, %r8
movl $0xa, %ebx
jmp 0x50aa
xorq %r11, %r8
movl $0x12, %ebx
jmp 0x50aa
xorq %rbx, %r8
movl $0x1a, %ebx
bsfq %r8, %r11
shrl $0x3, %r11d
addl %ebx, %r11d
xorl %r8d, %r8d
cmpl %eax, %r11d
seta %r8b
cmoval %r11d, %eax
movl 0x8(%rdx), %r10d
movq %rdi, %rdx
subq %r10, %rdx
cmpw %r9w, (%rdx)
jne 0x518d
leal -0x22(%rsi), %r9d
cmpl $-0x21, %r9d
ja 0x5228
movq 0x2(%rdx), %r9
movq 0x2(%rdi), %r10
cmpq %r10, %r9
jne 0x5148
movq 0xa(%rdx), %r9
movq 0xa(%rdi), %r10
cmpq %r10, %r9
jne 0x5153
movq 0x12(%rdx), %r9
movq 0x12(%rdi), %r10
cmpq %r10, %r9
jne 0x515e
movq 0x1a(%rdx), %r11
movq 0x1a(%rdi), %r10
movl $0x22, %r9d
cmpq %r10, %r11
jne 0x5169
leal 0x8(%r9), %r11d
cmpl %esi, %r11d
ja 0x51ea
movl %r9d, %r9d
movq (%rdx,%r9), %rbx
movq (%rdi,%r9), %r10
movl %r11d, %r9d
cmpq %r10, %rbx
je 0x511f
xorq %rbx, %r10
addl $-0x8, %r11d
jmp 0x5172
xorq %r9, %r10
movl $0x2, %r11d
jmp 0x5172
xorq %r9, %r10
movl $0xa, %r11d
jmp 0x5172
xorq %r9, %r10
movl $0x12, %r11d
jmp 0x5172
xorq %r11, %r10
movl $0x1a, %r11d
bsfq %r10, %r9
shrl $0x3, %r9d
addl %r11d, %r9d
cmpl %eax, %r9d
cmoval %r9d, %eax
movl $0x2, %edx
cmoval %edx, %r8d
movl %r8d, (%rcx)
popq %rbx
popq %r14
retq
cmpl %esi, %eax
jae 0x5001
movl %eax, %eax
movl %esi, %r11d
movb (%r10,%rax), %bl
cmpb (%rdi,%rax), %bl
jne 0x5001
incq %rax
cmpq %r11, %rax
jb 0x51a1
movl %esi, %eax
jmp 0x5001
cmpl %esi, %r11d
jae 0x50b5
movl %r11d, %r11d
movl %esi, %r8d
movb (%r10,%r11), %bl
cmpb (%rdi,%r11), %bl
jne 0x50b5
incq %r11
cmpq %r8, %r11
jb 0x51cc
movl %esi, %r11d
jmp 0x50b5
cmpl %esi, %r9d
jae 0x517d
movl %r9d, %r9d
movl %esi, %r10d
movb (%rdx,%r9), %r11b
cmpb (%rdi,%r9), %r11b
jne 0x517d
incq %r9
cmpq %r10, %r9
jb 0x51f5
movl %esi, %r9d
jmp 0x517d
movl $0x2, %eax
jmp 0x4fae
movl $0x2, %r11d
jmp 0x505d
movl $0x2, %r9d
jmp 0x511f
nop