#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 {
  char *sun_path;
  int /*<<< orphan*/ sun_family;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ addr2;
typedef int /*<<< orphan*/ addr1;

/* Variables and functions */
int /*<<< orphan*/ AF_LOCAL;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SUN_LEN(struct sockaddr_un *);
scalar_t__ bind(int, struct sockaddr *, int /*<<< orphan*/);
int /*<<< orphan*/ bzero(struct sockaddr_un *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ getsockname(int, struct sockaddr *, int *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, ...);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strncpy(char *, char *, int);
int /*<<< orphan*/ unlink(char *);
int main(int argc, char *argv[]) {
  int sockfd;
  socklen_t len;
  struct sockaddr_un addr1, addr2;
  if (2 != argc) {
    printf("USAGE : %s <pathname>\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  if ((sockfd = socket(AF_LOCAL, SOCK_STREAM, 0)) < 0) {
    perror("socket");
    exit(EXIT_FAILURE);
  }
  unlink(argv[1]);
  bzero(&addr1, sizeof(addr1));
  addr1.sun_family = AF_LOCAL;
  strncpy(addr1.sun_path, argv[1], sizeof(addr1.sun_path) - 1);
  if (bind(sockfd, (struct sockaddr *)&addr1, SUN_LEN(&addr1)) < 0) {
    perror("bind");
    exit(EXIT_FAILURE);
  }
  len = sizeof(addr2);
  if (getsockname(sockfd, (struct sockaddr *)&addr2, &len) < 0) {
    perror("getsockname");
    exit(EXIT_FAILURE);
  }
  printf("bound name = %s, returned len = %d\n", addr2.sun_path, len);
  exit(EXIT_FAILURE);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x2,%eax
cmp    -0x8(%rbp),%eax
je     11e7 <main+0x47>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe2e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2df0(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
mov    0x2de1(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1226 <main+0x86>
lea    0xe04(%rip),%rdi
call   1070 <perror@plt>
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <unlink@plt>
lea    -0x28(%rbp),%rdi
mov    $0x10,%esi
call   1080 <bzero@plt>
mov    0x2da0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    $0x7,%edx
call   1040 <strncpy@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x44(%rbp)
lea    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
lea    -0x28(%rbp),%rdi
call   10b0 <SUN_LEN@plt>
mov    -0x44(%rbp),%edi
mov    -0x40(%rbp),%rsi
mov    %eax,%edx
call   1060 <bind@plt>
cmp    $0x0,%rax
jge    12ac <main+0x10c>
lea    0xd85(%rip),%rdi
call   1070 <perror@plt>
mov    0x2d2b(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
movl   $0x10,-0x18(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x38(%rbp),%rsi
lea    -0x18(%rbp),%rdx
call   1090 <getsockname@plt>
cmp    $0x0,%rax
jge    12e7 <main+0x147>
lea    0xd4f(%rip),%rdi
call   1070 <perror@plt>
mov    0x2cf0(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x38(%rbp),%rsi
mov    -0x18(%rbp),%edx
lea    0xd3a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2ccd(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    11dc <main+0x3c>
mov    0x2e2f(%rip),%r15
mov    (%r15),%edi
mov    0x2e15(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
test   %eax,%eax
jns    11f2 <main+0x52>
lea    0xe40(%rip),%rdi
jmp    1270 <main+0xd0>
mov    (%rbx),%rsi
lea    0xe1a(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1275 <main+0xd5>
mov    %eax,%ebp
mov    0x8(%rbx),%rdi
call   1030 <unlink@plt>
lea    0x8(%rsp),%r14
mov    %r14,%rdi
mov    $0x10,%esi
call   1080 <bzero@plt>
mov    (%r15),%eax
mov    %eax,0x10(%rsp)
mov    0x8(%rsp),%rdi
mov    0x8(%rbx),%rsi
mov    $0x7,%edx
call   1040 <strncpy@plt>
mov    %r14,%rdi
call   10b0 <SUN_LEN@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1060 <bind@plt>
test   %rax,%rax
jns    124b <main+0xab>
lea    0xdd5(%rip),%rdi
jmp    1270 <main+0xd0>
movl   $0x10,0x4(%rsp)
lea    0x18(%rsp),%rsi
lea    0x4(%rsp),%rdx
mov    %ebp,%edi
call   1090 <getsockname@plt>
test   %rax,%rax
jns    1283 <main+0xe3>
lea    0xdb3(%rip),%rdi
call   1070 <perror@plt>
mov    0x2d54(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    0x18(%rsp),%rsi
mov    0x4(%rsp),%edx
lea    0xd9c(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1275 <main+0xd5>

LLVM IR (-O0):
%struct.sockaddr_un = type { i8*, i32 }
%struct.sockaddr = type { i32 }
@.str = [23 x i8] c"USAGE : %s <pathname>\0A\00"
@EXIT_FAILURE = global i32 0
@AF_LOCAL = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [7 x i8] c"socket\00"
@.str.2 = [5 x i8] c"bind\00"
@.str.3 = [12 x i8] c"getsockname\00"
@.str.4 = [36 x i8] c"bound name = %s, returned len = %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.sockaddr_un
%9 = alloca %struct.sockaddr_un
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 2, %10
br i1 %11, label %12, label %19
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %2
%20 = load i32, i32* @AF_LOCAL
%21 = load i32, i32* @SOCK_STREAM
%22 = call i32 @socket(i32 %20, i32 %21, i32 0)
store i32 %22, i32* %6
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %19
%25 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%26 = load i32, i32* @EXIT_FAILURE
%27 = call i32 @exit(i32 %26)
unreachable
28: ; preds = %19
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = call i32 @unlink(i8* %31)
%33 = call i32 @bzero(%struct.sockaddr_un* %8, i32 16)
%34 = load i32, i32* @AF_LOCAL
%35 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %8, i32 0, i32 1
store i32 %34, i32* %35
%36 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %8, i32 0, i32 0
%37 = load i8*, i8** %36
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 1
%40 = load i8*, i8** %39
%41 = call i32 @strncpy(i8* %37, i8* %40, i32 7)
%42 = load i32, i32* %6
%43 = bitcast %struct.sockaddr_un* %8 to %struct.sockaddr*
%44 = call i32 @SUN_LEN(%struct.sockaddr_un* %8)
%45 = call i64 @bind(i32 %42, %struct.sockaddr* %43, i32 %44)
%46 = icmp slt i64 %45, 0
br i1 %46, label %47, label %51
47: ; preds = %28
%48 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%49 = load i32, i32* @EXIT_FAILURE
%50 = call i32 @exit(i32 %49)
unreachable
51: ; preds = %28
store i32 16, i32* %7
%52 = load i32, i32* %6
%53 = bitcast %struct.sockaddr_un* %9 to %struct.sockaddr*
%54 = call i64 @getsockname(i32 %52, %struct.sockaddr* %53, i32* %7)
%55 = icmp slt i64 %54, 0
br i1 %55, label %56, label %60
56: ; preds = %51
%57 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%58 = load i32, i32* @EXIT_FAILURE
%59 = call i32 @exit(i32 %58)
unreachable
60: ; preds = %51
%61 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %9, i32 0, i32 0
%62 = load i8*, i8** %61
%63 = load i32, i32* %7
%64 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), i8* %62, i32 %63)
%65 = load i32, i32* @EXIT_FAILURE
%66 = call i32 @exit(i32 %65)
unreachable
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i8*, i32 }
%struct.sockaddr = type { i32 }
@.str = [23 x i8] c"USAGE : %s <pathname>\0A\00"
@EXIT_FAILURE = global i32 0
@AF_LOCAL = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [7 x i8] c"socket\00"
@.str.2 = [5 x i8] c"bind\00"
@.str.3 = [12 x i8] c"getsockname\00"
@.str.4 = [36 x i8] c"bound name = %s, returned len = %d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr_un
%5 = alloca %struct.sockaddr_un
%6 = bitcast i32* %3 to i8*
%7 = bitcast %struct.sockaddr_un* %4 to i8*
%8 = bitcast %struct.sockaddr_un* %5 to i8*
%9 = icmp eq i32 %0, 2
br i1 %9, label %15, label %10
10: ; preds = %2
%11 = load i8*, i8** %1
%12 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = load i32, i32* @EXIT_FAILURE
%14 = tail call i32 @exit(i32 %13)
unreachable
15: ; preds = %2
%16 = load i32, i32* @AF_LOCAL
%17 = load i32, i32* @SOCK_STREAM
%18 = tail call i32 @socket(i32 %16, i32 %17, i32 0)
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %15
%21 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%22 = load i32, i32* @EXIT_FAILURE
%23 = tail call i32 @exit(i32 %22)
unreachable
24: ; preds = %15
%25 = getelementptr inbounds i8*, i8** %1, i64 1
%26 = load i8*, i8** %25
%27 = tail call i32 @unlink(i8* %26)
%28 = call i32 @bzero(%struct.sockaddr_un* %4, i32 16)
%29 = load i32, i32* @AF_LOCAL
%30 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %4, i64 0, i32 1
store i32 %29, i32* %30
%31 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %4, i64 0, i32 0
%32 = load i8*, i8** %31
%33 = load i8*, i8** %25
%34 = tail call i32 @strncpy(i8* %32, i8* %33, i32 7)
%35 = bitcast %struct.sockaddr_un* %4 to %struct.sockaddr*
%36 = call i32 @SUN_LEN(%struct.sockaddr_un* %4)
%37 = call i64 @bind(i32 %18, %struct.sockaddr* %35, i32 %36)
%38 = icmp slt i64 %37, 0
br i1 %38, label %39, label %43
39: ; preds = %24
%40 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%41 = load i32, i32* @EXIT_FAILURE
%42 = call i32 @exit(i32 %41)
unreachable
43: ; preds = %24
store i32 16, i32* %3
%44 = bitcast %struct.sockaddr_un* %5 to %struct.sockaddr*
%45 = call i64 @getsockname(i32 %18, %struct.sockaddr* %44, i32* %3)
%46 = icmp slt i64 %45, 0
br i1 %46, label %47, label %51
47: ; preds = %43
%48 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%49 = load i32, i32* @EXIT_FAILURE
%50 = call i32 @exit(i32 %49)
unreachable
51: ; preds = %43
%52 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %5, i64 0, i32 0
%53 = load i8*, i8** %52
%54 = load i32, i32* %3
%55 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), i8* %53, i32 %54)
%56 = load i32, i32* @EXIT_FAILURE
%57 = call i32 @exit(i32 %56)
unreachable
}