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

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ SOCK_STREAM;
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ perror(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
int strlen(char *);
int main(int argc, char *argv[]) {
  int sfd;
  struct sockaddr_un sock;
  if (argc != 2) {
    fprintf(stderr, "Usage: %s PATH\n", argv[0]);
    return EXIT_FAILURE;
  }
  if (strlen(argv[1]) >= sizeof(sock.sun_path)) {
    fprintf(stderr, "%s: file name too long\n", argv[0]);
    return EXIT_FAILURE;
  }
  if ((sfd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
    perror("socket");
    return EXIT_FAILURE;
  }
  sock.sun_family = AF_UNIX;
  strcpy(sock.sun_path, argv[1]);
  if (bind(sfd, (struct sockaddr *)&sock, sizeof(sock)) == -1) {
    perror("bind");
    return EXIT_FAILURE;
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11ad <main+0x4d>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe69(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2e25(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1294 <main+0x134>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <strlen@plt>
cltq
cmp    $0x4,%rax
jb     11f3 <main+0x93>
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe33(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2ddf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1294 <main+0x134>
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
mov    0x2dcd(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    1235 <main+0xd5>
lea    0xe09(%rip),%rdi
call   1070 <perror@plt>
mov    0x2d9d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1294 <main+0x134>
mov    0x2dac(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1030 <strcpy@plt>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x8,%edx
call   1060 <bind@plt>
cmp    $0xffffffff,%eax
jne    1288 <main+0x128>
lea    0xdbd(%rip),%rdi
call   1070 <perror@plt>
mov    0x2d4a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1294 <main+0x134>
mov    0x2d31(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    1193 <main+0x33>
mov    0x8(%rbx),%rdi
call   1040 <strlen@plt>
cmp    $0x4,%eax
jb     11b4 <main+0x54>
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe7f(%rip),%rsi
jmp    11a6 <main+0x46>
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe5a(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2e16(%rip),%rax
jmp    1202 <main+0xa2>
mov    0x2e2d(%rip),%r14
mov    (%r14),%edi
mov    0x2e0b(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
cmp    $0xffffffff,%eax
je     120d <main+0xad>
mov    %eax,%ebp
mov    (%r14),%eax
mov    %eax,0xc(%rsp)
mov    0x8(%rbx),%rsi
call   1030 <strcpy@plt>
lea    0x8(%rsp),%rsi
mov    %ebp,%edi
mov    $0x8,%edx
call   1060 <bind@plt>
cmp    $0xffffffff,%eax
je     1216 <main+0xb6>
mov    0x2dbe(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe14(%rip),%rdi
jmp    121d <main+0xbd>
lea    0xe12(%rip),%rdi
call   1070 <perror@plt>
jmp    11ab <main+0x4b>

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [16 x i8] c"Usage: %s PATH\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [24 x i8] c"%s: file name too long\0A\00"
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str.2 = [7 x i8] c"socket\00"
@.str.3 = [5 x i8] c"bind\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.sockaddr_un
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %17
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = load i32, i32* @EXIT_FAILURE
store i32 %16, i32* %3
br label %57
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32 @strlen(i8* %20)
%22 = sext i32 %21 to i64
%23 = icmp uge i64 %22, 4
br i1 %23, label %24, label %31
24: ; preds = %17
%25 = load i32, i32* @stderr
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 0
%28 = load i8*, i8** %27
%29 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %28)
%30 = load i32, i32* @EXIT_FAILURE
store i32 %30, i32* %3
br label %57
31: ; preds = %17
%32 = load i32, i32* @AF_UNIX
%33 = load i32, i32* @SOCK_STREAM
%34 = call i32 @socket(i32 %32, i32 %33, i32 0)
store i32 %34, i32* %6
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %39
36: ; preds = %31
%37 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%38 = load i32, i32* @EXIT_FAILURE
store i32 %38, i32* %3
br label %57
39: ; preds = %31
%40 = load i32, i32* @AF_UNIX
%41 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %7, i32 0, i32 1
store i32 %40, i32* %41
%42 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %7, i32 0, i32 0
%43 = load i32, i32* %42
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 1
%46 = load i8*, i8** %45
%47 = call i32 @strcpy(i32 %43, i8* %46)
%48 = load i32, i32* %6
%49 = bitcast %struct.sockaddr_un* %7 to %struct.sockaddr*
%50 = call i32 @bind(i32 %48, %struct.sockaddr* %49, i32 8)
%51 = icmp eq i32 %50, -1
br i1 %51, label %52, label %55
52: ; preds = %39
%53 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%54 = load i32, i32* @EXIT_FAILURE
store i32 %54, i32* %3
br label %57
55: ; preds = %39
%56 = load i32, i32* @EXIT_SUCCESS
store i32 %56, i32* %3
br label %57
57: ; preds = %55, %52, %36, %24, %10
%58 = load i32, i32* %3
ret i32 %58
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [16 x i8] c"Usage: %s PATH\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [24 x i8] c"%s: file name too long\0A\00"
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str.2 = [7 x i8] c"socket\00"
@.str.3 = [5 x i8] c"bind\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_un
%4 = bitcast %struct.sockaddr_un* %3 to i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %36
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32 @strlen(i8* %12)
%14 = icmp ugt i32 %13, 3
br i1 %14, label %15, label %19
15: ; preds = %10
%16 = load i32, i32* @stderr
%17 = load i8*, i8** %1
%18 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %17)
br label %36
19: ; preds = %10
%20 = load i32, i32* @AF_UNIX
%21 = load i32, i32* @SOCK_STREAM
%22 = tail call i32 @socket(i32 %20, i32 %21, i32 0)
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %26
24: ; preds = %19
%25 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %36
26: ; preds = %19
%27 = load i32, i32* @AF_UNIX
%28 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 1
store i32 %27, i32* %28
%29 = load i8*, i8** %11
%30 = tail call i32 @strcpy(i32 undef, i8* %29)
%31 = bitcast %struct.sockaddr_un* %3 to %struct.sockaddr*
%32 = call i32 @bind(i32 %22, %struct.sockaddr* %31, i32 8)
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %36
34: ; preds = %26
%35 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %36
36: ; preds = %26, %34, %24, %15, %6
%37 = phi i32* [ @EXIT_FAILURE, %6 ], [ @EXIT_FAILURE, %15 ], [ @EXIT_FAILURE, %24 ], [ @EXIT_FAILURE, %34 ], [ @EXIT_SUCCESS, %26 ]
%38 = load i32, i32* %37
ret i32 %38
}