#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 dummy;
};
struct sockaddr {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ PF_LOCAL;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SUN_LEN(struct sockaddr_un *);
scalar_t__ bind(int, struct sockaddr *, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
scalar_t__ fill_sock_name(struct sockaddr_un *, char const *);
scalar_t__ listen(int, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int /*<<< orphan*/ test_msg(char *, char *, int, char const *,
                            int /*<<< orphan*/, ...);
int setup_srv_sock(const char *filename) {
  struct sockaddr_un name;
  int sock;
  if (fill_sock_name(&name, filename) < 0) {
    test_msg("ERR: %s:%d: "
             "filename \"%s\" is too long"
             " (errno = %d (%s))\n",
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/LK4D4/criu/refs/heads/master/test/zdtm/"
             "live/static/overmount_sock.c",
             37, filename, errno, strerror(errno));
    return -1;
  }
  sock = socket(PF_LOCAL, SOCK_STREAM, 0);
  if (sock < 0) {
    test_msg("ERR: %s:%d: "
             "can't create socket: %m"
             " (errno = %d (%s))\n",
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/LK4D4/criu/refs/heads/master/test/zdtm/"
             "live/static/overmount_sock.c",
             43, errno, strerror(errno));
    return -1;
  }
  if (bind(sock, (struct sockaddr *)&name, SUN_LEN(&name)) < 0) {
    test_msg("ERR: %s:%d: "
             "can't bind to socket \"%s\": %m"
             " (errno = %d (%s))\n",
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/LK4D4/criu/refs/heads/master/test/zdtm/"
             "live/static/overmount_sock.c",
             48, filename, errno, strerror(errno));
    goto err;
  }
  if (listen(sock, 1) < 0) {
    test_msg("ERR: %s:%d: "
             "can't listen on a socket \"%s\": %m\n"
             " (errno = %d (%s))\n",
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/LK4D4/criu/refs/heads/master/test/zdtm/"
             "live/static/overmount_sock.c",
             53, filename, errno, strerror(errno));
    goto err;
  }
  return sock;
err:
  close(sock);
  return -1;
}


x86 assembly (clang, -O0):
<setup_srv_sock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    -0x18(%rbp),%rdi
call   1050 <fill_sock_name@plt>
cmp    $0x0,%rax
jge    11f6 <setup_srv_sock+0x76>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e26(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x28(%rbp),%rcx
mov    -0x20(%rbp),%r8d
mov    %eax,%r9d
lea    0xe29(%rip),%rdi
lea    0xe5b(%rip),%rsi
mov    $0x25,%edx
mov    $0x0,%al
call   1040 <test_msg@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    135d <setup_srv_sock+0x1dd>
mov    0x2dd3(%rip),%rax
mov    (%rax),%edi
mov    0x2dda(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1265 <setup_srv_sock+0xe5>
mov    0x2db5(%rip),%rax
movslq (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    0x2da7(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x30(%rbp),%rcx
mov    %eax,%r8d
lea    0xe91(%rip),%rdi
lea    0xdec(%rip),%rsi
mov    $0x2b,%edx
mov    $0x0,%al
call   1040 <test_msg@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    135d <setup_srv_sock+0x1dd>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
lea    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
lea    -0x18(%rbp),%rdi
call   1090 <SUN_LEN@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
call   1070 <bind@plt>
cmp    $0x0,%rax
jge    12e0 <setup_srv_sock+0x160>
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    0x2d35(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
mov    0x2d29(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x48(%rbp),%rcx
mov    -0x40(%rbp),%r8d
mov    %eax,%r9d
lea    0xe46(%rip),%rdi
lea    0xd6a(%rip),%rsi
mov    $0x30,%edx
mov    $0x0,%al
call   1040 <test_msg@plt>
jmp    134e <setup_srv_sock+0x1ce>
mov    -0x1c(%rbp),%edi
mov    $0x1,%esi
call   1060 <listen@plt>
cmp    $0x0,%rax
jge    1343 <setup_srv_sock+0x1c3>
mov    -0x10(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    0x2cd2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    0x2cc6(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x58(%rbp),%rcx
mov    -0x4c(%rbp),%r8d
mov    %eax,%r9d
lea    0xe20(%rip),%rdi
lea    0xd07(%rip),%rsi
mov    $0x35,%edx
mov    $0x0,%al
call   1040 <test_msg@plt>
jmp    134e <setup_srv_sock+0x1ce>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    135d <setup_srv_sock+0x1dd>
mov    -0x1c(%rbp),%edi
call   1030 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setup_srv_sock>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rdi
mov    %rbx,%rsi
call   1050 <fill_sock_name@plt>
test   %rax,%rax
js     1225 <setup_srv_sock+0xa5>
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
mov    0x2e2f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
test   %eax,%eax
js     125a <setup_srv_sock+0xda>
mov    %eax,%ebp
lea    0x8(%rsp),%r14
mov    %r14,%rdi
call   1090 <SUN_LEN@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1070 <bind@plt>
test   %rax,%rax
js     128f <setup_srv_sock+0x10f>
mov    %ebp,%edi
mov    $0x1,%esi
call   1060 <listen@plt>
test   %rax,%rax
jns    12d0 <setup_srv_sock+0x150>
mov    0x2dd6(%rip),%rax
mov    (%rax),%r14d
mov    %r14d,%edi
call   1080 <strerror@plt>
lea    0xf37(%rip),%rdi
lea    0xe1e(%rip),%rsi
mov    $0x35,%edx
jmp    12b4 <setup_srv_sock+0x134>
mov    0x2dac(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1080 <strerror@plt>
lea    0xdc4(%rip),%rdi
lea    0xdf6(%rip),%rsi
mov    $0x25,%edx
mov    %rbx,%rcx
mov    %ebp,%r8d
mov    %eax,%r9d
xor    %eax,%eax
call   1040 <test_msg@plt>
jmp    12cb <setup_srv_sock+0x14b>
mov    0x2d77(%rip),%rax
mov    (%rax),%eax
movslq %eax,%rbx
mov    %ebx,%edi
call   1080 <strerror@plt>
lea    0xe63(%rip),%rdi
lea    0xdbe(%rip),%rsi
mov    $0x2b,%edx
mov    %rbx,%rcx
mov    %eax,%r8d
xor    %eax,%eax
call   1040 <test_msg@plt>
jmp    12cb <setup_srv_sock+0x14b>
mov    0x2d42(%rip),%rax
mov    (%rax),%r14d
mov    %r14d,%edi
call   1080 <strerror@plt>
lea    0xe66(%rip),%rdi
lea    0xd8a(%rip),%rsi
mov    $0x30,%edx
mov    %rbx,%rcx
mov    %r14d,%r8d
mov    %eax,%r9d
xor    %eax,%eax
call   1040 <test_msg@plt>
mov    %ebp,%edi
call   1030 <close@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_un = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [57 x i8] c"ERR: %s:%d: filename \22%s\22 is too long (errno = %d (%s))\0A\00"
@.str.1 = [158 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/LK4D4/criu/refs/heads/master/test/zdtm/live/static/overmount_sock.c\00"
@errno = global i32 0
@PF_LOCAL = global i32 0
@SOCK_STREAM = global i32 0
@.str.2 = [55 x i8] c"ERR: %s:%d: can't create socket: %m (errno = %d (%s))\0A\00"
@.str.3 = [61 x i8] c"ERR: %s:%d: can't bind to socket \22%s\22: %m (errno = %d (%s))\0A\00"
@.str.4 = [66 x i8] c"ERR: %s:%d: can't listen on a socket \22%s\22: %m\0A (errno = %d (%s))\0A\00"
define i32 @setup_srv_sock(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.sockaddr_un
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i64 @fill_sock_name(%struct.sockaddr_un* %4, i8* %6)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %15
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = load i32, i32* @errno
%12 = load i32, i32* @errno
%13 = call i32 @strerror(i32 %12)
%14 = call i32 (i8*, i8*, i32, i8*, i32, ...) @test_msg(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([158 x i8], [158 x i8]* @.str.1, i64 0, i64 0), i32 37, i8* %10, i32 %11, i32 %13)
store i32 -1, i32* %2
br label %55
15: ; preds = %1
%16 = load i32, i32* @PF_LOCAL
%17 = load i32, i32* @SOCK_STREAM
%18 = call i32 @socket(i32 %16, i32 %17, i32 0)
store i32 %18, i32* %5
%19 = load i32, i32* %5
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %28
21: ; preds = %15
%22 = load i32, i32* @errno
%23 = sext i32 %22 to i64
%24 = inttoptr i64 %23 to i8*
%25 = load i32, i32* @errno
%26 = call i32 @strerror(i32 %25)
%27 = call i32 (i8*, i8*, i32, i8*, i32, ...) @test_msg(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([158 x i8], [158 x i8]* @.str.1, i64 0, i64 0), i32 43, i8* %24, i32 %26)
store i32 -1, i32* %2
br label %55
28: ; preds = %15
%29 = load i32, i32* %5
%30 = bitcast %struct.sockaddr_un* %4 to %struct.sockaddr*
%31 = call i32 @SUN_LEN(%struct.sockaddr_un* %4)
%32 = call i64 @bind(i32 %29, %struct.sockaddr* %30, i32 %31)
%33 = icmp slt i64 %32, 0
br i1 %33, label %34, label %40
34: ; preds = %28
%35 = load i8*, i8** %3
%36 = load i32, i32* @errno
%37 = load i32, i32* @errno
%38 = call i32 @strerror(i32 %37)
%39 = call i32 (i8*, i8*, i32, i8*, i32, ...) @test_msg(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([158 x i8], [158 x i8]* @.str.1, i64 0, i64 0), i32 48, i8* %35, i32 %36, i32 %38)
br label %52
40: ; preds = %28
%41 = load i32, i32* %5
%42 = call i64 @listen(i32 %41, i32 1)
%43 = icmp slt i64 %42, 0
br i1 %43, label %44, label %50
44: ; preds = %40
%45 = load i8*, i8** %3
%46 = load i32, i32* @errno
%47 = load i32, i32* @errno
%48 = call i32 @strerror(i32 %47)
%49 = call i32 (i8*, i8*, i32, i8*, i32, ...) @test_msg(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([158 x i8], [158 x i8]* @.str.1, i64 0, i64 0), i32 53, i8* %45, i32 %46, i32 %48)
br label %52
50: ; preds = %40
%51 = load i32, i32* %5
store i32 %51, i32* %2
br label %55
52: ; preds = %44, %34
%53 = load i32, i32* %5
%54 = call i32 @close(i32 %53)
store i32 -1, i32* %2
br label %55
55: ; preds = %52, %50, %21, %9
%56 = load i32, i32* %2
ret i32 %56
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [57 x i8] c"ERR: %s:%d: filename \22%s\22 is too long (errno = %d (%s))\0A\00"
@.str.1 = [158 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/LK4D4/criu/refs/heads/master/test/zdtm/live/static/overmount_sock.c\00"
@errno = global i32 0
@PF_LOCAL = global i32 0
@SOCK_STREAM = global i32 0
@.str.2 = [55 x i8] c"ERR: %s:%d: can't create socket: %m (errno = %d (%s))\0A\00"
@.str.3 = [61 x i8] c"ERR: %s:%d: can't bind to socket \22%s\22: %m (errno = %d (%s))\0A\00"
@.str.4 = [66 x i8] c"ERR: %s:%d: can't listen on a socket \22%s\22: %m\0A (errno = %d (%s))\0A\00"
define i32 @setup_srv_sock(i8* %0) {
%2 = alloca %struct.sockaddr_un
%3 = bitcast %struct.sockaddr_un* %2 to i8*
%4 = call i64 @fill_sock_name(%struct.sockaddr_un* %2, i8* %0)
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %10
6: ; preds = %1
%7 = load i32, i32* @errno
%8 = call i32 @strerror(i32 %7)
%9 = call i32 (i8*, i8*, i32, i8*, i32, ...) @test_msg(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([158 x i8], [158 x i8]* @.str.1, i64 0, i64 0), i32 37, i8* %0, i32 %7, i32 %8)
br label %39
10: ; preds = %1
%11 = load i32, i32* @PF_LOCAL
%12 = load i32, i32* @SOCK_STREAM
%13 = call i32 @socket(i32 %11, i32 %12, i32 0)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %21
15: ; preds = %10
%16 = load i32, i32* @errno
%17 = sext i32 %16 to i64
%18 = inttoptr i64 %17 to i8*
%19 = call i32 @strerror(i32 %16)
%20 = call i32 (i8*, i8*, i32, i8*, i32, ...) @test_msg(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([158 x i8], [158 x i8]* @.str.1, i64 0, i64 0), i32 43, i8* %18, i32 %19)
br label %39
21: ; preds = %10
%22 = bitcast %struct.sockaddr_un* %2 to %struct.sockaddr*
%23 = call i32 @SUN_LEN(%struct.sockaddr_un* %2)
%24 = call i64 @bind(i32 %13, %struct.sockaddr* %22, i32 %23)
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %21
%27 = load i32, i32* @errno
%28 = call i32 @strerror(i32 %27)
%29 = call i32 (i8*, i8*, i32, i8*, i32, ...) @test_msg(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([158 x i8], [158 x i8]* @.str.1, i64 0, i64 0), i32 48, i8* %0, i32 %27, i32 %28)
br label %37
30: ; preds = %21
%31 = call i64 @listen(i32 %13, i32 1)
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %39
33: ; preds = %30
%34 = load i32, i32* @errno
%35 = call i32 @strerror(i32 %34)
%36 = call i32 (i8*, i8*, i32, i8*, i32, ...) @test_msg(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([158 x i8], [158 x i8]* @.str.1, i64 0, i64 0), i32 53, i8* %0, i32 %34, i32 %35)
br label %37
37: ; preds = %33, %26
%38 = call i32 @close(i32 %13)
br label %39
39: ; preds = %30, %37, %15, %6
%40 = phi i32 [ -1, %6 ], [ -1, %15 ], [ -1, %37 ], [ %13, %30 ]
ret i32 %40
}