// File: /workspace/github_c_makefile_star2_O0/findstr[P]version-database/diff.c
// Function: diff_content
static dr_t
diff_content(dr_t old, dr_t new)
{
	int *SA;
	drb_t drb;
	const uint8_t *np;
	int ni = 0, oi = 0, sim;
	int nsize = new->size;
	np = new->buf;
	SA = dc3(old->buf, old->size);
	drb_init(&drb, 1024);
	patch_total(&drb, new->size);
	while (ni < nsize) {
		struct COPY copy;
		sim = search(old, SA, &np[ni], nsize - ni, &oi);
		assert(sim <= nsize - ni);
		if (sim <= COST) { //has no match, so find first match segment
			struct INSERT insert;
			int xi, xn = 0, xs = 0;
			for (xi = ni+1; xi < nsize; xi++) {
				xs = search(old, SA, &np[xi], nsize - xi, &xn);
				assert(xs <= (nsize - xi));
				if (xs > COST)
					break;
			}
			insert.p = &new->buf[ni];
			insert.size = xi - ni;
			patch_insert(&drb, &insert);
			//printf("INSERTT INTO %d SIZE %d\n", ni, xi - ni);
			ni = xi;
			oi = xn;
			sim = xs;
		}
		if (sim > COST) {
			copy.pos = oi;
			copy.size = sim;
			patch_copy(&drb, &copy);
			//printf("COPY FROM %d TO %d SIZE %d\n", oi, ni, sim);
			ni += sim;
		}
	}
	free(SA);
	//printf("drb size:%d\n", drb.size);
	return drb_dump(&drb);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
movq -0x10(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x40(%rbp)
movq -0x10(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
addq $0x8, %rdi
movq -0x8(%rbp), %rax
movl 0x4(%rax), %esi
callq 0x89e0
movq %rax, -0x18(%rbp)
leaq -0x28(%rbp), %rdi
movl $0x400, %esi            # imm = 0x400
callq 0x3de0
movq -0x10(%rbp), %rax
movl 0x4(%rax), %esi
leaq -0x28(%rbp), %rdi
callq 0x7890
movl -0x34(%rbp), %eax
cmpl -0x40(%rbp), %eax
jge 0x4042
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x30(%rbp), %rdx
movslq -0x34(%rbp), %rax
addq %rax, %rdx
movl -0x40(%rbp), %ecx
subl -0x34(%rbp), %ecx
leaq -0x38(%rbp), %r8
callq 0x4450
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movl -0x40(%rbp), %ecx
subl -0x34(%rbp), %ecx
cmpl %ecx, %eax
jg 0x3f2a
jmp 0x3f49
leaq 0x83b7(%rip), %rdi      # 0xc2e8
leaq 0x83c2(%rip), %rsi      # 0xc2fa
movl $0x5a, %edx
leaq 0x83bd(%rip), %rcx      # 0xc301
callq 0x2120
cmpl $0xa, -0x3c(%rbp)
jg 0x4015
movl $0x0, -0x60(%rbp)
movl $0x0, -0x64(%rbp)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
cmpl -0x40(%rbp), %eax
jge 0x3fda
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x30(%rbp), %rdx
movslq -0x5c(%rbp), %rax
addq %rax, %rdx
movl -0x40(%rbp), %ecx
subl -0x5c(%rbp), %ecx
leaq -0x60(%rbp), %r8
callq 0x4450
movl %eax, -0x64(%rbp)
movl -0x64(%rbp), %eax
movl -0x40(%rbp), %ecx
subl -0x5c(%rbp), %ecx
cmpl %ecx, %eax
jg 0x3fa6
jmp 0x3fc5
leaq 0x8372(%rip), %rdi      # 0xc31f
leaq 0x8346(%rip), %rsi      # 0xc2fa
movl $0x60, %edx
leaq 0x8341(%rip), %rcx      # 0xc301
callq 0x2120
cmpl $0xa, -0x64(%rbp)
jle 0x3fcd
jmp 0x3fda
jmp 0x3fcf
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x3f6a
movq -0x10(%rbp), %rax
addq $0x8, %rax
movslq -0x34(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movl -0x5c(%rbp), %eax
subl -0x34(%rbp), %eax
movl %eax, -0x50(%rbp)
leaq -0x28(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x7a40
movl -0x5c(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x60(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x64(%rbp), %eax
movl %eax, -0x3c(%rbp)
cmpl $0xa, -0x3c(%rbp)
jle 0x403d
movl -0x38(%rbp), %eax
movl %eax, -0x48(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0x44(%rbp)
leaq -0x28(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x79c0
movl -0x3c(%rbp), %eax
addl -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
jmp 0x3eea
movq -0x18(%rbp), %rdi
callq 0x2030
leaq -0x28(%rbp), %rdi
callq 0x4060
addq $0x70, %rsp
popq %rbp
retq
nopw (%rax,%rax)