// File: /workspace/github_c_makefile_star2_O1/erikdubbelboer[P]discnt/src/server.c
// Function: serverSupervisedSystemd
int serverSupervisedSystemd(void) {
    const char *notify_socket = getenv("NOTIFY_SOCKET");
    int fd = 1;
    struct sockaddr_un su;
    struct iovec iov;
    struct msghdr hdr;
    int sendto_flags = 0;

    if (!notify_socket) {
        serverLog(LL_WARNING,
                "systemd supervision requested, but NOTIFY_SOCKET not found");
        return 0;
    }

    if ((strchr("@/", notify_socket[0])) == NULL || strlen(notify_socket) < 2) {
        return 0;
    }

    serverLog(LL_NOTICE, "supervised by systemd, will signal readyness");
    if ((fd = socket(AF_UNIX, SOCK_DGRAM, 0)) == -1) {
        serverLog(LL_WARNING,
                "Can't connect to systemd socket %s", notify_socket);
        return 0;
    }

    memset(&su, 0, sizeof(su));
    su.sun_family = AF_UNIX;
    strncpy (su.sun_path, notify_socket, sizeof(su.sun_path) -1);
    su.sun_path[sizeof(su.sun_path) - 1] = '\0';

    if (notify_socket[0] == '@')
        su.sun_path[0] = '\0';

    memset(&iov, 0, sizeof(iov));
    iov.iov_base = "READY=1";
    iov.iov_len = strlen("READY=1");

    memset(&hdr, 0, sizeof(hdr));
    hdr.msg_name = &su;
    hdr.msg_namelen = offsetof(struct sockaddr_un, sun_path) +
        strlen(notify_socket);
    hdr.msg_iov = &iov;
    hdr.msg_iovlen = 1;

    unsetenv("NOTIFY_SOCKET");
#ifdef HAVE_MSG_NOSIGNAL
    sendto_flags |= MSG_NOSIGNAL;
#endif
    if (sendmsg(fd, &hdr, sendto_flags) < 0) {
        serverLog(LL_WARNING, "Can't send notification to systemd");
        close(fd);
        return 0;
    }
    close(fd);
    return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0xc0, %rsp
leaq 0x367d9(%rip), %rdi     # 0x53ede
callq 0x12050
testq %rax, %rax
je 0x1d859
movq %rax, %rbx
movsbl (%rax), %esi
leaq 0x36807(%rip), %rdi     # 0x53f27
movl $0x3, %edx
callq 0x12400
xorl %ebp, %ebp
testq %rax, %rax
je 0x1d86e
movq %rbx, %rdi
callq 0x12250
cmpq $0x2, %rax
jb 0x1d86e
leaq 0x367dc(%rip), %rsi     # 0x53f2a
xorl %ebp, %ebp
movl $0x2, %edi
xorl %eax, %eax
callq 0x19fb1
movl $0x1, %edi
movl $0x2, %esi
xorl %edx, %edx
callq 0x129e0
cmpl $-0x1, %eax
je 0x1d880
movl %eax, %r14d
xorps %xmm0, %xmm0
leaq 0x12(%rsp), %r15
movaps %xmm0, -0x2(%r15)
movups %xmm0, 0x5c(%r15)
movaps %xmm0, 0x4e(%r15)
movaps %xmm0, 0x3e(%r15)
movaps %xmm0, 0x2e(%r15)
movaps %xmm0, 0x1e(%r15)
movaps %xmm0, 0xe(%r15)
movw $0x1, -0x2(%r15)
movl $0x6b, %edx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x12100
movb $0x0, 0x6b(%r15)
cmpb $0x40, (%rbx)
jne 0x1d7ca
movb $0x0, 0x12(%rsp)
movq %rsp, %r12
xorps %xmm0, %xmm0
movaps %xmm0, (%r12)
leaq 0x3679e(%rip), %rax     # 0x53f7a
movq %rax, (%r12)
movq $0x7, 0x8(%r12)
leaq 0x80(%rsp), %r15
movaps %xmm0, (%r15)
movaps %xmm0, 0x10(%r15)
movaps %xmm0, 0x20(%r15)
movq $0x0, 0x30(%r15)
leaq 0x10(%rsp), %rax
movq %rax, (%r15)
movq %rbx, %rdi
callq 0x12250
addl $0x2, %eax
movl %eax, 0x8(%r15)
movq %r12, 0x10(%r15)
movq $0x1, 0x18(%r15)
leaq 0x366ad(%rip), %rdi     # 0x53ede
callq 0x127c0
xorl %ebp, %ebp
movl %r14d, %edi
movq %r15, %rsi
xorl %edx, %edx
callq 0x12150
testq %rax, %rax
js 0x1d898
movl %r14d, %edi
callq 0x123b0
movl $0x1, %ebp
jmp 0x1d86e
leaq 0x3668c(%rip), %rsi     # 0x53eec
xorl %ebp, %ebp
movl $0x3, %edi
xorl %eax, %eax
callq 0x19fb1
movl %ebp, %eax
addq $0xc0, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x366d0(%rip), %rsi     # 0x53f57
movl $0x3, %edi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x19fb1
jmp 0x1d86e
leaq 0x366e3(%rip), %rsi     # 0x53f82
movl $0x3, %edi
xorl %eax, %eax
callq 0x19fb1
movl %r14d, %edi
callq 0x123b0
jmp 0x1d86e