#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 dummy;
};
struct sockaddr {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ SOCK_STREAM;
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ runes_die(char *, char *, ...);
int /*<<< orphan*/ runes_socket_populate_sockaddr(char *, struct sockaddr_un *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int runes_socket_client_open(char *path) {
  int s;
  struct sockaddr_un client;
  runes_socket_populate_sockaddr(path, &client);
  s = socket(AF_UNIX, SOCK_STREAM, 0);
  if (s < 0) {
    runes_die("couldn't create socket: %s", strerror(errno));
  }
  if (connect(s, (struct sockaddr *)(&client), sizeof(struct sockaddr_un))) {
    runes_die("couldn't connect to socket at %s: %s", path, strerror(errno));
  }
  return s;
}


x86 assembly (clang, -O0):
<runes_socket_client_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1060 <runes_socket_populate_sockaddr@plt>
mov    0x2e78(%rip),%rax
mov    (%rax),%edi
mov    0x2e5f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    11ae <runes_socket_client_open+0x5e>
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
movslq %eax,%rsi
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1030 <runes_die@plt>
mov    -0xc(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   1040 <connect@plt>
cmp    $0x0,%rax
je     11f3 <runes_socket_client_open+0xa3>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x18(%rbp),%rsi
mov    %eax,%edx
lea    0xe2f(%rip),%rdi
mov    $0x0,%al
call   1030 <runes_die@plt>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<runes_socket_client_open>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    %rsp,%rsi
call   1060 <runes_socket_populate_sockaddr@plt>
mov    0x2e83(%rip),%rax
mov    (%rax),%edi
mov    0x2e6a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    119c <runes_socket_client_open+0x4c>
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
movslq %eax,%rsi
lea    0xe6b(%rip),%rdi
xor    %eax,%eax
call   1030 <runes_die@plt>
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0x4,%edx
call   1040 <connect@plt>
test   %rax,%rax
je     11d1 <runes_socket_client_open+0x81>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe56(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <runes_die@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_un = type { i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str = [27 x i8] c"couldn't create socket: %s\00"
@errno = global i32 0
@.str.1 = [37 x i8] c"couldn't connect to socket at %s: %s\00"
define i32 @runes_socket_client_open(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca %struct.sockaddr_un
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @runes_socket_populate_sockaddr(i8* %5, %struct.sockaddr_un* %4)
%7 = load i32, i32* @AF_UNIX
%8 = load i32, i32* @SOCK_STREAM
%9 = call i32 @socket(i32 %7, i32 %8, i32 0)
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %18
12: ; preds = %1
%13 = load i32, i32* @errno
%14 = call i32 @strerror(i32 %13)
%15 = sext i32 %14 to i64
%16 = inttoptr i64 %15 to i8*
%17 = call i32 (i8*, i8*, ...) @runes_die(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %16)
br label %18
18: ; preds = %12, %1
%19 = load i32, i32* %3
%20 = bitcast %struct.sockaddr_un* %4 to %struct.sockaddr*
%21 = call i64 @connect(i32 %19, %struct.sockaddr* %20, i32 4)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %28
23: ; preds = %18
%24 = load i8*, i8** %2
%25 = load i32, i32* @errno
%26 = call i32 @strerror(i32 %25)
%27 = call i32 (i8*, i8*, ...) @runes_die(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %24, i32 %26)
br label %28
28: ; preds = %23, %18
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str = [27 x i8] c"couldn't create socket: %s\00"
@errno = global i32 0
@.str.1 = [37 x i8] c"couldn't connect to socket at %s: %s\00"
define i32 @runes_socket_client_open(i8* %0) {
%2 = alloca %struct.sockaddr_un
%3 = bitcast %struct.sockaddr_un* %2 to i8*
%4 = call i32 @runes_socket_populate_sockaddr(i8* %0, %struct.sockaddr_un* %2)
%5 = load i32, i32* @AF_UNIX
%6 = load i32, i32* @SOCK_STREAM
%7 = call i32 @socket(i32 %5, i32 %6, i32 0)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %15
9: ; preds = %1
%10 = load i32, i32* @errno
%11 = call i32 @strerror(i32 %10)
%12 = sext i32 %11 to i64
%13 = inttoptr i64 %12 to i8*
%14 = call i32 (i8*, i8*, ...) @runes_die(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %13)
br label %15
15: ; preds = %9, %1
%16 = bitcast %struct.sockaddr_un* %2 to %struct.sockaddr*
%17 = call i64 @connect(i32 %7, %struct.sockaddr* %16, i32 4)
%18 = icmp eq i64 %17, 0
br i1 %18, label %23, label %19
19: ; preds = %15
%20 = load i32, i32* @errno
%21 = call i32 @strerror(i32 %20)
%22 = call i32 (i8*, i8*, ...) @runes_die(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 %21)
br label %23
23: ; preds = %19, %15
ret i32 %7
}