// File: /workspace/github_c_makefile_star2_O2/findstr[P]version-database/diff.c
// Function: diff_tree
static void
diff_tree(dr_t a, dr_t b, dr_t root)
{
	int i;
	drb_t file;
	dr_t data, afinger;
	dr_t patchhash;
	char buf[2048];
	struct ref *r;
	struct release ra, rb;
	struct tree tb, ta_name, ta_hash;
	int add, dff, cpy, del;
	a = db_aliashash(a);
	b = db_aliashash(b);
	db_readrel(&ra, a);
	db_readrel(&rb, b);
	db_readtree(&ta_name, ra.tree);
	db_readtree(&tb, rb.tree);
	afinger = dr_ref(ra.finger);
	printf("tree a:%s\n", ra.tree->buf);
	printf("tree b:%s\n", rb.tree->buf);
	release_destroy(&ra);
	release_destroy(&rb);
	tree_clone(&ta_hash, &ta_name);
	tree_sort(&ta_name, ref_namecmp);
	tree_sort(&ta_hash, ref_hashcmp);
	drb_init(&file, 1024);
	printf("diff start\n");
	printf("detect change\n");
	add = 0; dff = 0; cpy = 0; del = 0;
	for (i = 0; i < tb.refn; i++) {
		struct ref *a, *b;
		dr_t patch = NULL;
		b = &tb.refs[i];
		if ((a = tree_search(&ta_hash, b, ref_hashcmp))) {
			if (dr_cmp(b->name, a->name) != 0) {
				struct CPY C;
				C.namea = a->name;
				C.name = b->name;
				ctrl_cpy(&file, &C);
				++cpy;
			} else {
				//printf("%s is same, skip it.\n", b->name->buf);
			}
			continue;
		}
		if (b->data == NULL)
			b->data = db_read(b->hash);
		a = tree_search(&ta_name, b, ref_namecmp);
		if (a == NULL) {
			struct NEW N;
			N.name = (b->name);
			N.data = (b->data);
			ctrl_new(&file, &N);
			add++;
		} else {
			if (a->data == NULL)
				a->data = db_read(a->hash);
			patch = diff_content(a->data, b->data);
			if (b->data->size <= patch->size) {//no fix patch
				struct NEW N;
				N.name = (b->name);
				N.data = (b->data);
				ctrl_new(&file, &N);
				add++;
			} else {
				struct DFF D;
				D.name = b->name;
				D.patch = patch;
				ctrl_dff(&file, &D);
				++dff;
			}
			dr_unref(patch);
		}
	}
	printf("detect recpye\n");
#if ENABLE_DEL
	tree_sort(&tb, ref_namecmp);
	for (i = 0; i < ta_name.refn; i++) {
		r = &ta_name.refs[i];
		if (tree_search(&tb, r, ref_namecmp) == NULL) { //clear
			struct DEL d;
			d.name = r->name;
			ctrl_del(&file, &d);
			++del;
		}
	}
#endif
	data = drb_dump(&file);
	patchhash = db_hash(data);
	snprintf(buf, sizeof(buf), "%s/patch.dat", str(afinger));
	dir_writefile(buf, data, root);
	snprintf(buf, sizeof(buf),
		"{\"add\":%d, \"dff\":%d, \"cpy\":%d, "
		"\"del\":%d, \"hash\":\"%s\", \"size\":%d }",
		add, dff, cpy, del, patchhash->buf, data->size);
	dr_unref(data);
	data = dr_newstr(buf);
	snprintf(buf, sizeof(buf), "%s/patch.json", str(afinger));
	dir_writefile(buf, data, root);
	printf("%s\n\n", str(data));
	snprintf(buf, sizeof(buf), "%s/%s/patch.dat", str(root), str(afinger));
	dr_unref(data);
	dr_unref(patchhash);
	dr_unref(afinger);
	tree_destroy(&ta_name);
	tree_destroy(&ta_hash);
	tree_destroy(&tb);
	data = dr_newstr(buf);
	verify(a, b, data);
	dr_unref(a);
	dr_unref(b);
	dr_unref(data);
	return ;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd58, %rsp            # imm = 0xD58
movq %rdx, -0xd0(%rbp)
movq %rsi, %rbx
callq 0x4fe3
movq %rax, %r14
movq %rbx, %rdi
callq 0x4fe3
movq %rax, %r15
leaq -0x178(%rbp), %rbx
movq %rbx, %rdi
movq %r14, -0x98(%rbp)
movq %r14, %rsi
callq 0x4ed3
leaq -0x148(%rbp), %r14
movq %r14, %rdi
movq %r15, -0x90(%rbp)
movq %r15, %rsi
callq 0x4ed3
movq 0x10(%rbx), %rsi
leaq -0xb8(%rbp), %rdi
callq 0x4eff
movq 0x10(%r14), %rsi
leaq -0xc8(%rbp), %rdi
callq 0x4eff
movq 0x28(%rbx), %rax
testq %rax, %rax
je 0x321a
incl (%rax)
movq %rax, -0xa0(%rbp)
movq 0x10(%rbx), %rsi
addq $0x8, %rsi
leaq 0x5016(%rip), %rdi      # 0x8246
xorl %eax, %eax
callq 0x2110
movq 0x10(%r14), %rsi
addq $0x8, %rsi
leaq 0x500b(%rip), %rdi      # 0x8251
xorl %eax, %eax
callq 0x2110
movq %rbx, %rdi
callq 0x5725
movq %r14, %rdi
callq 0x5725
leaq -0x118(%rbp), %rbx
leaq -0xb8(%rbp), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x54b4
leaq 0x1f43(%rip), %rsi      # 0x51c0
movq %r14, %rdi
callq 0x546f
leaq 0x1f1c(%rip), %rsi      # 0x51a8
movq %rbx, %rdi
callq 0x546f
leaq -0x88(%rbp), %rbx
andl $0x0, (%rbx)
movl $0x400, %edi            # imm = 0x400
xorl %esi, %esi
callq 0x3b70
movq %rax, 0x8(%rbx)
leaq 0x50fd(%rip), %rdi      # 0x83b2
callq 0x20a0
leaq 0x50fc(%rip), %rdi      # 0x83bd
callq 0x20a0
xorl %ecx, %ecx
leaq -0xd80(%rbp), %r13
leaq -0x580(%rbp), %r14
movl $0x0, -0x34(%rbp)
movl $0x0, -0x4c(%rbp)
movl $0x0, -0x50(%rbp)
movslq -0xc8(%rbp), %rax
cmpq %rax, %rcx
jge 0x363c
movq %rcx, -0xd8(%rbp)
imulq $0x18, %rcx, %rbx
addq -0xc0(%rbp), %rbx
leaq -0x118(%rbp), %rdi
movq %rbx, %rsi
leaq 0x1e8a(%rip), %rdx      # 0x51a8
callq 0x5490
testq %rax, %rax
je 0x336b
movq 0x8(%rbx), %rbx
movq 0x8(%rax), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3ab6
testl %eax, %eax
je 0x335f
movq %r14, -0xd78(%rbp)
movq %rbx, -0xd80(%rbp)
leaq -0x88(%rbp), %rdi
movq %r13, %rsi
callq 0x599c
incl -0x50(%rbp)
leaq -0x580(%rbp), %r14
jmp 0x362d
cmpq $0x0, 0x10(%rbx)
jne 0x337e
movq (%rbx), %rdi
callq 0x4d31
movq %rax, 0x10(%rbx)
leaq -0xb8(%rbp), %rdi
movq %rbx, %r15
movq %rbx, %rsi
leaq 0x1e2e(%rip), %rdx      # 0x51c0
callq 0x5490
testq %rax, %rax
je 0x35d7
movq %rax, %rbx
movq %r15, -0xa8(%rbp)
movq 0x10(%rax), %r15
testq %r15, %r15
jne 0x33c2
movq (%rbx), %rdi
callq 0x4d31
movq %rax, %r15
movq %rax, 0x10(%rbx)
movq -0xa8(%rbp), %rax
movq 0x10(%rax), %rbx
andl $0x0, -0x108(%rbp)
movl 0x4(%rbx), %r12d
leaq 0x8(%rbx), %rax
movq %rax, -0xf0(%rbp)
leaq 0x8(%r15), %rdi
movl 0x4(%r15), %esi
callq 0x6502
movq %rax, -0x30(%rbp)
andl $0x0, -0xd80(%rbp)
movl $0x400, %edi            # imm = 0x400
xorl %esi, %esi
callq 0x3b70
movq %rax, -0xd78(%rbp)
movl 0x4(%rbx), %esi
movq %r13, %rdi
callq 0x5bde
movl %r12d, -0x54(%rbp)
movslq %r12d, %rax
leaq -0x1(%rax), %rcx
movq %rcx, -0xe0(%rbp)
movq %rax, -0x70(%rbp)
decl %eax
movl %eax, -0x74(%rbp)
addq $0x9, %rbx
movq %rbx, -0xe8(%rbp)
movq %r15, %rbx
xorl %r15d, %r15d
movq %rbx, -0x40(%rbp)
movl -0x54(%rbp), %r12d
subl %r15d, %r12d
jle 0x358a
movq %r15, -0x48(%rbp)
movslq %r15d, %r15
movq -0xf0(%rbp), %rax
leaq (%rax,%r15), %rdx
movq %rbx, %rdi
movq -0x30(%rbp), %rsi
movq %rdx, -0x68(%rbp)
movl %r12d, %ecx
leaq -0x108(%rbp), %r8
callq 0x3bc0
movl %r12d, -0x78(%rbp)
cmpl %r12d, %eax
jg 0x3a1c
movl %eax, %r12d
cmpl $0xb, %eax
jge 0x3514
andl $0x0, -0x58(%rbp)
movq -0xe0(%rbp), %r13
subq %r15, %r13
movl -0x74(%rbp), %eax
subl -0x48(%rbp), %eax
movq %rax, -0x60(%rbp)
movq -0xe8(%rbp), %rax
leaq (%rax,%r15), %rbx
incq %r15
xorl %r14d, %r14d
xorl %r12d, %r12d
cmpq -0x70(%rbp), %r15
jge 0x3520
movq -0x60(%rbp), %rax
leal (%rax,%r14), %ecx
movq -0x40(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq %rbx, %rdx
leaq -0x58(%rbp), %r8
callq 0x3bc0
movl %eax, %r12d
cltq
cmpq %rax, %r13
jl 0x39ff
decl %r14d
decq %r13
incq %rbx
incq %r15
cmpl $0xb, %r12d
jl 0x34c3
movq -0x48(%rbp), %r15
subl %r14d, %r15d
negl %r14d
movl %r14d, %eax
jmp 0x3529
movl -0x108(%rbp), %eax
movq -0x48(%rbp), %r15
jmp 0x356a
movl -0x54(%rbp), %eax
movl %eax, %r15d
movl -0x78(%rbp), %eax
movq -0x68(%rbp), %rcx
movq %rcx, -0x580(%rbp)
movl %eax, -0x578(%rbp)
leaq -0xd80(%rbp), %r13
movq %r13, %rdi
leaq -0x580(%rbp), %r14
movq %r14, %rsi
callq 0x5ce2
movl -0x58(%rbp), %eax
movl %eax, -0x108(%rbp)
cmpl $0xb, %r12d
movq -0x40(%rbp), %rbx
jl 0x3449
movl %eax, -0x580(%rbp)
movl %r12d, -0x57c(%rbp)
movq %r13, %rdi
movq %r14, %rsi
callq 0x5cb1
addl %r12d, %r15d
jmp 0x3449
movq -0x30(%rbp), %rdi
callq 0x2030
movq %r13, %rdi
callq 0x3adc
movq %rax, %rbx
movq -0xa8(%rbp), %rdx
movq 0x10(%rdx), %rax
movl 0x4(%rax), %ecx
cmpl 0x4(%rbx), %ecx
jle 0x3601
movq 0x8(%rdx), %rax
movq %rax, -0xd80(%rbp)
movq %rbx, -0xd78(%rbp)
leaq -0x88(%rbp), %rdi
movq %r13, %rsi
callq 0x58b7
incl -0x4c(%rbp)
jmp 0x3625
movq 0x8(%r15), %rax
movq %rax, -0xd80(%rbp)
movq 0x10(%r15), %rax
movq %rax, -0xd78(%rbp)
leaq -0x88(%rbp), %rdi
movq %r13, %rsi
callq 0x5794
incl -0x34(%rbp)
jmp 0x362d
movq 0x8(%rdx), %rcx
movq %rcx, -0xd80(%rbp)
movq %rax, -0xd78(%rbp)
leaq -0x88(%rbp), %rdi
movq %r13, %rsi
callq 0x5794
incl -0x34(%rbp)
movq %rbx, %rdi
callq 0x3a7a
movq -0xd8(%rbp), %rcx
incq %rcx
jmp 0x32eb
leaq 0x4d88(%rip), %rdi      # 0x83cb
callq 0x20a0
leaq 0x1b71(%rip), %rsi      # 0x51c0
leaq -0xc8(%rbp), %r14
movq %r14, %rdi
callq 0x546f
xorl %r15d, %r15d
xorl %r12d, %r12d
xorl %r13d, %r13d
movslq -0xb8(%rbp), %rax
cmpq %rax, %r12
jge 0x36bd
movq -0xb0(%rbp), %rbx
leaq (%rbx,%r15), %rsi
movq %r14, %rdi
leaq 0x1b38(%rip), %rdx      # 0x51c0
callq 0x5490
testq %rax, %rax
jne 0x36b4
movq 0x8(%rbx,%r15), %rax
movq %rax, -0xd80(%rbp)
leaq -0x88(%rbp), %rdi
leaq -0xd80(%rbp), %rsi
callq 0x5963
incl %r13d
incq %r12
addq $0x18, %r15
jmp 0x3667
leaq -0x88(%rbp), %rdi
callq 0x3adc
movq %rax, %r12
movq %rax, %rdi
callq 0x4a14
movq %rax, %rbx
movq %rax, -0x30(%rbp)
movq -0xa0(%rbp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, -0x40(%rbp)
leaq 0x4bbe(%rip), %rdx      # 0x82af
leaq -0xd80(%rbp), %r15
movl $0x800, %esi            # imm = 0x800
movq %r15, %rdi
xorl %eax, %eax
callq 0x2120
movq %r15, %rdi
movq %r12, %rsi
movq -0xd0(%rbp), %r14
movq %r14, %rdx
callq 0x475e
leaq 0x8(%rbx), %r10
movl 0x4(%r12), %r11d
subq $0x8, %rsp
leaq 0x4b2c(%rip), %rdx      # 0x825c
movl $0x800, %esi            # imm = 0x800
movq %r15, %rdi
movl -0x34(%rbp), %ecx
movl -0x4c(%rbp), %r8d
movl -0x50(%rbp), %r9d
xorl %eax, %eax
pushq %r11
pushq %r10
pushq %r13
callq 0x2120
addq $0x20, %rsp
movq %r12, %rdi
callq 0x3a7a
movq %r15, %rdi
callq 0x3b55
movq %rax, %r12
leaq 0x4b30(%rip), %rdx      # 0x829e
movl $0x800, %esi            # imm = 0x800
movq %r15, %rdi
movq -0x40(%rbp), %r13
movq %r13, %rcx
xorl %eax, %eax
callq 0x2120
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x475e
leaq 0x8(%r12), %rsi
leaq 0x4a9a(%rip), %rdi      # 0x8238
xorl %eax, %eax
callq 0x2110
addq $0x8, %r14
leaq 0x4afc(%rip), %rdx      # 0x82ac
movl $0x800, %esi            # imm = 0x800
movq %r15, %rdi
movq %r14, %rcx
movq %r13, %r8
xorl %eax, %eax
callq 0x2120
movq %r12, %rdi
callq 0x3a7a
movq -0x30(%rbp), %rdi
callq 0x3a7a
movq -0xa0(%rbp), %rdi
callq 0x3a7a
leaq -0xb8(%rbp), %rdi
callq 0x5418
leaq -0x118(%rbp), %rdi
callq 0x5418
leaq -0xc8(%rbp), %rdi
callq 0x5418
movq %r15, %rdi
callq 0x3b55
movq %rax, -0x60(%rbp)
movq -0x98(%rbp), %r15
movq %r15, %rcx
addq $0x8, %rcx
leaq 0x4b1f(%rip), %r13      # 0x8346
leaq -0x580(%rbp), %rbx
movl $0x400, %esi            # imm = 0x400
movq %rbx, %rdi
movq %r13, %rdx
xorl %eax, %eax
callq 0x2120
movq %rbx, %rdi
callq 0x3b55
movq %rax, %r14
movq -0x90(%rbp), %r12
movq %r12, %rcx
addq $0x8, %rcx
movl $0x400, %esi            # imm = 0x400
movq %rbx, %rdi
movq %r13, %rdx
xorl %eax, %eax
callq 0x2120
movq %rbx, %rdi
callq 0x3b55
movq %rax, %r13
movq %r15, %rdi
movq %r14, %rsi
callq 0x41ec
movq %r12, %rdi
movq %r13, %rsi
callq 0x41ec
leaq -0x108(%rbp), %rdi
movq %r15, (%rdi)
movq -0x60(%rbp), %rax
movq %rax, 0x8(%rdi)
movq %r14, 0x10(%rdi)
callq 0x3ccc
movq %r14, -0x30(%rbp)
leaq 0x8(%r14), %rcx
leaq 0x4a9a(%rip), %r14      # 0x8350
movl $0x400, %esi            # imm = 0x400
movq %rbx, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x2120
movq %rbx, %rdi
xorl %esi, %esi
callq 0x4605
movq %r13, -0x70(%rbp)
leaq 0x8(%r13), %rcx
movq %rax, %r13
movl $0x400, %esi            # imm = 0x400
movq %rbx, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x2120
movq %rbx, %rdi
xorl %esi, %esi
callq 0x4605
movq %r13, %rdi
movq %rax, -0x48(%rbp)
movq %rax, %rsi
callq 0x3ab6
testl %eax, %eax
jne 0x3a5b
movslq 0x4(%r13), %rax
addq %r13, %rax
addq $0x8, %rax
movq %rax, -0x40(%rbp)
movq %r13, -0x68(%rbp)
addq $0x8, %r13
cmpq -0x40(%rbp), %r13
jae 0x399c
movq %r13, %rdi
pushq $0x9
popq %rsi
callq 0x2100
xorl %r14d, %r14d
movb %r14b, (%rax)
leaq 0x1(%rax), %rbx
movq %rbx, %rdi
pushq $0xa
popq %rsi
callq 0x2100
movq %rax, %r12
movb %r14b, (%rax)
movq %rbx, %rdi
movq -0x30(%rbp), %rsi
callq 0x4605
movq %rax, %rbx
movq %rax, %rdi
callq 0x4a14
movq %rax, %r15
leaq 0x8(%rax), %r14
movq %r14, %rdi
movq %r13, %rsi
callq 0x2180
testl %eax, %eax
jne 0x3a35
incq %r12
movq %rbx, %rdi
callq 0x3a7a
movq %r15, %rdi
callq 0x3a7a
movq %r12, %r13
jmp 0x3927
movq -0x68(%rbp), %rdi
callq 0x3a7a
movq -0x48(%rbp), %rdi
callq 0x3a7a
movq -0x30(%rbp), %rdi
callq 0x3a7a
movq -0x70(%rbp), %rdi
callq 0x3a7a
leaq 0x49de(%rip), %rdi      # 0x83a5
callq 0x20f0
movq -0x98(%rbp), %rdi
callq 0x3a7a
movq -0x90(%rbp), %rdi
callq 0x3a7a
movq -0x60(%rbp), %rdi
callq 0x3a7a
addq $0xd58, %rsp            # imm = 0xD58
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x48ed(%rip), %rdi      # 0x82f3
leaq 0x48c1(%rip), %rsi      # 0x82ce
leaq 0x48c1(%rip), %rcx      # 0x82d5
pushq $0x60
popq %rdx
callq 0x2130
leaq 0x4899(%rip), %rdi      # 0x82bc
leaq 0x48a4(%rip), %rsi      # 0x82ce
leaq 0x48a4(%rip), %rcx      # 0x82d5
pushq $0x5a
jmp 0x3a16
movq 0x75bc(%rip), %rax      # 0xaff8
movq (%rax), %rdi
leaq 0x4956(%rip), %rsi      # 0x839c
movq %r13, %rdx
movq %r14, %rcx
xorl %eax, %eax
callq 0x2190
pushq $0x16
popq %rdi
callq 0x2270
leaq 0x48fe(%rip), %rdi      # 0x8360
leaq 0x4865(%rip), %rsi      # 0x82ce
leaq 0x490e(%rip), %rcx      # 0x837e
movl $0x90, %edx
callq 0x2130