// File: /workspace/github_c_makefile_star2_O1/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 0x56a4
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
testl %eax, %eax
jne 0x4fb6
cmpq %r12, 0x68(%r14)
ja 0x4f43
cmpq %r12, 0x70(%r14)
jbe 0x4f43
movq 0x60(%r14), %rdi
xorl %esi, %esi
callq 0x5d7f
testq %rax, %rax
je 0x4f24
movq %rax, %r13
movl $0x1, %ebp
movq (%r13), %rax
movq 0x8(%r13), %rcx
addq %rax, %rcx
cmpq %r12, %rcx
ja 0x4f5b
movq 0x60(%r14), %rdi
movq %rbp, %rsi
callq 0x5d7f
movq %rax, %r13
incq %rbp
testq %rax, %rax
jne 0x4efd
leaq 0x8b50(%rip), %rdi      # 0xda7b
leaq 0x8a49(%rip), %rsi      # 0xd97b
leaq 0x8b4d(%rip), %rcx      # 0xda86
movl $0xe5, %edx
callq 0x2220
movq %r14, %rdi
callq 0x571c
xorl %ebp, %ebp
testl %eax, %eax
je 0x4fac
movq %rbp, %rdi
callq 0x2040
jmp 0x4fb6
cmpq %r12, %rax
ja 0x4ff6
movq %r14, %rdi
callq 0x571c
testl %eax, %eax
jne 0x4fb6
movq (%r13), %rsi
movq %r14, %rdi
callq 0x5758
testq %rax, %rax
je 0x4fb6
movq %rax, %rbp
subq (%r13), %r12
movq 0x8(%r14), %rdx
imulq %rdx, %r12
movq %rax, %rdi
movq %r12, %rsi
movq %r15, %rcx
callq 0x58c6
testl %eax, %eax
je 0x4fc7
callq 0x20a0
cmpl $0x2, (%rax)
jne 0x4f51
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 0x4fb6
leaq 0x8(%rsp), %rdi
movq $0x0, (%rdi)
movq %rax, 0x8(%rdi)
xorl %esi, %esi
callq 0x21e0
jmp 0x4fb6
leaq 0x8ac7(%rip), %rdi      # 0xdac4
leaq 0x8977(%rip), %rsi      # 0xd97b
leaq 0x8a7b(%rip), %rcx      # 0xda86
movl $0xe9, %edx
callq 0x2220