// File: /workspace/github_c_makefile_star2_O2/Tarsnap[P]kivaloo/lbs-dynamodb/deleteto.c
// Function: poke
static int
poke(void * cookie)
{
	struct deleteto * D = cookie;
	struct delete * D1;
	uint64_t deletedto;

	/* Tell the metadata code how far we've finished deleting. */
	if (D->ip_head != NULL)
		deletedto = D->ip_head->N;
	else
		deletedto = D->M;
	metadata_deletedto_write(D->MD, deletedto);

	/* Are we waiting to shut down? */
	if (D->shuttingdown) {
		/* If there are deletes in progress, we're not done yet. */
		if (D->npending != 0)
			return (0);

		/*
		 * If the metadata is up to date with how far we've deleted,
		 * we're done.
		 */
		if (metadata_deletedto_read(D->MD) == deletedto) {
			D->shutdown = 1;
			return (0);
		}

		/* If we haven't requested a metadata flush, ask for one now. */
		if (D->shuttingdown == 1) {
			if (metadata_flush(D->MD))
				goto err0;
			D->shuttingdown = 2;
		}

		/* Either way, return without issuing any more deletes. */
		return (0);
	}

	/* Can we issue more deletes? */
	while ((D->M < D->N) &&
	    (D->npending < MAXINPROGRESS) &&
	    (D->M < metadata_deletedto_read(D->MD) + MAXUNRECORDED)) {
		/* Bake a cookie for deleting M. */
		if ((D1 = malloc(sizeof(struct delete))) == NULL)
			goto err0;
		D1->D = D;
		D1->N = D->M;
		D1->prev = D->ip_tail;
		D1->next = NULL;
		if (D->ip_head == NULL)
			D->ip_head = D1;
		else
			D->ip_tail->next = D1;
		D->ip_tail = D1;

		/* Issue the delete. */
		if (proto_dynamodb_kv_request_delete(D->Q, objmap(D->M),
		    callback_done, D1))
			goto err0;
		D->npending++;

		/* We've issued deletes for everything under one more. */
		D->M++;
	}

	/*
	 * If the stored deletedto value is far behind, ask for a flush.  Under
	 * normal circumstances this won't be necessary as the metadata will be
	 * flushed frequently enough in response to data being written; this
	 * will only kick in if writes are quiescent and we're catching up on a
	 * large backlog of deletes.
	 */
	if ((deletedto - metadata_deletedto_read(D->MD) > MAXUNRECORDED / 2) &&
	    (deletedto - D->flushed > MAXUNRECORDED / 4)) {
		D->flushed = deletedto;
		if (metadata_flush(D->MD))
			goto err0;
	}

	/* Success! */
	return (0);

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x8(%rdi), %rdi
movq 0x38(%rbx), %rax
leaq 0x8(%rax), %rcx
leaq 0x18(%rbx), %rdx
testq %rax, %rax
cmoveq %rdx, %rcx
movq (%rcx), %r14
movq %r14, %rsi
callq 0x4116
cmpl $0x0, 0x30(%rbx)
je 0x3a4d
xorl %ebp, %ebp
cmpq $0x0, 0x28(%rbx)
jne 0x3b49
movq 0x8(%rbx), %rdi
callq 0x4111
cmpq %r14, %rax
jne 0x3b33
movl $0x1, 0x34(%rbx)
jmp 0x3b49
leaq 0x38(%rbx), %r12
movq 0x18(%rbx), %r13
pushq $0x20
popq %r15
cmpq 0x10(%rbx), %r13
jae 0x3af7
cmpq $0x3f, 0x28(%rbx)
ja 0x3af7
movq 0x8(%rbx), %rdi
callq 0x4111
addq $0x1f40, %rax           # imm = 0x1F40
cmpq %rax, %r13
jae 0x3af7
movq %r15, %rdi
callq 0x2270
testq %rax, %rax
je 0x3b46
movq %rax, %r13
movq %rbx, (%rax)
movq 0x18(%rbx), %rdi
movq %rdi, 0x8(%rax)
movq 0x40(%rbx), %rax
movq %rax, 0x10(%r13)
andq $0x0, 0x18(%r13)
addq $0x18, %rax
cmpq $0x0, 0x38(%rbx)
cmoveq %r12, %rax
movq %r13, (%rax)
movq %r13, 0x40(%rbx)
movq (%rbx), %rbp
callq 0x42c4
movq %rbp, %rdi
movq %rax, %rsi
leaq 0xea(%rip), %rdx        # 0x3bc1
movq %r13, %rcx
callq 0x930d
testl %eax, %eax
jne 0x3b46
incq 0x28(%rbx)
movq 0x18(%rbx), %r13
incq %r13
movq %r13, 0x18(%rbx)
jmp 0x3a59
movq 0x8(%rbx), %rdi
callq 0x4111
movq %r14, %rcx
subq %rax, %rcx
xorl %ebp, %ebp
cmpq $0xfa1, %rcx            # imm = 0xFA1
jb 0x3b49
movq %r14, %rax
subq 0x20(%rbx), %rax
cmpq $0x7d1, %rax            # imm = 0x7D1
jb 0x3b49
movq %r14, 0x20(%rbx)
movq 0x8(%rbx), %rdi
callq 0x412a
testl %eax, %eax
jne 0x3b46
jmp 0x3b49
cmpl $0x1, 0x30(%rbx)
jne 0x3b49
movq 0x8(%rbx), %rdi
callq 0x412a
testl %eax, %eax
je 0x3b5a
pushq $-0x1
popq %rbp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x2, 0x30(%rbx)
jmp 0x3b49