// File: /workspace/github_c_makefile_star2_O1/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 0x7280
movl %eax, %ebx
leaq 0x10(%rsp), %rsi
movl %eax, %edi
callq 0x35b0
testl %eax, %eax
je 0x72ad
callq 0x3040
cmpl $0x0, (%rax)
je 0x7348
movq %rax, %r15
leaq 0xa840(%rip), %rdi      # 0x11abb
jmp 0x737d
callq 0x3040
cmpl $0x0, (%rax)
je 0x7351
movq %rax, %rbx
leaq 0xa80a(%rip), %rdi      # 0x11aa2
movq %r14, %rsi
xorl %eax, %eax
callq 0x578c
movl $0x0, (%rbx)
jmp 0x7362
movl $0xf000, %eax           # imm = 0xF000
andl 0x28(%rsp), %eax
cmpl $0x8000, %eax           # imm = 0x8000
jne 0x7369
cmpq $0x0, 0x40(%rsp)
je 0x73e3
movl %ebx, %edi
movq $-0x1, %rsi
movl $0x2, %edx
callq 0x35f0
cmpq $-0x1, %rax
je 0x73f2
leaq 0xf(%rsp), %rsi
movl $0x1, %edx
movl %ebx, %edi
callq 0x3540
cmpq $0x1, %rax
jne 0x740b
cmpb $0xa, 0xf(%rsp)
je 0x73e3
leaq 0xf(%rsp), %rsi
movb $0xa, (%rsi)
movl $0x1, %edx
movl %ebx, %edi
callq 0xb90c
cmpq $0x1, %rax
je 0x73e3
callq 0x3040
cmpl $0x0, (%rax)
je 0x743c
movq %rax, %r15
leaq 0xa7c3(%rip), %rdi      # 0x11b09
jmp 0x737d
leaq 0xa76c(%rip), %rdi      # 0x11abb
jmp 0x7397
leaq 0xa74a(%rip), %rdi      # 0x11aa2
movq %r14, %rsi
xorl %eax, %eax
callq 0x58ab
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x73e3
callq 0x3040
cmpl $0x0, (%rax)
je 0x7390
movq %rax, %r15
leaq 0xa748(%rip), %rdi      # 0x11ac5
movq %r14, %rsi
xorl %eax, %eax
callq 0x578c
movl $0x0, (%r15)
jmp 0x73a1
leaq 0xa72e(%rip), %rdi      # 0x11ac5
movq %r14, %rsi
xorl %eax, %eax
callq 0x58ab
movl %ebx, %edi
callq 0x3640
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
testl %eax, %eax
je 0x73e3
callq 0x3040
cmpl $0x0, (%rax)
je 0x73d5
movq %rax, %r14
leaq 0x9e77(%rip), %rdi      # 0x1123c
xorl %eax, %eax
callq 0x578c
movl $0x0, (%r14)
jmp 0x73e3
leaq 0x9e60(%rip), %rdi      # 0x1123c
xorl %eax, %eax
callq 0x58ab
movl %ebx, %eax
addq $0xa0, %rsp
popq %rbx
popq %r14
popq %r15
retq
callq 0x3040
cmpl $0x0, (%rax)
je 0x7424
movq %rax, %r15
leaq 0xa6e2(%rip), %rdi      # 0x11ae8
jmp 0x737d
callq 0x3040
cmpl $0x0, (%rax)
je 0x7430
movq %rax, %r15
leaq 0xa6e1(%rip), %rdi      # 0x11b00
jmp 0x737d
leaq 0xa6bd(%rip), %rdi      # 0x11ae8
jmp 0x7397
leaq 0xa6c9(%rip), %rdi      # 0x11b00
jmp 0x7397
leaq 0xa6c6(%rip), %rdi      # 0x11b09
jmp 0x7397