#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;
int /*<<< orphan*/ FIONBIO;
int /*<<< orphan*/ SOCK_STREAM;
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *,
                           char const *, ...);
int ioctl(int, int /*<<< orphan*/, int *);
int listen(int, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char const *);
char *strerror(int /*<<< orphan*/);
int setup_unix_server_socket(const char *path, int backlog, 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",
            301);
    ;
    ;
    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",
              307);
      ;
      ;
      close(soc);
      return -1;
    }
  }
  addr.sun_family = AF_UNIX;
  strcpy(addr.sun_path, path);
  if (bind(soc, (struct sockaddr *)&addr, sizeof(addr)) == -1) {
    fprintf(stderr,
            "%s: "
            "bind: %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",
            315);
    ;
    ;
    close(soc);
    return -1;
  }
  if (listen(soc, backlog) == -1) {
    fprintf(stderr,
            "%s: "
            "listen: %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",
            320);
    ;
    ;
    close(soc);
    return -1;
  }
  return soc;
}


x86 assembly (clang, -O0):
<setup_unix_server_socket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
mov    0x2e2e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1206 <setup_unix_server_socket+0x86>
mov    0x2e19(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2dfd(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    %rax,%rcx
lea    0xe21(%rip),%rsi
lea    0xe32(%rip),%rdx
lea    0xe33(%rip),%r8
mov    $0x12d,%r9d
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1392 <setup_unix_server_socket+0x212>
cmpl   $0x0,-0x18(%rbp)
je     1290 <setup_unix_server_socket+0x110>
movl   $0x1,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2d9f(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    128b <setup_unix_server_socket+0x10b>
mov    0x2d9c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    0x2d80(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x30(%rbp),%edi
mov    %rax,%rcx
lea    0xe4d(%rip),%rsi
lea    0xdb5(%rip),%rdx
lea    0xdb6(%rip),%r8
mov    $0x133,%r9d
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1392 <setup_unix_server_socket+0x212>
jmp    1290 <setup_unix_server_socket+0x110>
mov    0x2d51(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x28(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x1c(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x8,%edx
call   1080 <bind@plt>
cmp    $0xffffffff,%eax
jne    131d <setup_unix_server_socket+0x19d>
mov    0x2d0f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x2cf3(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    %rax,%rcx
mov    -0x10(%rbp),%r8
lea    0xddd(%rip),%rsi
lea    0xd24(%rip),%rdx
lea    0xd25(%rip),%r9
movl   $0x13b,(%rsp)
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1392 <setup_unix_server_socket+0x212>
mov    -0x1c(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1070 <listen@plt>
cmp    $0xffffffff,%eax
jne    138c <setup_unix_server_socket+0x20c>
mov    0x2ca0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    0x2c84(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x38(%rbp),%edi
mov    %rax,%rcx
mov    -0x10(%rbp),%r8
lea    0xd8d(%rip),%rsi
lea    0xcb5(%rip),%rdx
lea    0xcb6(%rip),%r9
movl   $0x140,(%rsp)
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1392 <setup_unix_server_socket+0x212>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setup_unix_server_socket>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %edx,%ebp
mov    %esi,%r15d
mov    %rdi,%r14
mov    0x2e4d(%rip),%r12
mov    (%r12),%edi
mov    0x2e2a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
cmp    $0xffffffff,%eax
je     1244 <setup_unix_server_socket+0xc4>
mov    %eax,%ebx
test   %ebp,%ebp
je     11e4 <setup_unix_server_socket+0x64>
movl   $0x1,0x14(%rsp)
mov    0x2df3(%rip),%rax
mov    (%rax),%esi
lea    0x14(%rsp),%rdx
mov    %ebx,%edi
call   1040 <ioctl@plt>
cmp    $0xffffffff,%eax
je     12cb <setup_unix_server_socket+0x14b>
mov    (%r12),%eax
mov    %eax,0x1c(%rsp)
mov    %r14,%rsi
call   1030 <strcpy@plt>
lea    0x18(%rsp),%rsi
mov    %ebx,%edi
mov    $0x8,%edx
call   1080 <bind@plt>
cmp    $0xffffffff,%eax
je     1287 <setup_unix_server_socket+0x107>
mov    %ebx,%edi
mov    %r15d,%esi
call   1070 <listen@plt>
cmp    $0xffffffff,%eax
jne    1315 <setup_unix_server_socket+0x195>
mov    0x2db4(%rip),%rax
mov    (%rax),%ebp
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
movl   $0x140,(%rsp)
lea    0xea7(%rip),%rsi
jmp    12ac <setup_unix_server_socket+0x12c>
mov    0x2d8d(%rip),%rax
mov    (%rax),%ebx
mov    0x2d74(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xd9e(%rip),%rsi
lea    0xdaf(%rip),%rdx
lea    0xdb0(%rip),%r8
mov    %ebx,%edi
mov    %rax,%rcx
mov    $0x12d,%r9d
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    1310 <setup_unix_server_socket+0x190>
mov    0x2d4a(%rip),%rax
mov    (%rax),%ebp
mov    0x2d31(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
movl   $0x13b,(%rsp)
lea    0xe1e(%rip),%rsi
lea    0xd65(%rip),%rdx
lea    0xd66(%rip),%r9
mov    %ebp,%edi
mov    %rax,%rcx
mov    %r14,%r8
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    1309 <setup_unix_server_socket+0x189>
mov    0x2d06(%rip),%rax
mov    (%rax),%ebp
mov    0x2ced(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xdc0(%rip),%rsi
lea    0xd28(%rip),%rdx
lea    0xd29(%rip),%r8
mov    %ebp,%edi
mov    %rax,%rcx
mov    $0x133,%r9d
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %ebx,%edi
call   1050 <close@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
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 i32 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"
@.str.4 = [31 x i8] c"%s: bind: %s, path=%s (%s:%d)\0A\00"
@.str.5 = [33 x i8] c"%s: listen: %s, path=%s (%s:%d)\0A\00"
define i32 @setup_unix_server_socket(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.sockaddr_un
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%11 = load i32, i32* @AF_UNIX
%12 = load i32, i32* @SOCK_STREAM
%13 = call i32 @socket(i32 %11, i32 %12, i32 0)
store i32 %13, i32* %8
%14 = load i32, i32* %8
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %21
16: ; preds = %3
%17 = load i32, i32* @stderr
%18 = load i32, i32* @errno
%19 = call i8* @strerror(i32 %18)
%20 = call i32 (i32, i8*, i8*, i8*, i8*, ...) @fprintf(i32 %17, 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* %19, i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.2, i64 0, i64 0), i32 301)
store i32 -1, i32* %4
br label %71
21: ; preds = %3
%22 = load i32, i32* %7
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %37
24: ; preds = %21
store i32 1, i32* %9
%25 = load i32, i32* %8
%26 = load i32, i32* @FIONBIO
%27 = call i32 @ioctl(i32 %25, i32 %26, i32* %9)
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %36
29: ; preds = %24
%30 = load i32, i32* @stderr
%31 = load i32, i32* @errno
%32 = call i8* @strerror(i32 %31)
%33 = call i32 (i32, i8*, i8*, i8*, i8*, ...) @fprintf(i32 %30, 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* %32, i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.2, i64 0, i64 0), i32 307)
%34 = load i32, i32* %8
%35 = call i32 @close(i32 %34)
store i32 -1, i32* %4
br label %71
36: ; preds = %24
br label %37
37: ; preds = %36, %21
%38 = load i32, i32* @AF_UNIX
%39 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %10, i32 0, i32 1
store i32 %38, i32* %39
%40 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %10, i32 0, i32 0
%41 = load i32, i32* %40
%42 = load i8*, i8** %5
%43 = call i32 @strcpy(i32 %41, i8* %42)
%44 = load i32, i32* %8
%45 = bitcast %struct.sockaddr_un* %10 to %struct.sockaddr*
%46 = call i32 @bind(i32 %44, %struct.sockaddr* %45, i32 8)
%47 = icmp eq i32 %46, -1
br i1 %47, label %48, label %56
48: ; preds = %37
%49 = load i32, i32* @stderr
%50 = load i32, i32* @errno
%51 = call i8* @strerror(i32 %50)
%52 = load i8*, i8** %5
%53 = call i32 (i32, i8*, i8*, i8*, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %51, i8* %52, i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.2, i64 0, i64 0), i32 315)
%54 = load i32, i32* %8
%55 = call i32 @close(i32 %54)
store i32 -1, i32* %4
br label %71
56: ; preds = %37
%57 = load i32, i32* %8
%58 = load i32, i32* %6
%59 = call i32 @listen(i32 %57, i32 %58)
%60 = icmp eq i32 %59, -1
br i1 %60, label %61, label %69
61: ; preds = %56
%62 = load i32, i32* @stderr
%63 = load i32, i32* @errno
%64 = call i8* @strerror(i32 %63)
%65 = load i8*, i8** %5
%66 = call i32 (i32, i8*, i8*, i8*, i8*, ...) @fprintf(i32 %62, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %64, i8* %65, i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.2, i64 0, i64 0), i32 320)
%67 = load i32, i32* %8
%68 = call i32 @close(i32 %67)
store i32 -1, i32* %4
br label %71
69: ; preds = %56
%70 = load i32, i32* %8
store i32 %70, i32* %4
br label %71
71: ; preds = %69, %61, %48, %29, %16
%72 = load i32, i32* %4
ret i32 %72
}

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 i32 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"
@.str.4 = [31 x i8] c"%s: bind: %s, path=%s (%s:%d)\0A\00"
@.str.5 = [33 x i8] c"%s: listen: %s, path=%s (%s:%d)\0A\00"
define i32 @setup_unix_server_socket(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.sockaddr_un
%6 = bitcast i32* %4 to i8*
%7 = bitcast %struct.sockaddr_un* %5 to i8*
%8 = load i32, i32* @AF_UNIX
%9 = load i32, i32* @SOCK_STREAM
%10 = tail call i32 @socket(i32 %8, i32 %9, i32 0)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %17
12: ; preds = %3
%13 = load i32, i32* @stderr
%14 = load i32, i32* @errno
%15 = tail call i8* @strerror(i32 %14)
%16 = tail call i32 (i32, i8*, i8*, i8*, i8*, ...) @fprintf(i32 %13, 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* %15, i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.2, i64 0, i64 0), i32 301)
br label %51
17: ; preds = %3
%18 = icmp eq i32 %2, 0
br i1 %18, label %29, label %19
19: ; preds = %17
store i32 1, i32* %4
%20 = load i32, i32* @FIONBIO
%21 = call i32 @ioctl(i32 %10, i32 %20, i32* %4)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %29
23: ; preds = %19
%24 = load i32, i32* @stderr
%25 = load i32, i32* @errno
%26 = call i8* @strerror(i32 %25)
%27 = call i32 (i32, i8*, i8*, i8*, i8*, ...) @fprintf(i32 %24, 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* %26, i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.2, i64 0, i64 0), i32 307)
%28 = call i32 @close(i32 %10)
br label %51
29: ; preds = %19, %17
%30 = load i32, i32* @AF_UNIX
%31 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %5, i64 0, i32 1
store i32 %30, i32* %31
%32 = call i32 @strcpy(i32 undef, i8* %0)
%33 = bitcast %struct.sockaddr_un* %5 to %struct.sockaddr*
%34 = call i32 @bind(i32 %10, %struct.sockaddr* %33, i32 8)
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %42
36: ; preds = %29
%37 = load i32, i32* @stderr
%38 = load i32, i32* @errno
%39 = call i8* @strerror(i32 %38)
%40 = call i32 (i32, i8*, i8*, i8*, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %39, i8* %0, i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.2, i64 0, i64 0), i32 315)
%41 = call i32 @close(i32 %10)
br label %51
42: ; preds = %29
%43 = call i32 @listen(i32 %10, i32 %1)
%44 = icmp eq i32 %43, -1
br i1 %44, label %45, label %51
45: ; preds = %42
%46 = load i32, i32* @stderr
%47 = load i32, i32* @errno
%48 = call i8* @strerror(i32 %47)
%49 = call i32 (i32, i8*, i8*, i8*, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %48, i8* %0, i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.2, i64 0, i64 0), i32 320)
%50 = call i32 @close(i32 %10)
br label %51
51: ; preds = %42, %45, %36, %23, %12
%52 = phi i32 [ -1, %12 ], [ -1, %23 ], [ -1, %36 ], [ -1, %45 ], [ %10, %42 ]
ret i32 %52
}