// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
cmpq $0x0, 0x38(%rax)
je 0x46b1
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, -0x28(%rbp)
jmp 0x46bd
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x28(%rbp), %rsi
callq 0x5370
movq -0x18(%rbp), %rax
cmpl $0x0, 0x30(%rax)
je 0x4751
movq -0x18(%rbp), %rax
cmpq $0x0, 0x28(%rax)
je 0x46ef
movl $0x0, -0x4(%rbp)
jmp 0x4906
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x5350
cmpq -0x28(%rbp), %rax
jne 0x4719
movq -0x18(%rbp), %rax
movl $0x1, 0x34(%rax)
movl $0x0, -0x4(%rbp)
jmp 0x4906
movq -0x18(%rbp), %rax
cmpl $0x1, 0x30(%rax)
jne 0x4745
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x53c0
cmpl $0x0, %eax
je 0x473a
jmp 0x48ff
movq -0x18(%rbp), %rax
movl $0x2, 0x30(%rax)
movl $0x0, -0x4(%rbp)
jmp 0x4906
jmp 0x4753
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rcx
movq -0x18(%rbp), %rdx
xorl %eax, %eax
cmpq 0x10(%rdx), %rcx
movb %al, -0x29(%rbp)
jae 0x47aa
movq -0x18(%rbp), %rcx
xorl %eax, %eax
cmpq $0x40, 0x28(%rcx)
movb %al, -0x29(%rbp)
jae 0x47aa
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x5350
movq %rax, %rcx
movq -0x38(%rbp), %rax
addq $0x1f40, %rcx           # imm = 0x1F40
cmpq %rcx, %rax
setb %al
movb %al, -0x29(%rbp)
movb -0x29(%rbp), %al
testb $0x1, %al
jne 0x47b6
jmp 0x4899
movl $0x20, %edi
callq 0x2280
movq %rax, -0x20(%rbp)
cmpq $0x0, %rax
jne 0x47cf
jmp 0x48ff
movq -0x18(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x20(%rbp), %rax
movq $0x0, 0x18(%rax)
movq -0x18(%rbp), %rax
cmpq $0x0, 0x38(%rax)
jne 0x481f
movq -0x20(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x38(%rax)
jmp 0x482f
movq -0x20(%rbp), %rcx
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rax
movq %rcx, 0x18(%rax)
movq -0x20(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x5810
movq -0x40(%rbp), %rdi
movq %rax, %rsi
movq -0x20(%rbp), %rcx
leaq 0x16b(%rip), %rdx       # 0x49d0
callq 0xe1b0
cmpl $0x0, %eax
je 0x4874
jmp 0x48ff
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x28(%rax)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x18(%rax)
jmp 0x4753
movq -0x28(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x5350
movq %rax, %rcx
movq -0x48(%rbp), %rax
subq %rcx, %rax
cmpq $0xfa0, %rax            # imm = 0xFA0
jbe 0x48f6
movq -0x28(%rbp), %rax
movq -0x18(%rbp), %rcx
subq 0x20(%rcx), %rax
cmpq $0x7d0, %rax            # imm = 0x7D0
jbe 0x48f6
movq -0x28(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x53c0
cmpl $0x0, %eax
je 0x48f4
jmp 0x48ff
jmp 0x48f6
movl $0x0, -0x4(%rbp)
jmp 0x4906
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nop