// File: /workspace/github_c_makefile_star2_O2/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 %r15
pushq %r14
pushq %rbx
movzwl (%rdi), %r10d
movl (%rdx), %ebx
movq %rbx, %r11
negq %r11
xorl %r9d, %r9d
movl %esi, %r8d
movl $0x0, %eax
cmpw %r10w, (%rdi,%r11)
jne 0x391f
movq %rdi, %r11
subq %rbx, %r11
leal -0x22(%rsi), %eax
cmpl $-0x21, %eax
ja 0x3ac9
movq 0x2(%r11), %rbx
movq 0x2(%rdi), %rax
cmpq %rax, %rbx
jne 0x38f0
movq 0xa(%r11), %rbx
movq 0xa(%rdi), %rax
cmpq %rax, %rbx
jne 0x38fa
movq 0x12(%r11), %rbx
movq 0x12(%rdi), %rax
cmpq %rax, %rbx
jne 0x3904
movq 0x1a(%r11), %rbx
movq 0x1a(%rdi), %rax
cmpq %rax, %rbx
jne 0x390e
movl $0x22, %ebx
movl %ebx, %eax
addl $0x8, %ebx
cmpl %esi, %ebx
ja 0x38e9
movq (%r11,%rax), %r14
movq (%rdi,%rax), %rax
cmpq %rax, %r14
je 0x38bf
xorq %r14, %rax
addl $-0x8, %ebx
jmp 0x3916
movb (%r11,%rax), %bl
cmpb (%rdi,%rax), %bl
jne 0x391f
incq %rax
cmpq %r8, %rax
jb 0x38dd
jmp 0x391f
xorq %rbx, %rax
movl $0x2, %ebx
jmp 0x3916
xorq %rbx, %rax
movl $0xa, %ebx
jmp 0x3916
xorq %rbx, %rax
movl $0x12, %ebx
jmp 0x3916
xorq %rbx, %rax
movl $0x1a, %ebx
bsfq %rax, %rax
shrl $0x3, %eax
addl %ebx, %eax
movl 0x4(%rdx), %ebx
movq %rdi, %r11
subq %rbx, %r11
cmpw %r10w, (%r11)
jne 0x39ef
leal -0x22(%rsi), %r9d
cmpl $-0x21, %r9d
ja 0x3ad3
movq 0x2(%r11), %rbx
movq 0x2(%rdi), %r9
cmpq %r9, %rbx
jne 0x39b0
movq 0xa(%r11), %rbx
movq 0xa(%rdi), %r9
cmpq %r9, %rbx
jne 0x39ba
movq 0x12(%r11), %rbx
movq 0x12(%rdi), %r9
cmpq %r9, %rbx
jne 0x39c4
movq 0x1a(%r11), %rbx
movq 0x1a(%rdi), %r9
cmpq %r9, %rbx
jne 0x39ce
movl $0x22, %ebx
movl %ebx, %r9d
movl %ebx, %r14d
leal 0x8(%r9), %ebx
cmpl %esi, %ebx
ja 0x39a9
movq (%r11,%r14), %r15
movq (%rdi,%r14), %r9
cmpq %r9, %r15
je 0x3979
xorq %r15, %r9
addl $-0x8, %ebx
jmp 0x39d6
movb (%r11,%r14), %r9b
cmpb (%rdi,%r14), %r9b
jne 0x39e1
incq %r14
cmpq %r8, %r14
jb 0x399c
jmp 0x39e1
xorq %rbx, %r9
movl $0x2, %ebx
jmp 0x39d6
xorq %rbx, %r9
movl $0xa, %ebx
jmp 0x39d6
xorq %rbx, %r9
movl $0x12, %ebx
jmp 0x39d6
xorq %rbx, %r9
movl $0x1a, %ebx
bsfq %r9, %r14
shrl $0x3, %r14d
addl %ebx, %r14d
xorl %r9d, %r9d
cmpl %eax, %r14d
seta %r9b
cmoval %r14d, %eax
movl 0x8(%rdx), %r11d
movq %rdi, %rdx
subq %r11, %rdx
cmpw %r10w, (%rdx)
jne 0x3ac0
leal -0x22(%rsi), %r10d
cmpl $-0x21, %r10d
ja 0x3add
movq 0x2(%rdx), %r10
movq 0x2(%rdi), %r11
cmpq %r11, %r10
jne 0x3a81
movq 0xa(%rdx), %rbx
movq 0xa(%rdi), %r11
cmpq %r11, %rbx
jne 0x3a8c
movq 0x12(%rdx), %rbx
movq 0x12(%rdi), %r11
cmpq %r11, %rbx
jne 0x3a94
movq 0x1a(%rdx), %rbx
movq 0x1a(%rdi), %r11
cmpq %r11, %rbx
jne 0x3a9c
movl $0x22, %r10d
movl %r10d, %r11d
addl $0x8, %r10d
cmpl %esi, %r10d
ja 0x3a7a
movq (%rdx,%r11), %rbx
movq (%rdi,%r11), %r11
cmpq %r11, %rbx
je 0x3a4b
xorq %rbx, %r11
addl $-0x8, %r10d
jmp 0x3aa5
movb (%rdx,%r11), %sil
cmpb (%rdi,%r11), %sil
jne 0x3ab0
incq %r11
cmpq %r8, %r11
jb 0x3a6d
jmp 0x3ab0
xorq %r10, %r11
movl $0x2, %r10d
jmp 0x3aa5
movl $0xa, %r10d
jmp 0x3aa2
movl $0x12, %r10d
jmp 0x3aa2
movl $0x1a, %r10d
xorq %rbx, %r11
bsfq %r11, %r11
shrl $0x3, %r11d
addl %r10d, %r11d
cmpl %eax, %r11d
cmoval %r11d, %eax
movl $0x2, %edx
cmoval %edx, %r9d
movl %r9d, (%rcx)
popq %rbx
popq %r14
popq %r15
retq
movl $0x2, %ebx
jmp 0x38bf
movl $0x2, %ebx
jmp 0x3979
movl $0x2, %r10d
jmp 0x3a4b