// File: /workspace/github_c_makefile_star2_O2/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 %r15
pushq %r14
pushq %rbx
subq $0xa0, %rsp
movq %rdi, %r14
movl $0x442, %esi            # imm = 0x442
movl $0x1a4, %edx            # imm = 0x1A4
xorl %eax, %eax
callq 0x3240
cmpl $-0x1, %eax
je 0x6cdb
movl %eax, %ebx
leaq 0x10(%rsp), %rsi
movl %eax, %edi
callq 0x35c0
testl %eax, %eax
je 0x6d05
callq 0x3040
cmpl $0x0, (%rax)
je 0x6d96
movq %rax, %r15
leaq 0x9c2d(%rip), %rdi      # 0x10903
jmp 0x6dc9
callq 0x3040
cmpl $0x0, (%rax)
je 0x6d9f
movq %rax, %rbx
leaq 0x9bf7(%rip), %rdi      # 0x108ea
movq %r14, %rsi
xorl %eax, %eax
callq 0x53ad
andl $0x0, (%rbx)
jmp 0x6db0
movl $0xf000, %eax           # imm = 0xF000
andl 0x28(%rsp), %eax
cmpl $0x8000, %eax           # imm = 0x8000
jne 0x6db5
cmpq $0x0, 0x40(%rsp)
je 0x6e27
pushq $-0x1
popq %rsi
pushq $0x2
popq %rdx
movl %ebx, %edi
callq 0x3600
cmpq $-0x1, %rax
je 0x6e36
leaq 0xf(%rsp), %rsi
pushq $0x1
popq %rdx
movl %ebx, %edi
callq 0x3550
cmpq $0x1, %rax
jne 0x6e4f
cmpb $0xa, 0xf(%rsp)
je 0x6e27
leaq 0xf(%rsp), %rsi
movb $0xa, (%rsi)
pushq $0x1
popq %rdx
movl %ebx, %edi
callq 0xab28
cmpq $0x1, %rax
je 0x6e27
callq 0x3040
cmpl $0x0, (%rax)
je 0x6e80
movq %rax, %r15
leaq 0x9bbd(%rip), %rdi      # 0x10951
jmp 0x6dc9
leaq 0x9b66(%rip), %rdi      # 0x10903
jmp 0x6de0
leaq 0x9b44(%rip), %rdi      # 0x108ea
movq %r14, %rsi
xorl %eax, %eax
callq 0x553c
pushq $-0x1
popq %rbx
jmp 0x6e27
callq 0x3040
cmpl $0x0, (%rax)
je 0x6dd9
movq %rax, %r15
leaq 0x9b44(%rip), %rdi      # 0x1090d
movq %r14, %rsi
xorl %eax, %eax
callq 0x53ad
andl $0x0, (%r15)
jmp 0x6dea
leaq 0x9b2d(%rip), %rdi      # 0x1090d
movq %r14, %rsi
xorl %eax, %eax
callq 0x553c
movl %ebx, %edi
callq 0x3650
pushq $-0x1
popq %rbx
testl %eax, %eax
je 0x6e27
callq 0x3040
cmpl $0x0, (%rax)
je 0x6e19
movq %rax, %r14
leaq 0x9405(%rip), %rdi      # 0x10211
xorl %eax, %eax
callq 0x53ad
andl $0x0, (%r14)
jmp 0x6e27
leaq 0x93f1(%rip), %rdi      # 0x10211
xorl %eax, %eax
callq 0x553c
movl %ebx, %eax
addq $0xa0, %rsp
popq %rbx
popq %r14
popq %r15
retq
callq 0x3040
cmpl $0x0, (%rax)
je 0x6e68
movq %rax, %r15
leaq 0x9ae6(%rip), %rdi      # 0x10930
jmp 0x6dc9
callq 0x3040
cmpl $0x0, (%rax)
je 0x6e74
movq %rax, %r15
leaq 0x9ae5(%rip), %rdi      # 0x10948
jmp 0x6dc9
leaq 0x9ac1(%rip), %rdi      # 0x10930
jmp 0x6de0
leaq 0x9acd(%rip), %rdi      # 0x10948
jmp 0x6de0
leaq 0x9aca(%rip), %rdi      # 0x10951
jmp 0x6de0