// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x10(%rbp), %rdi
callq 0x6880
cmpl $0x0, %eax
je 0x5caf
jmp 0x5e46
movq -0x18(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x68(%rcx), %rax
jb 0x5ccb
movq -0x18(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x70(%rcx), %rax
jb 0x5cd0
jmp 0x5e19
movq $0x0, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rdi
movq -0x30(%rbp), %rsi
callq 0x72b0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x5cf6
jmp 0x5d15
leaq 0xcf1e(%rip), %rdi      # 0x12c1b
leaq 0xce17(%rip), %rsi      # 0x12b1b
movl $0xe5, %edx
leaq 0xcf16(%rip), %rcx      # 0x12c26
callq 0x2240
movq -0x18(%rbp), %rax
movq -0x28(%rbp), %rcx
movq (%rcx), %rcx
movq -0x28(%rbp), %rdx
addq 0x8(%rdx), %rcx
cmpq %rcx, %rax
jae 0x5d2f
jmp 0x5d3f
jmp 0x5d31
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x5cd8
movq -0x28(%rbp), %rax
movq (%rax), %rax
cmpq -0x18(%rbp), %rax
ja 0x5d4e
jmp 0x5d6d
leaq 0xcf0f(%rip), %rdi      # 0x12c64
leaq 0xcdbf(%rip), %rsi      # 0x12b1b
movl $0xe9, %edx
leaq 0xcebe(%rip), %rcx      # 0x12c26
callq 0x2240
movq -0x10(%rbp), %rdi
callq 0x6960
cmpl $0x0, %eax
je 0x5d80
jmp 0x5e46
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rax
movq (%rax), %rsi
callq 0x69d0
movq %rax, -0x38(%rbp)
cmpq $0x0, %rax
jne 0x5d9f
jmp 0x5e46
movq -0x38(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x28(%rbp), %rax
subq (%rax), %rsi
movq -0x10(%rbp), %rax
imulq 0x8(%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdx
movq -0x20(%rbp), %rcx
callq 0x6bf0
cmpl $0x0, %eax
je 0x5ddb
callq 0x20a0
cmpl $0x2, (%rax)
jne 0x5dd9
jmp 0x5e2b
jmp 0x5e3d
movq -0x38(%rbp), %rdi
callq 0x2040
movq -0x10(%rbp), %rax
cmpq $0x0, 0x18(%rax)
je 0x5e10
movq $0x0, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x40(%rbp)
leaq -0x48(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x2200
movl $0x1, -0x4(%rbp)
jmp 0x5e4d
movq -0x10(%rbp), %rdi
callq 0x6960
cmpl $0x0, %eax
je 0x5e29
jmp 0x5e3d
jmp 0x5e2b
movq -0x38(%rbp), %rdi
callq 0x2040
movl $0x0, -0x4(%rbp)
jmp 0x5e4d
movq -0x38(%rbp), %rdi
callq 0x2040
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)