#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ sun;
struct sockaddr_un {
  char *sun_path;
  int /*<<< orphan*/ sun_family;
};
struct sockaddr {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ F_SETFL;
int /*<<< orphan*/ O_NONBLOCK;
int /*<<< orphan*/ PF_UNIX;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ fcntl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int sendto(int, char const *, int /*<<< orphan*/, int /*<<< orphan*/,
           struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char const *);
int liveinfo_send(const char *cmd) {
  static int init = 0;
  static int sock = 0;
  struct sockaddr_un sun = {
      .sun_family = AF_UNIX,
      .sun_path = "\0liveinfo",
  };
  if (!init) {
    init = 1;
    sock = socket(PF_UNIX, SOCK_DGRAM, 0);
    int ret =
        sendto(sock, cmd, strlen(cmd), 0, (struct sockaddr *)&sun, sizeof(sun));
    fcntl(sock, F_SETFL, O_NONBLOCK);
    return ret;
  } else if (sock == -1) {
    return -1;
  }
  sendto(sock, cmd, strlen(cmd), 0, (struct sockaddr *)&sun, sizeof(sun));
  return 0;
}


x86 assembly (clang, -O0):
<liveinfo_send>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xead(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e7a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,0x2eda(%rip)
jne    11f8 <liveinfo_send+0xb8>
movl   $0x1,0x2eca(%rip)
mov    0x2e77(%rip),%rax
mov    (%rax),%edi
mov    0x2e46(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <socket@plt>
mov    %eax,0x2eaf(%rip)
mov    0x2ea9(%rip),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
lea    -0x20(%rbp),%r8
xor    %ecx,%ecx
mov    $0x10,%r9d
call   1050 <sendto@plt>
mov    %eax,-0x24(%rbp)
mov    0x2e72(%rip),%edi
mov    0x2de3(%rip),%rax
mov    (%rax),%esi
mov    0x2dfa(%rip),%rax
mov    (%rax),%edx
call   1030 <fcntl@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1251 <liveinfo_send+0x111>
cmpl   $0xffffffff,0x2e49(%rip)
jne    1211 <liveinfo_send+0xd1>
movl   $0xffffffff,-0x4(%rbp)
jmp    1251 <liveinfo_send+0x111>
jmp    1216 <liveinfo_send+0xd6>
mov    0x2e2c(%rip),%eax
mov    %eax,-0x44(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x44(%rbp),%edi
mov    -0x40(%rbp),%rsi
mov    %eax,%edx
lea    -0x20(%rbp),%r8
xor    %ecx,%ecx
mov    $0x10,%r9d
call   1050 <sendto@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<liveinfo_send>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0xeae(%rip),%rax
mov    %rax,(%rsp)
mov    0x2e7b(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
cmpb   $0x0,0x2eda(%rip)
je     11a1 <liveinfo_send+0x61>
mov    0x2ed5(%rip),%r14d
cmp    $0xffffffff,%r14d
je     1209 <liveinfo_send+0xc9>
mov    %rbx,%rdi
call   1040 <strlen@plt>
xor    %ebp,%ebp
mov    %rsp,%r8
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    $0x10,%r9d
call   1050 <sendto@plt>
jmp    120e <liveinfo_send+0xce>
movb   $0x1,0x2e9c(%rip)
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
mov    0x2e18(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <socket@plt>
mov    %eax,%ebp
mov    %eax,0x2e7f(%rip)
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rsp,%r8
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    $0x10,%r9d
call   1050 <sendto@plt>
mov    %eax,%ebp
mov    0x2e58(%rip),%edi
mov    0x2dc9(%rip),%rax
mov    (%rax),%esi
mov    0x2de0(%rip),%rax
mov    (%rax),%edx
call   1030 <fcntl@plt>
jmp    120e <liveinfo_send+0xce>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_un = type { i8*, i32 }
%struct.sockaddr = type { i32 }
@liveinfo_send.init = internal global i32 0
@liveinfo_send.sock = internal global i32 0
@.str = [10 x i8] c"\00liveinfo\00"
@AF_UNIX = global i32 0
@PF_UNIX = global i32 0
@SOCK_DGRAM = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
define i32 @liveinfo_send(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.sockaddr_un
%5 = alloca i32
store i8* %0, i8** %3
%6 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %4, i32 0, i32 0
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %6
%7 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %4, i32 0, i32 1
%8 = load i32, i32* @AF_UNIX
store i32 %8, i32* %7
%9 = load i32, i32* @liveinfo_send.init
%10 = icmp ne i32 %9, 0
br i1 %10, label %26, label %11
11: ; preds = %1
store i32 1, i32* @liveinfo_send.init
%12 = load i32, i32* @PF_UNIX
%13 = load i32, i32* @SOCK_DGRAM
%14 = call i32 @socket(i32 %12, i32 %13, i32 0)
store i32 %14, i32* @liveinfo_send.sock
%15 = load i32, i32* @liveinfo_send.sock
%16 = load i8*, i8** %3
%17 = load i8*, i8** %3
%18 = call i32 @strlen(i8* %17)
%19 = bitcast %struct.sockaddr_un* %4 to %struct.sockaddr*
%20 = call i32 @sendto(i32 %15, i8* %16, i32 %18, i32 0, %struct.sockaddr* %19, i32 16)
store i32 %20, i32* %5
%21 = load i32, i32* @liveinfo_send.sock
%22 = load i32, i32* @F_SETFL
%23 = load i32, i32* @O_NONBLOCK
%24 = call i32 @fcntl(i32 %21, i32 %22, i32 %23)
%25 = load i32, i32* %5
store i32 %25, i32* %2
br label %38
26: ; preds = %1
%27 = load i32, i32* @liveinfo_send.sock
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %30
29: ; preds = %26
store i32 -1, i32* %2
br label %38
30: ; preds = %26
br label %31
31: ; preds = %30
%32 = load i32, i32* @liveinfo_send.sock
%33 = load i8*, i8** %3
%34 = load i8*, i8** %3
%35 = call i32 @strlen(i8* %34)
%36 = bitcast %struct.sockaddr_un* %4 to %struct.sockaddr*
%37 = call i32 @sendto(i32 %32, i8* %33, i32 %35, i32 0, %struct.sockaddr* %36, i32 16)
store i32 0, i32* %2
br label %38
38: ; preds = %31, %29, %11
%39 = load i32, i32* %2
ret i32 %39
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i8*, i32 }
%struct.sockaddr = type { i32 }
@liveinfo_send.init = internal unnamed_addr global i1 false
@liveinfo_send.sock = internal unnamed_addr global i32 0
@.str = [10 x i8] c"\00liveinfo\00"
@AF_UNIX = global i32 0
@PF_UNIX = global i32 0
@SOCK_DGRAM = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
define i32 @liveinfo_send(i8* %0) {
%2 = alloca %struct.sockaddr_un
%3 = bitcast %struct.sockaddr_un* %2 to i8*
%4 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %2, i64 0, i32 0
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %4
%5 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %2, i64 0, i32 1
%6 = load i32, i32* @AF_UNIX
store i32 %6, i32* %5
%7 = load i1, i1* @liveinfo_send.init
br i1 %7, label %19, label %8
8: ; preds = %1
store i1 true, i1* @liveinfo_send.init
%9 = load i32, i32* @PF_UNIX
%10 = load i32, i32* @SOCK_DGRAM
%11 = tail call i32 @socket(i32 %9, i32 %10, i32 0)
store i32 %11, i32* @liveinfo_send.sock
%12 = tail call i32 @strlen(i8* %0)
%13 = bitcast %struct.sockaddr_un* %2 to %struct.sockaddr*
%14 = call i32 @sendto(i32 %11, i8* %0, i32 %12, i32 0, %struct.sockaddr* %13, i32 16)
%15 = load i32, i32* @liveinfo_send.sock
%16 = load i32, i32* @F_SETFL
%17 = load i32, i32* @O_NONBLOCK
%18 = call i32 @fcntl(i32 %15, i32 %16, i32 %17)
br label %26
19: ; preds = %1
%20 = load i32, i32* @liveinfo_send.sock
%21 = icmp eq i32 %20, -1
br i1 %21, label %26, label %22
22: ; preds = %19
%23 = tail call i32 @strlen(i8* %0)
%24 = bitcast %struct.sockaddr_un* %2 to %struct.sockaddr*
%25 = call i32 @sendto(i32 %20, i8* %0, i32 %23, i32 0, %struct.sockaddr* %24, i32 16)
br label %26
26: ; preds = %19, %22, %8
%27 = phi i32 [ 0, %22 ], [ %14, %8 ], [ -1, %19 ]
ret i32 %27
}