// File: /workspace/github_c_makefile_star2_O2/findstr[P]version-database/release.c
// Function: release
void
release(struct release_args *args)
{
	dr_t *list, head;
	int i, n, keep, del;
	struct release prevrel;
	struct tree prevtree, tree;
	n = dir_scan(str(args->fromdir), &list, 1);
	head = db_readhead(&prevrel, &prevtree);
	tree_sort(&prevtree, ref_namecmp);
	tree.refn = n;
	tree.refs = malloc(sizeof(struct ref) * (n+1));
	memset(tree.refs, 0, sizeof(struct ref) * (n+1));
	keep = 0;
	for (i = 0; i < n; i++) {
		dr_t d, name;
		struct ref *r, *f;
		r = &tree.refs[i];
		r->name = name = list[i];
		d = dir_readfile(str(name), args->fromdir);
		r->hash = db_write(name, d);
		dr_unref(d);
		f = tree_search(&prevtree, r, ref_namecmp);
		if (f && dr_cmp(f->hash, r->hash) == 0) {
			dr_unref(f->hash);
			f->hash= NULL;
			keep += 1;
		}
	}
	del = 0;
	if (keep == n) {
		int x = prevtree.refn;
		for (i = 0; i < x; i++) {
			struct ref *r = &prevtree.refs[i];
			dr_t hash = r->hash;
			if (hash== NULL)
				continue;
			if (strcmp(str(r->name), FINGERPRINT_NAME) != 0)
				++del;
		}
		if (del == 0)
			printf("clean workspace\n");
	}
	if (keep != n || del != 0) {
		struct release rel;
		dr_t treeobj;//, finger;
		dr_t relhash;
		dr_t treehash;
		rel.time = time(NULL);
		rel.prev = dr_ref(head);
		rel.ver = dr_ref(args->version);
		rel.note = dr_ref(args->describe);
		tree_sort(&tree, ref_hashcmp);
#if ENABLE_FINGERPRINT
		rel.finger = fingerprint(&tree);
#endif
		treeobj = tree_marshal(&tree);
		treehash = db_write(rel.ver, treeobj);
		rel.tree = dr_ref(treehash);
		relhash = db_writehead(&rel);
		release_destroy(&rel);
		if (args->checkout != NULL)
			checkout(relhash, args->checkout);
		dr_unref(treeobj);
		dr_unref(relhash);
		dr_unref(treehash);
		printf("release total:%d changed:%d del:%d\n", n, n-keep, del);
	}
	free(list);
	dr_unref(head);
	release_destroy(&prevrel);
	tree_destroy(&prevtree);
	tree_destroy(&tree);
	return ;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x8b8, %rsp            # imm = 0x8B8
movq %rdi, -0x38(%rbp)
movq 0x10(%rdi), %rdi
addq $0x8, %rdi
leaq -0x68(%rbp), %rsi
pushq $0x1
popq %rdx
callq 0x4300
movl %eax, %r14d
leaq -0xd8(%rbp), %rdi
leaq -0x78(%rbp), %rbx
movq %rbx, %rsi
callq 0x4f2b
movq %rax, -0x50(%rbp)
leaq 0x272b(%rip), %rsi      # 0x51c0
movq %rbx, %rdi
callq 0x546f
movl %r14d, -0x48(%rbp)
leal 0x1(%r14), %eax
cltq
imulq $0x18, %rax, %rsi
pushq $0x1
popq %rdi
callq 0x2170
movq %rax, %rbx
movq %rax, -0x40(%rbp)
xorl %r12d, %r12d
testl %r14d, %r14d
movl $0x0, %r13d
movq %r14, -0x58(%rbp)
cmovgl %r14d, %r13d
movl $0x0, -0x30(%rbp)
cmpq %r12, %r13
je 0x2b6a
movq -0x68(%rbp), %rax
movq (%rax,%r12,8), %r14
movq %r14, 0x8(%rbx)
leaq 0x8(%r14), %rdi
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0x4605
movq %rax, %r15
movq %r14, %rdi
movq %rax, %rsi
callq 0x4d8f
movq %rax, (%rbx)
movq %r15, %rdi
callq 0x2e50
leaq -0x78(%rbp), %rdi
movq %rbx, %rsi
leaq 0x269e(%rip), %rdx      # 0x51c0
callq 0x5490
testq %rax, %rax
je 0x2b5e
movq %rax, %r14
movq (%rax), %r15
movq (%rbx), %rsi
movslq 0x4(%r15), %rdx
cmpl 0x4(%rsi), %edx
jne 0x2b5e
leaq 0x8(%r15), %rdi
addq $0x8, %rsi
callq 0x2200
testl %eax, %eax
jne 0x2b5e
movq %r15, %rdi
callq 0x2e50
andq $0x0, (%r14)
incl -0x30(%rbp)
incq %r12
addq $0x18, %rbx
jmp 0x2ad5
movq -0x58(%rbp), %rax
movl %eax, %r14d
subl -0x30(%rbp), %r14d
movl %r14d, -0x60(%rbp)
jne 0x2bc3
movl -0x78(%rbp), %eax
xorl %r14d, %r14d
testl %eax, %eax
cmovlel %r14d, %eax
movq -0x70(%rbp), %r15
imulq $0x18, %rax, %r12
leaq 0x57bd(%rip), %rbx      # 0x8353
xorl %r13d, %r13d
cmpq %r14, %r12
je 0x2bcc
cmpq $0x0, (%r15,%r14)
je 0x2bbd
movq 0x8(%r15,%r14), %rdi
addq $0x8, %rdi
movq %rbx, %rsi
callq 0x2180
cmpl $0x1, %eax
sbbl $-0x1, %r13d
addq $0x18, %r14
jmp 0x2b99
xorl %r13d, %r13d
movq -0x50(%rbp), %rbx
jmp 0x2bf0
testl %r13d, %r13d
movq -0x50(%rbp), %rbx
jne 0x2bf0
leaq 0x5609(%rip), %rdi      # 0x81e5
callq 0x20a0
movl -0x30(%rbp), %eax
cmpl %eax, -0x58(%rbp)
je 0x2df2
xorl %r13d, %r13d
movl %r13d, -0x5c(%rbp)
xorl %edi, %edi
callq 0x21d0
movq %rax, -0xa8(%rbp)
testq %rbx, %rbx
je 0x2c09
incl (%rbx)
movq %rbx, -0xa0(%rbp)
movq -0x38(%rbp), %rax
movq (%rax), %rax
testq %rax, %rax
je 0x2c1e
incl (%rax)
movq %rax, -0x90(%rbp)
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
testq %rax, %rax
je 0x2c34
incl (%rax)
movq %rax, -0x88(%rbp)
leaq 0x2566(%rip), %rsi      # 0x51a8
leaq -0x48(%rbp), %rdi
callq 0x546f
movl $0x800, %edi            # imm = 0x800
xorl %esi, %esi
callq 0x2e8c
movq %rax, %rbx
leaq -0x8e0(%rbp), %r12
xorl %r15d, %r15d
xorl %r13d, %r13d
movslq -0x48(%rbp), %rax
cmpq %rax, %r15
jge 0x2d0b
movq -0x40(%rbp), %rax
movq %r15, -0x30(%rbp)
imulq $0x18, %r15, %rdx
movq (%rax,%rdx), %rcx
movq 0x8(%rax,%rdx), %r8
addq $0x8, %rcx
addq $0x8, %r8
movl $0x800, %esi            # imm = 0x800
movq %r12, %rdi
leaq 0x5504(%rip), %rdx      # 0x81a4
xorl %eax, %eax
callq 0x2120
cmpl $0x800, %eax            # imm = 0x800
jae 0x2e33
movl %eax, %r15d
movl 0x4(%rbx), %r12d
leal (%r15,%r13), %r14d
cmpl %r14d, %r12d
jge 0x2cd5
addl %r12d, %r12d
movq %rbx, %rdi
movl %r12d, %esi
callq 0x2edc
movq %rax, %rbx
jmp 0x2cbd
movl %r15d, %edx
leaq 0x8(%rbx), %r14
movslq %r13d, %rax
leaq (%rbx,%rax), %r13
addq $0x8, %r13
movq %r13, %rdi
leaq -0x8e0(%rbp), %r12
movq %r12, %rsi
callq 0x21c0
addl %r15d, %r13d
subl %r14d, %r13d
movq -0x30(%rbp), %r15
incq %r15
jmp 0x2c67
movq %rbx, %rdi
movl %r13d, %esi
callq 0x2edc
movq %rax, %rbx
movq -0x40(%rbp), %r14
movl %r15d, %eax
imulq $0x18, %rax, %r15
leaq 0x5628(%rip), %rsi      # 0x8353
pushq $0xc
popq %rdi
callq 0x2e8c
movq %rax, 0x8(%r14,%r15)
movq %rax, %rdi
movq %rbx, %rsi
callq 0x4d8f
movq %rax, (%r14,%r15)
incl -0x48(%rbp)
movq %rbx, %rdi
callq 0x2e50
movq (%r14,%r15), %rax
testq %rax, %rax
je 0x2d5d
incl (%rax)
movq %rax, -0x80(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x5200
movq %rax, %r14
movq -0x90(%rbp), %rdi
movq %rax, %rsi
callq 0x4d8f
movq %rax, %rbx
testq %rax, %rax
movl -0x60(%rbp), %r13d
je 0x2d8a
incl (%rbx)
leaq -0xa8(%rbp), %r12
movq %rbx, 0x10(%r12)
movq %r12, %rdi
callq 0x4fa1
movq %rax, %r15
movq %r12, %rdi
callq 0x5725
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rsi
testq %rsi, %rsi
je 0x2dbe
movq %r15, %rdi
callq 0x41ec
movq %r14, %rdi
callq 0x2e50
movq %r15, %rdi
callq 0x2e50
movq %rbx, %rdi
callq 0x2e50
leaq 0x53a3(%rip), %rdi      # 0x8180
movq -0x58(%rbp), %rsi
movl %r13d, %edx
movl -0x5c(%rbp), %ecx
xorl %eax, %eax
callq 0x2110
movq -0x50(%rbp), %rbx
movq -0x68(%rbp), %rdi
callq 0x2030
movq %rbx, %rdi
callq 0x2e50
leaq -0xd8(%rbp), %rdi
callq 0x5725
leaq -0x78(%rbp), %rdi
callq 0x5418
leaq -0x48(%rbp), %rdi
callq 0x5418
addq $0x8b8, %rsp            # imm = 0x8B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x5371(%rip), %rdi      # 0x81ab
leaq 0x537a(%rip), %rsi      # 0x81bb
leaq 0x537d(%rip), %rcx      # 0x81c5
pushq $0x1b
popq %rdx
callq 0x2130