// File: /workspace/github_c_makefile_star2_O3/Tarsnap[P]kivaloo/kvlds/btree_cleaning.c
// Function: tick
static int
tick(void * cookie)
{
	struct cleaner * C = cookie;
	struct btree * T = C->T;

	/* The timer is not running. */
	C->cleantimer = NULL;

	/*
	 * Adjust our "cleaning debt" based on current amount of garbage.
	 * This is an underestimate of the amount of garbage if page have
	 * been split and not yet synced, since nnodes reflects the current
	 * size of the dirty tree while npages reflects the on-disk storage
	 * used.  The if() eliminates potential arithmetic underflow in such
	 * circumstances.
	 */
	if (T->npages >= T->nnodes)
		C->cleandebt += (double)(T->npages - T->nnodes) * C->cleanrate;

	/**
	 * Limit our "cleaning balance" based on the size of the tree.  We
	 * allow the "cleaning debt" to be negative on the basis that if we
	 * have been dirtying lots of pages, we should wait for more than a
	 * momentary pause before we start cleaning; but if the debt is a
	 * negative value which is large compared to the size of the tree,
	 * it suggests that we have just finished doing a large batch of
	 * deletes (otherwise it's very difficult to dirty more pages than
	 * the tree contains), in which case we should be more aggressive.
	 *
	 * Conversely, having a cleaning debt which is larger than the size
	 * of the tree is absurd, since it will cause us to re-clean recently
	 * cleaned nodes even if the tree is now completely compact; so don't
	 * allow that either.
	 */
	if (C->cleandebt + (double)T->nnodes < 0)
		C->cleandebt = -(double)(T->nnodes);
	if (C->cleandebt > (double)T->nnodes)
		C->cleandebt = (double)T->nnodes;

	/* Launch cleaning if possible and appropriate. */
	if (poke(C))
		goto err0;

	/* Schedule the next timer tick. */
	if ((C->cleantimer =
	    events_timer_register(tick, C, &onesec)) == NULL) {
		warnp("events_timer_register");
		goto err0;
	}

	/* Success! */
	return (0);

err0:
	/* Failure! */
	return (-1);
}

// Assembly:
pushq %rbx
movq %rdi, %rbx
movq (%rdi), %rcx
movq $0x0, 0x18(%rdi)
movq 0x48(%rcx), %rax
movq 0x50(%rcx), %rcx
subq %rax, %rcx
jae 0x6fa8
movsd 0x10(%rbx), %xmm0
jmp 0x6fd8
movq %rcx, %xmm1
punpckldq 0xdb9b(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0xdba3(%rip), %xmm1     # 0x14b60
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x8(%rbx), %xmm0
addsd 0x10(%rbx), %xmm0
movsd %xmm0, 0x10(%rbx)
movq %rax, %xmm2
punpckldq 0xdb6b(%rip), %xmm2 # xmm2 = xmm2[0],mem[0],xmm2[1],mem[1]
subpd 0xdb73(%rip), %xmm2     # 0x14b60
movapd %xmm2, %xmm1
unpckhpd %xmm2, %xmm1            # xmm1 = xmm1[1],xmm2[1]
addsd %xmm2, %xmm1
movapd %xmm0, %xmm2
addsd %xmm1, %xmm2
xorpd %xmm3, %xmm3
ucomisd %xmm2, %xmm3
jbe 0x701c
movapd 0xdb5d(%rip), %xmm0     # 0x14b70
xorpd %xmm1, %xmm0
movlpd %xmm0, 0x10(%rbx)
ucomisd %xmm1, %xmm0
jbe 0x7027
movsd %xmm1, 0x10(%rbx)
movq %rbx, %rdi
callq 0x730a
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testl %ecx, %ecx
jne 0x7094
leaq -0xbc(%rip), %rdi       # 0x6f85
leaq 0xdb48(%rip), %rdx      # 0x14b90
movq %rbx, %rsi
callq 0xc618
movq %rax, %rcx
movq %rax, 0x18(%rbx)
xorl %eax, %eax
testq %rcx, %rcx
jne 0x7094
callq 0x20a0
cmpl $0x0, (%rax)
je 0x7081
movq %rax, %rbx
leaq 0xd37e(%rip), %rdi      # 0x143f0
xorl %eax, %eax
callq 0xffd0
movl $0x0, (%rbx)
jmp 0x708f
leaq 0xd368(%rip), %rdi      # 0x143f0
xorl %eax, %eax
callq 0x100ef
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
popq %rbx
retq