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

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_KEEPALIVE;
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ die(char *, ...);
int /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              int *, int);
int /*<<< orphan*/ strncpy(char *, char const *, int);
int xmkusock();
int xuconnect(const char *path) {
  int sd = xmkusock();
  int one = 1;
  setsockopt(sd, SOL_SOCKET, SO_KEEPALIVE, &one, sizeof one);
  struct sockaddr_un addr = {.sun_family = AF_UNIX};
  strncpy(addr.sun_path, path, sizeof addr.sun_path);
  if (addr.sun_path[sizeof addr.sun_path - 1] != '\0')
    die("path '%s' too long", path);
  if (connect(sd, (struct sockaddr *)&addr, sizeof addr) < 0)
    die("connect:");
  return sd;
}


x86 assembly (clang, -O0):
<xuconnect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1050 <xmkusock@plt>
mov    %eax,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
mov    -0xc(%rbp),%edi
mov    0x2e71(%rip),%rax
mov    (%rax),%esi
mov    0x2e48(%rip),%rax
mov    (%rax),%edx
lea    -0x10(%rbp),%rcx
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
movq   $0x0,-0x20(%rbp)
mov    0x2e40(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x8,%edx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rax
movsbl 0x7(%rax),%eax
cmp    $0x0,%eax
je     11da <xuconnect+0x8a>
mov    -0x8(%rbp),%rsi
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1060 <die@plt>
mov    -0xc(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x10,%edx
call   1070 <connect@plt>
cmp    $0x0,%rax
jge    1203 <xuconnect+0xb3>
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1060 <die@plt>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xuconnect>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r14
xor    %eax,%eax
call   1050 <xmkusock@plt>
mov    %eax,%ebx
movl   $0x1,0x4(%rsp)
mov    0x2e76(%rip),%rax
mov    (%rax),%esi
mov    0x2e4d(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
movq   $0x0,0x8(%rsp)
mov    0x2e41(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
xor    %edi,%edi
mov    %r14,%rsi
mov    $0x8,%edx
call   1030 <strncpy@plt>
cmpb   $0x0,0x7
je     11cf <xuconnect+0x7f>
lea    0xe3b(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <die@plt>
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0x10,%edx
call   1070 <connect@plt>
test   %rax,%rax
jns    11f3 <xuconnect+0xa3>
lea    0xe27(%rip),%rdi
xor    %eax,%eax
call   1060 <die@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.sockaddr_un = type { i8*, i32 }
%struct.sockaddr = type { i32 }
@SOL_SOCKET = global i32 0
@SO_KEEPALIVE = global i32 0
@AF_UNIX = global i32 0
@.str = [19 x i8] c"path '%s' too long\00"
@.str.1 = [9 x i8] c"connect:\00"
define i32 @xuconnect(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.sockaddr_un
store i8* %0, i8** %2
%6 = call i32 (...) @xmkusock()
store i32 %6, i32* %3
store i32 1, i32* %4
%7 = load i32, i32* %3
%8 = load i32, i32* @SOL_SOCKET
%9 = load i32, i32* @SO_KEEPALIVE
%10 = call i32 @setsockopt(i32 %7, i32 %8, i32 %9, i32* %4, i32 4)
%11 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %5, i32 0, i32 0
store i8* null, i8** %11
%12 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %5, i32 0, i32 1
%13 = load i32, i32* @AF_UNIX
store i32 %13, i32* %12
%14 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %5, i32 0, i32 0
%15 = load i8*, i8** %14
%16 = load i8*, i8** %2
%17 = call i32 @strncpy(i8* %15, i8* %16, i32 8)
%18 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %5, i32 0, i32 0
%19 = load i8*, i8** %18
%20 = getelementptr inbounds i8, i8* %19, i64 7
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %1
%25 = load i8*, i8** %2
%26 = call i32 (i8*, ...) @die(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %25)
br label %27
27: ; preds = %24, %1
%28 = load i32, i32* %3
%29 = bitcast %struct.sockaddr_un* %5 to %struct.sockaddr*
%30 = call i64 @connect(i32 %28, %struct.sockaddr* %29, i32 16)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %27
%33 = call i32 (i8*, ...) @die(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %34
34: ; preds = %32, %27
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i8*, i32 }
%struct.sockaddr = type { i32 }
@SOL_SOCKET = global i32 0
@SO_KEEPALIVE = global i32 0
@AF_UNIX = global i32 0
@.str = [19 x i8] c"path '%s' too long\00"
@.str.1 = [9 x i8] c"connect:\00"
define i32 @xuconnect(i8* %0) {
%2 = alloca i32
%3 = alloca %struct.sockaddr_un
%4 = tail call i32 (...) @xmkusock()
%5 = bitcast i32* %2 to i8*
store i32 1, i32* %2
%6 = load i32, i32* @SOL_SOCKET
%7 = load i32, i32* @SO_KEEPALIVE
%8 = call i32 @setsockopt(i32 %4, i32 %6, i32 %7, i32* %2, i32 4)
%9 = bitcast %struct.sockaddr_un* %3 to i8*
%10 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 0
store i8* null, i8** %10
%11 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 1
%12 = load i32, i32* @AF_UNIX
store i32 %12, i32* %11
%13 = call i32 @strncpy(i8* null, i8* %0, i32 8)
%14 = load i8, i8* inttoptr (i64 7 to i8*)
%15 = icmp eq i8 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %1
%17 = call i32 (i8*, ...) @die(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %18
18: ; preds = %16, %1
%19 = bitcast %struct.sockaddr_un* %3 to %struct.sockaddr*
%20 = call i64 @connect(i32 %4, %struct.sockaddr* %19, i32 16)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = call i32 (i8*, ...) @die(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %24
24: ; preds = %22, %18
ret i32 %4
}