// File: /workspace/github_c_makefile_star2_O2/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 %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq (%rdi), %rcx
andq $0x0, 0x18(%rdi)
movq 0x48(%rcx), %rax
movq 0x50(%rcx), %rcx
subq %rax, %rcx
jae 0x5ffc
movsd 0x10(%rbx), %xmm0
jmp 0x602c
movq %rcx, %xmm1
punpckldq 0xbb67(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0xbb6f(%rip), %xmm1     # 0x11b80
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 0xbb37(%rip), %xmm2 # xmm2 = xmm2[0],mem[0],xmm2[1],mem[1]
subpd 0xbb3f(%rip), %xmm2     # 0x11b80
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 0x6070
movapd 0xbb29(%rip), %xmm0     # 0x11b90
xorpd %xmm1, %xmm0
movlpd %xmm0, 0x10(%rbx)
ucomisd %xmm1, %xmm0
jbe 0x607b
movsd %xmm1, 0x10(%rbx)
movq %rbx, %rdi
callq 0x6303
pushq $-0x1
popq %rbp
testl %eax, %eax
je 0x608e
movl %ebp, %eax
jmp 0x60b2
leaq -0xbb(%rip), %rdi       # 0x5fda
leaq 0xbb14(%rip), %rdx      # 0x11bb0
movq %rbx, %rsi
callq 0xaa98
movq %rax, %rcx
movq %rax, 0x18(%rbx)
xorl %eax, %eax
testq %rcx, %rcx
je 0x60b9
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
callq 0x20a0
cmpl $0x0, (%rax)
je 0x60d9
movq %rax, %rbx
leaq 0xb36b(%rip), %rdi      # 0x11438
xorl %eax, %eax
callq 0xdf55
andl $0x0, (%rbx)
jmp 0x608a
leaq 0xb358(%rip), %rdi      # 0x11438
xorl %eax, %eax
callq 0xe0e4
jmp 0x608a