// File: /workspace/github_c_makefile_star2_O1/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 0x592c
callq 0x20a0
movq %rax, %r13
movl (%rax), %eax
cmpl $0x4, %eax
je 0x58dd
testl %eax, %eax
je 0x59ce
cmpl $0x2, %eax
je 0x59df
leaq 0x8b71(%rip), %rdi      # 0xe486
movq %rbx, %rsi
xorl %eax, %eax
callq 0xac18
movl $0x0, (%r13)
jmp 0x59df
movl %eax, %ebp
movl %eax, %edi
movq %r12, %rsi
xorl %edx, %edx
callq 0x2210
cmpq $-0x1, %rax
je 0x59f5
testq %r15, %r15
je 0x5992
xorl %r12d, %r12d
leaq (%r14,%r12), %rsi
movq %r15, %rdx
subq %r12, %rdx
movl %ebp, %edi
callq 0x22b0
cmpq $-0x1, %rax
je 0x596d
testq %rax, %rax
jne 0x5980
jmp 0x5a59
callq 0x20a0
movq %rax, %rcx
xorl %eax, %eax
cmpl $0x4, (%rcx)
setne %al
negq %rax
cmpq $-0x1, %rax
je 0x5a18
addq %rax, %r12
cmpq %r15, %r12
jb 0x594c
movl %ebp, %edi
callq 0x2240
testl %eax, %eax
je 0x5a55
callq 0x20a0
movq %rax, %r14
movl (%rax), %eax
cmpl $0x4, %eax
je 0x5992
leaq 0x82fb(%rip), %rdi      # 0xdcb2
testl %eax, %eax
je 0x59d5
movq %rbx, %rsi
xorl %eax, %eax
callq 0xac18
movl $0x0, (%r14)
jmp 0x59df
leaq 0x8ab1(%rip), %rdi      # 0xe486
movq %rbx, %rsi
xorl %eax, %eax
callq 0xad37
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 0x5a3f
movq %rax, %r14
leaq 0x82b3(%rip), %rdi      # 0xdcbc
movq %rbx, %rsi
movq %r12, %rdx
xorl %eax, %eax
callq 0xac18
jmp 0x5a36
callq 0x20a0
cmpl $0x0, (%rax)
je 0x5a77
movq %rax, %r14
leaq 0x82bf(%rip), %rdi      # 0xdceb
movq %rbx, %rsi
xorl %eax, %eax
callq 0xac18
movl $0x0, (%r14)
jmp 0x5a88
leaq 0x8276(%rip), %rdi      # 0xdcbc
movq %rbx, %rsi
movq %r12, %rdx
xorl %eax, %eax
callq 0xad37
jmp 0x5a88
xorl %ebx, %ebx
jmp 0x59e4
leaq 0x826b(%rip), %rdi      # 0xdccb
movq %rbx, %rsi
xorl %eax, %eax
callq 0xad37
callq 0x20a0
movl $0x0, (%rax)
jmp 0x5a88
leaq 0x826d(%rip), %rdi      # 0xdceb
movq %rbx, %rsi
xorl %eax, %eax
callq 0xad37
movl %ebp, %edi
callq 0x2240
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
testl %eax, %eax
je 0x59e4
callq 0x20a0
cmpl $0x0, (%rax)
je 0x5ac3
movq %rax, %r14
leaq 0x89ec(%rip), %rdi      # 0xe49c
xorl %eax, %eax
callq 0xac18
movl $0x0, (%r14)
jmp 0x59e4
leaq 0x89d2(%rip), %rdi      # 0xe49c
xorl %eax, %eax
callq 0xad37
jmp 0x59e4