#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;
};
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
int /*<<< orphan*/ strlen(char const *);
int /*<<< orphan*/ write(int, char const *, int /*<<< orphan*/);
void communicate_with_server(const char *sig, int *res, char *buffer) {
  int sockfd, len;
  struct sockaddr_un addr;
  sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
  addr.sun_family = AF_UNIX;
  strcpy(addr.sun_path, "/tmp/kbpm.sock");
  len = sizeof(addr);
  *res = connect(sockfd, (struct sockaddr *)&addr, len);
  if (*res == -1) {
    return;
  }
  write(sockfd, sig, strlen(sig));
  read(sockfd, buffer, 40 * 1024);
  close(sockfd);
  *res = 0;
}


x86 assembly (clang, -O0):
<communicate_with_server>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    0x2e5d(%rip),%rax
mov    (%rax),%edi
mov    0x2e44(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e41(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x28(%rbp),%edi
lea    0xe4a(%rip),%rsi
call   1030 <strcpy@plt>
movl   $0x8,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   1080 <connect@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
cmpl   $0xffffffff,(%rax)
jne    11eb <communicate_with_server+0x7b>
jmp    1233 <communicate_with_server+0xc3>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    $0xa000,%edx
call   1070 <read@plt>
mov    -0x1c(%rbp),%edi
call   1060 <close@plt>
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<communicate_with_server>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
mov    0x2e5c(%rip),%rbx
mov    (%rbx),%edi
mov    0x2e43(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,%ebp
mov    (%rbx),%eax
mov    %eax,0xc(%rsp)
lea    0xe53(%rip),%rsi
call   1030 <strcpy@plt>
lea    0x8(%rsp),%rsi
mov    %ebp,%edi
mov    $0x8,%edx
call   1080 <connect@plt>
mov    %eax,(%r15)
cmp    $0xffffffff,%eax
je     11fc <communicate_with_server+0x8c>
mov    %r12,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %r12,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0xa000,%edx
call   1070 <read@plt>
mov    %ebp,%edi
call   1060 <close@plt>
movl   $0x0,(%r15)
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
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
@.str = [15 x i8] c"/tmp/kbpm.sock\00"
define void @communicate_with_server(i8* %0, i32* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.sockaddr_un
store i8* %0, i8** %4
store i32* %1, i32** %5
store i8* %2, i8** %6
%10 = load i32, i32* @AF_UNIX
%11 = load i32, i32* @SOCK_STREAM
%12 = call i32 @socket(i32 %10, i32 %11, i32 0)
store i32 %12, i32* %7
%13 = load i32, i32* @AF_UNIX
%14 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %9, i32 0, i32 1
store i32 %13, i32* %14
%15 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %9, i32 0, i32 0
%16 = load i32, i32* %15
%17 = call i32 @strcpy(i32 %16, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i32 8, i32* %8
%18 = load i32, i32* %7
%19 = bitcast %struct.sockaddr_un* %9 to %struct.sockaddr*
%20 = load i32, i32* %8
%21 = call i32 @connect(i32 %18, %struct.sockaddr* %19, i32 %20)
%22 = load i32*, i32** %5
store i32 %21, i32* %22
%23 = load i32*, i32** %5
%24 = load i32, i32* %23
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %27
26: ; preds = %3
br label %39
27: ; preds = %3
%28 = load i32, i32* %7
%29 = load i8*, i8** %4
%30 = load i8*, i8** %4
%31 = call i32 @strlen(i8* %30)
%32 = call i32 @write(i32 %28, i8* %29, i32 %31)
%33 = load i32, i32* %7
%34 = load i8*, i8** %6
%35 = call i32 @read(i32 %33, i8* %34, i32 40960)
%36 = load i32, i32* %7
%37 = call i32 @close(i32 %36)
%38 = load i32*, i32** %5
store i32 0, i32* %38
br label %39
39: ; preds = %27, %26
ret void
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str = [15 x i8] c"/tmp/kbpm.sock\00"
define void @communicate_with_server(i8* %0, i32* nocapture writeonly %1, i8* nocapture %2) {
%4 = alloca %struct.sockaddr_un
%5 = bitcast %struct.sockaddr_un* %4 to i8*
%6 = load i32, i32* @AF_UNIX
%7 = load i32, i32* @SOCK_STREAM
%8 = tail call i32 @socket(i32 %6, i32 %7, i32 0)
%9 = load i32, i32* @AF_UNIX
%10 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %4, i64 0, i32 1
store i32 %9, i32* %10
%11 = tail call i32 @strcpy(i32 undef, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%12 = bitcast %struct.sockaddr_un* %4 to %struct.sockaddr*
%13 = call i32 @connect(i32 %8, %struct.sockaddr* %12, i32 8)
store i32 %13, i32* %1
%14 = icmp eq i32 %13, -1
br i1 %14, label %20, label %15
15: ; preds = %3
%16 = call i32 @strlen(i8* %0)
%17 = call i32 @write(i32 %8, i8* %0, i32 %16)
%18 = call i32 @read(i32 %8, i8* %2, i32 40960)
%19 = call i32 @close(i32 %8)
store i32 0, i32* %1
br label %20
20: ; preds = %3, %15
ret void
}