// File: /workspace/github_c_makefile_star2_O2/LemonBoy[P]autobahn/xdiff/xhistogram.c
// Function: histogram_diff
static int histogram_diff(xpparam_t const *xpp, xdfenv_t *env,
	int line1, int count1, int line2, int count2)
{
	struct histindex index;
	struct region lcs;
	int sz;
	int result = -1;

	if (count1 <= 0 && count2 <= 0)
		return 0;

	if (LINE_END(1) >= MAX_PTR)
		return -1;

	if (!count1) {
		while(count2--)
			env->xdf2.rchg[line2++ - 1] = 1;
		return 0;
	} else if (!count2) {
		while(count1--)
			env->xdf1.rchg[line1++ - 1] = 1;
		return 0;
	}

	memset(&index, 0, sizeof(index));

	index.env = env;
	index.xpp = xpp;

	index.records = NULL;
	index.line_map = NULL;
	/* in case of early xdl_cha_free() */
	index.rcha.head = NULL;

	index.table_bits = xdl_hashbits(count1);
	sz = index.records_size = 1 << index.table_bits;
	sz *= sizeof(struct record *);
	if (!(index.records = (struct record **) xdl_malloc(sz)))
		goto cleanup;
	memset(index.records, 0, sz);

	sz = index.line_map_size = count1;
	sz *= sizeof(struct record *);
	if (!(index.line_map = (struct record **) xdl_malloc(sz)))
		goto cleanup;
	memset(index.line_map, 0, sz);

	sz = index.line_map_size;
	sz *= sizeof(unsigned int);
	if (!(index.next_ptrs = (unsigned int *) xdl_malloc(sz)))
		goto cleanup;
	memset(index.next_ptrs, 0, sz);

	/* lines / 4 + 1 comes from xprepare.c:xdl_prepare_ctx() */
	if (xdl_cha_init(&index.rcha, sizeof(struct record), count1 / 4 + 1) < 0)
		goto cleanup;

	index.ptr_shift = line1;
	index.max_chain_length = 64;

	memset(&lcs, 0, sizeof(lcs));
	if (find_lcs(&index, &lcs, line1, count1, line2, count2))
		result = fall_back_to_classic_diff(&index, line1, count1, line2, count2);
	else {
		if (lcs.begin1 == 0 && lcs.begin2 == 0) {
			while (count1--)
				env->xdf1.rchg[line1++ - 1] = 1;
			while (count2--)
				env->xdf2.rchg[line2++ - 1] = 1;
			result = 0;
		} else {
			result = histogram_diff(xpp, env,
						line1, lcs.begin1 - line1,
						line2, lcs.begin2 - line2);
			if (result)
				goto cleanup;
			result = histogram_diff(xpp, env,
						lcs.end1 + 1, LINE_END(1) - lcs.end1,
						lcs.end2 + 1, LINE_END(2) - lcs.end2);
			if (result)
				goto cleanup;
		}
	}

cleanup:
	xdl_free(index.records);
	xdl_free(index.line_map);
	xdl_free(index.next_ptrs);
	xdl_cha_free(&index.rcha);

	return result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x148, %rsp            # imm = 0x148
movq %r8, 0x10(%rsp)
movl %ecx, %r12d
testl %ecx, %ecx
setle %al
movq %r9, 0x8(%rsp)
testl %r9d, %r9d
setle %cl
xorl %ebx, %ebx
testb %cl, %al
jne 0x5ca3
movl %r12d, %eax
addl %edx, %eax
je 0x5700
movq %rsi, %r15
testl %r12d, %r12d
je 0x5708
cmpl $0x0, 0x8(%rsp)
je 0x5731
movq %rdi, %r13
movl %edx, 0x4(%rsp)
movq %rax, 0x28(%rsp)
xorps %xmm0, %xmm0
leaq 0x68(%rsp), %r14
movups %xmm0, 0x48(%r14)
movups %xmm0, 0x38(%r14)
movups %xmm0, 0x28(%r14)
movups %xmm0, 0x18(%r14)
andq $0x0, 0x58(%r14)
movups %xmm0, 0x8(%r14)
movq %r15, 0x60(%r14)
movq %rdi, 0x68(%r14)
movups %xmm0, -0x8(%r14)
movl %r12d, %edi
callq 0x40c7
movl %eax, %ecx
pushq $0x1
popq %rax
shll %cl, %eax
movl %ecx, 0x40(%r14)
movl %eax, 0x44(%r14)
pushq $0x8
popq %rax
shll %cl, %eax
movslq %eax, %rsi
pushq $0x1
popq %rdi
callq 0x10b0
movq %rax, -0x10(%r14)
pushq $-0x1
popq %rbx
testq %rax, %rax
je 0x5c7a
movl %r12d, 0xb0(%rsp)
leal (,%r12,8), %eax
movslq %eax, %rsi
pushq $0x1
popq %rdi
callq 0x10b0
movq %rax, 0x60(%rsp)
testq %rax, %rax
je 0x5c7a
leal (,%r12,4), %eax
movslq %eax, %rsi
pushq $0x1
popq %rdi
callq 0x10b0
movq %rax, 0xa0(%rsp)
testq %rax, %rax
je 0x5c7a
pushq $0x4
popq %rcx
movl %r12d, %eax
cltd
idivl %ecx
incl %eax
movslq %eax, %rdx
pushq $0x10
popq %rsi
movq %r14, %rdi
callq 0x3b7a
testl %eax, %eax
js 0x5c7a
movq %r13, 0x108(%rsp)
movq %r12, 0xe0(%rsp)
movq %r15, 0xd8(%rsp)
movl $0xfffffffe, %ecx       # imm = 0xFFFFFFFE
movl 0x4(%rsp), %eax
movl %eax, 0xbc(%rsp)
movl $0x40, 0xb4(%rsp)
leaq 0x1(%rcx), %r14
movq 0x28(%rsp), %r15
leal -0x1(%r15), %ebp
cmpl %eax, %ebp
jb 0x574c
movq 0xc8(%rsp), %rax
movq 0x60(%rax), %rax
addl $-0x2, %r15d
movq (%rax,%r15,8), %rax
movq 0x18(%rax), %rax
movb 0xa8(%rsp), %cl
movq %rax, %rdx
shrq %cl, %rdx
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
shrq %cl, %r12
shlq %cl, %r12
addq %rax, %rdx
xorq %r14, %r12
andq %rdx, %r12
shlq $0x3, %r12
addq 0x58(%rsp), %r12
xorl %r13d, %r13d
movq %r12, %rbx
movq (%rbx), %rbx
testq %rbx, %rbx
je 0x568c
movq 0xc8(%rsp), %rax
movq 0xd0(%rsp), %rdi
movq 0x60(%rax), %rax
movl (%rbx), %ecx
decl %ecx
movq (%rax,%rcx,8), %rsi
movq (%rax,%r15,8), %rdx
callq 0x5cb7
testl %eax, %eax
jne 0x56c7
addq $0x8, %rbx
incl %r13d
jmp 0x5652
cmpl %r13d, 0xb4(%rsp)
je 0x5b62
leaq 0x68(%rsp), %rdi
callq 0x3bb0
testq %rax, %rax
je 0x5b62
movq %rax, %rbx
movl %ebp, (%rax)
movl $0x1, 0x4(%rax)
movq (%r12), %rax
movq %rax, 0x8(%rbx)
movq %rbx, (%r12)
jmp 0x56e2
movl (%rbx), %eax
movq 0xa0(%rsp), %rcx
movl %ebp, %edx
subl 0xbc(%rsp), %edx
movl %eax, (%rcx,%rdx,4)
movl %ebp, (%rbx)
incl 0x4(%rbx)
movq 0x60(%rsp), %rax
movl %ebp, %ecx
subl 0xbc(%rsp), %ecx
movq %rbx, (%rax,%rcx,8)
movl %ebp, %r15d
movl 0x4(%rsp), %eax
jmp 0x55fd
pushq $-0x1
popq %rbx
jmp 0x5ca3
movslq 0x10(%rsp), %rax
movq 0x8(%rsp), %rcx
subl $0x1, %ecx
movq %rcx, 0x8(%rsp)
jb 0x5ca3
movq 0xf0(%r15), %rcx
movb $0x1, -0x1(%rcx,%rax)
incq %rax
jmp 0x570d
movslq %edx, %rax
subl $0x1, %r12d
jb 0x5ca3
movq 0x68(%r15), %rcx
movb $0x1, -0x1(%rcx,%rax)
incq %rax
jmp 0x5734
movl 0xb4(%rsp), %eax
incl %eax
movl %eax, 0xc0(%rsp)
movq 0x8(%rsp), %rax
movq 0x10(%rsp), %rcx
leal (%rax,%rcx), %edx
movl %edx, 0x20(%rsp)
leal -0x1(%rax,%rcx), %eax
movq %rax, 0x118(%rsp)
movq 0x28(%rsp), %rax
decl %eax
movq %rax, 0x120(%rsp)
movl 0x4(%rsp), %r12d
movl %ecx, %eax
movq %rax, 0x110(%rsp)
movq $0x0, 0x38(%rsp)
movq $0x0, 0x30(%rsp)
movl $0x0, 0x24(%rsp)
movq $0x0, 0xe8(%rsp)
movl $0xfffffffe, %r14d      # imm = 0xFFFFFFFE
movq %r12, 0xf8(%rsp)
cmpl 0x20(%rsp), %ecx
jge 0x5b48
movslq %ecx, %rbx
movl %ecx, %eax
movq %rax, 0x100(%rsp)
leal 0x1(%rcx), %eax
movq 0xc8(%rsp), %rcx
movq 0xe8(%rcx), %rcx
movq -0x8(%rcx,%rbx,8), %rcx
movq 0x18(%rcx), %rdx
movb 0xa8(%rsp), %cl
movq %rdx, %rsi
shrq %cl, %rsi
pushq $-0x1
popq %r15
shlq %cl, %r15
decq %rbx
addq %rdx, %rsi
notq %r15
andq %rsi, %r15
shlq $0x3, %r15
addq 0x58(%rsp), %r15
movq %rax, 0x48(%rsp)
movq %rbx, 0xf0(%rsp)
movq (%r15), %r15
testq %r15, %r15
je 0x5b3e
movl 0x4(%r15), %eax
cmpl 0xc0(%rsp), %eax
jbe 0x5893
cmpl $0x0, 0xc4(%rsp)
jne 0x5b35
movq 0xc8(%rsp), %rax
movq 0xd0(%rsp), %rdi
movl (%r15), %ecx
decl %ecx
movq 0x60(%rax), %rdx
movq 0xe8(%rax), %rax
movq (%rdx,%rcx,8), %rsi
movq (%rax,%rbx,8), %rdx
callq 0x5cb7
movl %eax, 0xc4(%rsp)
jmp 0x5b35
movl (%r15), %ebp
movq 0xc8(%rsp), %rax
movq 0xd0(%rsp), %rdi
leal -0x1(%rbp), %ecx
movq 0x60(%rax), %rdx
movq 0xe8(%rax), %rax
movq (%rdx,%rcx,8), %rsi
movq (%rax,%rbx,8), %rdx
callq 0x5cb7
testl %eax, %eax
je 0x5b35
movl $0x1, 0xc4(%rsp)
movq 0xa0(%rsp), %rax
movl 0xbc(%rsp), %ecx
movq %r15, 0x40(%rsp)
movl %ebp, %edx
subl %ecx, %ebp
movl (%rax,%rbp,4), %ebp
movl 0x4(%r15), %eax
movl %eax, (%rsp)
movq 0x100(%rsp), %rbx
movq %rdx, 0x18(%rsp)
movq %rdx, %r15
movl %r15d, %r13d
negl %r13d
cmpq %r12, %r15
jbe 0x5982
cmpq 0x110(%rsp), %rbx
jbe 0x5982
movq 0xc8(%rsp), %rax
movq 0xd0(%rsp), %rdi
leal (%r15,%r14), %ecx
movq 0x60(%rax), %rdx
movq 0xe8(%rax), %rax
movq (%rdx,%rcx,8), %rsi
leal (%rbx,%r14), %ecx
movq (%rax,%rcx,8), %rdx
callq 0x5cb7
testl %eax, %eax
je 0x5982
decq %r15
decq %rbx
incl %r13d
cmpl $0x2, (%rsp)
jb 0x590c
movq 0x60(%rsp), %rax
addl 0xbc(%rsp), %r13d
negl %r13d
movq (%rax,%r13,8), %rax
movl 0x4(%rax), %eax
movl (%rsp), %ecx
cmpl %eax, %ecx
cmovael %eax, %ecx
movl %ecx, (%rsp)
jmp 0x5906
movl %r13d, %eax
negl %eax
movl %eax, 0x54(%rsp)
movq 0x100(%rsp), %rdi
leaq (,%rdi,8), %rax
movq %rax, 0x130(%rsp)
movq 0x18(%rsp), %rax
leaq (,%rax,8), %rax
movq %rax, 0x128(%rsp)
xorl %r14d, %r14d
leaq (%rdi,%r14), %r12
movq 0x18(%rsp), %rax
addq %r14, %rax
movq %rax, 0x138(%rsp)
cmpq 0x120(%rsp), %rax
jae 0x5a81
cmpq 0x118(%rsp), %r12
jae 0x5a81
movq 0xc8(%rsp), %rax
movq %rbx, %r15
movq %r13, %rbx
movq %rdi, %r13
movq 0xd0(%rsp), %rdi
movq 0x60(%rax), %rcx
addq 0x128(%rsp), %rcx
movq (%rcx,%r14,8), %rsi
movq 0xe8(%rax), %rax
addq 0x130(%rsp), %rax
movq (%rax,%r14,8), %rdx
callq 0x5cb7
movq %r13, %rdi
movq %rbx, %r13
movq %r15, %rbx
testl %eax, %eax
je 0x5a81
incq %r14
cmpl $0x2, (%rsp)
jb 0x59bb
movq 0x60(%rsp), %rax
movl 0xbc(%rsp), %ecx
movq 0x18(%rsp), %rsi
movl %esi, %edx
subl %ecx, %edx
leal (%r14,%rdx), %ecx
movq (%rax,%rcx,8), %rax
movl 0x4(%rax), %eax
movl (%rsp), %ecx
cmpl %eax, %ecx
cmovael %eax, %ecx
movl %ecx, (%rsp)
addq %r14, %rdi
addq %r14, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x5993
leal 0x1(%r12), %eax
movq 0x48(%rsp), %rcx
cmpl %r12d, %ecx
cmovbel %eax, %ecx
movq %rcx, 0x48(%rsp)
movq 0x30(%rsp), %rax
subl 0x38(%rsp), %eax
addl 0x18(%rsp), %r13d
addl %r13d, %r14d
cmpl %r14d, %eax
movq 0x138(%rsp), %rdx
jb 0x5ac0
movl (%rsp), %eax
cmpl 0xc0(%rsp), %eax
jae 0x5ae6
movl (%rsp), %eax
movl %eax, 0xc0(%rsp)
movl 0x54(%rsp), %eax
movq %rax, 0x38(%rsp)
movl %edx, %eax
movq %rax, 0x30(%rsp)
movl %ebx, 0x24(%rsp)
movq %r12, 0xe8(%rsp)
testl %ebp, %ebp
movl $0xfffffffe, %r14d      # imm = 0xFFFFFFFE
je 0x5b20
movq 0xa0(%rsp), %rax
movl 0xbc(%rsp), %ecx
movq 0xf8(%rsp), %r12
cmpl %edx, %ebp
ja 0x5b16
subl %ecx, %ebp
movl (%rax,%rbp,4), %ebp
testl %ebp, %ebp
jne 0x5b07
jmp 0x5b28
movq 0x40(%rsp), %r15
jmp 0x58e8
movq 0xf8(%rsp), %r12
movq 0xf0(%rsp), %rbx
movq 0x40(%rsp), %r15
addq $0x8, %r15
jmp 0x5833
movq 0x48(%rsp), %rcx
jmp 0x57cb
cmpl $0x0, 0xc4(%rsp)
je 0x5bab
movl 0xb4(%rsp), %eax
cmpl 0xc0(%rsp), %eax
jae 0x5bab
movq 0xc8(%rsp), %rdi
movq 0xd0(%rsp), %rax
movq (%rax), %rax
andq $-0x61, %rax
leaq 0x140(%rsp), %rsi
movq %rax, (%rsi)
movl 0x4(%rsp), %edx
movq 0xe0(%rsp), %rcx
movq 0x10(%rsp), %r8
movq 0x8(%rsp), %r9
callq 0x42ab
movl %eax, %ebx
leaq 0x68(%rsp), %r14
jmp 0x5c7a
movq 0x38(%rsp), %rcx
movl %ecx, %eax
movl 0x24(%rsp), %r9d
orl %r9d, %eax
jne 0x5be9
movslq 0x4(%rsp), %rax
leaq 0x68(%rsp), %r14
movq 0xd8(%rsp), %rdx
movq 0xe0(%rsp), %rsi
subl $0x1, %esi
jb 0x5c53
movq 0x68(%rdx), %rcx
movb $0x1, -0x1(%rcx,%rax)
incq %rax
jmp 0x5bd6
movl 0x4(%rsp), %edx
subl %edx, %ecx
movq 0x10(%rsp), %r8
subl %r8d, %r9d
movq 0x108(%rsp), %r12
movq %r12, %rdi
movq 0xd8(%rsp), %r15
movq %r15, %rsi
callq 0x5488
movl %eax, %ebx
testl %eax, %eax
leaq 0x68(%rsp), %r14
jne 0x5c7a
movq 0x30(%rsp), %rax
leal 0x1(%rax), %edx
notl %eax
movq 0x28(%rsp), %rcx
addl %eax, %ecx
movq 0xe8(%rsp), %rax
leal 0x1(%rax), %r8d
notl %eax
movl 0x20(%rsp), %r9d
addl %eax, %r9d
movq %r12, %rdi
movq %r15, %rsi
callq 0x5488
movl %eax, %ebx
jmp 0x5c7a
movslq 0x10(%rsp), %rax
movq 0x8(%rsp), %rcx
subl $0x1, %ecx
movq %rcx, 0x8(%rsp)
jb 0x5c78
movq 0xf0(%rdx), %rcx
movb $0x1, -0x1(%rcx,%rax)
incq %rax
jmp 0x5c58
xorl %ebx, %ebx
movq 0x58(%rsp), %rdi
callq 0x1030
movq 0x60(%rsp), %rdi
callq 0x1030
movq 0xa0(%rsp), %rdi
callq 0x1030
movq %r14, %rdi
callq 0x3b98
movl %ebx, %eax
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq