// File: /workspace/github_c_makefile_star2_O2/Tarsnap[P]kivaloo/lbs/disk.c
// Function: disk_read
int
disk_read(const char * path, off_t offset, size_t nbytes, uint8_t * buf)
{
	int fd;
	size_t bufpos;
	ssize_t lenread;

	/*
	 * Attempt to open the file.  Pass an errno value of ENOENT back
	 * without printing a warning, since it might be a non-error.
	 */
	while ((fd = open(path, O_RDONLY | O_BINARY)) == -1) {
		/* Try again on EINTR. */
		if (errno == EINTR)
			continue;

		/* Fail without printing a warning on ENOENT. */
		if (errno == ENOENT)
			goto err0;

		/* Print a warning and fail for anything else. */
		warnp("open(%s)", path);
		goto err0;
	}

	/* Seek to the appropriate position. */
	if (lseek(fd, offset, SEEK_SET) == -1) {
		warnp("lseek(%s, %" PRIu64 ")", path, (uint64_t)(offset));
		goto err1;
	}

	/* Read into the buffer. */
	for (bufpos = 0; bufpos < nbytes; bufpos += (size_t)lenread) {
		/* Read some bytes. */
		lenread = read(fd, &buf[bufpos], nbytes - bufpos);

		/* EOF? */
		if (lenread == 0) {
			warn0("Unexpected EOF reading file: %s", path);
			goto err1;
		}

		/* EINTR is harmless. */
		if ((lenread == -1) && (errno == EINTR))
			lenread = 0;

		/* Print a warning and fail on other errors. */
		if (lenread == -1) {
			warnp("Error reading file: %s", path);
			goto err1;
		}
	}

	/* Close the file. */
	while (close(fd)) {
		if (errno != EINTR) {
			warnp("close(%s)", path);
			goto err0;
		}
	}

	/* Success! */
	return (0);

err1:
	if (close(fd))
		warnp("close");
err0:
	/* Failure! */
	return (-1);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rcx, %r14
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %rbx
movq %rbx, %rdi
xorl %esi, %esi
xorl %eax, %eax
callq 0x2460
cmpl $-0x1, %eax
jne 0x5200
callq 0x20a0
movq %rax, %r13
movl (%rax), %eax
cmpl $0x4, %eax
je 0x51b4
testl %eax, %eax
je 0x5291
cmpl $0x2, %eax
je 0x52a2
leaq 0x826a(%rip), %rdi      # 0xd456
movq %rbx, %rsi
xorl %eax, %eax
callq 0x9d39
andl $0x0, (%r13)
jmp 0x52a2
movl %eax, %ebp
movl %eax, %edi
movq %r12, %rsi
xorl %edx, %edx
callq 0x2210
cmpq $-0x1, %rax
je 0x52b6
xorl %r13d, %r13d
movq %r15, %rdx
subq %r13, %rdx
jbe 0x5258
leaq (%r14,%r13), %rsi
movl %ebp, %edi
callq 0x22b0
cmpq $-0x1, %rax
je 0x523e
testq %rax, %rax
jne 0x5253
jmp 0x530a
callq 0x20a0
movq %rax, %r12
movl (%rax), %eax
cmpl $0x4, %eax
jne 0x52dd
xorl %eax, %eax
addq %rax, %r13
jmp 0x521b
movl %ebp, %edi
callq 0x2240
testl %eax, %eax
je 0x537a
callq 0x20a0
movq %rax, %r14
movl (%rax), %eax
cmpl $0x4, %eax
je 0x5258
leaq 0x79f1(%rip), %rdi      # 0xcc6e
testl %eax, %eax
je 0x5298
movq %rbx, %rsi
xorl %eax, %eax
callq 0x9d39
andl $0x0, (%r14)
jmp 0x52a2
leaq 0x81be(%rip), %rdi      # 0xd456
movq %rbx, %rsi
xorl %eax, %eax
callq 0x9ec8
pushq $-0x1
popq %rbx
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x20a0
cmpl $0x0, (%rax)
je 0x52f4
movq %rax, %r14
leaq 0x79ae(%rip), %rdi      # 0xcc78
movq %rbx, %rsi
movq %r12, %rdx
xorl %eax, %eax
callq 0x9d39
andl $0x0, (%r14)
jmp 0x5331
leaq 0x79c3(%rip), %rdi      # 0xcca7
movq %rbx, %rsi
testl %eax, %eax
jne 0x5325
xorl %eax, %eax
callq 0x9ec8
jmp 0x5331
leaq 0x797d(%rip), %rdi      # 0xcc78
movq %rbx, %rsi
movq %r12, %rdx
xorl %eax, %eax
callq 0x9ec8
jmp 0x5331
leaq 0x7976(%rip), %rdi      # 0xcc87
movq %rbx, %rsi
xorl %eax, %eax
callq 0x9ec8
callq 0x20a0
andl $0x0, (%rax)
jmp 0x5331
xorl %eax, %eax
callq 0x9d39
andl $0x0, (%r12)
movl %ebp, %edi
callq 0x2240
pushq $-0x1
popq %rbx
testl %eax, %eax
je 0x52a5
callq 0x20a0
cmpl $0x0, (%rax)
je 0x5367
movq %rax, %r14
leaq 0x8115(%rip), %rdi      # 0xd46c
xorl %eax, %eax
callq 0x9d39
andl $0x0, (%r14)
jmp 0x52a5
leaq 0x80fe(%rip), %rdi      # 0xd46c
xorl %eax, %eax
callq 0x9ec8
jmp 0x52a5
xorl %ebx, %ebx
jmp 0x52a5