// File: /workspace/github_c_makefile_star2_O3/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, 0x40(%rsp)
testq %rsi, %rsi
je 0x3506
movq %rdx, %r12
movq %rdi, %r13
movq $-0x1, 0x48(%rsp)
leaq 0x40(%rsp), %r14
xorl %ebp, %ebp
movq %rcx, 0x10(%rsp)
movq %r14, %rdi
movq %rcx, %rsi
movq %rcx, %r15
callq 0x2f1c
movq 0x40(%rsp), %rdx
testq %rdx, %rdx
je 0x3508
movq %rax, %rbx
movq %r13, 0x20(%rsp)
movq %r12, 0x58(%rsp)
movq 0x8(%rdx), %rcx
movq (%r15), %rax
movq %rcx, %r14
subq %rax, %r14
testq %r14, %r14
movl $0x0, %r12d
cmovgq %r14, %r12
movq %rdx, 0x18(%rsp)
movq 0x10(%rdx), %r13
movq %r13, %rdx
subq %rax, %rdx
testq %rdx, %rdx
cmovleq %rbp, %rdx
movq %rdx, 0x50(%rsp)
testb $0x4, 0x10(%r15)
movq %r15, %rsi
jne 0x30cb
movq %r12, 0x30(%rsp)
jmp 0x3183
movq 0x20(%rsp), %rdi
movq 0x38(%rdi), %r15
cmpq %r15, %rcx
jl 0x314e
movq %r12, 0x30(%rsp)
movq 0xc0(%rdi), %r12
cmpq %r12, %r13
jge 0x313e
movq 0xe8(%rdi), %rbp
movq %rbp, %rdi
movq %r13, %rsi
callq 0x351c
testl %eax, %eax
je 0x310a
incq %r13
cmpq %r13, %r12
jne 0x30f1
jmp 0x3137
movl $0x1, %r8d
movq %rbp, %rdi
movq 0x10(%rsp), %rsi
movq %r13, %rdx
leaq 0x2f(%rsp), %rcx
callq 0x3566
testq %rax, %rax
jns 0x325d
movq 0x20(%rsp), %rax
movq 0x38(%rax), %r15
xorl %ebp, %ebp
movq 0x10(%rsp), %rsi
decq %r15
movq %r15, %rcx
movq 0x20(%rsp), %rdi
movq 0x30(%rsp), %r12
xorl %edx, %edx
movq $-0x1, %r8
callq 0x3617
movq 0x10(%rsp), %rsi
testq %rax, %rax
cmovleq %rbp, %rax
movq %rax, %rcx
subq %r12, %rcx
cmpq %rax, %r14
cmovgq %rax, %r12
movq %r12, 0x30(%rsp)
cmovleq %rbp, %rcx
addq %rcx, 0x50(%rsp)
movq 0x20(%rsp), %rdi
movq (%rsi), %rax
movq 0x38(%rdi), %r8
movq 0xc0(%rdi), %r15
movq 0x18(%rbx), %rcx
addq 0x8(%rbx), %rcx
movq 0x20(%rbx), %r14
movq %r8, %rdx
subq %rcx, %rdx
cmpq %rdx, %rax
cmovlq %rax, %rdx
movq %rbx, 0x38(%rsp)
addq 0x10(%rbx), %r14
subq %r14, %r15
cmpq %r15, %rdx
cmovlq %rdx, %r15
leaq (%r15,%rcx), %r12
testb $0x4, 0x10(%rsi)
je 0x3267
movq %rdi, %rbx
xorl %edx, %edx
callq 0x3617
movq %rax, %rbp
testq %rbp, %rbp
jle 0x31fa
decq %rbp
movq 0x60(%rbx), %rdi
movq %rbp, %rsi
callq 0x351c
testl %eax, %eax
jne 0x31dd
incq %rbp
jmp 0x3204
js 0x3200
xorl %ebp, %ebp
jmp 0x3204
movq 0x38(%rbx), %rbp
movq 0x10(%rsp), %rsi
cmpq %r12, %rbp
movq %r12, %r13
cmovgq %rbp, %r13
movq 0x38(%rsp), %rax
movq (%rax), %rbx
testq %rbx, %rbx
je 0x3272
movq 0x8(%rbx), %rax
movq 0x20(%rsp), %rdi
movq 0x38(%rdi), %rcx
decq %rcx
cmpq %rcx, %rax
cmovlq %rax, %rcx
movq %rcx, %rax
subq (%rsi), %rax
cmpq %r13, %rax
jle 0x3188
xorl %edx, %edx
movq %r13, %r8
callq 0x3617
testq %rax, %rax
jns 0x3286
movq 0x38(%rsp), %rax
movq (%rax), %rbx
movq 0x10(%rsp), %rsi
jmp 0x3183
addq %r14, %r15
movq %r12, %r13
movq %r15, %rbp
jmp 0x329d
addq %r14, %r15
subq %r12, %rbp
movl $0x0, %eax
cmovleq %rax, %rbp
addq %r15, %rbp
jmp 0x329d
addq %r14, %r15
subq %r12, %rbp
movl $0x0, %eax
cmovleq %rax, %rbp
addq %r15, %rbp
movq 0x10(%rsp), %rsi
testb $0x1, 0x10(%rsi)
movq 0x58(%rsp), %r12
movq 0x18(%rsp), %r15
jne 0x32b4
movq 0x30(%rsp), %rbx
jmp 0x32d9
movq 0x30(%rsp), %rbx
leaq -0x1(%rbx), %r14
movq 0x20(%rsp), %rdi
leaq 0x60(%rsp), %rdx
movq %r14, %rcx
movq 0x48(%rsp), %r8
callq 0x3617
movq %r14, 0x48(%rsp)
subq %rbx, %r13
incq %rbx
movq 0x50(%rsp), %r14
leaq 0x1(%r14), %rdx
movq %rbp, %rcx
subq %r14, %rcx
movq 0x60(%rsp), %r9
movq %r12, (%rsp)
movq %rbx, %rdi
movq %r13, %rsi
leaq 0x68(%rsp), %r8
callq 0x47ce
testl %eax, %eax
js 0x34ff
movq 0x10(%r15), %rbx
cmpq %rbx, %r14
movq 0x20(%rsp), %r13
jge 0x3358
movq 0xe8(%r13), %rax
movq (%rax,%r14,8), %rax
movq 0x8(%rax), %rdi
movq 0x10(%rax), %rsi
movl $0x1, %ecx
leaq 0x3dc7(%rip), %rdx      # 0x7103
movq %r12, %r8
callq 0x4162
testl %eax, %eax
js 0x34ff
incq %r14
movq 0x10(%r15), %rbx
cmpq %rbx, %r14
jl 0x331d
movq 0x8(%r15), %r14
movq %r14, %r15
cmpq %r14, %r15
jge 0x33bb
movq 0x18(%rsp), %rax
cmpq 0x10(%rax), %rbx
jge 0x33bb
incq %r15
movq 0xe8(%r13), %rax
movq (%rax,%rbx,8), %rax
movq 0x8(%rax), %rdi
movq 0x10(%rax), %rsi
movl $0x1, %ecx
leaq 0x3d72(%rip), %rdx      # 0x7103
movq %r12, %r8
callq 0x4162
testl %eax, %eax
js 0x34ff
movq 0x18(%rsp), %rax
movq 0x8(%rax), %r14
cmpq %r14, %r15
jge 0x33bb
incq %rbx
incq %r15
cmpq 0x10(%rax), %rbx
jl 0x3372
movq 0x18(%rsp), %rax
cmpq $0x0, 0x18(%rax)
leaq 0x3d39(%rip), %rbx      # 0x7105
leaq 0x3d34(%rip), %r15      # 0x7107
jle 0x3412
movq 0x60(%r13), %rax
movq (%rax,%r14,8), %rax
movq 0x8(%rax), %rdi
movq 0x10(%rax), %rsi
movl $0x1, %ecx
movq %rbx, %rdx
movq %r12, %r8
callq 0x4162
testl %eax, %eax
js 0x34ff
incq %r14
movq 0x18(%rsp), %rcx
movq 0x18(%rcx), %rax
addq 0x8(%rcx), %rax
cmpq %rax, %r14
jl 0x33d5
movq 0x18(%rsp), %rax
movq 0x10(%rax), %r14
movq 0x20(%rax), %rbx
testq %rbx, %rbx
jle 0x3466
movq 0xe8(%r13), %rax
movq (%rax,%r14,8), %rax
movq 0x8(%rax), %rdi
movq 0x10(%rax), %rsi
movl $0x1, %ecx
movq %r15, %rdx
movq %r12, %r8
callq 0x4162
testl %eax, %eax
js 0x34ff
incq %r14
movq 0x18(%rsp), %rax
movq 0x20(%rax), %rbx
addq 0x10(%rax), %rbx
cmpq %rbx, %r14
jl 0x3424
jmp 0x3469
addq %r14, %rbx
movq 0x18(%rsp), %rax
cmpq 0x38(%rsp), %rax
je 0x348e
movq 0x18(%rax), %r15
addq 0x8(%rax), %r15
movq (%rax), %rax
movq 0x8(%rax), %r14
movq %rax, 0x18(%rsp)
jmp 0x335f
movq %rax, 0x40(%rsp)
movq 0x38(%rsp), %rax
movq 0x20(%rax), %rbx
addq 0x10(%rax), %rbx
cmpq %rbp, %rbx
leaq 0x40(%rsp), %r14
jge 0x34dd
movq 0xe8(%r13), %rax
movq (%rax,%rbx,8), %rax
movq 0x8(%rax), %rdi
movq 0x10(%rax), %rsi
movl $0x1, %ecx
leaq 0x3c3a(%rip), %rdx      # 0x7103
movq %r12, %r8
callq 0x4162
testl %eax, %eax
js 0x34ff
incq %rbx
cmpq %rbp, %rbx
jl 0x34aa
movq 0x38(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x40(%rsp)
testq %rax, %rax
movl $0x0, %ebp
movq 0x10(%rsp), %rcx
jne 0x3059
jmp 0x3508
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x3508
xorl %ebp, %ebp
movl %ebp, %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq