#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 */
typedef int /*<<< orphan*/ uaddr;
struct sockaddr_un {
  int /*<<< orphan*/ sun_path;
  int /*<<< orphan*/ sun_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ message;

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ PF_UNIX;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
int /*<<< orphan*/ unlink(char *);
int /*<<< orphan*/ write(int /*<<< orphan*/, char *, int);
int main(void) {
  struct sockaddr_un uaddr;
  int rc, sd;
  char message[1024];
  uaddr.sun_family = AF_UNIX;
  strcpy(uaddr.sun_path, "/tmp/mysock");
  sd = socket(PF_UNIX, SOCK_DGRAM, 0);
  unlink("/tmp/mysock");
  bind(sd, (struct sockaddr *)&uaddr, sizeof(uaddr));
  for (;;) {
    rc = read(sd, message, sizeof(message));
    write(STDOUT_FILENO, message, rc);
  }
  close(sd);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e5f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%edi
lea    0xe78(%rip),%rsi
call   1040 <strcpy@plt>
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
mov    0x2e33(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %eax,-0x18(%rbp)
lea    0xe50(%rip),%rdi
call   1030 <unlink@plt>
mov    -0x18(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0x8,%edx
call   1070 <bind@plt>
mov    -0x18(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1060 <read@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e04(%rip),%rax
mov    (%rax),%edi
lea    -0x420(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1050 <write@plt>
jmp    11c6 <main+0x66>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x410,%rsp
mov    0x2e66(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
lea    0xe81(%rip),%rbx
mov    %rbx,%rsi
call   1040 <strcpy@plt>
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
mov    0x2e39(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <unlink@plt>
lea    0x8(%rsp),%rsi
mov    %ebp,%edi
mov    $0x8,%edx
call   1070 <bind@plt>
lea    0x10(%rsp),%rbx
mov    0x2e21(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1060 <read@plt>
mov    (%r14),%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <write@plt>
jmp    11d0 <main+0x70>

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@.str = [12 x i8] c"/tmp/mysock\00"
@PF_UNIX = global i32 0
@SOCK_DGRAM = global i32 0
@STDOUT_FILENO = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.sockaddr_un
%3 = alloca i32
%4 = alloca i32
%5 = alloca [1024 x i8]
store i32 0, i32* %1
%6 = load i32, i32* @AF_UNIX
%7 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %2, i32 0, i32 1
store i32 %6, i32* %7
%8 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %2, i32 0, i32 0
%9 = load i32, i32* %8
%10 = call i32 @strcpy(i32 %9, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* @PF_UNIX
%12 = load i32, i32* @SOCK_DGRAM
%13 = call i32 @socket(i32 %11, i32 %12, i32 0)
store i32 %13, i32* %4
%14 = call i32 @unlink(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* %4
%16 = bitcast %struct.sockaddr_un* %2 to %struct.sockaddr*
%17 = call i32 @bind(i32 %15, %struct.sockaddr* %16, i32 8)
br label %18
18: ; preds = %18, %0
%19 = load i32, i32* %4
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%21 = call i32 @read(i32 %19, i8* %20, i32 1024)
store i32 %21, i32* %3
%22 = load i32, i32* @STDOUT_FILENO
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%24 = load i32, i32* %3
%25 = call i32 @write(i32 %22, i8* %23, i32 %24)
br label %18
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@.str = [12 x i8] c"/tmp/mysock\00"
@PF_UNIX = global i32 0
@SOCK_DGRAM = global i32 0
@STDOUT_FILENO = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca %struct.sockaddr_un
%2 = alloca [1024 x i8]
%3 = bitcast %struct.sockaddr_un* %1 to i8*
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%5 = load i32, i32* @AF_UNIX
%6 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %1, i64 0, i32 1
store i32 %5, i32* %6
%7 = tail call i32 @strcpy(i32 undef, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* @PF_UNIX
%9 = load i32, i32* @SOCK_DGRAM
%10 = tail call i32 @socket(i32 %8, i32 %9, i32 0)
%11 = tail call i32 @unlink(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%12 = bitcast %struct.sockaddr_un* %1 to %struct.sockaddr*
%13 = call i32 @bind(i32 %10, %struct.sockaddr* %12, i32 8)
br label %14
14: ; preds = %14, %0
%15 = call i32 @read(i32 %10, i8* %4, i32 1024)
%16 = load i32, i32* @STDOUT_FILENO
%17 = call i32 @write(i32 %16, i8* %4, i32 %15)
br label %14
}