// File: /workspace/github_c_makefile_star2_O3/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 0x479c
cmpl $0x0, 0x30(%rbx)
je 0x4061
xorl %ebp, %ebp
cmpq $0x0, 0x28(%rbx)
jne 0x4178
movq 0x8(%rbx), %rdi
callq 0x4797
cmpq %r14, %rax
jne 0x4160
movl $0x1, 0x34(%rbx)
jmp 0x4178
movq 0x18(%rbx), %r12
cmpq 0x10(%rbx), %r12
jae 0x4124
leaq 0x38(%rbx), %rbp
movq 0x28(%rbx), %rax
leaq 0x174(%rip), %r15       # 0x41f2
cmpq $0x3f, %rax
ja 0x4124
movq 0x8(%rbx), %rdi
callq 0x4797
addq $0x1f40, %rax           # imm = 0x1F40
cmpq %rax, %r12
jae 0x4124
movl $0x20, %edi
callq 0x2270
testq %rax, %rax
je 0x4173
movq %rax, %r12
movq %rbx, (%rax)
movq 0x18(%rbx), %rdi
movq %rdi, 0x8(%rax)
movq 0x40(%rbx), %rax
movq %rax, 0x10(%r12)
movq $0x0, 0x18(%r12)
addq $0x18, %rax
cmpq $0x0, 0x38(%rbx)
cmoveq %rbp, %rax
movq %r12, (%rax)
movq %r12, 0x40(%rbx)
movq (%rbx), %r13
callq 0x4954
movq %r13, %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r12, %rcx
callq 0xa0ad
testl %eax, %eax
jne 0x4173
movq 0x18(%rbx), %r12
movq 0x28(%rbx), %rax
incq %rax
movq %rax, 0x28(%rbx)
incq %r12
movq %r12, 0x18(%rbx)
cmpq 0x10(%rbx), %r12
jb 0x407e
movq 0x8(%rbx), %rdi
callq 0x4797
movq %r14, %rcx
subq %rax, %rcx
xorl %ebp, %ebp
cmpq $0xfa1, %rcx            # imm = 0xFA1
jb 0x4178
movq %r14, %rax
subq 0x20(%rbx), %rax
cmpq $0x7d1, %rax            # imm = 0x7D1
jb 0x4178
movq %r14, 0x20(%rbx)
movq 0x8(%rbx), %rdi
callq 0x47b0
testl %eax, %eax
jne 0x4173
jmp 0x4178
cmpl $0x1, 0x30(%rbx)
jne 0x4178
movq 0x8(%rbx), %rdi
callq 0x47b0
testl %eax, %eax
je 0x4189
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x2, 0x30(%rbx)
jmp 0x4178