// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x88, %rsp
movq %rdi, 0x80(%rsp)
movq %rsi, 0x78(%rsp)
movq %rdx, 0x70(%rsp)
movq 0x80(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x29f0
movq 0x78(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x29f0
movq 0x68(%rsp), %rax
cmpq 0x60(%rsp), %rax
jne 0x26db
jmp 0x2980
jmp 0x26dd
movq 0x68(%rsp), %rax
subq 0x60(%rsp), %rax
movq %rax, 0x38(%rsp)
movq $-0x1, 0x40(%rsp)
movq 0x80(%rsp), %rdi
movq 0x70(%rsp), %rdx
leaq 0x60(%rsp), %rsi
callq 0x2a40
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x271a
jmp 0x273c
movq 0x78(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x2b30
cmpl $0x0, %eax
je 0x273a
leaq 0x98cf(%rip), %rdi      # 0xc004
callq 0x2bb0
jmp 0x26f5
movq 0x68(%rsp), %rax
movq %rax, 0x48(%rsp)
movq 0x58(%rsp), %rax
cmpq 0x50(%rsp), %rax
jle 0x275c
movq 0x68(%rsp), %rax
movq %rax, 0x40(%rsp)
jmp 0x275e
movq 0x80(%rsp), %rdi
movq 0x70(%rsp), %rdx
leaq 0x60(%rsp), %rsi
callq 0x2be0
cmpl $0x0, %eax
je 0x277c
jmp 0x27b4
movq 0x78(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x2cd0
cmpl $0x0, %eax
je 0x279c
leaq 0x988a(%rip), %rdi      # 0xc021
callq 0x2bb0
movq 0x58(%rsp), %rax
cmpq 0x50(%rsp), %rax
jle 0x27b2
movq 0x68(%rsp), %rax
movq %rax, 0x40(%rsp)
jmp 0x275e
jmp 0x27b6
movq 0x38(%rsp), %rax
movq 0x68(%rsp), %rcx
subq 0x60(%rsp), %rcx
cmpq %rcx, %rax
jne 0x26dd
movq 0x68(%rsp), %rax
cmpq 0x48(%rsp), %rax
jne 0x27df
jmp 0x297e
cmpq $-0x1, 0x40(%rsp)
je 0x2844
jmp 0x27e9
movq 0x58(%rsp), %rax
cmpq 0x50(%rsp), %rax
jne 0x283f
movq 0x80(%rsp), %rdi
movq 0x70(%rsp), %rdx
leaq 0x60(%rsp), %rsi
callq 0x2a40
cmpl $0x0, %eax
je 0x281d
leaq 0x9828(%rip), %rdi      # 0xc040
callq 0x2bb0
movq 0x78(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x2b30
cmpl $0x0, %eax
je 0x283d
leaq 0x981a(%rip), %rdi      # 0xc052
callq 0x2bb0
jmp 0x27e9
jmp 0x297c
movq 0x70(%rsp), %rax
andq $0x100, %rax            # imm = 0x100
cmpq $0x0, %rax
je 0x297a
movq $-0x1, 0x28(%rsp)
movq 0x48(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x30(%rsp), %rax
cmpq 0x68(%rsp), %rax
jg 0x2920
movq %rsp, %rdi
xorl %esi, %esi
movl $0x8, %edx
callq 0x1090
movq 0x80(%rsp), %rdi
movq 0x30(%rsp), %rsi
leaq 0x8(%rsp), %rdx
callq 0x2d60
leaq 0x8(%rsp), %rdi
movq %rsp, %rsi
callq 0x2f00
movq 0x80(%rsp), %rdi
movq 0x30(%rsp), %rsi
subq 0x38(%rsp), %rsi
leaq 0x8(%rsp), %rdx
callq 0x2d60
leaq 0x8(%rsp), %rdi
movq %rsp, %rsi
callq 0x2f00
cmpq $-0x1, 0x28(%rsp)
je 0x28f2
movq %rsp, %rdi
leaq 0x20(%rsp), %rsi
callq 0x30b0
cmpl $0x0, %eax
jg 0x290b
movl (%rsp), %eax
movl %eax, 0x20(%rsp)
movl 0x4(%rsp), %eax
movl %eax, 0x24(%rsp)
movq 0x30(%rsp), %rax
movq %rax, 0x28(%rsp)
jmp 0x290d
movq 0x30(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x30(%rsp)
jmp 0x286c
jmp 0x2922
movq 0x68(%rsp), %rax
cmpq 0x28(%rsp), %rax
jle 0x2978
movq 0x80(%rsp), %rdi
movq 0x70(%rsp), %rdx
leaq 0x60(%rsp), %rsi
callq 0x2a40
cmpl $0x0, %eax
je 0x2956
leaq 0x9724(%rip), %rdi      # 0xc075
callq 0x2bb0
movq 0x78(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x2b30
cmpl $0x0, %eax
je 0x2976
leaq 0x9719(%rip), %rdi      # 0xc08a
callq 0x2bb0
jmp 0x2922
jmp 0x297a
jmp 0x297c
jmp 0x297e
jmp 0x2980
movq 0x80(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x2cd0
cmpl $0x0, %eax
je 0x2999
jmp 0x29be
movq 0x78(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x2cd0
cmpl $0x0, %eax
je 0x29b9
leaq 0x96fe(%rip), %rdi      # 0xc0b2
callq 0x2bb0
jmp 0x26ca
movq 0x78(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x2cd0
cmpl $0x0, %eax
jne 0x29de
leaq 0x9700(%rip), %rdi      # 0xc0d9
callq 0x2bb0
xorl %eax, %eax
addq $0x88, %rsp
retq
nopl (%rax,%rax)