// File: /workspace/github_c_makefile_star2_O1/LemonBoy[P]autobahn/xdiff/xdiffi.c
// Function: xdl_change_compact
int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) {
	struct xdlgroup g, go;
	long earliest_end, end_matching_other;
	long groupsize;

	group_init(xdf, &g);
	group_init(xdfo, &go);

	while (1) {
		/* If the group is empty in the to-be-compacted file, skip it: */
		if (g.end == g.start)
			goto next;

		/*
		 * Now shift the change up and then down as far as possible in
		 * each direction. If it bumps into any other changes, merge them.
		 */
		do {
			groupsize = g.end - g.start;

			/*
			 * Keep track of the last "end" index that causes this
			 * group to align with a group of changed lines in the
			 * other file. -1 indicates that we haven't found such
			 * a match yet:
			 */
			end_matching_other = -1;

			/* Shift the group backward as much as possible: */
			while (!group_slide_up(xdf, &g, flags))
				if (group_previous(xdfo, &go))
					xdl_bug("group sync broken sliding up");

			/*
			 * This is this highest that this group can be shifted.
			 * Record its end index:
			 */
			earliest_end = g.end;

			if (go.end > go.start)
				end_matching_other = g.end;

			/* Now shift the group forward as far as possible: */
			while (1) {
				if (group_slide_down(xdf, &g, flags))
					break;
				if (group_next(xdfo, &go))
					xdl_bug("group sync broken sliding down");

				if (go.end > go.start)
					end_matching_other = g.end;
			}
		} while (groupsize != g.end - g.start);

		/*
		 * If the group can be shifted, then we can possibly use this
		 * freedom to produce a more intuitive diff.
		 *
		 * The group is currently shifted as far down as possible, so the
		 * heuristics below only have to handle upwards shifts.
		 */

		if (g.end == earliest_end) {
			/* no shifting was possible */
		} else if (end_matching_other != -1) {
			/*
			 * Move the possibly merged group of changes back to line
			 * up with the last group of changes from the other file
			 * that it can align with.
			 */
			while (go.end == go.start) {
				if (group_slide_up(xdf, &g, flags))
					xdl_bug("match disappeared");
				if (group_previous(xdfo, &go))
					xdl_bug("group sync broken sliding to match");
			}
		} else if (flags & XDF_INDENT_HEURISTIC) {
			/*
			 * Indent heuristic: a group of pure add/delete lines
			 * implies two splits, one between the end of the "before"
			 * context and the start of the group, and another between
			 * the end of the group and the beginning of the "after"
			 * context. Some splits are aesthetically better and some
			 * are worse. We compute a badness "score" for each split,
			 * and add the scores for the two splits to define a
			 * "score" for each position that the group can be shifted
			 * to. Then we pick the shift with the lowest score.
			 */
			long shift, best_shift = -1;
			struct split_score best_score;

			for (shift = earliest_end; shift <= g.end; shift++) {
				struct split_measurement m;
				struct split_score score = {0, 0};

				measure_split(xdf, shift, &m);
				score_add_split(&m, &score);
				measure_split(xdf, shift - groupsize, &m);
				score_add_split(&m, &score);
				if (best_shift == -1 ||
				    score_cmp(&score, &best_score) <= 0) {
					best_score.effective_indent = score.effective_indent;
					best_score.penalty = score.penalty;
					best_shift = shift;
				}
			}

			while (g.end > best_shift) {
				if (group_slide_up(xdf, &g, flags))
					xdl_bug("best shift unreached");
				if (group_previous(xdfo, &go))
					xdl_bug("group sync broken sliding to blank line");
			}
		}

	next:
		/* Move past the just-processed group: */
		if (group_next(xdf, &g))
			break;
		if (group_next(xdfo, &go))
			xdl_bug("group sync broken moving to next group");
	}

	if (!group_next(xdfo, &go))
		xdl_bug("group sync broken at end of file");

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rdx, %rbx
movq %rsi, %r15
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq 0x68(%rdi), %rax
cmpb $0x0, (%rax)
je 0x1ef7
xorl %ecx, %ecx
cmpb $0x0, 0x1(%rax,%rcx)
leaq 0x1(%rcx), %rcx
jne 0x1ee7
movq %rcx, 0x8(%rsp)
movq %rdi, 0x10(%rsp)
movq 0x68(%r15), %rax
cmpb $0x0, (%rax)
je 0x1f17
xorl %ecx, %ecx
leaq 0x1(%rcx), %rbp
cmpb $0x0, 0x1(%rax,%rcx)
movq %rbp, %rcx
jne 0x1f07
jmp 0x1f19
xorl %ebp, %ebp
xorl %r13d, %r13d
movq %r15, 0x38(%rsp)
movq %rbx, 0x28(%rsp)
movq 0x8(%rsp), %rax
cmpq (%rsp), %rax
je 0x20b3
movq (%rsp), %rax
movq 0x8(%rsp), %rcx
movq %rcx, 0x50(%rsp)
movq %rax, 0x48(%rsp)
subq %rax, %rcx
movq %rcx, 0x58(%rsp)
movq %rbp, %rbx
movq 0x28(%rsp), %r14
movq 0x10(%rsp), %r12
movq %rsp, %rbp
movq %r12, %rdi
movq %rbp, %rsi
movq %r14, %rdx
callq 0x2321
testl %eax, %eax
jne 0x1f9d
movq %r13, %rax
testq %r13, %r13
je 0x1f90
leaq -0x1(%r13), %rbx
movq 0x68(%r15), %rcx
movq %r13, %rax
cmpb $0x0, -0x2(%rcx,%rax)
leaq -0x1(%rax), %rax
jne 0x1f85
testq %r13, %r13
movq %rax, %r13
jne 0x1f60
jmp 0x22d1
movq (%rsp), %r15
movq 0x8(%rsp), %rax
cmpq %r13, %rbx
movq $-0x1, %rcx
cmovgq %rax, %rcx
cmpq 0x38(%r12), %rax
movq %rax, 0x30(%rsp)
movq %rax, %r12
jge 0x207d
movq 0x10(%rsp), %r14
movq %rcx, 0x18(%rsp)
movq 0x60(%r14), %rax
movq (%rax,%r15,8), %rdi
movq (%rax,%r12,8), %rsi
movq 0x28(%rsp), %rdx
callq 0x28a5
testl %eax, %eax
je 0x2082
movq 0x68(%r14), %rax
movb $0x0, (%rax,%r15)
movq 0x68(%r14), %rcx
leaq 0x1(%r12), %rax
movb $0x1, (%rcx,%r12)
movq 0x68(%r14), %rcx
cmpb $0x0, 0x1(%rcx,%r12)
je 0x2022
leaq 0x1(%rax), %r12
cmpb $0x0, 0x1(%rcx,%rax)
movq %r12, %rax
jne 0x2012
jmp 0x2025
movq %rax, %r12
movq 0x38(%rsp), %rax
movq 0x38(%rax), %rax
movq %rbx, %rbp
cmpq %rax, %rbx
je 0x2051
leaq 0x1(%rbx), %r13
movq 0x38(%rsp), %rcx
movq 0x68(%rcx), %rcx
movq %rbx, %rbp
cmpb $0x0, 0x1(%rcx,%rbp)
leaq 0x1(%rbp), %rbp
jne 0x2046
incq %r15
cmpq %rax, %rbx
je 0x22d6
cmpq %r13, %rbp
movq 0x18(%rsp), %rcx
cmovgq %r12, %rcx
movq %rbp, %rbx
movq 0x10(%rsp), %r14
cmpq 0x38(%r14), %r12
jl 0x1fcc
jmp 0x208a
movq %rbx, %rbp
jmp 0x208a
movq %rbx, %rbp
movq 0x18(%rsp), %rcx
movq %r12, 0x8(%rsp)
movq %r15, (%rsp)
movq %r12, %rax
subq %r15, %rax
cmpq %rax, 0x58(%rsp)
movq 0x38(%rsp), %r15
jne 0x1f35
movq 0x30(%rsp), %r14
cmpq %r14, %r12
jne 0x212a
movq 0x8(%rsp), %rax
movq 0x10(%rsp), %rcx
movq 0x38(%rcx), %rcx
cmpq %rcx, %rax
je 0x22ba
leaq 0x1(%rax), %rdx
movq %rdx, (%rsp)
movq 0x10(%rsp), %rdx
movq 0x68(%rdx), %rdx
movq %rax, %rsi
cmpb $0x0, 0x1(%rdx,%rsi)
leaq 0x1(%rsi), %rsi
jne 0x20de
movq %rsi, 0x8(%rsp)
cmpq %rcx, %rax
je 0x22ba
movq 0x38(%r15), %rax
movq %rbp, %rcx
cmpq %rax, %rbp
je 0x2119
leaq 0x1(%rbp), %r13
movq 0x68(%r15), %rdx
movq %rbp, %rcx
cmpb $0x0, 0x1(%rdx,%rcx)
leaq 0x1(%rcx), %rcx
jne 0x210e
cmpq %rax, %rbp
movq %rcx, %rbp
jne 0x1f26
jmp 0x2317
cmpq $-0x1, %rcx
je 0x2181
movq 0x28(%rsp), %rbx
cmpq %r13, %rbp
jne 0x20b3
movq 0x10(%rsp), %rdi
movq %rsp, %rsi
movq %rbx, %rdx
callq 0x2321
testl %eax, %eax
jne 0x230d
movq %r13, %rax
testq %r13, %r13
je 0x2174
leaq -0x1(%r13), %rbp
movq 0x68(%r15), %rcx
movq %r13, %rax
cmpb $0x0, -0x2(%rcx,%rax)
leaq -0x1(%rax), %rax
jne 0x2169
testq %r13, %r13
movq %rax, %r13
jne 0x2135
jmp 0x2308
movq 0x28(%rsp), %rbx
btl $0x8, %ebx
jae 0x20b3
movq $-0x1, 0x18(%rsp)
cmpq %r12, %r14
jg 0x2262
incq %r12
movq 0x50(%rsp), %rax
subq %rax, 0x48(%rsp)
movq $-0x1, 0x18(%rsp)
movq %r14, 0x30(%rsp)
movq $0x0, 0x20(%rsp)
movq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
leaq 0x60(%rsp), %r14
movq %r14, %rdx
callq 0x23a3
movq %r14, %rdi
leaq 0x20(%rsp), %rsi
callq 0x246d
movq 0x48(%rsp), %rax
movq 0x30(%rsp), %rcx
leaq (%rax,%rcx), %rsi
movq %rbx, %rdi
movq %r14, %rdx
callq 0x23a3
movq %r14, %rdi
movq 0x30(%rsp), %r14
leaq 0x20(%rsp), %rsi
callq 0x246d
cmpq $-0x1, 0x18(%rsp)
je 0x2241
movl 0x24(%rsp), %eax
xorl %ecx, %ecx
xorl %edx, %edx
movl 0x40(%rsp), %esi
cmpl %esi, 0x20(%rsp)
setg %cl
setl %dl
subl %edx, %ecx
imull $0x3c, %ecx, %ecx
subl 0x44(%rsp), %eax
addl %ecx, %eax
jg 0x2256
movl 0x20(%rsp), %eax
movl %eax, 0x40(%rsp)
movl 0x24(%rsp), %eax
movl %eax, 0x44(%rsp)
movq %r14, 0x18(%rsp)
incq %r14
cmpq %r14, %r12
jne 0x21b8
movq 0x28(%rsp), %rbx
movq 0x18(%rsp), %r14
cmpq %r14, 0x8(%rsp)
jle 0x20b3
movq 0x10(%rsp), %rdi
movq %rsp, %rsi
movq %rbx, %rdx
callq 0x2321
testl %eax, %eax
jne 0x2312
movq %r13, %rax
testq %r13, %r13
je 0x22ad
leaq -0x1(%r13), %rbp
movq 0x68(%r15), %rcx
movq %r13, %rax
cmpb $0x0, -0x2(%rcx,%rax)
leaq -0x1(%rax), %rax
jne 0x22a2
testq %r13, %r13
movq %rax, %r13
jne 0x226c
callq 0x11d8
cmpq 0x38(%r15), %rbp
jne 0x231c
xorl %eax, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x1200
movq %r12, 0x8(%rsp)
movq %r15, (%rsp)
movq 0x7d12(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x4e0a(%rip), %rsi      # 0x70fa
leaq 0x4d2a(%rip), %rdx      # 0x7021
xorl %eax, %eax
callq 0x10b0
movl $0x1, %edi
callq 0x1130
callq 0x1188
callq 0x1160
callq 0x11b0
callq 0x1228
callq 0x1250