// File: /workspace/github_c_makefile_star2_O3/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 0x3230
cmpl $-0x1, %eax
je 0x7114
movl %eax, %ebx
leaq 0x10(%rsp), %rsi
movl %eax, %edi
callq 0x35b0
testl %eax, %eax
je 0x7141
callq 0x3040
cmpl $0x0, (%rax)
je 0x71dc
movq %rax, %r15
leaq 0xa824(%rip), %rdi      # 0x11933
jmp 0x7211
callq 0x3040
cmpl $0x0, (%rax)
je 0x71e5
movq %rax, %rbx
leaq 0xa7ee(%rip), %rdi      # 0x1191a
movq %r14, %rsi
xorl %eax, %eax
callq 0x57b8
movl $0x0, (%rbx)
jmp 0x71f6
movl $0xf000, %eax           # imm = 0xF000
andl 0x28(%rsp), %eax
cmpl $0x8000, %eax           # imm = 0x8000
jne 0x71fd
cmpq $0x0, 0x40(%rsp)
je 0x7277
movl %ebx, %edi
movq $-0x1, %rsi
movl $0x2, %edx
callq 0x35f0
cmpq $-0x1, %rax
je 0x7286
leaq 0xf(%rsp), %rsi
movl $0x1, %edx
movl %ebx, %edi
callq 0x3540
cmpq $0x1, %rax
jne 0x729f
cmpb $0xa, 0xf(%rsp)
je 0x7277
leaq 0xf(%rsp), %rsi
movb $0xa, (%rsi)
movl $0x1, %edx
movl %ebx, %edi
callq 0xb7b8
cmpq $0x1, %rax
je 0x7277
callq 0x3040
cmpl $0x0, (%rax)
je 0x72d0
movq %rax, %r15
leaq 0xa7a7(%rip), %rdi      # 0x11981
jmp 0x7211
leaq 0xa750(%rip), %rdi      # 0x11933
jmp 0x722b
leaq 0xa72e(%rip), %rdi      # 0x1191a
movq %r14, %rsi
xorl %eax, %eax
callq 0x58d7
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x7277
callq 0x3040
cmpl $0x0, (%rax)
je 0x7224
movq %rax, %r15
leaq 0xa72c(%rip), %rdi      # 0x1193d
movq %r14, %rsi
xorl %eax, %eax
callq 0x57b8
movl $0x0, (%r15)
jmp 0x7235
leaq 0xa712(%rip), %rdi      # 0x1193d
movq %r14, %rsi
xorl %eax, %eax
callq 0x58d7
movl %ebx, %edi
callq 0x3640
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
testl %eax, %eax
je 0x7277
callq 0x3040
cmpl $0x0, (%rax)
je 0x7269
movq %rax, %r14
leaq 0x9fe3(%rip), %rdi      # 0x1123c
xorl %eax, %eax
callq 0x57b8
movl $0x0, (%r14)
jmp 0x7277
leaq 0x9fcc(%rip), %rdi      # 0x1123c
xorl %eax, %eax
callq 0x58d7
movl %ebx, %eax
addq $0xa0, %rsp
popq %rbx
popq %r14
popq %r15
retq
callq 0x3040
cmpl $0x0, (%rax)
je 0x72b8
movq %rax, %r15
leaq 0xa6c6(%rip), %rdi      # 0x11960
jmp 0x7211
callq 0x3040
cmpl $0x0, (%rax)
je 0x72c4
movq %rax, %r15
leaq 0xa6c5(%rip), %rdi      # 0x11978
jmp 0x7211
leaq 0xa6a1(%rip), %rdi      # 0x11960
jmp 0x722b
leaq 0xa6ad(%rip), %rdi      # 0x11978
jmp 0x722b
leaq 0xa6aa(%rip), %rdi      # 0x11981
jmp 0x722b