// File: /workspace/github_c_makefile_star2_O0/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
subq $0x100, %rsp            # imm = 0x100
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdi
addq $0x8, %rdi
leaq -0x10(%rbp), %rsi
movl $0x1, %edx
callq 0x4fe0
movl %eax, -0x20(%rbp)
leaq -0x58(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x6140
movq %rax, -0x18(%rbp)
leaq -0x68(%rbp), %rdi
leaq 0x3908(%rip), %rsi      # 0x6500
callq 0x6a00
movl -0x20(%rbp), %eax
movl %eax, -0x78(%rbp)
movl -0x20(%rbp), %eax
addl $0x1, %eax
cltq
imulq $0x18, %rax, %rdi
callq 0x2200
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rdi
movl -0x20(%rbp), %eax
addl $0x1, %eax
cltq
imulq $0x18, %rax, %rdx
xorl %esi, %esi
callq 0x2140
movl $0x0, -0x24(%rbp)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0x2d3b
movq -0x70(%rbp), %rax
movslq -0x1c(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x90(%rbp)
movq -0x10(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rcx
movq %rcx, -0x88(%rbp)
movq -0x90(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x88(%rbp), %rdi
addq $0x8, %rdi
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0x5390
movq %rax, -0x80(%rbp)
movq -0x88(%rbp), %rdi
movq -0x80(%rbp), %rsi
callq 0x5f10
movq %rax, %rcx
movq -0x90(%rbp), %rax
movq %rcx, (%rax)
movq -0x80(%rbp), %rdi
callq 0x2f50
movq -0x90(%rbp), %rsi
leaq -0x68(%rbp), %rdi
leaq 0x382f(%rip), %rdx      # 0x6500
callq 0x6a40
movq %rax, -0x98(%rbp)
cmpq $0x0, -0x98(%rbp)
je 0x2d2b
movq -0x98(%rbp), %rax
movq (%rax), %rdi
movq -0x90(%rbp), %rax
movq (%rax), %rsi
callq 0x2fb0
cmpl $0x0, %eax
jne 0x2d2b
movq -0x98(%rbp), %rax
movq (%rax), %rdi
callq 0x2f50
movq -0x98(%rbp), %rax
movq $0x0, (%rax)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x2d2d
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x2c3d
movl $0x0, -0x28(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x20(%rbp), %eax
jne 0x2de8
movl -0x68(%rbp), %eax
movl %eax, -0x9c(%rbp)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x9c(%rbp), %eax
jge 0x2dd2
movq -0x60(%rbp), %rax
movslq -0x1c(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0xa8(%rbp)
movq -0xa8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0xb0(%rbp)
cmpq $0x0, -0xb0(%rbp)
jne 0x2d9c
jmp 0x2dc7
movq -0xa8(%rbp), %rax
movq 0x8(%rax), %rdi
addq $0x8, %rdi
leaq 0x95cd(%rip), %rsi      # 0xc37f
callq 0x2190
cmpl $0x0, %eax
je 0x2dc5
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x2dc7
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x2d5e
cmpl $0x0, -0x28(%rbp)
jne 0x2de6
leaq 0x93a1(%rip), %rdi      # 0xc180
movb $0x0, %al
callq 0x2100
jmp 0x2de8
movl -0x24(%rbp), %eax
cmpl -0x20(%rbp), %eax
jne 0x2dfa
cmpl $0x0, -0x28(%rbp)
je 0x2f1a
xorl %eax, %eax
movl %eax, %edi
callq 0x21e0
movq %rax, -0xe0(%rbp)
movq -0x18(%rbp), %rdi
callq 0x3010
movq %rax, -0xd8(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rdi
callq 0x3010
movq %rax, -0xc8(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x3010
movq %rax, -0xc0(%rbp)
leaq -0x78(%rbp), %rdi
leaq 0x3664(%rip), %rsi      # 0x64b0
callq 0x6a00
leaq -0x78(%rbp), %rdi
callq 0x3030
movq %rax, -0xb8(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x65d0
movq %rax, -0xe8(%rbp)
movq -0xc8(%rbp), %rdi
movq -0xe8(%rbp), %rsi
callq 0x5f10
movq %rax, -0xf8(%rbp)
movq -0xf8(%rbp), %rdi
callq 0x3010
movq %rax, -0xd0(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x61e0
movq %rax, -0xf0(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x6f70
movq -0x8(%rbp), %rax
cmpq $0x0, 0x18(%rax)
je 0x2edc
movq -0xf0(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rsi
callq 0x4e70
movq -0xe8(%rbp), %rdi
callq 0x2f50
movq -0xf0(%rbp), %rdi
callq 0x2f50
movq -0xf8(%rbp), %rdi
callq 0x2f50
movl -0x20(%rbp), %esi
movl -0x20(%rbp), %edx
subl -0x24(%rbp), %edx
movl -0x28(%rbp), %ecx
leaq 0x927e(%rip), %rdi      # 0xc191
movb $0x0, %al
callq 0x2100
movq -0x10(%rbp), %rdi
callq 0x2030
movq -0x18(%rbp), %rdi
callq 0x2f50
leaq -0x58(%rbp), %rdi
callq 0x6f70
leaq -0x68(%rbp), %rdi
callq 0x6960
leaq -0x78(%rbp), %rdi
callq 0x6960
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq