#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 BUFSIZ;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ bind(int, struct sockaddr *, scalar_t__);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ unlink(char *);
int main() {
  struct sockaddr_un local;
  int sk;
  int i;
  char buf[BUFSIZ];
  sk = socket(AF_UNIX, SOCK_DGRAM, 0);
  local.sun_family = AF_UNIX;
  strcpy(local.sun_path, "socket_name");
  bind(sk, (struct sockaddr *)&local, strlen("socket_name") + 2);
  read(sk, buf, BUFSIZ);
  printf("%s\n", buf);
  unlink("socket_name");
  close(sk);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e3a(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
mov    0x2e15(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e0a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%edi
lea    0xe13(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x3c(%rbp)
lea    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
lea    0xdf9(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    %rax,%rdx
add    $0x2,%rdx
call   1090 <bind@plt>
mov    -0x30(%rbp),%rsi
mov    -0x14(%rbp),%edi
mov    0x2da3(%rip),%rax
mov    (%rax),%edx
call   1080 <read@plt>
mov    -0x30(%rbp),%rsi
lea    0xdcd(%rip),%rdi
call   1060 <printf@plt>
lea    0xdb5(%rip),%rdi
call   1030 <unlink@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsp,%r12
mov    0x2e48(%rip),%r13
mov    0x0(%r13),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    0x2e44(%rip),%r15
mov    (%r15),%edi
mov    0x2e32(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,%r14d
mov    (%r15),%eax
mov    %eax,-0x2c(%rbp)
lea    0xe39(%rip),%r15
mov    %r15,%rsi
call   1040 <strcpy@plt>
lea    -0x30(%rbp),%rsi
mov    $0xd,%edx
mov    %r14d,%edi
call   1080 <bind@plt>
mov    0x0(%r13),%edx
mov    %r14d,%edi
mov    %rbx,%rsi
call   1070 <read@plt>
lea    0xe16(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    %r15,%rdi
call   1030 <unlink@plt>
mov    %r14d,%edi
call   1060 <close@plt>
mov    %r12,%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@BUFSIZ = global i32 0
@AF_UNIX = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [12 x i8] c"socket_name\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.sockaddr_un
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
store i32 0, i32* %1
%7 = load i32, i32* @BUFSIZ
%8 = zext i32 %7 to i64
%9 = call i8* @llvm.stacksave()
store i8* %9, i8** %5
%10 = alloca i8, i64 %8
store i64 %8, i64* %6
%11 = load i32, i32* @AF_UNIX
%12 = load i32, i32* @SOCK_DGRAM
%13 = call i32 @socket(i32 %11, i32 %12, i32 0)
store i32 %13, i32* %3
%14 = load i32, i32* @AF_UNIX
%15 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %2, i32 0, i32 1
store i32 %14, i32* %15
%16 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %2, i32 0, i32 0
%17 = load i32, i32* %16
%18 = call i32 @strcpy(i32 %17, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%19 = load i32, i32* %3
%20 = bitcast %struct.sockaddr_un* %2 to %struct.sockaddr*
%21 = call i64 @strlen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%22 = add nsw i64 %21, 2
%23 = call i32 @bind(i32 %19, %struct.sockaddr* %20, i64 %22)
%24 = load i32, i32* %3
%25 = load i32, i32* @BUFSIZ
%26 = call i32 @read(i32 %24, i8* %10, i32 %25)
%27 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%28 = call i32 @unlink(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%29 = load i32, i32* %3
%30 = call i32 @close(i32 %29)
store i32 0, i32* %1
%31 = load i8*, i8** %5
%32 = load i32, i32* %1
ret i32 %32
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@BUFSIZ = global i32 0
@AF_UNIX = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [12 x i8] c"socket_name\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_un
%2 = bitcast %struct.sockaddr_un* %1 to i8*
%3 = load i32, i32* @BUFSIZ
%4 = zext i32 %3 to i64
%5 = tail call i8* @llvm.stacksave()
%6 = alloca i8, i64 %4
%7 = load i32, i32* @AF_UNIX
%8 = load i32, i32* @SOCK_DGRAM
%9 = tail call i32 @socket(i32 %7, i32 %8, i32 0)
%10 = load i32, i32* @AF_UNIX
%11 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %1, i64 0, i32 1
store i32 %10, i32* %11
%12 = tail call i32 @strcpy(i32 undef, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%13 = bitcast %struct.sockaddr_un* %1 to %struct.sockaddr*
%14 = call i32 @bind(i32 %9, %struct.sockaddr* %13, i64 13)
%15 = load i32, i32* @BUFSIZ
%16 = call i32 @read(i32 %9, i8* %6, i32 %15)
%17 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%18 = call i32 @unlink(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @close(i32 %9)
ret i32 0
}