// File: /workspace/github_c_makefile_star2_O0/Tarsnap[P]kivaloo/liball/../lib/logging/logging.c
// Function: doopen
static int
doopen(const char * path)
{
	struct stat sb;
	int fd;
	char lastbyte;

	/* Attempt to open the file. */
	if ((fd = open(path, O_RDWR | O_APPEND | O_CREAT,
	    S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) == -1) {
		warnp("Cannot open log file: %s", path);
		goto err0;
	}

	/* Make sure the log file we opened is a regular file. */
	if (fstat(fd, &sb)) {
		warnp("fstat(%s)", path);
		goto err1;
	}
	if (! S_ISREG(sb.st_mode)) {
		warnp("Log file is not a regular file: %s", path);
		goto err1;
	}

	/* If the file is empty, it doesn't need EOL-termination. */
	if (sb.st_size == 0)
		goto done;

	/* Check if the last byte of the file is '\n'. */
	if (lseek(fd, -1, SEEK_END) == -1) {
		warnp("lseek(%s, -1, SEEK_END)", path);
		goto err1;
	}
	if (read(fd, &lastbyte, 1) != 1) {
		warnp("read(%s)", path);
		goto err1;
	}
	if (lastbyte == '\n')
		goto done;

	/* EOL-terminate the file. */
	lastbyte = '\n';
	if (noeintr_write(fd, &lastbyte, 1) != 1) {
		warnp("Cannot EOL-terminate log file: %s", path);
		goto err1;
	}

done:
	/* Success! */
	return (fd);

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

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
movl $0x442, %esi            # imm = 0x442
movl $0x1a4, %edx            # imm = 0x1A4
movb $0x0, %al
callq 0x3270
movl %eax, -0xa4(%rbp)
cmpl $-0x1, %eax
jne 0x9b23
jmp 0x9ae1
callq 0x3040
cmpl $0x0, (%rax)
je 0x9b0a
movq -0x10(%rbp), %rsi
leaq 0x15090(%rip), %rdi     # 0x1eb86
movb $0x0, %al
callq 0x66e0
callq 0x3040
movl $0x0, (%rax)
jmp 0x9b1c
movq -0x10(%rbp), %rsi
leaq 0x15071(%rip), %rdi     # 0x1eb86
movb $0x0, %al
callq 0x6930
jmp 0x9b1e
jmp 0x9d6d
movl -0xa4(%rbp), %edi
leaq -0xa0(%rbp), %rsi
callq 0x35b0
cmpl $0x0, %eax
je 0x9b7e
jmp 0x9b3c
callq 0x3040
cmpl $0x0, (%rax)
je 0x9b65
movq -0x10(%rbp), %rsi
leaq 0x1504e(%rip), %rdi     # 0x1eb9f
movb $0x0, %al
callq 0x66e0
callq 0x3040
movl $0x0, (%rax)
jmp 0x9b77
movq -0x10(%rbp), %rsi
leaq 0x1502f(%rip), %rdi     # 0x1eb9f
movb $0x0, %al
callq 0x6930
jmp 0x9b79
jmp 0x9d22
movl -0x88(%rbp), %eax
andl $0xf000, %eax           # imm = 0xF000
cmpl $0x8000, %eax           # imm = 0x8000
je 0x9bd4
jmp 0x9b92
callq 0x3040
cmpl $0x0, (%rax)
je 0x9bbb
movq -0x10(%rbp), %rsi
leaq 0x15002(%rip), %rdi     # 0x1eba9
movb $0x0, %al
callq 0x66e0
callq 0x3040
movl $0x0, (%rax)
jmp 0x9bcd
movq -0x10(%rbp), %rsi
leaq 0x14fe3(%rip), %rdi     # 0x1eba9
movb $0x0, %al
callq 0x6930
jmp 0x9bcf
jmp 0x9d22
cmpq $0x0, -0x70(%rbp)
jne 0x9be0
jmp 0x9d17
movl -0xa4(%rbp), %edi
movq $-0x1, %rsi
movl $0x2, %edx
callq 0x3600
cmpq $-0x1, %rax
jne 0x9c41
jmp 0x9bff
callq 0x3040
cmpl $0x0, (%rax)
je 0x9c28
movq -0x10(%rbp), %rsi
leaq 0x14fb8(%rip), %rdi     # 0x1ebcc
movb $0x0, %al
callq 0x66e0
callq 0x3040
movl $0x0, (%rax)
jmp 0x9c3a
movq -0x10(%rbp), %rsi
leaq 0x14f99(%rip), %rdi     # 0x1ebcc
movb $0x0, %al
callq 0x6930
jmp 0x9c3c
jmp 0x9d22
movl -0xa4(%rbp), %edi
leaq -0xa5(%rbp), %rsi
movl $0x1, %edx
callq 0x3540
cmpq $0x1, %rax
je 0x9ca2
jmp 0x9c60
callq 0x3040
cmpl $0x0, (%rax)
je 0x9c89
movq -0x10(%rbp), %rsi
leaq 0x14f6f(%rip), %rdi     # 0x1ebe4
movb $0x0, %al
callq 0x66e0
callq 0x3040
movl $0x0, (%rax)
jmp 0x9c9b
movq -0x10(%rbp), %rsi
leaq 0x14f50(%rip), %rdi     # 0x1ebe4
movb $0x0, %al
callq 0x6930
jmp 0x9c9d
jmp 0x9d22
movsbl -0xa5(%rbp), %eax
cmpl $0xa, %eax
jne 0x9cb0
jmp 0x9d17
movb $0xa, -0xa5(%rbp)
movl -0xa4(%rbp), %edi
leaq -0xa5(%rbp), %rsi
movl $0x1, %edx
callq 0x10d50
cmpq $0x1, %rax
je 0x9d15
jmp 0x9cd6
callq 0x3040
cmpl $0x0, (%rax)
je 0x9cff
movq -0x10(%rbp), %rsi
leaq 0x14f02(%rip), %rdi     # 0x1ebed
movb $0x0, %al
callq 0x66e0
callq 0x3040
movl $0x0, (%rax)
jmp 0x9d11
movq -0x10(%rbp), %rsi
leaq 0x14ee3(%rip), %rdi     # 0x1ebed
movb $0x0, %al
callq 0x6930
jmp 0x9d13
jmp 0x9d22
jmp 0x9d17
movl -0xa4(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x9d74
movl -0xa4(%rbp), %edi
callq 0x3650
cmpl $0x0, %eax
je 0x9d6b
jmp 0x9d34
callq 0x3040
cmpl $0x0, (%rax)
je 0x9d59
leaq 0x144cc(%rip), %rdi     # 0x1e211
movb $0x0, %al
callq 0x66e0
callq 0x3040
movl $0x0, (%rax)
jmp 0x9d67
leaq 0x144b1(%rip), %rdi     # 0x1e211
movb $0x0, %al
callq 0x6930
jmp 0x9d69
jmp 0x9d6b
jmp 0x9d6d
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0xb0, %rsp
popq %rbp
retq