#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 */
struct sockaddr_un {
  char *sun_path;
  int /*<<< orphan*/ sun_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ buf;
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
#define ECONNREFUSED 128
int /*<<< orphan*/ SOCK_STREAM;
scalar_t__ connect(int, struct sockaddr *, int);
int errno;
int /*<<< orphan*/ memset(struct sockaddr_un *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, scalar_t__);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  (void)argc;
  (void)argv;
  int fd = socket(AF_UNIX, SOCK_STREAM, 0);
  if (fd < 0) {
    perror("socket");
    return -1;
  }
  struct sockaddr_un addr;
  memset(&addr, 0, sizeof(addr));
  addr.sun_family = AF_UNIX;
  addr.sun_path[0] = '\0';
  strncpy(addr.sun_path + 1, "/org/freedesktop/plymouthd",
          strlen("/org/freedesktop/plymouthd") + 1);
  if (connect(fd, (struct sockaddr *)&addr, sizeof(addr) - 81) < 0) {
    switch (errno) {
    case ECONNREFUSED:
      return 0;
    default:
      perror("connect");
      return -1;
    }
  }
  char buf[4];
  buf[0] = 'Q';
  buf[1] = '\2';
  buf[2] = '\1';
  buf[3] = '\0';
  write(fd, buf, sizeof(buf));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
mov    0x2e42(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11c4 <main+0x54>
lea    0xe4d(%rip),%rdi
call   1070 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1296 <main+0x126>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
mov    0x2e0d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
lea    0xe0d(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    %rax,%rdx
add    $0x1,%rdx
lea    0xdf6(%rip),%rsi
call   1030 <strncpy@plt>
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0xffffffbf,%edx
call   1080 <connect@plt>
cmp    $0x0,%rax
jge    126e <main+0xfe>
mov    0x2d98(%rip),%rax
mov    (%rax),%eax
sub    $0x80,%eax
jne    1256 <main+0xe6>
jmp    124a <main+0xda>
movl   $0x0,-0x4(%rbp)
jmp    1296 <main+0x126>
lea    0xdc5(%rip),%rdi
call   1070 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1296 <main+0x126>
movb   $0x51,-0x2c(%rbp)
movb   $0x2,-0x2b(%rbp)
movb   $0x1,-0x2a(%rbp)
movb   $0x0,-0x29(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x2c(%rbp),%rsi
mov    $0x4,%edx
call   1040 <write@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    0x2e77(%rip),%rbx
mov    (%rbx),%edi
mov    0x2e5e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
test   %eax,%eax
js     1218 <main+0xb8>
mov    %eax,%ebp
lea    0x8(%rsp),%r15
xor    %r14d,%r14d
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
mov    (%rbx),%eax
mov    %eax,0x10(%rsp)
mov    0x8(%rsp),%rax
movb   $0x0,(%rax)
mov    0x8(%rsp),%rdi
add    $0x1,%rdi
lea    0xe45(%rip),%rsi
mov    $0x1b,%edx
call   1030 <strncpy@plt>
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0xffffffbf,%edx
call   1070 <connect@plt>
test   %rax,%rax
js     11fb <main+0x9b>
movl   $0x10251,0x4(%rsp)
lea    0x4(%rsp),%rsi
mov    %ebp,%edi
mov    $0x4,%edx
call   1040 <write@plt>
jmp    120a <main+0xaa>
mov    0x2dce(%rip),%rax
cmpl   $0x80,(%rax)
jne    1221 <main+0xc1>
mov    %r14d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xde1(%rip),%rdi
jmp    1228 <main+0xc8>
lea    0xdfa(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%r14d
jmp    120a <main+0xaa>

LLVM IR (-O0):
%struct.sockaddr_un = type { i8*, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str = [7 x i8] c"socket\00"
@.str.1 = [27 x i8] c"/org/freedesktop/plymouthd\00"
@errno = global i32 0
@.str.2 = [8 x i8] c"connect\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.sockaddr_un
%8 = alloca [4 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = load i8**, i8*** %5
%11 = load i32, i32* @AF_UNIX
%12 = load i32, i32* @SOCK_STREAM
%13 = call i32 @socket(i32 %11, i32 %12, i32 0)
store i32 %13, i32* %6
%14 = load i32, i32* %6
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %48
18: ; preds = %2
%19 = call i32 @memset(%struct.sockaddr_un* %7, i32 0, i32 16)
%20 = load i32, i32* @AF_UNIX
%21 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %7, i32 0, i32 1
store i32 %20, i32* %21
%22 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %7, i32 0, i32 0
%23 = load i8*, i8** %22
%24 = getelementptr inbounds i8, i8* %23, i64 0
store i8 0, i8* %24
%25 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %7, i32 0, i32 0
%26 = load i8*, i8** %25
%27 = getelementptr inbounds i8, i8* %26, i64 1
%28 = call i64 @strlen(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%29 = add nsw i64 %28, 1
%30 = call i32 @strncpy(i8* %27, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i64 %29)
%31 = load i32, i32* %6
%32 = bitcast %struct.sockaddr_un* %7 to %struct.sockaddr*
%33 = call i64 @connect(i32 %31, %struct.sockaddr* %32, i32 -65)
%34 = icmp slt i64 %33, 0
br i1 %34, label %35, label %40
35: ; preds = %18
%36 = load i32, i32* @errno
switch i32 %36, label %38 [
i32 128, label %37
]
37: ; preds = %35
store i32 0, i32* %3
br label %48
38: ; preds = %35
%39 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %48
40: ; preds = %18
%41 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
store i8 81, i8* %41
%42 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 1
store i8 2, i8* %42
%43 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 2
store i8 1, i8* %43
%44 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 3
store i8 0, i8* %44
%45 = load i32, i32* %6
%46 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
%47 = call i32 @write(i32 %45, i8* %46, i32 4)
store i32 0, i32* %3
br label %48
48: ; preds = %40, %38, %37, %16
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i8*, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str = [7 x i8] c"socket\00"
@.str.1 = [27 x i8] c"/org/freedesktop/plymouthd\00"
@errno = global i32 0
@.str.2 = [8 x i8] c"connect\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_un
%4 = alloca [4 x i8]
%5 = load i32, i32* @AF_UNIX
%6 = load i32, i32* @SOCK_STREAM
%7 = tail call i32 @socket(i32 %5, i32 %6, i32 0)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %37
11: ; preds = %2
%12 = bitcast %struct.sockaddr_un* %3 to i8*
%13 = call i32 @memset(%struct.sockaddr_un* %3, i32 0, i32 16)
%14 = load i32, i32* @AF_UNIX
%15 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 1
store i32 %14, i32* %15
%16 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 0
%17 = load i8*, i8** %16
store i8 0, i8* %17
%18 = load i8*, i8** %16
%19 = getelementptr inbounds i8, i8* %18, i64 1
%20 = call i32 @strncpy(i8* %19, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i64 27)
%21 = bitcast %struct.sockaddr_un* %3 to %struct.sockaddr*
%22 = call i64 @connect(i32 %7, %struct.sockaddr* %21, i32 -65)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %29
24: ; preds = %11
%25 = load i32, i32* @errno
%26 = icmp eq i32 %25, 128
br i1 %26, label %35, label %27
27: ; preds = %24
%28 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %35
29: ; preds = %11
%30 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
store i8 81, i8* %30
%31 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 1
store i8 2, i8* %31
%32 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 2
store i8 1, i8* %32
%33 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 3
store i8 0, i8* %33
%34 = call i32 @write(i32 %7, i8* %30, i32 4)
br label %35
35: ; preds = %24, %29, %27
%36 = phi i32 [ -1, %27 ], [ 0, %29 ], [ 0, %24 ]
br label %37
37: ; preds = %35, %9
%38 = phi i32 [ -1, %9 ], [ %36, %35 ]
ret i32 %38
}