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

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
scalar_t__ EINPROGRESS;
int /*<<< orphan*/ FIONBIO;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *,
                           char const *, ...);
int ioctl(int, int /*<<< orphan*/, int *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char const *);
char *strerror(scalar_t__);
int setup_unix_client_socket(const char *path, int nonblock) {
  int soc, opt;
  struct sockaddr_un addr;
  soc = socket(AF_UNIX, SOCK_STREAM, 0);
  if (soc == -1) {
    fprintf(stderr,
            "%s: "
            "socket: %s"
            " (%s:%d)\n",
            "warning", strerror(errno),
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/pandax381/rlogd/refs/heads/master/src/"
            "common.c",
            201);
    ;
    ;
    return -1;
  }
  if (nonblock) {
    opt = 1;
    if (ioctl(soc, FIONBIO, &opt) == -1) {
      fprintf(stderr,
              "%s: "
              "ioctl [FIONBIO]: %s"
              " (%s:%d)\n",
              "warning", strerror(errno),
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/pandax381/rlogd/refs/heads/master/src/"
              "common.c",
              207);
      ;
      ;
      close(soc);
      return -1;
    }
  }
  addr.sun_family = AF_UNIX;
  strcpy(addr.sun_path, path);
  if (connect(soc, (struct sockaddr *)&addr, sizeof(addr)) == -1) {
    if (!nonblock || errno != EINPROGRESS) {
      fprintf(stderr,
              "%s: "
              "connect: %s, path=%s"
              " (%s:%d)\n",
              "warning", strerror(errno), path,
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/pandax381/rlogd/refs/heads/master/src/"
              "common.c",
              216);
      ;
      ;
      close(soc);
      return -1;
    }
  }
  return soc;
}


x86 assembly (clang, -O0):
<setup_unix_client_socket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
mov    0x2e39(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    11f4 <setup_unix_client_socket+0x84>
mov    0x2e24(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2e08(%rip),%rax
mov    (%rax),%rdi
call   1080 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    %rax,%rcx
lea    0xe33(%rip),%rsi
lea    0xe44(%rip),%rdx
lea    0xe45(%rip),%r8
mov    $0xc9,%r9d
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    133c <setup_unix_client_socket+0x1cc>
cmpl   $0x0,-0x14(%rbp)
je     127f <setup_unix_client_socket+0x10f>
movl   $0x1,-0x1c(%rbp)
mov    -0x18(%rbp),%edi
mov    0x2da9(%rip),%rax
mov    (%rax),%esi
lea    -0x1c(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    127a <setup_unix_client_socket+0x10a>
mov    0x2da6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    0x2d8a(%rip),%rax
mov    (%rax),%rdi
call   1080 <strerror@plt>
mov    -0x30(%rbp),%edi
mov    %rax,%rcx
lea    0xe5e(%rip),%rsi
lea    0xdc6(%rip),%rdx
lea    0xdc7(%rip),%r8
mov    $0xcf,%r9d
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    133c <setup_unix_client_socket+0x1cc>
jmp    127f <setup_unix_client_socket+0x10f>
mov    0x2d5a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x28(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x8,%edx
call   1070 <connect@plt>
cmp    $0xffffffff,%eax
jne    1336 <setup_unix_client_socket+0x1c6>
cmpl   $0x0,-0x14(%rbp)
je     12d5 <setup_unix_client_socket+0x165>
mov    0x2cfe(%rip),%rax
mov    (%rax),%rax
mov    0x2d1c(%rip),%rcx
cmp    (%rcx),%rax
je     1331 <setup_unix_client_socket+0x1c1>
mov    0x2cf4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x2cd8(%rip),%rax
mov    (%rax),%rdi
call   1080 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    %rax,%rcx
mov    -0x10(%rbp),%r8
lea    0xdc9(%rip),%rsi
lea    0xd10(%rip),%rdx
lea    0xd11(%rip),%r9
movl   $0xd8,(%rsp)
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    133c <setup_unix_client_socket+0x1cc>
jmp    1336 <setup_unix_client_socket+0x1c6>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setup_unix_client_socket>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %esi,%ebp
mov    %rdi,%r14
mov    0x2e5a(%rip),%r15
mov    (%r15),%edi
mov    0x2e38(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
cmp    $0xffffffff,%eax
je     1253 <setup_unix_client_socket+0xe3>
mov    %eax,%ebx
test   %ebp,%ebp
je     11ce <setup_unix_client_socket+0x5e>
movl   $0x1,0xc(%rsp)
mov    0x2e01(%rip),%rax
mov    (%rax),%esi
lea    0xc(%rsp),%rdx
mov    %ebx,%edi
call   1040 <ioctl@plt>
cmp    $0xffffffff,%eax
je     1294 <setup_unix_client_socket+0x124>
mov    (%r15),%eax
mov    %eax,0x14(%rsp)
mov    %r14,%rsi
call   1030 <strcpy@plt>
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0x8,%edx
call   1070 <connect@plt>
cmp    $0xffffffff,%eax
jne    12df <setup_unix_client_socket+0x16f>
mov    0x2dc2(%rip),%rax
mov    (%rax),%rdi
test   %ebp,%ebp
je     1215 <setup_unix_client_socket+0xa5>
mov    0x2ddc(%rip),%rax
cmp    (%rax),%rdi
je     12df <setup_unix_client_socket+0x16f>
mov    0x2db4(%rip),%rax
mov    (%rax),%ebp
call   1080 <strerror@plt>
movl   $0xd8,(%rsp)
lea    0xe99(%rip),%rsi
lea    0xde0(%rip),%rdx
lea    0xde1(%rip),%r9
mov    %ebp,%edi
mov    %rax,%rcx
mov    %r14,%r8
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    12d3 <setup_unix_client_socket+0x163>
mov    0x2d76(%rip),%rax
mov    (%rax),%ebx
mov    0x2d5d(%rip),%rax
mov    (%rax),%rdi
call   1080 <strerror@plt>
lea    0xd8e(%rip),%rsi
lea    0xd9f(%rip),%rdx
lea    0xda0(%rip),%r8
mov    %ebx,%edi
mov    %rax,%rcx
mov    $0xc9,%r9d
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    12da <setup_unix_client_socket+0x16a>
mov    0x2d35(%rip),%rax
mov    (%rax),%ebp
mov    0x2d1c(%rip),%rax
mov    (%rax),%rdi
call   1080 <strerror@plt>
lea    0xdf6(%rip),%rsi
lea    0xd5e(%rip),%rdx
lea    0xd5f(%rip),%r8
mov    %ebp,%edi
mov    %rax,%rcx
mov    $0xcf,%r9d
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %ebx,%edi
call   1050 <close@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@stderr = global i32 0
@.str = [24 x i8] c"%s: socket: %s (%s:%d)\0A\00"
@.str.1 = [8 x i8] c"warning\00"
@errno = global i64 0
@.str.2 = [137 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/pandax381/rlogd/refs/heads/master/src/common.c\00"
@FIONBIO = global i32 0
@.str.3 = [33 x i8] c"%s: ioctl [FIONBIO]: %s (%s:%d)\0A\00"
@EINPROGRESS = global i64 0
@.str.4 = [34 x i8] c"%s: connect: %s, path=%s (%s:%d)\0A\00"
define i32 @setup_unix_client_socket(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.sockaddr_un
store i8* %0, i8** %4
store i32 %1, i32* %5
%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* %6
%12 = load i32, i32* %6
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %19
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i64, i64* @errno
%17 = call i8* @strerror(i64 %16)
%18 = call i32 (i32, i8*, i8*, i8*, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %17, i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.2, i64 0, i64 0), i32 201)
store i32 -1, i32* %3
br label %64
19: ; preds = %2
%20 = load i32, i32* %5
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %35
22: ; preds = %19
store i32 1, i32* %7
%23 = load i32, i32* %6
%24 = load i32, i32* @FIONBIO
%25 = call i32 @ioctl(i32 %23, i32 %24, i32* %7)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %34
27: ; preds = %22
%28 = load i32, i32* @stderr
%29 = load i64, i64* @errno
%30 = call i8* @strerror(i64 %29)
%31 = call i32 (i32, i8*, i8*, i8*, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %30, i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.2, i64 0, i64 0), i32 207)
%32 = load i32, i32* %6
%33 = call i32 @close(i32 %32)
store i32 -1, i32* %3
br label %64
34: ; preds = %22
br label %35
35: ; preds = %34, %19
%36 = load i32, i32* @AF_UNIX
%37 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %8, i32 0, i32 1
store i32 %36, i32* %37
%38 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %8, i32 0, i32 0
%39 = load i32, i32* %38
%40 = load i8*, i8** %4
%41 = call i32 @strcpy(i32 %39, i8* %40)
%42 = load i32, i32* %6
%43 = bitcast %struct.sockaddr_un* %8 to %struct.sockaddr*
%44 = call i32 @connect(i32 %42, %struct.sockaddr* %43, i32 8)
%45 = icmp eq i32 %44, -1
br i1 %45, label %46, label %62
46: ; preds = %35
%47 = load i32, i32* %5
%48 = icmp ne i32 %47, 0
br i1 %48, label %49, label %53
49: ; preds = %46
%50 = load i64, i64* @errno
%51 = load i64, i64* @EINPROGRESS
%52 = icmp ne i64 %50, %51
br i1 %52, label %53, label %61
53: ; preds = %49, %46
%54 = load i32, i32* @stderr
%55 = load i64, i64* @errno
%56 = call i8* @strerror(i64 %55)
%57 = load i8*, i8** %4
%58 = call i32 (i32, i8*, i8*, i8*, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %56, i8* %57, i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.2, i64 0, i64 0), i32 216)
%59 = load i32, i32* %6
%60 = call i32 @close(i32 %59)
store i32 -1, i32* %3
br label %64
61: ; preds = %49
br label %62
62: ; preds = %61, %35
%63 = load i32, i32* %6
store i32 %63, i32* %3
br label %64
64: ; preds = %62, %53, %27, %14
%65 = load i32, i32* %3
ret i32 %65
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@stderr = global i32 0
@.str = [24 x i8] c"%s: socket: %s (%s:%d)\0A\00"
@.str.1 = [8 x i8] c"warning\00"
@errno = global i64 0
@.str.2 = [137 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/pandax381/rlogd/refs/heads/master/src/common.c\00"
@FIONBIO = global i32 0
@.str.3 = [33 x i8] c"%s: ioctl [FIONBIO]: %s (%s:%d)\0A\00"
@EINPROGRESS = global i64 0
@.str.4 = [34 x i8] c"%s: connect: %s, path=%s (%s:%d)\0A\00"
define i32 @setup_unix_client_socket(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr_un
%5 = bitcast i32* %3 to i8*
%6 = bitcast %struct.sockaddr_un* %4 to i8*
%7 = load i32, i32* @AF_UNIX
%8 = load i32, i32* @SOCK_STREAM
%9 = tail call i32 @socket(i32 %7, i32 %8, i32 0)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i64, i64* @errno
%14 = tail call i8* @strerror(i64 %13)
%15 = tail call i32 (i32, i8*, i8*, i8*, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %14, i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.2, i64 0, i64 0), i32 201)
br label %46
16: ; preds = %2
%17 = icmp eq i32 %1, 0
br i1 %17, label %28, label %18
18: ; preds = %16
store i32 1, i32* %3
%19 = load i32, i32* @FIONBIO
%20 = call i32 @ioctl(i32 %9, i32 %19, i32* %3)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %28
22: ; preds = %18
%23 = load i32, i32* @stderr
%24 = load i64, i64* @errno
%25 = call i8* @strerror(i64 %24)
%26 = call i32 (i32, i8*, i8*, i8*, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %25, i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.2, i64 0, i64 0), i32 207)
%27 = call i32 @close(i32 %9)
br label %46
28: ; preds = %18, %16
%29 = load i32, i32* @AF_UNIX
%30 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %4, i64 0, i32 1
store i32 %29, i32* %30
%31 = call i32 @strcpy(i32 undef, i8* %0)
%32 = bitcast %struct.sockaddr_un* %4 to %struct.sockaddr*
%33 = call i32 @connect(i32 %9, %struct.sockaddr* %32, i32 8)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %46
35: ; preds = %28
%36 = load i64, i64* @errno
%37 = xor i1 %17, true
%38 = load i64, i64* @EINPROGRESS
%39 = icmp eq i64 %36, %38
%40 = select i1 %37, i1 %39, i1 false
br i1 %40, label %46, label %41
41: ; preds = %35
%42 = load i32, i32* @stderr
%43 = call i8* @strerror(i64 %36)
%44 = call i32 (i32, i8*, i8*, i8*, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %43, i8* %0, i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.2, i64 0, i64 0), i32 216)
%45 = call i32 @close(i32 %9)
br label %46
46: ; preds = %35, %28, %41, %22, %11
%47 = phi i32 [ -1, %11 ], [ -1, %22 ], [ -1, %41 ], [ %9, %28 ], [ %9, %35 ]
ret i32 %47
}