// File: /workspace/github_c_makefile_star2_O1/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 $0xb8, %rsp
xorps %xmm0, %xmm0
movaps %xmm0, 0xa0(%rsp)
movaps %xmm0, 0x90(%rsp)
movaps %xmm0, 0x80(%rsp)
movaps %xmm0, 0x70(%rsp)
movaps %xmm0, 0x60(%rsp)
movq $0x0, 0xb0(%rsp)
movq %rsi, 0x10(%rsp)
testq %rsi, %rsi
je 0x35ed
movq %rdx, %rbp
movq %rdi, %r15
leaq 0x88(%rdi), %rax
movq %rax, 0x48(%rsp)
movq $-0x1, %rbx
leaq 0x10(%rsp), %rdi
xorl %r12d, %r12d
movq %rcx, 0x8(%rsp)
movq %rcx, %rsi
movq %rcx, %r14
callq 0x2fe4
movq 0x10(%rsp), %rcx
testq %rcx, %rcx
je 0x35ed
movq %rax, %rdi
movq %rbx, 0x38(%rsp)
movq %rbp, 0x30(%rsp)
movq 0x8(%rcx), %rbp
movq (%r14), %rax
movq %rbp, %rbx
subq %rax, %rbx
testq %rbx, %rbx
movl $0x0, %edx
cmovgq %rbx, %rdx
movq %rdx, 0x28(%rsp)
movq %rcx, 0x50(%rsp)
movq 0x10(%rcx), %r13
movq %r13, %rcx
subq %rax, %rcx
testq %rcx, %rcx
cmovleq %r12, %rcx
movq %rcx, 0x40(%rsp)
testb $0x4, 0x10(%r14)
movq %r14, %rsi
je 0x3292
cmpq 0x38(%r15), %rbp
movq %rdi, 0x18(%rsp)
jge 0x319e
movq 0x28(%rsp), %r12
jmp 0x323a
movq 0xc0(%r15), %r14
cmpq %r14, %r13
setl %r12b
jge 0x3225
movq 0x48(%rsp), %rdi
movq %r13, %rsi
callq 0x360f
testl %eax, %eax
je 0x31ef
leaq -0x1(%r14), %r12
movq 0x8(%rsp), %rsi
cmpq %r13, %r12
je 0x3225
incq %r13
movq 0x48(%rsp), %rdi
movq %r13, %rsi
callq 0x360f
movq 0x8(%rsp), %rsi
testl %eax, %eax
jne 0x31c8
cmpq %r14, %r13
setl %r12b
jmp 0x31f4
movq 0x8(%rsp), %rsi
testb %r12b, %r12b
je 0x3225
movl $0x1, %r8d
movq 0x48(%rsp), %rdi
movq %r13, %rdx
leaq 0x27(%rsp), %rcx
callq 0x365d
movq 0x8(%rsp), %rsi
testq %rax, %rax
js 0x3225
movl $0x7, %r14d
xorl %eax, %eax
jmp 0x3231
movq 0x38(%r15), %rbp
decq %rbp
xorl %r14d, %r14d
movb $0x1, %al
movq 0x28(%rsp), %r12
testb %al, %al
je 0x326e
xorl %r14d, %r14d
movq %r15, %rdi
xorl %edx, %edx
movq %rbp, %rcx
movq $-0x1, %r8
callq 0x3712
testq %rax, %rax
cmovleq %r14, %rax
movq %rax, %rcx
subq %r12, %rcx
cmpq %rax, %rbx
cmovgq %rax, %r12
cmovleq %r14, %rcx
addq %rcx, 0x40(%rsp)
movq 0x18(%rsp), %rdi
movq %r12, 0x28(%rsp)
cmpl $0x7, %r14d
je 0x328d
testl %r14d, %r14d
movq 0x8(%rsp), %rsi
je 0x3292
jmp 0x35fb
movq 0x8(%rsp), %rsi
movq %r15, 0x58(%rsp)
movq (%rsi), %rax
movq 0x38(%r15), %r8
movq 0xc0(%r15), %r12
movq 0x18(%rdi), %rcx
addq 0x8(%rdi), %rcx
movq 0x20(%rdi), %r14
movq %r8, %rdx
subq %rcx, %rdx
cmpq %rdx, %rax
cmovlq %rax, %rdx
addq 0x10(%rdi), %r14
subq %r14, %r12
cmpq %r12, %rdx
cmovlq %rdx, %r12
leaq (%r12,%rcx), %rbp
testb $0x4, 0x10(%rsi)
je 0x3393
movq %rdi, 0x18(%rsp)
movq %r15, %rdi
xorl %edx, %edx
callq 0x3712
movq %rax, %r13
movq %r13, %rbx
testq %r13, %r13
jle 0x3307
leaq -0x1(%rbx), %r13
movq %r15, %rdi
movq %r13, %rsi
callq 0x360f
testl %eax, %eax
jne 0x32ec
testq %rbx, %rbx
movq 0x18(%rsp), %rdi
jns 0x3315
movq 0x38(%r15), %rbx
cmpq %rbp, %rbx
movq %rbp, %r8
cmovgq %rbx, %r8
movq (%rdi), %rax
movb $0x1, %r13b
testq %rax, %rax
movq 0x8(%rsp), %rsi
je 0x3376
movq 0x8(%rax), %rax
movq 0x38(%r15), %rcx
decq %rcx
cmpq %rcx, %rax
cmovlq %rax, %rcx
movq %rcx, %rax
subq (%rsi), %rax
cmpq %r8, %rax
jle 0x3370
movq %r15, %rdi
xorl %edx, %edx
movq %r8, %r15
callq 0x3712
movq %r15, %r8
movq 0x58(%rsp), %r15
movq 0x18(%rsp), %rdi
movq 0x8(%rsp), %rsi
testq %rax, %rax
jns 0x3376
movq (%rdi), %rdi
xorl %r13d, %r13d
testb %r13b, %r13b
je 0x3297
addq %r14, %r12
subq %rbp, %rbx
movl $0x0, %eax
cmovleq %rax, %rbx
addq %r12, %rbx
jmp 0x339c
addq %r14, %r12
movq %rbp, %r8
movq %r12, %rbx
movq %rdi, 0x18(%rsp)
testb $0x1, 0x10(%rsi)
movq 0x30(%rsp), %r13
movq 0x28(%rsp), %r12
je 0x33dc
leaq -0x1(%r12), %r14
movq %r15, %rdi
leaq 0x60(%rsp), %rdx
movq %r14, %rcx
movq %r15, %rbp
movq %r8, %r15
movq 0x38(%rsp), %r8
callq 0x3712
movq %r15, %r8
movq %rbp, %r15
movq %r14, 0x38(%rsp)
movq 0x50(%rsp), %r14
movq 0x40(%rsp), %rbp
subq %r12, %r8
incq %r12
leaq 0x1(%rbp), %rdx
movq %rbx, %rcx
subq %rbp, %rcx
movq 0x60(%rsp), %r9
movq %r13, (%rsp)
movq %r12, %rdi
movq %r8, %rsi
leaq 0x68(%rsp), %r8
callq 0x4a03
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
testl %eax, %eax
js 0x35fb
movq 0x10(%r14), %r12
cmpq %r12, %rbp
jge 0x3459
movq 0xe8(%r15), %rax
movq (%rax,%rbp,8), %rax
movq 0x8(%rax), %rdi
movq 0x10(%rax), %rsi
movl $0x1, %ecx
leaq 0x3cbf(%rip), %rdx      # 0x7103
movq %r13, %r8
callq 0x42ba
testl %eax, %eax
js 0x35f6
incq %rbp
jmp 0x341c
movq 0x8(%r14), %r13
leaq 0x10(%rsp), %r14
movq (%r14), %r14
movq 0x8(%r14), %rbp
cmpq %rbp, %r13
jge 0x34bd
cmpq 0x10(%r14), %r12
jge 0x34bd
incq %r13
movq 0xe8(%r15), %rax
movq (%rax,%r12,8), %rax
movq 0x8(%rax), %rdi
movq 0x10(%rax), %rsi
movl $0x1, %ecx
leaq 0x3c6d(%rip), %rdx      # 0x7103
movq 0x30(%rsp), %r8
callq 0x42ba
testl %eax, %eax
js 0x35f1
movq 0x8(%r14), %rbp
cmpq %rbp, %r13
jge 0x34bd
incq %r12
incq %r13
cmpq 0x10(%r14), %r12
jl 0x3477
movq 0x18(%r14), %rax
addq 0x8(%r14), %rax
cmpq %rax, %rbp
leaq 0x3c36(%rip), %r12      # 0x7105
jge 0x350b
movq 0x60(%r15), %rax
movq (%rax,%rbp,8), %rax
movq 0x8(%rax), %rdi
movq 0x10(%rax), %rsi
movl $0x1, %ecx
movq %r12, %rdx
movq 0x30(%rsp), %r8
callq 0x42ba
testl %eax, %eax
js 0x35f1
incq %rbp
movq 0x18(%r14), %rax
addq 0x8(%r14), %rax
cmpq %rax, %rbp
jl 0x34d1
movq 0x10(%r14), %r13
movq 0x20(%r14), %r12
testq %r12, %r12
jle 0x355e
movq 0x30(%rsp), %rbp
movq 0xe8(%r15), %rax
movq (%rax,%r13,8), %rax
movq 0x8(%rax), %rdi
movq 0x10(%rax), %rsi
movl $0x1, %ecx
leaq 0x3bcb(%rip), %rdx      # 0x7107
movq %rbp, %r8
callq 0x42ba
testl %eax, %eax
js 0x35f1
incq %r13
movq 0x20(%r14), %r12
addq 0x10(%r14), %r12
cmpq %r12, %r13
jl 0x351d
jmp 0x3566
addq %r13, %r12
movq 0x30(%rsp), %rbp
movq 0x18(%rsp), %rax
cmpq %rax, %r14
je 0x357d
movq 0x18(%r14), %r13
addq 0x8(%r14), %r13
jmp 0x3462
movq %r14, 0x10(%rsp)
movq 0x20(%rax), %r14
addq 0x10(%rax), %r14
cmpq %rbx, %r14
movl $0x0, %r12d
jge 0x35c8
movq 0xe8(%r15), %rax
movq (%rax,%r14,8), %rax
movq 0x8(%rax), %rdi
movq 0x10(%rax), %rsi
movl $0x1, %ecx
leaq 0x3b4f(%rip), %rdx      # 0x7103
movq %rbp, %r8
callq 0x42ba
testl %eax, %eax
js 0x35f6
incq %r14
cmpq %rbx, %r14
jl 0x3595
movq 0x18(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x10(%rsp)
testq %rax, %rax
movq 0x8(%rsp), %rcx
leaq 0x10(%rsp), %rdi
movq 0x38(%rsp), %rbx
jne 0x311c
xorl %ecx, %ecx
jmp 0x35fb
movq %r14, 0x10(%rsp)
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movl %ecx, %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq