// File: /workspace/github_c_makefile_star2_O3/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 0x5954
callq 0x20a0
movq %rax, %r13
movl (%rax), %eax
cmpl $0x4, %eax
je 0x5905
testl %eax, %eax
je 0x59ee
cmpl $0x2, %eax
je 0x59ff
leaq 0x8ad9(%rip), %rdi      # 0xe416
movq %rbx, %rsi
xorl %eax, %eax
callq 0xacd8
movl $0x0, (%r13)
jmp 0x59ff
movl %eax, %ebp
movl %eax, %edi
movq %r12, %rsi
xorl %edx, %edx
callq 0x2210
cmpq $-0x1, %rax
je 0x5a15
testq %r15, %r15
je 0x59b2
xorl %r13d, %r13d
leaq (%r14,%r13), %rsi
movq %r15, %rdx
subq %r13, %rdx
movl %ebp, %edi
callq 0x22b0
cmpq $-0x1, %rax
je 0x5995
testq %rax, %rax
jne 0x59aa
jmp 0x5a70
callq 0x20a0
movq %rax, %r12
movl (%rax), %eax
cmpl $0x4, %eax
jne 0x5a3f
xorl %eax, %eax
addq %rax, %r13
cmpq %r15, %r13
jb 0x5974
movl %ebp, %edi
callq 0x2240
testl %eax, %eax
je 0x5a6c
callq 0x20a0
movq %rax, %r14
movl (%rax), %eax
cmpl $0x4, %eax
je 0x59b2
leaq 0x825b(%rip), %rdi      # 0xdc32
testl %eax, %eax
je 0x59f5
movq %rbx, %rsi
xorl %eax, %eax
callq 0xacd8
movl $0x0, (%r14)
jmp 0x59ff
leaq 0x8a21(%rip), %rdi      # 0xe416
movq %rbx, %rsi
xorl %eax, %eax
callq 0xadf7
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
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 0x5a56
movq %rax, %r14
leaq 0x8213(%rip), %rdi      # 0xdc3c
movq %rbx, %rsi
movq %r12, %rdx
xorl %eax, %eax
callq 0xacd8
movl $0x0, (%r14)
jmp 0x5a9d
leaq 0x8225(%rip), %rdi      # 0xdc6b
movq %rbx, %rsi
testl %eax, %eax
jne 0x5a8e
xorl %eax, %eax
callq 0xadf7
jmp 0x5a9d
leaq 0x81df(%rip), %rdi      # 0xdc3c
movq %rbx, %rsi
movq %r12, %rdx
xorl %eax, %eax
callq 0xadf7
jmp 0x5a9d
xorl %ebx, %ebx
jmp 0x5a04
leaq 0x81d4(%rip), %rdi      # 0xdc4b
movq %rbx, %rsi
xorl %eax, %eax
callq 0xadf7
callq 0x20a0
movl $0x0, (%rax)
jmp 0x5a9d
xorl %eax, %eax
callq 0xacd8
movl $0x0, (%r12)
movl %ebp, %edi
callq 0x2240
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
testl %eax, %eax
je 0x5a04
callq 0x20a0
cmpl $0x0, (%rax)
je 0x5ad8
movq %rax, %r14
leaq 0x8967(%rip), %rdi      # 0xe42c
xorl %eax, %eax
callq 0xacd8
movl $0x0, (%r14)
jmp 0x5a04
leaq 0x894d(%rip), %rdi      # 0xe42c
xorl %eax, %eax
callq 0xadf7
jmp 0x5a04