#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*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, scalar_t__);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
scalar_t__ strlen(int /*<<< orphan*/);
int get_send_socket() {
  struct sockaddr_un remote;
  int sock = socket(AF_UNIX, SOCK_STREAM, 0);
  remote.sun_family = AF_UNIX;
  strcpy(remote.sun_path, "/var/run/kropkid_sock");
  if (connect(sock, (struct sockaddr *)&remote,
              strlen(remote.sun_path) + sizeof(remote.sun_family)) == -1) {
    close(sock);
    return -1;
  }
  return sock;
}


x86 assembly (clang, -O0):
<get_send_socket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0x2e89(%rip),%rax
mov    (%rax),%edi
mov    0x2e70(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e6d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%edi
lea    0xe76(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
lea    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%edi
call   1040 <strlen@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    %rax,%rdx
add    $0x4,%rdx
call   1060 <connect@plt>
cmp    $0xffffffff,%eax
jne    11d5 <get_send_socket+0x85>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11db <get_send_socket+0x8b>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_send_socket>:
push   %r14
push   %rbx
push   %rax
mov    0x2e8d(%rip),%r14
mov    (%r14),%edi
mov    0x2e73(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
mov    %eax,%ebx
mov    (%r14),%eax
mov    %eax,0x4(%rsp)
lea    0xe82(%rip),%rsi
call   1030 <strcpy@plt>
call   1040 <strlen@plt>
lea    0x4(%rax),%rdx
mov    %rsp,%rsi
mov    %ebx,%edi
call   1060 <connect@plt>
cmp    $0xffffffff,%eax
jne    11a7 <get_send_socket+0x57>
mov    %ebx,%edi
call   1050 <close@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
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 = [22 x i8] c"/var/run/kropkid_sock\00"
define i32 @get_send_socket() {
%1 = alloca i32
%2 = alloca %struct.sockaddr_un
%3 = alloca i32
%4 = load i32, i32* @AF_UNIX
%5 = load i32, i32* @SOCK_STREAM
%6 = call i32 @socket(i32 %4, i32 %5, i32 0)
store i32 %6, i32* %3
%7 = load i32, i32* @AF_UNIX
%8 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %2, i32 0, i32 1
store i32 %7, i32* %8
%9 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %2, i32 0, i32 0
%10 = load i32, i32* %9
%11 = call i32 @strcpy(i32 %10, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* %3
%13 = bitcast %struct.sockaddr_un* %2 to %struct.sockaddr*
%14 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %2, i32 0, i32 0
%15 = load i32, i32* %14
%16 = call i64 @strlen(i32 %15)
%17 = add i64 %16, 4
%18 = call i32 @connect(i32 %12, %struct.sockaddr* %13, i64 %17)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %23
20: ; preds = %0
%21 = load i32, i32* %3
%22 = call i32 @close(i32 %21)
store i32 -1, i32* %1
br label %25
23: ; preds = %0
%24 = load i32, i32* %3
store i32 %24, i32* %1
br label %25
25: ; preds = %23, %20
%26 = load i32, i32* %1
ret i32 %26
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str = [22 x i8] c"/var/run/kropkid_sock\00"
define i32 @get_send_socket() {
%1 = alloca %struct.sockaddr_un
%2 = bitcast %struct.sockaddr_un* %1 to i8*
%3 = load i32, i32* @AF_UNIX
%4 = load i32, i32* @SOCK_STREAM
%5 = tail call i32 @socket(i32 %3, i32 %4, i32 0)
%6 = load i32, i32* @AF_UNIX
%7 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %1, i64 0, i32 1
store i32 %6, i32* %7
%8 = tail call i32 @strcpy(i32 undef, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%9 = bitcast %struct.sockaddr_un* %1 to %struct.sockaddr*
%10 = tail call i64 @strlen(i32 undef)
%11 = add i64 %10, 4
%12 = call i32 @connect(i32 %5, %struct.sockaddr* %9, i64 %11)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %0
%15 = call i32 @close(i32 %5)
br label %16
16: ; preds = %0, %14
%17 = phi i32 [ -1, %14 ], [ %5, %0 ]
ret i32 %17
}