// File: /workspace/github_c_makefile_star2_O1/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 0x4752
cmpl $0x0, 0x30(%rbx)
je 0x403a
xorl %ebp, %ebp
cmpq $0x0, 0x28(%rbx)
jne 0x4143
movq 0x8(%rbx), %rdi
callq 0x474d
cmpq %r14, %rax
jne 0x412b
movl $0x1, 0x34(%rbx)
jmp 0x4143
movq 0x18(%rbx), %r12
cmpq 0x10(%rbx), %r12
jae 0x40ef
leaq 0x38(%rbx), %rbp
leaq 0x16a(%rip), %r15       # 0x41bd
cmpq $0x3f, 0x28(%rbx)
ja 0x40ef
movq 0x8(%rbx), %rdi
callq 0x474d
addq $0x1f40, %rax           # imm = 0x1F40
cmpq %rax, %r12
jae 0x40ef
movl $0x20, %edi
callq 0x2270
testq %rax, %rax
je 0x413e
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 0x4908
movq %r13, %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r12, %rcx
callq 0x9fc5
testl %eax, %eax
jne 0x413e
incq 0x28(%rbx)
movq 0x18(%rbx), %r12
incq %r12
movq %r12, 0x18(%rbx)
cmpq 0x10(%rbx), %r12
jb 0x4053
movq 0x8(%rbx), %rdi
callq 0x474d
movq %r14, %rcx
subq %rax, %rcx
xorl %ebp, %ebp
cmpq $0xfa1, %rcx            # imm = 0xFA1
jb 0x4143
movq %r14, %rax
subq 0x20(%rbx), %rax
cmpq $0x7d1, %rax            # imm = 0x7D1
jb 0x4143
movq %r14, 0x20(%rbx)
movq 0x8(%rbx), %rdi
callq 0x4766
testl %eax, %eax
jne 0x413e
jmp 0x4143
cmpl $0x1, 0x30(%rbx)
jne 0x4143
movq 0x8(%rbx), %rdi
callq 0x4766
testl %eax, %eax
je 0x4154
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 0x4143