// File: /workspace/github_c_makefile_star2_O1/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
jb 0x7025
movq %rcx, %xmm0
punpckldq 0xdb7e(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0xdb86(%rip), %xmm0     # 0x14b90
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x8(%rbx), %xmm1
addsd 0x10(%rbx), %xmm1
movsd %xmm1, 0x10(%rbx)
movq %rax, %xmm1
punpckldq 0xdb4e(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0xdb56(%rip), %xmm1     # 0x14b90
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
movsd 0x10(%rbx), %xmm1
addsd %xmm0, %xmm1
xorpd %xmm2, %xmm2
ucomisd %xmm1, %xmm2
jbe 0x706a
movapd 0xdb3f(%rip), %xmm1     # 0x14ba0
xorpd %xmm0, %xmm1
movlpd %xmm1, 0x10(%rbx)
movsd 0x10(%rbx), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x707a
movsd %xmm0, 0x10(%rbx)
movq %rbx, %rdi
callq 0x7365
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testl %ecx, %ecx
jne 0x70e7
leaq -0xbb(%rip), %rdi       # 0x6fd9
leaq 0xdb25(%rip), %rdx      # 0x14bc0
movq %rbx, %rsi
callq 0xc738
movq %rax, %rcx
movq %rax, 0x18(%rbx)
xorl %eax, %eax
testq %rcx, %rcx
jne 0x70e7
callq 0x20a0
cmpl $0x0, (%rax)
je 0x70d4
movq %rax, %rbx
leaq 0xd38b(%rip), %rdi      # 0x14450
xorl %eax, %eax
callq 0x10048
movl $0x0, (%rbx)
jmp 0x70e2
leaq 0xd375(%rip), %rdi      # 0x14450
xorl %eax, %eax
callq 0x10167
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
popq %rbx
retq