// File: /workspace/github_c_makefile_star2_O0/Tarsnap[P]kivaloo/lbs/storage.c
// Function: storage_delete
int
storage_delete(struct storage_state * S, uint64_t blkno)
{
	struct file_state * fs;
	uint64_t fileno;
	char * s;

	/* Loop until we don't need to delete anything. */
	do {
		/*
		 * First, figure out if we need to delete a file; if we do,
		 * remove it from the file queue.
		 */

		/* Grab a write lock. */
		if (storage_util_writelock(S))
			goto err0;

		/* If we have less than 2 files, don't delete anything. */
		if (elasticqueue_getlen(S->files) < 2)
			break;

		/* If the first file has blocks we need, don't delete. */
		fs = elasticqueue_get(S->files, 0);
		if (fs->start + fs->len > blkno)
			break;

		/* We want to delete the first file. */
		fileno = fs->start;

		/* Remove the file from the file queue. */
		elasticqueue_delete(S->files);

		/* Adjust our first-block-held value. */
		fs = elasticqueue_get(S->files, 0);
		S->minblk = fs->start;

		/* Release the lock. */
		if (storage_util_unlock(S))
			goto err0;

		/*
		 * Delete the file.  We don't need to worry about racing
		 * against the writer, since we will never delete the last
		 * file; and racing against readers is handled by readers
		 * treating ENOENT properly.
		 */
		if ((s = storage_util_mkpath(S, fileno)) == NULL)
			goto err0;
		if (unlink(s)) {
			warnp("unlink(%s)", s);
			goto err1;
		}
		free(s);

		/* Make sure the file deletion is flushed to disk. */
		if (disk_syncdir(S->storagedir))
			goto err0;
	} while (1);

	/* Release the write lock. */
	if (storage_util_unlock(S))
		goto err0;

	/* Success! */
	return (0);

err1:
	free(s);
err0:

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

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rdi
callq 0x68f0
cmpl $0x0, %eax
je 0x6183
jmp 0x62d0
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rdi
callq 0x7290
cmpq $0x2, %rax
jae 0x619b
jmp 0x62ae
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x72b0
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq -0x20(%rbp), %rcx
addq 0x8(%rcx), %rax
cmpq -0x18(%rbp), %rax
jbe 0x61ca
jmp 0x62ae
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rdi
callq 0x7190
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x72b0
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x68(%rax)
movq -0x10(%rbp), %rdi
callq 0x6960
cmpl $0x0, %eax
je 0x6219
jmp 0x62d0
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x69d0
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
jne 0x6235
jmp 0x62d0
movq -0x30(%rbp), %rdi
callq 0x20b0
cmpl $0x0, %eax
je 0x6284
jmp 0x6245
callq 0x20a0
cmpl $0x0, (%rax)
je 0x626e
movq -0x30(%rbp), %rsi
leaq 0xcaec(%rip), %rdi      # 0x12d46
movb $0x0, %al
callq 0xf070
callq 0x20a0
movl $0x0, (%rax)
jmp 0x6280
movq -0x30(%rbp), %rsi
leaq 0xcacd(%rip), %rdi      # 0x12d46
movb $0x0, %al
callq 0xf2c0
jmp 0x6282
jmp 0x62c7
movq -0x30(%rbp), %rdi
callq 0x2040
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x6a60
cmpl $0x0, %eax
je 0x62a0
jmp 0x62d0
jmp 0x62a2
movb $0x1, %al
testb $0x1, %al
jne 0x6170
jmp 0x62ae
movq -0x10(%rbp), %rdi
callq 0x6960
cmpl $0x0, %eax
je 0x62be
jmp 0x62d0
movl $0x0, -0x4(%rbp)
jmp 0x62d7
movq -0x30(%rbp), %rdi
callq 0x2040
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq