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

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ LOG_ERR;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/, char const *, size_t);
int /*<<< orphan*/ memset(struct sockaddr_un *, int /*<<< orphan*/, size_t);
int send(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ strlen(char const *);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *);
int SendShutdownCmd(const char *path) {
  struct sockaddr_un addr;
  memset((&addr), (0), (size_t)(sizeof(struct sockaddr_un)));
  addr.sun_family = AF_UNIX;
  memcpy((addr.sun_path), (path), (size_t)((int)strlen((const char *)(path))));
  int ctrlSock = socket(AF_UNIX, SOCK_STREAM, 0);
  if (ctrlSock < 0) {
    syslog(LOG_ERR,
           "Failed to create the control socket.. can not shut down...");
    return -1;
  }
  if (connect(ctrlSock, (struct sockaddr *)&addr, sizeof(struct sockaddr_un)) <
      0) {
    syslog(LOG_ERR,
           "Can not connect to the control socket.. can not shut down...");
    return -1;
  }
  if (send(ctrlSock, "SHUTDOWN", 8, 0) < 8) {
    syslog(LOG_ERR, "can not send SHUTDOWN command..");
    return -1;
  }
  close(ctrlSock);
}


x86 assembly (clang, -O0):
<SendShutdownCmd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
mov    0x2e45(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
movslq %eax,%rdx
call   1070 <memcpy@plt>
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
mov    0x2dfa(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1215 <SendShutdownCmd+0x95>
mov    0x2dcd(%rip),%rax
mov    (%rax),%edi
lea    0xdfc(%rip),%rsi
call   1080 <syslog@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1299 <SendShutdownCmd+0x119>
mov    -0x1c(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x8,%edx
call   1090 <connect@plt>
cmp    $0x0,%rax
jge    1251 <SendShutdownCmd+0xd1>
mov    0x2d91(%rip),%rax
mov    (%rax),%edi
lea    0xdfb(%rip),%rsi
call   1080 <syslog@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1299 <SendShutdownCmd+0x119>
mov    -0x1c(%rbp),%edi
lea    0xe1d(%rip),%rsi
mov    $0x8,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
cmp    $0x8,%eax
jge    1291 <SendShutdownCmd+0x111>
mov    0x2d51(%rip),%rax
mov    (%rax),%edi
lea    0xe01(%rip),%rsi
call   1080 <syslog@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1299 <SendShutdownCmd+0x119>
mov    -0x1c(%rbp),%edi
call   1060 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SendShutdownCmd>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rdi
mov    $0x8,%edx
xor    %esi,%esi
call   1050 <memset@plt>
mov    0x2e45(%rip),%r14
mov    (%r14),%eax
mov    %eax,0xc(%rsp)
mov    0x8(%rsp),%ebp
mov    %rbx,%rdi
call   1030 <strlen@plt>
movslq %eax,%rdx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1070 <memcpy@plt>
mov    (%r14),%edi
mov    0x2e0b(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
test   %eax,%eax
js     1223 <SendShutdownCmd+0xa3>
mov    %eax,%ebx
lea    0x8(%rsp),%rsi
mov    %eax,%edi
mov    $0x8,%edx
call   1090 <connect@plt>
test   %rax,%rax
js     123a <SendShutdownCmd+0xba>
lea    0xe7f(%rip),%rsi
mov    %ebx,%edi
mov    $0x8,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
cmp    $0x7,%eax
jg     1251 <SendShutdownCmd+0xd1>
mov    0x2db5(%rip),%rax
mov    (%rax),%edi
lea    0xe65(%rip),%rsi
call   1080 <syslog@plt>
jmp    1258 <SendShutdownCmd+0xd8>
mov    0x2d9e(%rip),%rax
mov    (%rax),%edi
lea    0xdcd(%rip),%rsi
call   1080 <syslog@plt>
jmp    1258 <SendShutdownCmd+0xd8>
mov    0x2d87(%rip),%rax
mov    (%rax),%edi
lea    0xdf1(%rip),%rsi
call   1080 <syslog@plt>
jmp    1258 <SendShutdownCmd+0xd8>
mov    %ebx,%edi
call   1060 <close@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@LOG_ERR = global i32 0
@.str = [59 x i8] c"Failed to create the control socket.. can not shut down...\00"
@.str.1 = [61 x i8] c"Can not connect to the control socket.. can not shut down...\00"
@.str.2 = [9 x i8] c"SHUTDOWN\00"
@.str.3 = [32 x i8] c"can not send SHUTDOWN command..\00"
define i32 @SendShutdownCmd(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.sockaddr_un
%5 = alloca i32
store i8* %0, i8** %3
%6 = call i32 @memset(%struct.sockaddr_un* %4, i32 0, i64 8)
%7 = load i32, i32* @AF_UNIX
%8 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %4, i32 0, i32 1
store i32 %7, i32* %8
%9 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %4, i32 0, i32 0
%10 = load i32, i32* %9
%11 = load i8*, i8** %3
%12 = load i8*, i8** %3
%13 = call i64 @strlen(i8* %12)
%14 = trunc i64 %13 to i32
%15 = sext i32 %14 to i64
%16 = call i32 @memcpy(i32 %10, i8* %11, i64 %15)
%17 = load i32, i32* @AF_UNIX
%18 = load i32, i32* @SOCK_STREAM
%19 = call i32 @socket(i32 %17, i32 %18, i32 0)
store i32 %19, i32* %5
%20 = load i32, i32* %5
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %1
%23 = load i32, i32* @LOG_ERR
%24 = call i32 @syslog(i32 %23, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %43
25: ; preds = %1
%26 = load i32, i32* %5
%27 = bitcast %struct.sockaddr_un* %4 to %struct.sockaddr*
%28 = call i64 @connect(i32 %26, %struct.sockaddr* %27, i32 8)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %25
%31 = load i32, i32* @LOG_ERR
%32 = call i32 @syslog(i32 %31, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %2
br label %43
33: ; preds = %25
%34 = load i32, i32* %5
%35 = call i32 @send(i32 %34, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 8, i32 0)
%36 = icmp slt i32 %35, 8
br i1 %36, label %37, label %40
37: ; preds = %33
%38 = load i32, i32* @LOG_ERR
%39 = call i32 @syslog(i32 %38, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %2
br label %43
40: ; preds = %33
%41 = load i32, i32* %5
%42 = call i32 @close(i32 %41)
br label %43
43: ; preds = %40, %37, %30, %22
%44 = load i32, i32* %2
ret i32 %44
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@LOG_ERR = global i32 0
@.str = [59 x i8] c"Failed to create the control socket.. can not shut down...\00"
@.str.1 = [61 x i8] c"Can not connect to the control socket.. can not shut down...\00"
@.str.2 = [9 x i8] c"SHUTDOWN\00"
@.str.3 = [32 x i8] c"can not send SHUTDOWN command..\00"
define i32 @SendShutdownCmd(i8* %0) {
%2 = alloca %struct.sockaddr_un
%3 = bitcast %struct.sockaddr_un* %2 to i8*
%4 = call i32 @memset(%struct.sockaddr_un* %2, i32 0, i64 8)
%5 = load i32, i32* @AF_UNIX
%6 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %2, i64 0, i32 1
store i32 %5, i32* %6
%7 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %2, i64 0, i32 0
%8 = load i32, i32* %7
%9 = call i64 @strlen(i8* dereferenceable(1) %0)
%10 = shl i64 %9, 32
%11 = ashr exact i64 %10, 32
%12 = call i32 @memcpy(i32 %8, i8* %0, i64 %11)
%13 = load i32, i32* @AF_UNIX
%14 = load i32, i32* @SOCK_STREAM
%15 = call i32 @socket(i32 %13, i32 %14, i32 0)
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %1
%18 = load i32, i32* @LOG_ERR
%19 = call i32 @syslog(i32 %18, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0))
br label %35
20: ; preds = %1
%21 = bitcast %struct.sockaddr_un* %2 to %struct.sockaddr*
%22 = call i64 @connect(i32 %15, %struct.sockaddr* %21, i32 8)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %20
%25 = load i32, i32* @LOG_ERR
%26 = call i32 @syslog(i32 %25, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.1, i64 0, i64 0))
br label %35
27: ; preds = %20
%28 = call i32 @send(i32 %15, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 8, i32 0)
%29 = icmp slt i32 %28, 8
br i1 %29, label %30, label %33
30: ; preds = %27
%31 = load i32, i32* @LOG_ERR
%32 = call i32 @syslog(i32 %31, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
br label %35
33: ; preds = %27
%34 = call i32 @close(i32 %15)
br label %35
35: ; preds = %33, %30, %24, %17
ret i32 -1
}