// File: /workspace/github_c_makefile_star2_O2/LemonBoy[P]autobahn/xdiff/xemit.c
// Function: xdl_emit_diff
int xdl_emit_diff(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb,
		  xdemitconf_t const *xecfg) {
	long s1, s2, e1, e2, lctx;
	xdchange_t *xch, *xche;
	long funclineprev = -1;
	struct func_line func_line = { 0 };

	for (xch = xscr; xch; xch = xche->next) {
		xche = xdl_get_hunk(&xch, xecfg);
		if (!xch)
			break;

		s1 = XDL_MAX(xch->i1 - xecfg->ctxlen, 0);
		s2 = XDL_MAX(xch->i2 - xecfg->ctxlen, 0);

		if (xecfg->flags & XDL_EMIT_FUNCCONTEXT) {
			long fs1, i1 = xch->i1;

			/* Appended chunk? */
			if (i1 >= xe->xdf1.nrec) {
				char dummy[1];
				long i2 = xch->i2;

				/*
				 * We don't need additional context if
				 * a whole function was added, possibly
				 * starting with empty lines.
				 */
				while (i2 < xe->xdf2.nrec &&
				       is_empty_rec(&xe->xdf2, i2))
					i2++;
				if (i2 < xe->xdf2.nrec &&
				    match_func_rec(&xe->xdf2, xecfg, i2,
						   dummy, sizeof(dummy)) >= 0)
					goto post_context_calculation;

				/*
				 * Otherwise get more context from the
				 * pre-image.
				 */
				i1 = xe->xdf1.nrec - 1;
			}

			fs1 = get_func_line(xe, xecfg, NULL, i1, -1);
			if (fs1 < 0)
				fs1 = 0;
			if (fs1 < s1) {
				s2 -= s1 - fs1;
				s1 = fs1;
			}
		}

 post_context_calculation:
		lctx = xecfg->ctxlen;
		lctx = XDL_MIN(lctx, xe->xdf1.nrec - (xche->i1 + xche->chg1));
		lctx = XDL_MIN(lctx, xe->xdf2.nrec - (xche->i2 + xche->chg2));

		e1 = xche->i1 + xche->chg1 + lctx;
		e2 = xche->i2 + xche->chg2 + lctx;

		if (xecfg->flags & XDL_EMIT_FUNCCONTEXT) {
			long fe1 = get_func_line(xe, xecfg, NULL,
						 xche->i1 + xche->chg1,
						 xe->xdf1.nrec);
			while (fe1 > 0 && is_empty_rec(&xe->xdf1, fe1 - 1))
				fe1--;
			if (fe1 < 0)
				fe1 = xe->xdf1.nrec;
			if (fe1 > e1) {
				e2 += fe1 - e1;
				e1 = fe1;
			}

			/*
			 * Overlap with next change?  Then include it
			 * in the current hunk and start over to find
			 * its new end.
			 */
			if (xche->next) {
				long l = XDL_MIN(xche->next->i1,
						 xe->xdf1.nrec - 1);
				if (l - xecfg->ctxlen <= e1 ||
				    get_func_line(xe, xecfg, NULL, l, e1) < 0) {
					xche = xche->next;
					goto post_context_calculation;
				}
			}
		}

		/*
		 * Emit current hunk header.
		 */

		if (xecfg->flags & XDL_EMIT_FUNCNAMES) {
			get_func_line(xe, xecfg, &func_line,
				      s1 - 1, funclineprev);
			funclineprev = s1 - 1;
		}
		if (xdl_emit_hunk_hdr(s1 + 1, e1 - s1, s2 + 1, e2 - s2,
				      func_line.buf, func_line.len, ecb) < 0)
			return -1;

		/*
		 * Emit pre-context.
		 */
		for (; s2 < xch->i2; s2++)
			if (xdl_emit_record(&xe->xdf2, s2, " ", ecb) < 0)
				return -1;

		for (s1 = xch->i1, s2 = xch->i2;; xch = xch->next) {
			/*
			 * Merge previous with current change atom.
			 */
			for (; s1 < xch->i1 && s2 < xch->i2; s1++, s2++)
				if (xdl_emit_record(&xe->xdf2, s2, " ", ecb) < 0)
					return -1;

			/*
			 * Removes lines from the first file.
			 */
			for (s1 = xch->i1; s1 < xch->i1 + xch->chg1; s1++)
				if (xdl_emit_record(&xe->xdf1, s1, "-", ecb) < 0)
					return -1;

			/*
			 * Adds lines from the second file.
			 */
			for (s2 = xch->i2; s2 < xch->i2 + xch->chg2; s2++)
				if (xdl_emit_record(&xe->xdf2, s2, "+", ecb) < 0)
					return -1;

			if (xch == xche)
				break;
			s1 = xch->i1 + xch->chg1;
			s2 = xch->i2 + xch->chg2;
		}

		/*
		 * Emit post-context.
		 */
		for (s2 = xche->i2 + xche->chg2; s2 < e2; s2++)
			if (xdl_emit_record(&xe->xdf2, s2, " ", ecb) < 0)
				return -1;
	}

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %rdx, 0x28(%rsp)
movq %rdi, %r15
xorps %xmm0, %xmm0
leaq 0x78(%rsp), %r8
movaps %xmm0, 0x38(%r8)
movaps %xmm0, 0x28(%r8)
movaps %xmm0, 0x18(%r8)
movaps %xmm0, 0x8(%r8)
movaps %xmm0, -0x8(%r8)
andq $0x0, 0x48(%r8)
leaq 0x88(%rdi), %r14
pushq $-0x1
popq %rbx
leaq 0x48(%rsp), %rdi
xorl %r13d, %r13d
movq %rcx, 0x10(%rsp)
movq %rsi, 0x48(%rsp)
testq %rsi, %rsi
je 0x2f92
movq %r14, 0x30(%rsp)
movq %rcx, %rsi
movq %rcx, %r14
callq 0x2a7c
movq 0x48(%rsp), %rdx
testq %rdx, %rdx
je 0x2f92
movq %rax, %rbp
movq %rbx, 0x58(%rsp)
movq %r15, 0x18(%rsp)
movq 0x8(%rdx), %rcx
movq (%r14), %rax
movq %rcx, %rbx
subq %rax, %rbx
testq %rbx, %rbx
movl $0x0, %esi
cmovgq %rbx, %rsi
movq %rsi, 0x40(%rsp)
movq %rdx, 0x68(%rsp)
movq 0x10(%rdx), %r15
movq %r15, %r12
subq %rax, %r12
testq %r12, %r12
cmovleq %r13, %r12
testb $0x4, 0x10(%r14)
movq %r14, %rsi
je 0x2ca3
movq 0x18(%rsp), %rdi
movq 0x38(%rdi), %r14
cmpq %r14, %rcx
jl 0x2c6e
movq %r12, 0x38(%rsp)
movq 0xc0(%rdi), %r12
cmpq %r12, %r15
jge 0x2c59
movq 0x30(%rsp), %rdi
movq %r15, %rsi
callq 0x2fa7
testl %eax, %eax
je 0x2c2c
incq %r15
jmp 0x2c11
movq 0x30(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq %r15, %rdx
leaq 0x27(%rsp), %rcx
pushq $0x1
popq %r8
callq 0x3004
testq %rax, %rax
jns 0x2d7d
movq 0x18(%rsp), %rax
movq 0x38(%rax), %r14
decq %r14
movq %r14, %rcx
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdi
movq 0x38(%rsp), %r12
xorl %edx, %edx
pushq $-0x1
popq %r8
callq 0x30b6
movq 0x10(%rsp), %rsi
testq %rax, %rax
cmovleq %r13, %rax
movq %rax, %rcx
movq 0x40(%rsp), %rdx
subq %rdx, %rcx
cmpq %rax, %rbx
cmovgq %rax, %rdx
movq %rdx, 0x40(%rsp)
cmovleq %r13, %rcx
addq %rcx, %r12
movq %r12, 0x38(%rsp)
movq 0x18(%rsp), %rdi
movq (%rsi), %rax
movq 0x38(%rdi), %r8
movq 0xc0(%rdi), %r14
movq 0x18(%rbp), %rcx
addq 0x8(%rbp), %rcx
movq 0x20(%rbp), %rbx
movq %r8, %rdx
subq %rcx, %rdx
cmpq %rdx, %rax
cmovlq %rax, %rdx
addq 0x10(%rbp), %rbx
subq %rbx, %r14
cmpq %r14, %rdx
cmovlq %rdx, %r14
leaq (%r14,%rcx), %r12
testb $0x4, 0x10(%rsi)
je 0x2d87
movq %rdi, %r15
xorl %edx, %edx
callq 0x30b6
movq %rax, %r13
testq %r13, %r13
jle 0x2d19
decq %r13
movq %r15, %rdi
movq %r13, %rsi
callq 0x2fa7
testl %eax, %eax
jne 0x2cfd
incq %r13
jmp 0x2d24
js 0x2d20
xorl %r13d, %r13d
jmp 0x2d24
movq 0x38(%r15), %r13
movq 0x10(%rsp), %rsi
cmpq %r12, %r13
movq %r12, 0x60(%rsp)
movq %r12, %r15
cmovgq %r13, %r15
movq %rbp, %r12
movq (%rbp), %rbp
testq %rbp, %rbp
je 0x2d92
movq 0x8(%rbp), %rax
movq 0x18(%rsp), %rdi
movq 0x38(%rdi), %rcx
decq %rcx
cmpq %rcx, %rax
cmovlq %rax, %rcx
movq %rcx, %rax
subq (%rsi), %rax
cmpq %r15, %rax
jle 0x2cad
xorl %edx, %edx
movq %r15, %r8
callq 0x30b6
testq %rax, %rax
jns 0x2da8
movq (%r12), %rbp
movq 0x10(%rsp), %rsi
jmp 0x2ca8
addq %rbx, %r14
movq %r12, %r15
movq %r14, %r13
jmp 0x2dc4
addq %rbx, %r14
subq 0x60(%rsp), %r13
movl $0x0, %eax
cmovleq %rax, %r13
addq %r14, %r13
jmp 0x2dc1
addq %rbx, %r14
subq 0x60(%rsp), %r13
movl $0x0, %eax
cmovleq %rax, %r13
addq %r14, %r13
movq 0x10(%rsp), %rsi
movq %r12, %rbp
movq %rbp, 0x50(%rsp)
testb $0x1, 0x10(%rsi)
movq 0x30(%rsp), %rbx
leaq 0x432a(%rip), %r14      # 0x7103
movq 0x38(%rsp), %r12
movq 0x40(%rsp), %rdi
je 0x2e0a
leaq -0x1(%rdi), %rbp
movq 0x18(%rsp), %rdi
leaq 0x70(%rsp), %rdx
movq %rbp, %rcx
movq 0x58(%rsp), %r8
callq 0x30b6
movq 0x40(%rsp), %rdi
movq %rbp, 0x58(%rsp)
leaq 0x78(%rsp), %r8
pushq $-0x1
popq %rbp
subq %rdi, %r15
incq %rdi
leaq 0x1(%r12), %rdx
movq %r13, %rcx
subq %r12, %rcx
movq 0x70(%rsp), %r9
movq 0x28(%rsp), %rax
movq %rax, (%rsp)
movq %r15, %rsi
callq 0x4165
testl %eax, %eax
js 0x2f8f
movq 0x68(%rsp), %rcx
movq 0x10(%rcx), %r15
cmpq %r15, %r12
jge 0x2e67
movq %rbx, %rdi
movq %r12, %rsi
movq %r14, %rdx
movq 0x28(%rsp), %rcx
callq 0x315b
incq %r12
jmp 0x2e39
movq 0x8(%rcx), %r14
movq %rcx, %r12
movq 0x8(%rcx), %rbx
cmpq %rbx, %r14
jge 0x2ea9
cmpq 0x10(%rcx), %r15
jge 0x2ea9
movq 0x30(%rsp), %rdi
movq %r15, %rsi
leaq 0x4277(%rip), %rdx      # 0x7103
movq 0x28(%rsp), %rcx
callq 0x315b
testl %eax, %eax
js 0x2f8f
incq %r14
incq %r15
movq %r12, %rcx
jmp 0x2e6e
movq 0x18(%rsp), %r14
leaq 0x4250(%rip), %r15      # 0x7105
movq 0x18(%rcx), %rax
addq 0x8(%rcx), %rax
cmpq %rax, %rbx
jge 0x2ee4
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
movq 0x28(%rsp), %rcx
callq 0x315b
movq %r12, %rcx
incq %rbx
testl %eax, %eax
jns 0x2eb5
jmp 0x2f8f
movq 0x10(%rcx), %rbx
movq 0x30(%rsp), %r14
movq 0x20(%rcx), %r15
addq 0x10(%rcx), %r15
cmpq %r15, %rbx
jge 0x2f1d
movq %r14, %rdi
movq %rbx, %rsi
leaq 0x4200(%rip), %rdx      # 0x7107
movq 0x28(%rsp), %rcx
callq 0x315b
movq %r12, %rcx
incq %rbx
testl %eax, %eax
jns 0x2eed
jmp 0x2f8f
cmpq 0x50(%rsp), %rcx
je 0x2f34
movq 0x18(%rcx), %r14
addq 0x8(%rcx), %r14
movq (%rcx), %rcx
jmp 0x2e6b
movq %rcx, 0x48(%rsp)
movq 0x50(%rsp), %rax
movq 0x20(%rax), %rbx
addq 0x10(%rax), %rbx
movq 0x18(%rsp), %r15
cmpq %r13, %rbx
jge 0x2f70
movq %r14, %rdi
movq %rbx, %rsi
leaq 0x41a6(%rip), %rdx      # 0x7103
movq 0x28(%rsp), %rcx
callq 0x315b
incq %rbx
testl %eax, %eax
jns 0x2f4b
jmp 0x2f8f
movq 0x50(%rsp), %rax
movq (%rax), %rsi
xorl %r13d, %r13d
movq 0x10(%rsp), %rcx
leaq 0x48(%rsp), %rdi
movq 0x58(%rsp), %rbx
jmp 0x2b7c
movl %ebp, %r13d
movl %r13d, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq