#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;
};

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ EINVAL;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ F_SETFL;
int /*<<< orphan*/ O_NONBLOCK;
int /*<<< orphan*/ SOCK_STREAM;
int bind(int, struct sockaddr *, size_t);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fcntl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *, ...);
int listen(int, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
char *strerror(int /*<<< orphan*/);
int strlen(char *);
int init_socket(char *name, char *path) {
  if (strlen(path) >= 92) {
    fprintf(stderr, "%s: \"%s\" too long (max %zu bytes)\n", name, path,
            strlen(path));
    exit(EINVAL);
  }
  int sock = socket(AF_UNIX, SOCK_STREAM, 0);
  if (sock == -1) {
    fprintf(stderr, "%s: socket(): %s\n", name, strerror(errno));
    exit(EXIT_FAILURE);
  }
  if (fcntl(sock, F_SETFL, O_NONBLOCK) == -1) {
    fprintf(stderr, "%s: fcntl(): %s\n", name, strerror(errno));
    exit(EXIT_FAILURE);
  }
  struct sockaddr_un bound_sock;
  bound_sock.sun_family = AF_UNIX;
  strcpy(bound_sock.sun_path, path);
  size_t len = strlen(path) + sizeof(bound_sock.sun_family);
  if (bind(sock, (struct sockaddr *)(&bound_sock), len) == -1) {
    fprintf(stderr, "%s: bind(): %s\n", name, strerror(errno));
    exit(EXIT_FAILURE);
  }
  if (listen(sock, 1) == -1) {
    fprintf(stderr, "%s: listen(): %s\n", name, strerror(errno));
    exit(EXIT_FAILURE);
  }
  return sock;
}


x86 assembly (clang, -O0):
<init_socket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x5c,%eax
jl     1204 <init_socket+0x74>
mov    0x2e14(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    %eax,%r8d
lea    0xe11(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2dab(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
mov    0x2dac(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1272 <init_socket+0xe2>
mov    0x2d9f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    0x2d73(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%rdx
mov    %rax,%rcx
lea    0xdc6(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d45(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x14(%rbp),%edi
mov    0x2d4c(%rip),%rax
mov    (%rax),%esi
mov    0x2d63(%rip),%rax
mov    (%rax),%edx
call   1040 <fcntl@plt>
cmp    $0xffffffff,%eax
jne    12dd <init_socket+0x14d>
mov    0x2d34(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    0x2d08(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x5c(%rbp),%edi
mov    -0x58(%rbp),%rdx
mov    %rax,%rcx
lea    0xd6d(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2cda(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    0x2cfc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
cltq
add    $0x4,%rax
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1080 <bind@plt>
cmp    $0xffffffff,%eax
jne    1369 <init_socket+0x1d9>
mov    0x2ca8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    0x2c7c(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x6c(%rbp),%edi
mov    -0x68(%rbp),%rdx
mov    %rax,%rcx
lea    0xcf2(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2c4e(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x14(%rbp),%edi
mov    $0x1,%esi
call   1070 <listen@plt>
cmp    $0xffffffff,%eax
jne    13c7 <init_socket+0x237>
mov    0x2c4a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x7c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    0x2c1e(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x7c(%rbp),%edi
mov    -0x78(%rbp),%rdx
mov    %rax,%rcx
lea    0xca4(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2bf0(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x14(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_socket>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1050 <strlen@plt>
cmp    $0x5c,%eax
jge    1248 <init_socket+0xb8>
mov    0x2e2b(%rip),%r15
mov    (%r15),%edi
mov    0x2e01(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
cmp    $0xffffffff,%eax
je     1280 <init_socket+0xf0>
mov    %eax,%ebp
mov    0x2dee(%rip),%rax
mov    (%rax),%esi
mov    0x2e05(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
call   1040 <fcntl@plt>
cmp    $0xffffffff,%eax
je     12a0 <init_socket+0x110>
mov    (%r15),%eax
mov    %eax,0x4(%rsp)
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
movslq %eax,%rdx
add    $0x4,%rdx
mov    %rsp,%rsi
mov    %ebp,%edi
call   1080 <bind@plt>
cmp    $0xffffffff,%eax
je     12c0 <init_socket+0x130>
mov    %ebp,%edi
mov    $0x1,%esi
call   1070 <listen@plt>
cmp    $0xffffffff,%eax
je     12e0 <init_socket+0x150>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d81(%rip),%rax
mov    (%rax),%ebp
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0xda0(%rip),%rsi
mov    %ebp,%edi
mov    %r14,%rdx
mov    %rbx,%rcx
mov    %eax,%r8d
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x2d2f(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    0x2d49(%rip),%rax
mov    (%rax),%ebx
mov    0x2d28(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xd85(%rip),%rsi
jmp    12fe <init_socket+0x16e>
mov    0x2d29(%rip),%rax
mov    (%rax),%ebx
mov    0x2d08(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xd77(%rip),%rsi
jmp    12fe <init_socket+0x16e>
mov    0x2d09(%rip),%rax
mov    (%rax),%ebx
mov    0x2ce8(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xd68(%rip),%rsi
jmp    12fe <init_socket+0x16e>
mov    0x2ce9(%rip),%rax
mov    (%rax),%ebx
mov    0x2cc8(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xd58(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x2c9c(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [35 x i8] c"%s: \22%s\22 too long (max %zu bytes)\0A\00"
@EINVAL = global i32 0
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [18 x i8] c"%s: socket(): %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@.str.2 = [17 x i8] c"%s: fcntl(): %s\0A\00"
@.str.3 = [16 x i8] c"%s: bind(): %s\0A\00"
@.str.4 = [18 x i8] c"%s: listen(): %s\0A\00"
define i32 @init_socket(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca %struct.sockaddr_un
%7 = alloca i64
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %4
%9 = call i32 @strlen(i8* %8)
%10 = icmp sge i32 %9, 92
br i1 %10, label %11, label %20
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8*, i8** %3
%14 = load i8*, i8** %4
%15 = load i8*, i8** %4
%16 = call i32 @strlen(i8* %15)
%17 = call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %13, i8* %14, i32 %16)
%18 = load i32, i32* @EINVAL
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %2
%21 = load i32, i32* @AF_UNIX
%22 = load i32, i32* @SOCK_STREAM
%23 = call i32 @socket(i32 %21, i32 %22, i32 0)
store i32 %23, i32* %5
%24 = load i32, i32* %5
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %34
26: ; preds = %20
%27 = load i32, i32* @stderr
%28 = load i8*, i8** %3
%29 = load i32, i32* @errno
%30 = call i8* @strerror(i32 %29)
%31 = call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %28, i8* %30)
%32 = load i32, i32* @EXIT_FAILURE
%33 = call i32 @exit(i32 %32)
unreachable
34: ; preds = %20
%35 = load i32, i32* %5
%36 = load i32, i32* @F_SETFL
%37 = load i32, i32* @O_NONBLOCK
%38 = call i32 @fcntl(i32 %35, i32 %36, i32 %37)
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %48
40: ; preds = %34
%41 = load i32, i32* @stderr
%42 = load i8*, i8** %3
%43 = load i32, i32* @errno
%44 = call i8* @strerror(i32 %43)
%45 = call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %42, i8* %44)
%46 = load i32, i32* @EXIT_FAILURE
%47 = call i32 @exit(i32 %46)
unreachable
48: ; preds = %34
%49 = load i32, i32* @AF_UNIX
%50 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %6, i32 0, i32 1
store i32 %49, i32* %50
%51 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %6, i32 0, i32 0
%52 = load i32, i32* %51
%53 = load i8*, i8** %4
%54 = call i32 @strcpy(i32 %52, i8* %53)
%55 = load i8*, i8** %4
%56 = call i32 @strlen(i8* %55)
%57 = sext i32 %56 to i64
%58 = add i64 %57, 4
store i64 %58, i64* %7
%59 = load i32, i32* %5
%60 = bitcast %struct.sockaddr_un* %6 to %struct.sockaddr*
%61 = load i64, i64* %7
%62 = call i32 @bind(i32 %59, %struct.sockaddr* %60, i64 %61)
%63 = icmp eq i32 %62, -1
br i1 %63, label %64, label %72
64: ; preds = %48
%65 = load i32, i32* @stderr
%66 = load i8*, i8** %3
%67 = load i32, i32* @errno
%68 = call i8* @strerror(i32 %67)
%69 = call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %65, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %66, i8* %68)
%70 = load i32, i32* @EXIT_FAILURE
%71 = call i32 @exit(i32 %70)
unreachable
72: ; preds = %48
%73 = load i32, i32* %5
%74 = call i32 @listen(i32 %73, i32 1)
%75 = icmp eq i32 %74, -1
br i1 %75, label %76, label %84
76: ; preds = %72
%77 = load i32, i32* @stderr
%78 = load i8*, i8** %3
%79 = load i32, i32* @errno
%80 = call i8* @strerror(i32 %79)
%81 = call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %77, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %78, i8* %80)
%82 = load i32, i32* @EXIT_FAILURE
%83 = call i32 @exit(i32 %82)
unreachable
84: ; preds = %72
%85 = load i32, i32* %5
ret i32 %85
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [35 x i8] c"%s: \22%s\22 too long (max %zu bytes)\0A\00"
@EINVAL = global i32 0
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [18 x i8] c"%s: socket(): %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@.str.2 = [17 x i8] c"%s: fcntl(): %s\0A\00"
@.str.3 = [16 x i8] c"%s: bind(): %s\0A\00"
@.str.4 = [18 x i8] c"%s: listen(): %s\0A\00"
define i32 @init_socket(i8* %0, i8* %1) {
%3 = alloca %struct.sockaddr_un
%4 = tail call i32 @strlen(i8* %1)
%5 = icmp sgt i32 %4, 91
br i1 %5, label %6, label %12
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 @strlen(i8* %1)
%9 = tail call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1, i32 %8)
%10 = load i32, i32* @EINVAL
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %2
%13 = load i32, i32* @AF_UNIX
%14 = load i32, i32* @SOCK_STREAM
%15 = tail call i32 @socket(i32 %13, i32 %14, i32 0)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %24
17: ; preds = %12
%18 = load i32, i32* @stderr
%19 = load i32, i32* @errno
%20 = tail call i8* @strerror(i32 %19)
%21 = tail call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %20)
%22 = load i32, i32* @EXIT_FAILURE
%23 = tail call i32 @exit(i32 %22)
unreachable
24: ; preds = %12
%25 = load i32, i32* @F_SETFL
%26 = load i32, i32* @O_NONBLOCK
%27 = tail call i32 @fcntl(i32 %15, i32 %25, i32 %26)
%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 = tail call i8* @strerror(i32 %31)
%33 = tail call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* %32)
%34 = load i32, i32* @EXIT_FAILURE
%35 = tail call i32 @exit(i32 %34)
unreachable
36: ; preds = %24
%37 = bitcast %struct.sockaddr_un* %3 to i8*
%38 = load i32, i32* @AF_UNIX
%39 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 1
store i32 %38, i32* %39
%40 = tail call i32 @strcpy(i32 undef, i8* %1)
%41 = tail call i32 @strlen(i8* %1)
%42 = sext i32 %41 to i64
%43 = add nsw i64 %42, 4
%44 = bitcast %struct.sockaddr_un* %3 to %struct.sockaddr*
%45 = call i32 @bind(i32 %15, %struct.sockaddr* %44, i64 %43)
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %54
47: ; preds = %36
%48 = load i32, i32* @stderr
%49 = load i32, i32* @errno
%50 = call i8* @strerror(i32 %49)
%51 = call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %0, i8* %50)
%52 = load i32, i32* @EXIT_FAILURE
%53 = call i32 @exit(i32 %52)
unreachable
54: ; preds = %36
%55 = call i32 @listen(i32 %15, i32 1)
%56 = icmp eq i32 %55, -1
br i1 %56, label %57, label %64
57: ; preds = %54
%58 = load i32, i32* @stderr
%59 = load i32, i32* @errno
%60 = call i8* @strerror(i32 %59)
%61 = call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %58, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %0, i8* %60)
%62 = load i32, i32* @EXIT_FAILURE
%63 = call i32 @exit(i32 %62)
unreachable
64: ; preds = %54
ret i32 %15
}