// File: /workspace/github_c_makefile_star2_O0/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:
subq $0xc8, %rsp
movq %rdi, 0xb8(%rsp)
movq %rsi, 0xb0(%rsp)
movl %edx, 0xac(%rsp)
movl %ecx, 0xa8(%rsp)
movl %r8d, 0xa4(%rsp)
movl %r9d, 0xa0(%rsp)
movl $0xffffffff, 0x8(%rsp)  # imm = 0xFFFFFFFF
cmpl $0x0, 0xa8(%rsp)
jg 0xaaa1
cmpl $0x0, 0xa0(%rsp)
jg 0xaaa1
movl $0x0, 0xc4(%rsp)
jmp 0xaf09
movl 0xac(%rsp), %eax
addl 0xa8(%rsp), %eax
subl $0x1, %eax
cmpl $-0x1, %eax
jb 0xaac7
movl $0xffffffff, 0xc4(%rsp) # imm = 0xFFFFFFFF
jmp 0xaf09
cmpl $0x0, 0xa8(%rsp)
jne 0xab29
jmp 0xaad3
movl 0xa0(%rsp), %eax
movl %eax, %ecx
addl $-0x1, %ecx
movl %ecx, 0xa0(%rsp)
cmpl $0x0, %eax
je 0xab19
movq 0xb0(%rsp), %rax
movq 0xf0(%rax), %rax
movl 0xa4(%rsp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, 0xa4(%rsp)
subl $0x1, %ecx
movslq %ecx, %rcx
movb $0x1, (%rax,%rcx)
jmp 0xaad3
movl $0x0, 0xc4(%rsp)
jmp 0xaf09
cmpl $0x0, 0xa0(%rsp)
jne 0xab88
jmp 0xab35
movl 0xa8(%rsp), %eax
movl %eax, %ecx
addl $-0x1, %ecx
movl %ecx, 0xa8(%rsp)
cmpl $0x0, %eax
je 0xab78
movq 0xb0(%rsp), %rax
movq 0x68(%rax), %rax
movl 0xac(%rsp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, 0xac(%rsp)
subl $0x1, %ecx
movslq %ecx, %rcx
movb $0x1, (%rax,%rcx)
jmp 0xab35
movl $0x0, 0xc4(%rsp)
jmp 0xaf09
jmp 0xab8a
leaq 0x20(%rsp), %rdi
xorl %esi, %esi
movl $0x80, %edx
callq 0x1090
movq 0xb0(%rsp), %rax
movq %rax, 0x90(%rsp)
movq 0xb8(%rsp), %rax
movq %rax, 0x98(%rsp)
movq $0x0, 0x20(%rsp)
movq $0x0, 0x28(%rsp)
movq $0x0, 0x30(%rsp)
movl 0xa8(%rsp), %edi
callq 0x79f0
movl %eax, 0x70(%rsp)
movl 0x70(%rsp), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, 0x74(%rsp)
movl %eax, 0xc(%rsp)
movslq 0xc(%rsp), %rax
shlq $0x3, %rax
movl %eax, 0xc(%rsp)
movslq 0xc(%rsp), %rdi
callq 0x10f0
movq %rax, 0x20(%rsp)
cmpq $0x0, %rax
jne 0xac20
jmp 0xaed2
movq 0x20(%rsp), %rdi
movslq 0xc(%rsp), %rdx
xorl %esi, %esi
callq 0x1090
movl 0xa8(%rsp), %eax
movl %eax, 0x78(%rsp)
movl %eax, 0xc(%rsp)
movslq 0xc(%rsp), %rax
shlq $0x3, %rax
movl %eax, 0xc(%rsp)
movslq 0xc(%rsp), %rdi
callq 0x10f0
movq %rax, 0x28(%rsp)
cmpq $0x0, %rax
jne 0xac67
jmp 0xaed2
movq 0x28(%rsp), %rdi
movslq 0xc(%rsp), %rdx
xorl %esi, %esi
callq 0x1090
movl 0x78(%rsp), %eax
movl %eax, 0xc(%rsp)
movslq 0xc(%rsp), %rax
shlq $0x2, %rax
movl %eax, 0xc(%rsp)
movslq 0xc(%rsp), %rdi
callq 0x10f0
movq %rax, 0x68(%rsp)
cmpq $0x0, %rax
jne 0xaca7
jmp 0xaed2
movq 0x68(%rsp), %rdi
movslq 0xc(%rsp), %rdx
xorl %esi, %esi
callq 0x1090
leaq 0x20(%rsp), %rdi
addq $0x10, %rdi
movl 0xa8(%rsp), %eax
movl $0x4, %ecx
cltd
idivl %ecx
addl $0x1, %eax
movslq %eax, %rdx
movl $0x10, %esi
callq 0x6db0
cmpl $0x0, %eax
jge 0xacea
jmp 0xaed2
movl 0xac(%rsp), %eax
movl %eax, 0x84(%rsp)
movl $0x40, 0x7c(%rsp)
leaq 0x10(%rsp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x1090
movl 0xac(%rsp), %edx
movl 0xa8(%rsp), %ecx
movl 0xa4(%rsp), %r8d
movl 0xa0(%rsp), %r9d
leaq 0x20(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0xaf20
cmpl $0x0, %eax
je 0xad73
movl 0xac(%rsp), %esi
movl 0xa8(%rsp), %edx
movl 0xa4(%rsp), %ecx
movl 0xa0(%rsp), %r8d
leaq 0x20(%rsp), %rdi
callq 0xb000
movl %eax, 0x8(%rsp)
jmp 0xaed0
cmpl $0x0, 0x10(%rsp)
jne 0xae23
cmpl $0x0, 0x18(%rsp)
jne 0xae23
jmp 0xad8b
movl 0xa8(%rsp), %eax
movl %eax, %ecx
addl $-0x1, %ecx
movl %ecx, 0xa8(%rsp)
cmpl $0x0, %eax
je 0xadce
movq 0xb0(%rsp), %rax
movq 0x68(%rax), %rax
movl 0xac(%rsp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, 0xac(%rsp)
subl $0x1, %ecx
movslq %ecx, %rcx
movb $0x1, (%rax,%rcx)
jmp 0xad8b
jmp 0xadd0
movl 0xa0(%rsp), %eax
movl %eax, %ecx
addl $-0x1, %ecx
movl %ecx, 0xa0(%rsp)
cmpl $0x0, %eax
je 0xae16
movq 0xb0(%rsp), %rax
movq 0xf0(%rax), %rax
movl 0xa4(%rsp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, 0xa4(%rsp)
subl $0x1, %ecx
movslq %ecx, %rcx
movb $0x1, (%rax,%rcx)
jmp 0xadd0
movl $0x0, 0x8(%rsp)
jmp 0xaece
movq 0xb8(%rsp), %rdi
movq 0xb0(%rsp), %rsi
movl 0xac(%rsp), %edx
movl 0x10(%rsp), %ecx
subl 0xac(%rsp), %ecx
movl 0xa4(%rsp), %r8d
movl 0x18(%rsp), %r9d
subl 0xa4(%rsp), %r9d
callq 0xaa40
movl %eax, 0x8(%rsp)
cmpl $0x0, 0x8(%rsp)
je 0xae6c
jmp 0xaed2
movq 0xb8(%rsp), %rdi
movq 0xb0(%rsp), %rsi
movl 0x14(%rsp), %edx
addl $0x1, %edx
movl 0xac(%rsp), %ecx
addl 0xa8(%rsp), %ecx
subl $0x1, %ecx
subl 0x14(%rsp), %ecx
movl 0x1c(%rsp), %r8d
addl $0x1, %r8d
movl 0xa4(%rsp), %r9d
addl 0xa0(%rsp), %r9d
subl $0x1, %r9d
subl 0x1c(%rsp), %r9d
callq 0xaa40
movl %eax, 0x8(%rsp)
cmpl $0x0, 0x8(%rsp)
je 0xaecc
jmp 0xaed2
jmp 0xaece
jmp 0xaed0
jmp 0xaed2
movq 0x20(%rsp), %rdi
callq 0x1030
movq 0x28(%rsp), %rdi
callq 0x1030
movq 0x68(%rsp), %rdi
callq 0x1030
leaq 0x20(%rsp), %rdi
addq $0x10, %rdi
callq 0x6e30
movl 0x8(%rsp), %eax
movl %eax, 0xc4(%rsp)
movl 0xc4(%rsp), %eax
addq $0xc8, %rsp
retq
nopl (%rax,%rax)