// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x10(%rbp), %rdi
xorl %esi, %esi
movb $0x0, %al
callq 0x2480
movl %eax, -0x2c(%rbp)
cmpl $-0x1, %eax
jne 0x6c7c
callq 0x20a0
cmpl $0x4, (%rax)
jne 0x6c29
jmp 0x6c08
callq 0x20a0
cmpl $0x2, (%rax)
jne 0x6c38
jmp 0x6e5a
jmp 0x6c3a
callq 0x20a0
cmpl $0x0, (%rax)
je 0x6c63
movq -0x10(%rbp), %rsi
leaq 0xc9bf(%rip), %rdi      # 0x1360e
movb $0x0, %al
callq 0xf070
callq 0x20a0
movl $0x0, (%rax)
jmp 0x6c75
movq -0x10(%rbp), %rsi
leaq 0xc9a0(%rip), %rdi      # 0x1360e
movb $0x0, %al
callq 0xf2c0
jmp 0x6c77
jmp 0x6e5a
movl -0x2c(%rbp), %edi
movq -0x18(%rbp), %rsi
xorl %edx, %edx
callq 0x2230
cmpq $-0x1, %rax
jne 0x6cdc
jmp 0x6c92
callq 0x20a0
cmpl $0x0, (%rax)
je 0x6cbf
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
leaq 0xc1b1(%rip), %rdi      # 0x12e5c
movb $0x0, %al
callq 0xf070
callq 0x20a0
movl $0x0, (%rax)
jmp 0x6cd5
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
leaq 0xc18e(%rip), %rdi      # 0x12e5c
movb $0x0, %al
callq 0xf2c0
jmp 0x6cd7
jmp 0x6e12
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x20(%rbp), %rax
jae 0x6dad
movl -0x2c(%rbp), %edi
movq -0x28(%rbp), %rsi
addq -0x38(%rbp), %rsi
movq -0x20(%rbp), %rdx
subq -0x38(%rbp), %rdx
callq 0x22c0
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x6d39
jmp 0x6d17
movq -0x10(%rbp), %rsi
leaq 0xc149(%rip), %rdi      # 0x12e6b
movb $0x0, %al
callq 0xf2c0
callq 0x20a0
movl $0x0, (%rax)
jmp 0x6e12
cmpq $-0x1, -0x40(%rbp)
jne 0x6d52
callq 0x20a0
cmpl $0x4, (%rax)
jne 0x6d52
movq $0x0, -0x40(%rbp)
cmpq $-0x1, -0x40(%rbp)
jne 0x6d9a
jmp 0x6d5b
callq 0x20a0
cmpl $0x0, (%rax)
je 0x6d84
movq -0x10(%rbp), %rsi
leaq 0xc11b(%rip), %rdi      # 0x12e8b
movb $0x0, %al
callq 0xf070
callq 0x20a0
movl $0x0, (%rax)
jmp 0x6d96
movq -0x10(%rbp), %rsi
leaq 0xc0fc(%rip), %rdi      # 0x12e8b
movb $0x0, %al
callq 0xf2c0
jmp 0x6d98
jmp 0x6e12
jmp 0x6d9c
movq -0x40(%rbp), %rax
addq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
jmp 0x6ce4
jmp 0x6daf
movl -0x2c(%rbp), %edi
callq 0x2260
cmpl $0x0, %eax
je 0x6e09
callq 0x20a0
cmpl $0x4, (%rax)
je 0x6e07
jmp 0x6dc8
callq 0x20a0
cmpl $0x0, (%rax)
je 0x6df1
movq -0x10(%rbp), %rsi
leaq 0xc075(%rip), %rdi      # 0x12e52
movb $0x0, %al
callq 0xf070
callq 0x20a0
movl $0x0, (%rax)
jmp 0x6e03
movq -0x10(%rbp), %rsi
leaq 0xc056(%rip), %rdi      # 0x12e52
movb $0x0, %al
callq 0xf2c0
jmp 0x6e05
jmp 0x6e5a
jmp 0x6daf
movl $0x0, -0x4(%rbp)
jmp 0x6e61
movl -0x2c(%rbp), %edi
callq 0x2260
cmpl $0x0, %eax
je 0x6e58
jmp 0x6e21
callq 0x20a0
cmpl $0x0, (%rax)
je 0x6e46
leaq 0xc7f2(%rip), %rdi      # 0x13624
movb $0x0, %al
callq 0xf070
callq 0x20a0
movl $0x0, (%rax)
jmp 0x6e54
leaq 0xc7d7(%rip), %rdi      # 0x13624
movb $0x0, %al
callq 0xf2c0
jmp 0x6e56
jmp 0x6e58
jmp 0x6e5a
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw (%rax,%rax)