// File: /workspace/github_c_makefile_star2_O0/Tarsnap[P]kivaloo/lbs-s3/deleteto.c
// Function: poke
static int
poke(struct deleteto * D)
{
	uint64_t BIT;
	uint64_t X;
	uint8_t DeletedMarker[8];

	/* If we're trying to shut down, don't do anything. */
	if (D->shuttingdown)
		return (0);

	/* If operations are already in progress, don't do anything. */
	if (! D->idle)
		return (0);

	/* Sanity-check. */
	assert(D->npending == 0);

	/*
	 * Store the M to object DeletedMarker if it's a multiple of 256
	 * (periodic stores so DeletedMarker doesn't fall too far behind
	 * reality if we are doing a very large number of deletes) and we
	 * haven't yet stored this value of M.
	 *
	 * If we crash and restart, we may end up re-issuing as many as ~256
	 * deletes; but this is better than more-frequent updating of the
	 * deletion marker since (a) DELETEs are free but PUTs aren't, and
	 * (b) we want to optimize for the common case, which is a long-lived
	 * lbs-s3 process.
	 */
	if ((D->M % 256 == 0) && (D->updateDeletedTo == 1)) {
		D->idle = 0;
		D->npending += 1;
		be64enc(DeletedMarker, D->M);
		if (proto_s3_request_put(D->Q, D->bucket, "DeletedMarker",
		    8, DeletedMarker, callback_done, D))
			goto err0;
		D->updateDeletedTo = 0;
	}

	/* If we can't delete anything, don't. */
	if (D->N <= D->M)
		return (0);

	/*
	 * We want to run one step of the DeleteTo algorithm: Delete or
	 * overwrite objects which are needed by M but not by M+1, and
	 * increment M.  If nothing needs to be done, we'll repeat the
	 * process for the new (incremented) M.
	 */

	/* For each bit... */
	for (BIT = 1; BIT != 0; BIT += BIT) {
		/* If it's set in M but not in M+1... */
		if (((D->M & BIT) == BIT) &&
		    (((D->M + 1) & BIT) == 0)) {
			/* M - M % BIT is deletable... */
			X = D->M - (D->M % BIT);

			/* ... unless it's a power of two. */
			if (X == BIT)
				continue;

			/* Issue a delete. */
			D->idle = 0;
			D->npending += 1;
			if (proto_s3_request_delete(D->Q, D->bucket,
			    objmap(X), callback_done, D))
				goto err0;
		}
	}

	/*
	 * Powers of 2 will never be DELETEd, and multiples of 256 can't be
	 * deleted until at least 256 iterations later (since N = ...abcdefgh)
	 * needs the file ...00000000 to still exist), but we don't need the
	 * data for M any more; so issue an empty PUT for it if it falls into
	 * one of those two categories.
	 */
	if (((D->M & (D->M-1)) == 0) || ((D->M % 256) == 0)) {
		D->idle = 0;
		D->npending += 1;
		if (proto_s3_request_put(D->Q, D->bucket, objmap(D->M),
		    0, NULL, callback_done, D))
			goto err0;
	}

	/* We've issued all the deletes needed for this M. */
	D->M = D->M + 1;
	D->updateDeletedTo = 1;

	/* If we haven't found anything to do yet, poke ourselves again. */
	if (D->idle)
		return (poke(D));

	/* Success! */
	return (0);

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

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x38(%rax)
je 0x47e2
movl $0x0, -0x4(%rbp)
jmp 0x4aa6
movq -0x10(%rbp), %rax
cmpl $0x0, 0x30(%rax)
jne 0x47f8
movl $0x0, -0x4(%rbp)
jmp 0x4aa6
movq -0x10(%rbp), %rax
cmpq $0x0, 0x28(%rax)
jne 0x4805
jmp 0x4824
leaq 0xfcaf(%rip), %rdi      # 0x144bb
leaq 0x1002e(%rip), %rsi     # 0x14841
movl $0xa8, %edx
leaq 0x1002d(%rip), %rcx     # 0x1484c
callq 0x21c0
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
andq $0xff, %rax
cmpq $0x0, %rax
jne 0x48b6
movq -0x10(%rbp), %rax
cmpl $0x1, 0x34(%rax)
jne 0x48b6
movq -0x10(%rbp), %rax
movl $0x0, 0x30(%rax)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x28(%rax)
leaq -0x28(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rsi
callq 0x4b90
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
leaq -0x28(%rbp), %r8
movq -0x10(%rbp), %rax
leaq 0xff32(%rip), %rdx      # 0x147be
movl $0x8, %ecx
leaq 0x3c8(%rip), %r9        # 0x4c60
movq %rax, (%rsp)
callq 0xea80
cmpl $0x0, %eax
je 0x48ab
jmp 0x4a9f
movq -0x10(%rbp), %rax
movl $0x0, 0x34(%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0x18(%rcx), %rax
ja 0x48d4
movl $0x0, -0x4(%rbp)
jmp 0x4aa6
movq $0x1, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x49bf
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
andq -0x18(%rbp), %rax
cmpq -0x18(%rbp), %rax
jne 0x49ac
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
addq $0x1, %rax
andq -0x18(%rbp), %rax
cmpq $0x0, %rax
jne 0x49ac
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
xorl %ecx, %ecx
movl %ecx, %edx
divq -0x18(%rbp)
movq -0x30(%rbp), %rax
subq %rdx, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
cmpq -0x18(%rbp), %rax
jne 0x494a
jmp 0x49ae
movq -0x10(%rbp), %rax
movl $0x0, 0x30(%rax)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x28(%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x20(%rbp), %rdi
callq 0x5060
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq %rax, %rdx
movq -0x10(%rbp), %r8
leaq 0x2c5(%rip), %rcx       # 0x4c60
callq 0xf940
cmpl $0x0, %eax
je 0x49aa
jmp 0x4a9f
jmp 0x49ac
jmp 0x49ae
movq -0x18(%rbp), %rax
addq -0x18(%rbp), %rax
movq %rax, -0x18(%rbp)
jmp 0x48dc
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x18(%rcx), %rcx
subq $0x1, %rcx
andq %rcx, %rax
cmpq $0x0, %rax
je 0x49f0
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
andq $0xff, %rax
cmpq $0x0, %rax
jne 0x4a5f
movq -0x10(%rbp), %rax
movl $0x0, 0x30(%rax)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x28(%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x5060
movq -0x50(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq %rax, %rdx
movq -0x10(%rbp), %rax
xorl %ecx, %ecx
movl %ecx, %r8d
leaq 0x216(%rip), %r9        # 0x4c60
movq %r8, %rcx
movq %rax, (%rsp)
callq 0xea80
cmpl $0x0, %eax
je 0x4a5d
jmp 0x4a9f
jmp 0x4a5f
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rcx
addq $0x1, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rax
movl $0x1, 0x34(%rax)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x30(%rax)
je 0x4a96
movq -0x10(%rbp), %rdi
callq 0x47c0
movl %eax, -0x4(%rbp)
jmp 0x4aa6
movl $0x0, -0x4(%rbp)
jmp 0x4aa6
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nop