// File: /workspace/github_c_makefile_star2_O3/Tarsnap[P]kivaloo/lbs/storage.c
// Function: storage_read
int
storage_read(struct storage_state * S, uint64_t blkno, uint8_t * buf)
{
	struct file_state * fs;
	size_t i;
	char * s = NULL;	/* free(NULL) simplifies error path. */
	struct timespec nstime;

	/* Grab a read lock. */
	if (storage_util_readlock(S))
		goto err0;

	/* Figure out if we have this block. */
	if ((blkno < S->minblk) || (blkno >= S->nextblk))
		goto enoent2;

	/* Figure out which file to read from, and at what position. */
	for (i = 0; ; i++) {
		fs = elasticqueue_get(S->files, i);
		assert(fs != NULL);
		if (blkno < fs->start + fs->len)
			break;
	}
	assert(fs->start <= blkno);

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

	/* Read the block. */
	if ((s = storage_util_mkpath(S, fs->start)) == NULL)
		goto err0;
	if (disk_read(s, (off_t)((blkno - fs->start) * S->blocklen),
	    S->blocklen, buf)) {
		/*
		 * If errno is ENOENT, we lost a race against the deleter
		 * thread.  The block does not exist.
		 */
		if (errno == ENOENT)
			goto enoent1;

		/* Anything else is an error. */
		goto err1;
	}
	free(s);

	/* Sleep the indicated duration. */
	if (S->latency) {
		nstime.tv_sec = 0;
		nstime.tv_nsec = S->latency;
		nanosleep(&nstime, NULL);
	}

	/* Success! */
	return (1);

enoent2:
	/* Release the lock. */
	if (storage_util_unlock(S))
		goto err1;
enoent1:
	free(s);

	/* This block is not available. */
	return (0);

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %r14
callq 0x56cc
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
testl %eax, %eax
jne 0x4fde
cmpq %r12, 0x68(%r14)
ja 0x4f6b
cmpq %r12, 0x70(%r14)
jbe 0x4f6b
movq 0x60(%r14), %rdi
xorl %esi, %esi
callq 0x5d95
testq %rax, %rax
je 0x4f4c
movq %rax, %r13
movl $0x1, %ebp
movq (%r13), %rax
movq 0x8(%r13), %rcx
addq %rax, %rcx
cmpq %r12, %rcx
ja 0x4f83
movq 0x60(%r14), %rdi
movq %rbp, %rsi
callq 0x5d95
movq %rax, %r13
incq %rbp
testq %rax, %rax
jne 0x4f25
leaq 0x8aa8(%rip), %rdi      # 0xd9fb
leaq 0x89a1(%rip), %rsi      # 0xd8fb
leaq 0x8aa5(%rip), %rcx      # 0xda06
movl $0xe5, %edx
callq 0x2220
movq %r14, %rdi
callq 0x5744
xorl %ebp, %ebp
testl %eax, %eax
je 0x4fd4
movq %rbp, %rdi
callq 0x2040
jmp 0x4fde
cmpq %r12, %rax
ja 0x501e
movq %r14, %rdi
callq 0x5744
testl %eax, %eax
jne 0x4fde
movq (%r13), %rsi
movq %r14, %rdi
callq 0x5780
testq %rax, %rax
je 0x4fde
movq %rax, %rbp
subq (%r13), %r12
movq 0x8(%r14), %rdx
imulq %rdx, %r12
movq %rax, %rdi
movq %r12, %rsi
movq %r15, %rcx
callq 0x58ee
testl %eax, %eax
je 0x4fef
callq 0x20a0
cmpl $0x2, (%rax)
jne 0x4f79
movq %rbp, %rdi
callq 0x2040
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbp, %rdi
callq 0x2040
movq 0x18(%r14), %rax
movl $0x1, %ebx
testq %rax, %rax
je 0x4fde
leaq 0x8(%rsp), %rdi
movq $0x0, (%rdi)
movq %rax, 0x8(%rdi)
xorl %esi, %esi
callq 0x21e0
jmp 0x4fde
leaq 0x8a1f(%rip), %rdi      # 0xda44
leaq 0x88cf(%rip), %rsi      # 0xd8fb
leaq 0x89d3(%rip), %rcx      # 0xda06
movl $0xe9, %edx
callq 0x2220