#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*/ fd_set;

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ SOCK_STREAM;
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
int strlen(int /*<<< orphan*/);
int setup(void) {
  int s, t, len;
  struct sockaddr_un remote;
  char str[150];
  fd_set fds, tfds;
  FD_ZERO(&fds);
  if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
    perror("socket");
    exit(1);
  }
  remote.sun_family = AF_UNIX;
  strcpy(remote.sun_path, "./socket");
  len = strlen(remote.sun_path) + sizeof(remote.sun_family);
  if (connect(s, (struct sockaddr *)&remote, len) == -1) {
    perror("connect");
    exit(1);
  }
  return s;
}


x86 assembly (clang, -O0):
<setup>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
lea    -0xb4(%rbp),%rdi
call   1050 <FD_ZERO@plt>
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
mov    0x2e41(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,-0x4(%rbp)
cmp    $0xffffffff,%eax
jne    11c2 <setup+0x52>
lea    0xe4f(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    0x2e1f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%edi
lea    0xe28(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%edi
call   1040 <strlen@plt>
cltq
add    $0x4,%rax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1080 <connect@plt>
cmp    $0xffffffff,%eax
jne    121c <setup+0xac>
lea    0xdfc(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x4(%rbp),%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setup>:
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0x14(%rsp),%rdi
call   1050 <FD_ZERO@plt>
mov    0x2e60(%rip),%r14
mov    (%r14),%edi
mov    0x2e46(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
cmp    $0xffffffff,%eax
je     11d8 <setup+0x68>
mov    %eax,%ebx
mov    (%r14),%eax
mov    %eax,0xc(%rsp)
lea    0xe50(%rip),%rsi
call   1030 <strcpy@plt>
call   1040 <strlen@plt>
lea    0x4(%rax),%edx
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
call   1080 <connect@plt>
cmp    $0xffffffff,%eax
je     11e1 <setup+0x71>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe23(%rip),%rdi
jmp    11e8 <setup+0x78>
lea    0xe21(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str = [7 x i8] c"socket\00"
@.str.1 = [9 x i8] c"./socket\00"
@.str.2 = [8 x i8] c"connect\00"
define i32 @setup() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.sockaddr_un
%5 = alloca [150 x i8]
%6 = alloca i32
%7 = alloca i32
%8 = call i32 @FD_ZERO(i32* %6)
%9 = load i32, i32* @AF_UNIX
%10 = load i32, i32* @SOCK_STREAM
%11 = call i32 @socket(i32 %9, i32 %10, i32 0)
store i32 %11, i32* %1
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %16
13: ; preds = %0
%14 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %0
%17 = load i32, i32* @AF_UNIX
%18 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %4, i32 0, i32 1
store i32 %17, i32* %18
%19 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %4, i32 0, i32 0
%20 = load i32, i32* %19
%21 = call i32 @strcpy(i32 %20, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%22 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %4, i32 0, i32 0
%23 = load i32, i32* %22
%24 = call i32 @strlen(i32 %23)
%25 = sext i32 %24 to i64
%26 = add i64 %25, 4
%27 = trunc i64 %26 to i32
store i32 %27, i32* %3
%28 = load i32, i32* %1
%29 = bitcast %struct.sockaddr_un* %4 to %struct.sockaddr*
%30 = load i32, i32* %3
%31 = call i32 @connect(i32 %28, %struct.sockaddr* %29, i32 %30)
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %36
33: ; preds = %16
%34 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %16
%37 = load i32, i32* %1
ret i32 %37
}

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