// File: /workspace/github_c_makefile_star2_O2/gplessis[P]dotdeb-redis/src/server.c
// Function: redisSupervisedSystemd
int redisSupervisedSystemd(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 readiness");
    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 %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
leaq 0x805ff(%rip), %rdi     # 0xb0f77
callq 0x26850
testq %rax, %rax
je 0x30a99
movq %rax, %rbx
movzbl (%rax), %eax
xorl %ebp, %ebp
testl %eax, %eax
je 0x309a0
cmpl $0x40, %eax
je 0x309a0
cmpl $0x2f, %eax
jne 0x30aac
movq %rbx, %rdi
callq 0x26500
cmpq $0x2, %rax
jb 0x30aac
leaq 0x80607(%rip), %rsi     # 0xb0fc0
xorl %ebp, %ebp
pushq $0x2
popq %r14
movl %r14d, %edi
xorl %eax, %eax
callq 0x2b699
pushq $0x1
popq %r15
movl %r15d, %edi
movl %r14d, %esi
xorl %edx, %edx
callq 0x26800
cmpl $-0x1, %eax
je 0x30ac0
movl %eax, %r14d
leaq 0x14(%rsp), %r12
movw $0x1, -0x2(%r12)
pushq $0x6b
popq %rdx
movq %r12, %rdi
movq %rbx, %rsi
callq 0x26a40
movb $0x0, 0x6b(%r12)
cmpb $0x40, (%rbx)
jne 0x30a11
movb $0x0, 0x14(%rsp)
leaq 0x805f8(%rip), %rax     # 0xb1010
movq %rsp, %r13
movq %rax, (%r13)
movq $0x7, 0x8(%r13)
xorps %xmm0, %xmm0
leaq 0x80(%rsp), %r12
movups %xmm0, 0x8(%r12)
movups %xmm0, 0x18(%r12)
movups %xmm0, 0x28(%r12)
leaq 0x12(%rsp), %rax
movq %rax, (%r12)
movq %rbx, %rdi
callq 0x26500
addl $0x2, %eax
movl %eax, 0x8(%r12)
movq %r13, 0x10(%r12)
movq $0x1, 0x18(%r12)
leaq 0x80505(%rip), %rdi     # 0xb0f77
callq 0x26a80
movl %r14d, %edi
movq %r12, %rsi
movl $0x4000, %edx           # imm = 0x4000
callq 0x26630
testq %rax, %rax
js 0x30ad6
movl %r14d, %edi
callq 0x26180
movl %r15d, %ebp
jmp 0x30aac
leaq 0x804e5(%rip), %rsi     # 0xb0f85
xorl %ebp, %ebp
pushq $0x3
popq %rdi
xorl %eax, %eax
callq 0x2b699
movl %ebp, %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x80526(%rip), %rsi     # 0xb0fed
pushq $0x3
popq %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2b699
jmp 0x30aac
leaq 0x8053b(%rip), %rsi     # 0xb1018
xorl %ebp, %ebp
pushq $0x3
popq %rdi
xorl %eax, %eax
callq 0x2b699
movl %r14d, %edi
callq 0x26180
jmp 0x30aac