// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq $0x0, 0x18(%rax)
movq -0x20(%rbp), %rax
movq 0x50(%rax), %rax
movq -0x20(%rbp), %rcx
cmpq 0x48(%rcx), %rax
jb 0x9362
movq -0x20(%rbp), %rax
movq 0x48(%rax), %rcx
movq 0x50(%rax), %rax
subq %rcx, %rax
movq %rax, %xmm0
movaps 0x14d08(%rip), %xmm1    # 0x1e030
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x14d0c(%rip), %xmm1    # 0x1e040
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movq -0x18(%rbp), %rax
movsd 0x8(%rax), %xmm2
movq -0x18(%rbp), %rax
movsd 0x10(%rax), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x10(%rax)
movq -0x18(%rbp), %rax
movsd 0x10(%rax), %xmm1
movq -0x20(%rbp), %rax
movq 0x48(%rax), %xmm0
movaps 0x14cb5(%rip), %xmm2    # 0x1e030
punpckldq %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
movapd 0x14cb9(%rip), %xmm2    # 0x1e040
subpd %xmm2, %xmm0
movaps %xmm0, %xmm2
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm2, %xmm0
addsd %xmm0, %xmm1
xorps %xmm0, %xmm0
ucomisd %xmm1, %xmm0
jbe 0x93ee
movq -0x20(%rbp), %rax
movq 0x48(%rax), %xmm0
movaps 0x14c7d(%rip), %xmm1    # 0x1e030
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x14c81(%rip), %xmm1    # 0x1e040
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movq -0x18(%rbp), %rax
movsd %xmm0, 0x10(%rax)
movq -0x18(%rbp), %rax
movsd 0x10(%rax), %xmm0
movq -0x20(%rbp), %rax
movq 0x48(%rax), %xmm1
movaps 0x14c29(%rip), %xmm2    # 0x1e030
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x14c2d(%rip), %xmm2    # 0x1e040
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x945c
movq -0x20(%rbp), %rax
movq 0x48(%rax), %xmm0
movaps 0x14bf8(%rip), %xmm1    # 0x1e030
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x14bfc(%rip), %xmm1    # 0x1e040
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movq -0x18(%rbp), %rax
movsd %xmm0, 0x10(%rax)
movq -0x18(%rbp), %rdi
callq 0x98d0
cmpl $0x0, %eax
je 0x946c
jmp 0x94d3
movq -0x18(%rbp), %rsi
leaq -0x1a7(%rip), %rdi      # 0x92d0
leaq 0x15b12(%rip), %rdx     # 0x1ef90
callq 0x12560
movq -0x18(%rbp), %rcx
movq %rax, 0x18(%rcx)
cmpq $0x0, %rax
jne 0x94ca
jmp 0x9493
callq 0x20a0
cmpl $0x0, (%rax)
je 0x94b8
leaq 0x152ac(%rip), %rdi     # 0x1e750
movb $0x0, %al
callq 0x180a0
callq 0x20a0
movl $0x0, (%rax)
jmp 0x94c6
leaq 0x15291(%rip), %rdi     # 0x1e750
movb $0x0, %al
callq 0x182f0
jmp 0x94c8
jmp 0x94d3
movl $0x0, -0x4(%rbp)
jmp 0x94da
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)