// File: /workspace/github_c_makefile_star2_O3/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, 0x28(%rsp)
movq %rsi, 0x8(%rsp)
movq %rdi, %r15
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq 0x68(%rdi), %rax
cmpb $0x0, (%rax)
je 0x1ee7
xorl %ebp, %ebp
cmpb $0x0, 0x1(%rax,%rbp)
leaq 0x1(%rbp), %rbp
jne 0x1ed5
movq %rbp, 0x18(%rsp)
jmp 0x1ee9
xorl %ebp, %ebp
movq 0x8(%rsp), %rax
movq 0x68(%rax), %rax
cmpb $0x0, (%rax)
je 0x1f09
xorl %ecx, %ecx
leaq 0x1(%rcx), %r12
cmpb $0x0, 0x1(%rax,%rcx)
movq %r12, %rcx
jne 0x1ef9
jmp 0x1f0c
xorl %r12d, %r12d
xorl %r14d, %r14d
xorl %r13d, %r13d
cmpq %r14, %rbp
jne 0x1f1f
movq %r14, %rbp
jmp 0x2224
movq %rbp, 0x30(%rsp)
movq %r14, 0x38(%rsp)
movq %r15, %rdi
leaq 0x10(%rsp), %r14
movq %r14, %rsi
movq 0x28(%rsp), %rbp
movq %rbp, %rdx
callq 0x22b9
testl %eax, %eax
jne 0x1f79
movq 0x8(%rsp), %rbx
testq %r13, %r13
je 0x2291
leaq -0x1(%r13), %r12
movq 0x68(%rbx), %rax
cmpb $0x0, -0x2(%rax,%r13)
leaq -0x1(%r13), %r13
jne 0x1f5b
movq %r15, %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x22b9
testl %eax, %eax
je 0x1f4a
movq 0x10(%rsp), %r14
movq 0x18(%rsp), %rcx
cmpq %r13, %r12
movq $-0x1, %rbx
cmovgq %rcx, %rbx
cmpq 0x38(%r15), %rcx
movq %rcx, 0x50(%rsp)
jge 0x205d
movq 0x60(%r15), %rax
movq (%rax,%r14,8), %rdi
movq (%rax,%rcx,8), %rsi
movq %rbp, %rdx
callq 0x2841
movq 0x50(%rsp), %rbp
testl %eax, %eax
movq 0x38(%rsp), %rdx
movq 0x30(%rsp), %rdi
je 0x206a
movq 0x68(%r15), %rax
movb $0x0, (%rax,%r14)
movq 0x68(%r15), %rcx
leaq 0x1(%rbp), %rax
movb $0x1, (%rcx,%rbp)
movq 0x68(%r15), %rcx
cmpb $0x0, 0x1(%rcx,%rbp)
je 0x1ffb
leaq 0x1(%rax), %rbp
cmpb $0x0, 0x1(%rcx,%rax)
movq %rbp, %rax
jne 0x1feb
jmp 0x1ffe
movq %rax, %rbp
movq 0x8(%rsp), %rax
cmpq 0x38(%rax), %r12
je 0x2296
incq %r14
leaq 0x1(%r12), %r13
movq 0x68(%rax), %rax
cmpb $0x0, 0x1(%rax,%r12)
leaq 0x1(%r12), %r12
jne 0x2019
cmpq %r13, %r12
cmovgq %rbp, %rbx
cmpq 0x38(%r15), %rbp
jge 0x206a
movq 0x60(%r15), %rax
movq (%rax,%r14,8), %rdi
movq (%rax,%rbp,8), %rsi
movq 0x28(%rsp), %rdx
callq 0x2841
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %rdx
testl %eax, %eax
jne 0x1fcb
jmp 0x206a
movq %rcx, %rbp
movq 0x38(%rsp), %rdx
movq 0x30(%rsp), %rdi
movq %rdi, %rax
subq %rdx, %rax
movq %rbp, 0x18(%rsp)
movq %r14, 0x10(%rsp)
movq %rbp, %rcx
subq %r14, %rcx
cmpq %rcx, %rax
jne 0x1f1f
movq 0x50(%rsp), %rsi
cmpq %rsi, %rbp
jne 0x209b
movq %rsi, %rbp
jmp 0x2224
cmpq $-0x1, %rbx
je 0x2103
cmpq %r13, %r12
jne 0x2224
leaq -0x2(%r13), %rbx
movq 0x8(%rsp), %r14
movq 0x28(%rsp), %r12
movq %r15, %rdi
leaq 0x10(%rsp), %rsi
movq %r12, %rdx
callq 0x22b9
testl %eax, %eax
jne 0x229b
subq $0x1, %r13
jb 0x22a0
movq 0x68(%r14), %rax
addq %rbx, %rax
movl $0x1, %ecx
cmpb $0x0, -0x1(%rax,%rcx)
leaq -0x1(%rcx), %rcx
jne 0x20e6
decq %rbx
testq %rcx, %rcx
je 0x20b8
movq 0x18(%rsp), %rbp
jmp 0x2227
btl $0x8, 0x28(%rsp)
jae 0x2224
movq $-0x1, %rbx
cmpq %rbp, %rsi
jg 0x21d1
leaq 0x1(%rbp), %rax
movq %rax, 0x58(%rsp)
subq %rdi, %rdx
movq %rdx, 0x38(%rsp)
movq %rbx, 0x30(%rsp)
movq $0x0, 0x40(%rsp)
movq %r15, %rdi
leaq 0x60(%rsp), %rbx
movq %rsi, %r14
movq %rbx, %rdx
callq 0x233b
movq %rbx, %rdi
leaq 0x40(%rsp), %rsi
callq 0x2413
movq 0x38(%rsp), %rax
leaq (%rax,%r14), %rsi
movq %r15, %rdi
leaq 0x60(%rsp), %rbx
movq %rbx, %rdx
callq 0x233b
movq %rbx, %rdi
leaq 0x40(%rsp), %rsi
movq 0x30(%rsp), %rbx
callq 0x2413
movl 0x40(%rsp), %eax
movl 0x44(%rsp), %ecx
cmpq $-0x1, %rbx
je 0x21b5
xorl %edx, %edx
xorl %esi, %esi
cmpl 0x48(%rsp), %eax
setg %dl
setl %sil
subl %esi, %edx
imull $0x3c, %edx, %edx
movl %ecx, %esi
subl 0x4c(%rsp), %esi
addl %edx, %esi
jg 0x21c0
movl %ecx, 0x4c(%rsp)
movl %eax, 0x48(%rsp)
movq %r14, %rbx
incq %r14
cmpq %r14, 0x58(%rsp)
movq %r14, %rsi
jne 0x2130
cmpq %rbx, %rbp
leaq 0x10(%rsp), %r14
jle 0x2224
movq %r15, %rdi
movq %r14, %rsi
movq 0x28(%rsp), %rdx
callq 0x22b9
testl %eax, %eax
jne 0x22aa
testq %r13, %r13
movq 0x8(%rsp), %rcx
je 0x22af
leaq -0x1(%r13), %rax
movq 0x68(%rcx), %rcx
cmpb $0x0, -0x2(%rcx,%r13)
leaq -0x1(%r13), %r13
jne 0x2209
movq 0x18(%rsp), %rbp
cmpq %rbx, %rbp
jg 0x21db
movq %rax, %r13
jmp 0x2227
movq %r12, %r13
cmpq 0x38(%r15), %rbp
je 0x2275
leaq 0x1(%rbp), %r14
movq %r14, 0x10(%rsp)
movq 0x68(%r15), %rax
cmpb $0x0, 0x1(%rax,%rbp)
leaq 0x1(%rbp), %rbp
jne 0x223a
movq %rbp, 0x18(%rsp)
movq 0x8(%rsp), %rcx
cmpq 0x38(%rcx), %r13
je 0x22a5
leaq 0x1(%r13), %rax
movq 0x68(%rcx), %rcx
movq %r13, %r12
cmpb $0x0, 0x1(%rcx,%r12)
leaq 0x1(%r12), %r12
jne 0x2260
movq %rax, %r13
jmp 0x1f12
movq 0x8(%rsp), %rax
cmpq 0x38(%rax), %r13
jne 0x22b4
xorl %eax, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x1238
callq 0x1170
callq 0x1198
callq 0x11c0
callq 0x1260
callq 0x11e8
callq 0x1210
callq 0x1288