#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 socklen_t;
typedef int /*<<< orphan*/ server_addr;
typedef int /*<<< orphan*/ msgbuff;
typedef int /*<<< orphan*/ client_addr;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
scalar_t__ listen(int, int);
int /*<<< orphan*/ memset(struct sockaddr_un *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ send(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
int /*<<< orphan*/ unlink(char *);
int main() {
  int listensocket;
  int connectsocket;
  FILE *fp;
  char msgbuff[255];
  struct sockaddr_un server_addr;
  struct sockaddr_un client_addr;
  socklen_t ca_len;
  if ((listensocket = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
    perror("Server: socket");
    return EXIT_FAILURE;
  }
  printf("Server: socket ready!\n");
  memset(&server_addr, 0, sizeof(struct sockaddr_un));
  server_addr.sun_family = AF_UNIX;
  strcpy(server_addr.sun_path, "mysocketname");
  if (bind(listensocket, (struct sockaddr *)&server_addr, sizeof(server_addr)) <
      0) {
    perror("Server: bind");
    return EXIT_FAILURE;
  }
  printf("Server: bind is ok!\n");
  if (listen(listensocket, 5) < 0) {
    perror("Server: listen");
    return EXIT_FAILURE;
  }
  printf("Server: listening...\n");
  memset(&client_addr, 0, sizeof(struct sockaddr_un));
  ca_len = sizeof(client_addr);
  if ((connectsocket = accept(listensocket, (struct sockaddr *)&client_addr,
                              &ca_len)) < 0) {
    perror("Server: accept");
    return EXIT_FAILURE;
  }
  printf("Server: accept new connection.\n");
  send(connectsocket, "Hello", 6, 0);
  recv(connectsocket, msgbuff, sizeof(msgbuff), 0);
  printf("%s\n", msgbuff);
  close(listensocket);
  close(connectsocket);
  unlink("mysocketname");
  printf("Server: exiting...\n");
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
mov    0x2df6(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    1214 <main+0x54>
lea    0xe02(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2dc6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13c2 <main+0x202>
lea    0xdf4(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x128(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1080 <memset@plt>
mov    0x2dac(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x124(%rbp)
mov    -0x128(%rbp),%edi
lea    0xdd5(%rip),%rsi
call   1050 <strcpy@plt>
mov    -0x8(%rbp),%edi
lea    -0x128(%rbp),%rsi
mov    $0x8,%edx
call   10b0 <bind@plt>
cmp    $0x0,%rax
jge    1291 <main+0xd1>
lea    0xdb8(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2d49(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13c2 <main+0x202>
lea    0xda8(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x8(%rbp),%edi
mov    $0x5,%esi
call   10a0 <listen@plt>
cmp    $0x0,%rax
jge    12d3 <main+0x113>
lea    0xd98(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2d07(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13c2 <main+0x202>
lea    0xd8a(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x130(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1080 <memset@plt>
movl   $0x8,-0x134(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x130(%rbp),%rsi
lea    -0x134(%rbp),%rdx
call   10d0 <accept@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    133d <main+0x17d>
lea    0xd53(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2c9d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13c2 <main+0x202>
lea    0xd45(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0xc(%rbp),%edi
lea    0xd54(%rip),%rsi
mov    $0x6,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    -0xc(%rbp),%edi
lea    -0x120(%rbp),%rsi
mov    $0xff,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
lea    -0x120(%rbp),%rsi
lea    0xd2a(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x8(%rbp),%edi
call   1090 <close@plt>
mov    -0xc(%rbp),%edi
call   1090 <close@plt>
lea    0xc83(%rip),%rdi
call   1040 <unlink@plt>
lea    0xd04(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    0x2c0b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x120,%rsp
mov    0x2e16(%rip),%r14
mov    (%r14),%edi
mov    0x2dfc(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
test   %eax,%eax
js     130e <main+0x14e>
mov    %eax,%ebx
lea    0xe57(%rip),%rdi
call   1060 <puts@plt>
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1080 <memset@plt>
mov    (%r14),%eax
mov    %eax,0x14(%rsp)
mov    0x10(%rsp),%edi
lea    0xdee(%rip),%rsi
call   1050 <strcpy@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x8,%edx
call   10b0 <bind@plt>
test   %rax,%rax
js     1317 <main+0x157>
lea    0xe1e(%rip),%rdi
call   1060 <puts@plt>
mov    %ebx,%edi
mov    $0x5,%esi
call   10a0 <listen@plt>
test   %rax,%rax
js     1320 <main+0x160>
lea    0xe11(%rip),%rdi
call   1060 <puts@plt>
lea    0x18(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1080 <memset@plt>
movl   $0x8,0xc(%rsp)
lea    0xc(%rsp),%rdx
mov    %ebx,%edi
mov    %rbp,%rsi
call   10d0 <accept@plt>
test   %eax,%eax
js     1329 <main+0x169>
mov    %eax,%ebp
lea    0xde5(%rip),%rdi
call   1060 <puts@plt>
lea    0xd94(%rip),%rsi
mov    %ebp,%edi
mov    $0x6,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
lea    0x20(%rsp),%r14
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0xff,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %r14,%rdi
call   1060 <puts@plt>
mov    %ebx,%edi
call   1090 <close@plt>
mov    %ebp,%edi
call   1090 <close@plt>
lea    0xd1b(%rip),%rdi
call   1040 <unlink@plt>
lea    0xdab(%rip),%rdi
call   1060 <puts@plt>
mov    0x2cbc(%rip),%rax
jmp    133c <main+0x17c>
lea    0xceb(%rip),%rdi
jmp    1330 <main+0x170>
lea    0xcfe(%rip),%rdi
jmp    1330 <main+0x170>
lea    0xd02(%rip),%rdi
jmp    1330 <main+0x170>
lea    0xd08(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2c94(%rip),%rax
mov    (%rax),%eax
add    $0x120,%rsp
pop    %rbx
pop    %r14
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
@.str = [15 x i8] c"Server: socket\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [23 x i8] c"Server: socket ready!\0A\00"
@.str.2 = [13 x i8] c"mysocketname\00"
@.str.3 = [13 x i8] c"Server: bind\00"
@.str.4 = [21 x i8] c"Server: bind is ok!\0A\00"
@.str.5 = [15 x i8] c"Server: listen\00"
@.str.6 = [22 x i8] c"Server: listening...\0A\00"
@.str.7 = [15 x i8] c"Server: accept\00"
@.str.8 = [32 x i8] c"Server: accept new connection.\0A\00"
@.str.9 = [6 x i8] c"Hello\00"
@.str.10 = [4 x i8] c"%s\0A\00"
@.str.11 = [20 x i8] c"Server: exiting...\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
%5 = alloca [255 x i8]
%6 = alloca %struct.sockaddr_un
%7 = alloca %struct.sockaddr_un
%8 = alloca i32
store i32 0, i32* %1
%9 = load i32, i32* @AF_UNIX
%10 = load i32, i32* @SOCK_STREAM
%11 = call i32 @socket(i32 %9, i32 %10, i32 0)
store i32 %11, i32* %2
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %0
%14 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
store i32 %15, i32* %1
br label %65
16: ; preds = %0
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 @memset(%struct.sockaddr_un* %6, i32 0, i32 8)
%19 = load i32, i32* @AF_UNIX
%20 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %6, i32 0, i32 1
store i32 %19, i32* %20
%21 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %6, i32 0, i32 0
%22 = load i32, i32* %21
%23 = call i32 @strcpy(i32 %22, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%24 = load i32, i32* %2
%25 = bitcast %struct.sockaddr_un* %6 to %struct.sockaddr*
%26 = call i64 @bind(i32 %24, %struct.sockaddr* %25, i32 8)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %16
%29 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%30 = load i32, i32* @EXIT_FAILURE
store i32 %30, i32* %1
br label %65
31: ; preds = %16
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
%33 = load i32, i32* %2
%34 = call i64 @listen(i32 %33, i32 5)
%35 = icmp slt i64 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %31
%37 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
%38 = load i32, i32* @EXIT_FAILURE
store i32 %38, i32* %1
br label %65
39: ; preds = %31
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0))
%41 = call i32 @memset(%struct.sockaddr_un* %7, i32 0, i32 8)
store i32 8, i32* %8
%42 = load i32, i32* %2
%43 = bitcast %struct.sockaddr_un* %7 to %struct.sockaddr*
%44 = call i32 @accept(i32 %42, %struct.sockaddr* %43, i32* %8)
store i32 %44, i32* %3
%45 = icmp slt i32 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %39
%47 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0))
%48 = load i32, i32* @EXIT_FAILURE
store i32 %48, i32* %1
br label %65
49: ; preds = %39
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.8, i64 0, i64 0))
%51 = load i32, i32* %3
%52 = call i32 @send(i32 %51, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0), i32 6, i32 0)
%53 = load i32, i32* %3
%54 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
%55 = call i32 @recv(i32 %53, i8* %54, i32 255, i32 0)
%56 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0), i8* %56)
%58 = load i32, i32* %2
%59 = call i32 @close(i32 %58)
%60 = load i32, i32* %3
%61 = call i32 @close(i32 %60)
%62 = call i32 @unlink(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.11, i64 0, i64 0))
%64 = load i32, i32* @EXIT_SUCCESS
store i32 %64, i32* %1
br label %65
65: ; preds = %49, %46, %36, %28, %13
%66 = load i32, i32* %1
ret i32 %66
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str = [15 x i8] c"Server: socket\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [13 x i8] c"mysocketname\00"
@.str.3 = [13 x i8] c"Server: bind\00"
@.str.5 = [15 x i8] c"Server: listen\00"
@.str.7 = [15 x i8] c"Server: accept\00"
@.str.9 = [6 x i8] c"Hello\00"
@EXIT_SUCCESS = global i32 0
@str = [22 x i8] c"Server: socket ready!\00"
@str.12 = [20 x i8] c"Server: bind is ok!\00"
@str.13 = [21 x i8] c"Server: listening...\00"
@str.14 = [31 x i8] c"Server: accept new connection.\00"
@str.15 = [19 x i8] c"Server: exiting...\00"
define i32 @main() {
%1 = alloca [255 x i8]
%2 = alloca %struct.sockaddr_un
%3 = alloca %struct.sockaddr_un
%4 = alloca i32
%5 = getelementptr inbounds [255 x i8], [255 x i8]* %1, i64 0, i64 0
%6 = bitcast %struct.sockaddr_un* %2 to i8*
%7 = bitcast %struct.sockaddr_un* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = load i32, i32* @AF_UNIX
%10 = load i32, i32* @SOCK_STREAM
%11 = tail call i32 @socket(i32 %9, i32 %10, i32 0)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %0
%14 = tail call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %51
15: ; preds = %0
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%17 = call i32 @memset(%struct.sockaddr_un* %2, i32 0, i32 8)
%18 = load i32, i32* @AF_UNIX
%19 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %2, i64 0, i32 1
store i32 %18, i32* %19
%20 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %2, i64 0, i32 0
%21 = load i32, i32* %20
%22 = call i32 @strcpy(i32 %21, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%23 = bitcast %struct.sockaddr_un* %2 to %struct.sockaddr*
%24 = call i64 @bind(i32 %11, %struct.sockaddr* %23, i32 8)
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %15
%27 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %51
28: ; preds = %15
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.12, i64 0, i64 0))
%30 = call i64 @listen(i32 %11, i32 5)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %28
%33 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
br label %51
34: ; preds = %28
%35 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.13, i64 0, i64 0))
%36 = call i32 @memset(%struct.sockaddr_un* %3, i32 0, i32 8)
store i32 8, i32* %4
%37 = bitcast %struct.sockaddr_un* %3 to %struct.sockaddr*
%38 = call i32 @accept(i32 %11, %struct.sockaddr* %37, i32* %4)
%39 = icmp slt i32 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %34
%41 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0))
br label %51
42: ; preds = %34
%43 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.14, i64 0, i64 0))
%44 = call i32 @send(i32 %38, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0), i32 6, i32 0)
%45 = call i32 @recv(i32 %38, i8* %5, i32 255, i32 0)
%46 = call i32 @puts(i8* %5)
%47 = call i32 @close(i32 %11)
%48 = call i32 @close(i32 %38)
%49 = call i32 @unlink(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%50 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.15, i64 0, i64 0))
br label %51
51: ; preds = %42, %40, %32, %26, %13
%52 = phi i32* [ @EXIT_FAILURE, %13 ], [ @EXIT_FAILURE, %26 ], [ @EXIT_FAILURE, %32 ], [ @EXIT_FAILURE, %40 ], [ @EXIT_SUCCESS, %42 ]
%53 = load i32, i32* %52
ret i32 %53
}