#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_family;
  int /*<<< orphan*/ sun_path;
};

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ SOCK_STREAM;
scalar_t__ connect(int, struct sockaddr_un *, int);
int /*<<< orphan*/ memset(struct sockaddr_un *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strncpy(int /*<<< orphan*/, char *, int);
int clientsocket(void) {
  int sh;
  struct sockaddr_un addr;
  if ((sh = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
    perror("client: socket()");
    return -1;
  }
  memset(&addr, 0, sizeof(struct sockaddr_un));
  strncpy(addr.sun_path, "accept4-test", sizeof(addr.sun_path) - 1);
  addr.sun_family = AF_UNIX;
  if (connect(sh, &addr, sizeof(struct sockaddr_un))) {
    perror("client: connect() for "
           "accept4-test");
    return -1;
  }
  return sh;
}


x86 assembly (clang, -O0):
<clientsocket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e89(%rip),%rax
mov    (%rax),%edi
mov    0x2e70(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    1195 <clientsocket+0x45>
lea    0xe7c(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fe <clientsocket+0xae>
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    -0xc(%rbp),%edi
lea    0xe78(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncpy@plt>
mov    0x2e28(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0x8,%edx
call   1060 <connect@plt>
cmp    $0x0,%rax
je     11f8 <clientsocket+0xa8>
lea    0xe2a(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fe <clientsocket+0xae>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clientsocket>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e88(%rip),%r15
mov    (%r15),%edi
mov    0x2e6e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
test   %eax,%eax
js     11c9 <clientsocket+0x79>
mov    %eax,%ebx
lea    0x8(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    0xc(%rsp),%edi
lea    0xe8f(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncpy@plt>
mov    (%r15),%eax
mov    %eax,0x8(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x8,%edx
call   1060 <connect@plt>
test   %rax,%rax
jne    11d2 <clientsocket+0x82>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe30(%rip),%rdi
jmp    11d9 <clientsocket+0x89>
lea    0xe38(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%ebx
jmp    11bd <clientsocket+0x6d>

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i32 }
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str = [17 x i8] c"client: socket()\00"
@.str.1 = [13 x i8] c"accept4-test\00"
@.str.2 = [35 x i8] c"client: connect() for accept4-test\00"
define i32 @clientsocket() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_un
%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* %2
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %1
br label %24
10: ; preds = %0
%11 = call i32 @memset(%struct.sockaddr_un* %3, i32 0, i32 8)
%12 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i32 0, i32 1
%13 = load i32, i32* %12
%14 = call i32 @strncpy(i32 %13, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 3)
%15 = load i32, i32* @AF_UNIX
%16 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i32 0, i32 0
store i32 %15, i32* %16
%17 = load i32, i32* %2
%18 = call i64 @connect(i32 %17, %struct.sockaddr_un* %3, i32 8)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %10
%21 = call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %24
22: ; preds = %10
%23 = load i32, i32* %2
store i32 %23, i32* %1
br label %24
24: ; preds = %22, %20, %8
%25 = load i32, i32* %1
ret i32 %25
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str = [17 x i8] c"client: socket()\00"
@.str.1 = [13 x i8] c"accept4-test\00"
@.str.2 = [35 x i8] c"client: connect() for accept4-test\00"
define i32 @clientsocket() {
%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 = icmp slt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = tail call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %20
9: ; preds = %0
%10 = call i32 @memset(%struct.sockaddr_un* %1, i32 0, i32 8)
%11 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %1, i64 0, i32 1
%12 = load i32, i32* %11
%13 = call i32 @strncpy(i32 %12, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 3)
%14 = load i32, i32* @AF_UNIX
%15 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %1, i64 0, i32 0
store i32 %14, i32* %15
%16 = call i64 @connect(i32 %5, %struct.sockaddr_un* %1, i32 8)
%17 = icmp eq i64 %16, 0
br i1 %17, label %20, label %18
18: ; preds = %9
%19 = call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
br label %20
20: ; preds = %9, %18, %7
%21 = phi i32 [ -1, %7 ], [ -1, %18 ], [ %5, %9 ]
ret i32 %21
}