// File: /workspace/github_c_makefile_star2_O3/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 $0x8c8, %rsp            # imm = 0x8C8
movq %rdi, -0x48(%rbp)
movq 0x10(%rdi), %rdi
addq $0x8, %rdi
leaq -0x70(%rbp), %rsi
movl $0x1, %edx
callq 0x4fd0
movl %eax, %r14d
leaq -0xe8(%rbp), %rdi
leaq -0x80(%rbp), %rbx
movq %rbx, %rsi
callq 0x5c48
movq %rax, -0x68(%rbp)
leaq 0x2cb9(%rip), %rsi      # 0x5f0c
movq %rbx, %rdi
callq 0x6244
movl %r14d, -0x58(%rbp)
movslq %r14d, %rax
shlq $0x3, %rax
leaq (%rax,%rax,2), %rsi
addq $0x18, %rsi
movl $0x1, %edi
callq 0x2180
movq %rax, -0x50(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x38(%rbp)
movl %r14d, -0x30(%rbp)
testl %r14d, %r14d
jle 0x3386
movl -0x30(%rbp), %eax
movq %rax, -0x40(%rbp)
xorl %r14d, %r14d
movl $0x8, %ebx
movl $0x0, -0x38(%rbp)
movq -0x50(%rbp), %r13
movq -0x70(%rbp), %rax
movq (%rax,%r14,8), %r12
movq %r12, (%r13,%rbx)
leaq 0x8(%r12), %rdi
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0x52b7
movq %rax, %r15
movq %r12, %rdi
movq %rax, %rsi
callq 0x5a05
movq %rax, -0x8(%r13,%rbx)
testq %r15, %r15
je 0x3306
movl (%r15), %ecx
leal -0x1(%rcx), %eax
movl %eax, (%r15)
cmpl $0x1, %ecx
jg 0x3306
testl %eax, %eax
jne 0x3834
movq %r15, %rdi
callq 0x2030
addq %rbx, %r13
addq $-0x8, %r13
leaq -0x80(%rbp), %rdi
movq %r13, %rsi
leaq 0x2bf1(%rip), %rdx      # 0x5f0c
callq 0x6260
testq %rax, %rax
je 0x3375
movq %rax, %r15
movq (%rax), %r12
movq (%r13), %rsi
movslq 0x4(%r12), %rdx
cmpl 0x4(%rsi), %edx
jne 0x3375
leaq 0x8(%r12), %rdi
addq $0x8, %rsi
callq 0x2210
testl %eax, %eax
jne 0x3375
movl (%r12), %ecx
leal -0x1(%rcx), %eax
movl %eax, (%r12)
cmpl $0x1, %ecx
jg 0x336b
testl %eax, %eax
jne 0x3834
movq %r12, %rdi
callq 0x2030
movq $0x0, (%r15)
incl -0x38(%rbp)
incq %r14
addq $0x18, %rbx
cmpq %r14, -0x40(%rbp)
jne 0x32ad
movl -0x30(%rbp), %eax
subl -0x38(%rbp), %eax
movl %eax, -0x5c(%rbp)
jne 0x3408
movslq -0x80(%rbp), %rax
testq %rax, %rax
jle 0x381a
movq -0x78(%rbp), %r14
shlq $0x3, %rax
leaq (%rax,%rax,2), %r15
xorl %r12d, %r12d
leaq 0x6f9d(%rip), %rbx      # 0xa351
movl $0x0, -0x2c(%rbp)
cmpq $0x0, (%r14,%r12)
je 0x33da
movq 0x8(%r14,%r12), %rdi
addq $0x8, %rdi
movq %rbx, %rsi
callq 0x2190
cmpl $0x1, %eax
sbbl $-0x1, -0x2c(%rbp)
addq $0x18, %r12
cmpq %r12, %r15
jne 0x33bb
cmpl $0x0, -0x2c(%rbp)
jne 0x3408
leaq 0x6df3(%rip), %rdi      # 0xa1e3
callq 0x20a0
movl $0x0, -0x2c(%rbp)
movl -0x38(%rbp), %eax
cmpl %eax, -0x30(%rbp)
je 0x3758
xorl %edi, %edi
callq 0x21e0
movq %rax, -0xb8(%rbp)
movq -0x68(%rbp), %rax
testq %rax, %rax
je 0x3421
incl (%rax)
movq %rax, -0xb0(%rbp)
movq -0x48(%rbp), %rax
movq (%rax), %rax
testq %rax, %rax
je 0x3436
incl (%rax)
movq %rax, -0xa0(%rbp)
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rax
testq %rax, %rax
je 0x344c
incl (%rax)
movq %rax, -0x98(%rbp)
leaq 0x2a9a(%rip), %rsi      # 0x5ef4
leaq -0x58(%rbp), %rbx
movq %rbx, %rdi
callq 0x6244
movl $0x80c, %edi            # imm = 0x80C
callq 0x2200
movq %rax, %r12
movabsq $0x80000000001, %rax    # imm = 0x80000000001
movq %rax, (%r12)
movb $0x0, 0x808(%r12)
cmpl $0x0, (%rbx)
jle 0x35e8
leaq -0x8f0(%rbp), %r14
xorl %ebx, %ebx
xorl %r15d, %r15d
movq -0x50(%rbp), %rax
leaq (%rbx,%rbx,2), %rdx
movq (%rax,%rdx,8), %rcx
movq 0x8(%rax,%rdx,8), %r8
addq $0x8, %rcx
addq $0x8, %r8
movl $0x800, %esi            # imm = 0x800
movq %r14, %rdi
leaq 0x6cdb(%rip), %rdx      # 0xa1a2
xorl %eax, %eax
callq 0x2120
cmpl $0x800, %eax            # imm = 0x800
jae 0x3853
movl 0x4(%r12), %r14d
movq %r15, -0x40(%rbp)
movq %rax, -0x88(%rbp)
addl %eax, %r15d
cmpl %r15d, %r14d
movq %rbx, -0x38(%rbp)
jge 0x3588
movq %r12, %r13
movslq %r14d, %rax
leaq (%rax,%rax), %r14
movl (%r13), %ebx
leaq 0xc(,%rax,2), %rsi
cmpl $0x1, %ebx
jne 0x3525
movq %r13, %rdi
callq 0x2220
movq %rax, %r12
movl %r14d, 0x4(%rax)
jmp 0x357c
movq %rsi, %rdi
callq 0x2200
movq %rax, %r12
movl $0x1, (%rax)
movl %r14d, 0x4(%rax)
movb $0x0, 0x8(%rax,%r14)
movl 0x4(%r13), %eax
cmpl %r14d, %eax
cmovgel %r14d, %eax
leaq 0x8(%r12), %rdi
movl %eax, 0x4(%r13)
leaq 0x8(%r13), %rsi
movslq %eax, %rdx
callq 0x21d0
leal -0x1(%rbx), %eax
movl %eax, (%r13)
cmpl $0x1, %ebx
jg 0x357c
testl %eax, %eax
jne 0x3834
movq %r13, %rdi
callq 0x2030
movq %r12, %r13
cmpl %r15d, %r14d
jl 0x34fc
movl -0x88(%rbp), %r15d
movslq -0x40(%rbp), %rbx
leaq (%r12,%rbx), %rdi
addq $0x8, %rdi
leaq -0x8f0(%rbp), %r14
movq %r14, %rsi
movq %r15, %rdx
callq 0x21d0
addq %rbx, %r15
movq -0x38(%rbp), %rbx
incq %rbx
movslq -0x58(%rbp), %rax
cmpq %rax, %rbx
jl 0x349f
movl (%r12), %r14d
movl %ebx, %eax
movq %rax, -0x40(%rbp)
movslq %r15d, %rbx
leaq 0xc(%rbx), %rsi
cmpl $0x1, %r14d
movq %r15, %r13
jne 0x37b3
movq -0x40(%rbp), %r14
jmp 0x35f3
xorl %r14d, %r14d
movl $0xc, %esi
xorl %r13d, %r13d
movq %r12, %rdi
callq 0x2220
movq %rax, %r15
movl %r13d, 0x4(%rax)
movq -0x50(%rbp), %rbx
leaq (%r14,%r14,2), %r12
movl $0x18, %edi
callq 0x2200
movabsq $0xc00000001, %rcx      # imm = 0xC00000001
movq %rcx, (%rax)
movabsq $0x707265676e69665f, %rcx # imm = 0x707265676E69665F
movq %rcx, 0x8(%rax)
movl $0x746e6972, 0x10(%rax) # imm = 0x746E6972
movb $0x0, 0x14(%rax)
movq %rax, 0x8(%rbx,%r12,8)
movq %rax, %rdi
movq %r15, %rsi
callq 0x5a05
movq %rax, %r14
movq %rax, (%rbx,%r12,8)
incl -0x58(%rbp)
movl (%r15), %ecx
leal -0x1(%rcx), %eax
movl %eax, (%r15)
cmpl $0x1, %ecx
jg 0x3672
testl %eax, %eax
jne 0x3834
movq %r15, %rdi
callq 0x2030
testq %r14, %r14
je 0x367a
incl (%r14)
movq %r14, -0x90(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x5f4c
movq %rax, %r14
movq -0xa0(%rbp), %rdi
movq %rax, %rsi
callq 0x5a05
movq %rax, %rbx
testq %rax, %rax
je 0x36a6
incl (%rbx)
leaq -0xb8(%rbp), %r12
movq %rbx, 0x10(%r12)
movq %r12, %rdi
callq 0x5ccc
movq %rax, %r15
movq %r12, %rdi
callq 0x65fc
movq -0x48(%rbp), %rax
movq 0x18(%rax), %rsi
testq %rsi, %rsi
je 0x36da
movq %r15, %rdi
callq 0x4eb4
testq %r14, %r14
je 0x36fd
movl (%r14), %ecx
leal -0x1(%rcx), %eax
movl %eax, (%r14)
cmpl $0x1, %ecx
jg 0x36fd
testl %eax, %eax
jne 0x3834
movq %r14, %rdi
callq 0x2030
testq %r15, %r15
je 0x3720
movl (%r15), %ecx
leal -0x1(%rcx), %eax
movl %eax, (%r15)
cmpl $0x1, %ecx
jg 0x3720
testl %eax, %eax
jne 0x3834
movq %r15, %rdi
callq 0x2030
testq %rbx, %rbx
je 0x3741
movl (%rbx), %ecx
leal -0x1(%rcx), %eax
movl %eax, (%rbx)
cmpl $0x1, %ecx
jg 0x3741
testl %eax, %eax
jne 0x3834
movq %rbx, %rdi
callq 0x2030
leaq 0x6a36(%rip), %rdi      # 0xa17e
movl -0x30(%rbp), %esi
movl -0x5c(%rbp), %edx
movl -0x2c(%rbp), %ecx
xorl %eax, %eax
callq 0x2110
movq -0x70(%rbp), %rdi
callq 0x2030
movq -0x68(%rbp), %rdi
testq %rdi, %rdi
je 0x3783
movl (%rdi), %ecx
leal -0x1(%rcx), %eax
movl %eax, (%rdi)
cmpl $0x1, %ecx
jg 0x3783
testl %eax, %eax
jne 0x3834
callq 0x2030
leaq -0xe8(%rbp), %rdi
callq 0x65fc
leaq -0x80(%rbp), %rdi
callq 0x6189
leaq -0x58(%rbp), %rdi
callq 0x6189
addq $0x8c8, %rsp            # imm = 0x8C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x8(%r12), %rax
movq %rax, -0x38(%rbp)
movq %rsi, %rdi
callq 0x2200
movq %rax, %r15
movl $0x1, (%rax)
movl %r13d, 0x4(%rax)
movb $0x0, 0x8(%rax,%rbx)
leaq 0x8(%rax), %rdi
movl 0x4(%r12), %eax
cmpl %r13d, %eax
cmovgel %r13d, %eax
movl %eax, 0x4(%r12)
movslq %eax, %rdx
movq -0x38(%rbp), %rsi
callq 0x21d0
leal -0x1(%r14), %eax
movl %eax, (%r12)
cmpl $0x1, %r14d
jg 0x382b
testl %eax, %eax
movq -0x40(%rbp), %r14
jne 0x3834
movq %r12, %rdi
callq 0x2030
jmp 0x3602
leaq 0x69c2(%rip), %rdi      # 0xa1e3
callq 0x20a0
jmp 0x3758
movq -0x40(%rbp), %r14
jmp 0x3602
leaq 0x6846(%rip), %rdi      # 0xa081
leaq 0x684b(%rip), %rsi      # 0xa08d
leaq 0x684b(%rip), %rcx      # 0xa094
movl $0x2d, %edx
callq 0x2130
leaq 0x694f(%rip), %rdi      # 0xa1a9
leaq 0x6958(%rip), %rsi      # 0xa1b9
leaq 0x695b(%rip), %rcx      # 0xa1c3
movl $0x1b, %edx
callq 0x2130
nop