// File: /workspace/github_c_makefile_star2_O0/Tarsnap[P]kivaloo/lbs/disk.c
// Function: disk_write
int
disk_write(const char * path, int create, size_t nbytes, const uint8_t * buf,
    int nosync)
{
	int fd;

	/* Open or create the file, depending on ${creat}. */
	do {
		/* Attempt to open/create. */
		if (create) {
			fd = open(path, O_WRONLY | O_BINARY | O_APPEND |
			    O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
		} else {
			fd = open(path, O_WRONLY | O_BINARY | O_APPEND);
		}

		/* If we hit EINTR, try again. */
	} while ((fd == -1) && (errno == EINTR));

	/* If we failed to open the file, error out. */
	if (fd == -1) {
		warnp("open(%s)", path);
		goto err0;
	}

	/* Write from the buffer. */
	if (noeintr_write(fd, buf, nbytes) != (ssize_t)nbytes)
		goto err1;

	/* Ask to have the write flushed to disk. */
	if (nosync == 0) {
		while (fsync(fd)) {
			if (errno != EINTR) {
				warnp("fsync(%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)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movl %r8d, -0x2c(%rbp)
cmpl $0x0, -0x14(%rbp)
je 0x6eab
movq -0x10(%rbp), %rdi
movl $0x4c1, %esi            # imm = 0x4C1
movl $0x180, %edx            # imm = 0x180
movb $0x0, %al
callq 0x2480
movl %eax, -0x30(%rbp)
jmp 0x6ebe
movq -0x10(%rbp), %rdi
movl $0x401, %esi            # imm = 0x401
movb $0x0, %al
callq 0x2480
movl %eax, -0x30(%rbp)
jmp 0x6ec0
xorl %eax, %eax
cmpl $-0x1, -0x30(%rbp)
movb %al, -0x31(%rbp)
jne 0x6ed9
callq 0x20a0
cmpl $0x4, (%rax)
sete %al
movb %al, -0x31(%rbp)
movb -0x31(%rbp), %al
testb $0x1, %al
jne 0x6e8b
cmpl $-0x1, -0x30(%rbp)
jne 0x6f2a
jmp 0x6ee8
callq 0x20a0
cmpl $0x0, (%rax)
je 0x6f11
movq -0x10(%rbp), %rsi
leaq 0xc711(%rip), %rdi      # 0x1360e
movb $0x0, %al
callq 0xf070
callq 0x20a0
movl $0x0, (%rax)
jmp 0x6f23
movq -0x10(%rbp), %rsi
leaq 0xc6f2(%rip), %rdi      # 0x1360e
movb $0x0, %al
callq 0xf2c0
jmp 0x6f25
jmp 0x7056
movl -0x30(%rbp), %edi
movq -0x28(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0xd2e0
cmpq -0x20(%rbp), %rax
je 0x6f45
jmp 0x700e
cmpl $0x0, -0x2c(%rbp)
jne 0x6fa9
jmp 0x6f4d
movl -0x30(%rbp), %edi
callq 0x2460
cmpl $0x0, %eax
je 0x6fa7
callq 0x20a0
cmpl $0x4, (%rax)
je 0x6fa5
jmp 0x6f66
callq 0x20a0
cmpl $0x0, (%rax)
je 0x6f8f
movq -0x10(%rbp), %rsi
leaq 0xbecd(%rip), %rdi      # 0x12e48
movb $0x0, %al
callq 0xf070
callq 0x20a0
movl $0x0, (%rax)
jmp 0x6fa1
movq -0x10(%rbp), %rsi
leaq 0xbeae(%rip), %rdi      # 0x12e48
movb $0x0, %al
callq 0xf2c0
jmp 0x6fa3
jmp 0x700e
jmp 0x6f4d
jmp 0x6fa9
jmp 0x6fab
movl -0x30(%rbp), %edi
callq 0x2260
cmpl $0x0, %eax
je 0x7005
callq 0x20a0
cmpl $0x4, (%rax)
je 0x7003
jmp 0x6fc4
callq 0x20a0
cmpl $0x0, (%rax)
je 0x6fed
movq -0x10(%rbp), %rsi
leaq 0xbe79(%rip), %rdi      # 0x12e52
movb $0x0, %al
callq 0xf070
callq 0x20a0
movl $0x0, (%rax)
jmp 0x6fff
movq -0x10(%rbp), %rsi
leaq 0xbe5a(%rip), %rdi      # 0x12e52
movb $0x0, %al
callq 0xf2c0
jmp 0x7001
jmp 0x7056
jmp 0x6fab
movl $0x0, -0x4(%rbp)
jmp 0x705d
movl -0x30(%rbp), %edi
callq 0x2260
cmpl $0x0, %eax
je 0x7054
jmp 0x701d
callq 0x20a0
cmpl $0x0, (%rax)
je 0x7042
leaq 0xc5f6(%rip), %rdi      # 0x13624
movb $0x0, %al
callq 0xf070
callq 0x20a0
movl $0x0, (%rax)
jmp 0x7050
leaq 0xc5db(%rip), %rdi      # 0x13624
movb $0x0, %al
callq 0xf2c0
jmp 0x7052
jmp 0x7054
jmp 0x7056
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)