#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*/ message;
typedef int /*<<< orphan*/ addr;

/* 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 recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *, 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 addr;
  int rc, sd;
  socklen_t alen = sizeof(struct sockaddr_un);
  char message[1024];
  addr.sun_family = AF_UNIX;
  strcpy(addr.sun_path, "/tmp/mysock");
  sd = socket(PF_UNIX, SOCK_DGRAM, 0);
  unlink("/tmp/mysock");
  bind(sd, (struct sockaddr *)&addr, sizeof(addr));
  for (;;) {
    rc = recvfrom(sd, message, sizeof(message), 0, (struct sockaddr *)&addr,
                  &alen);
    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)
movl   $0x8,-0x1c(%rbp)
mov    0x2e58(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%edi
lea    0xe71(%rip),%rsi
call   1040 <strcpy@plt>
mov    0x2e5d(%rip),%rax
mov    (%rax),%edi
mov    0x2e2c(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %eax,-0x18(%rbp)
lea    0xe49(%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
lea    -0x10(%rbp),%r8
mov    $0x400,%edx
xor    %ecx,%ecx
lea    -0x1c(%rbp),%r9
call   1060 <recvfrom@plt>
mov    %eax,-0x14(%rbp)
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
lea    -0x420(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1050 <write@plt>
jmp    11cd <main+0x6d>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x410,%rsp
movl   $0x8,0x4(%rsp)
mov    0x2e5a(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
lea    0xe75(%rip),%rbx
mov    %rbx,%rsi
call   1040 <strcpy@plt>
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
mov    0x2e2d(%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),%r14
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x8,%edx
call   1070 <bind@plt>
lea    0x10(%rsp),%rbx
lea    0x4(%rsp),%r15
mov    0x2e0d(%rip),%r12
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    %r15,%r9
call   1060 <recvfrom@plt>
mov    (%r12),%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <write@plt>
jmp    11e0 <main+0x80>

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 i32
%6 = alloca [1024 x i8]
store i32 0, i32* %1
store i32 8, i32* %5
%7 = load i32, i32* @AF_UNIX
%8 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %2, i32 0, i32 1
store i32 %7, i32* %8
%9 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %2, i32 0, i32 0
%10 = load i32, i32* %9
%11 = call i32 @strcpy(i32 %10, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* @PF_UNIX
%13 = load i32, i32* @SOCK_DGRAM
%14 = call i32 @socket(i32 %12, i32 %13, i32 0)
store i32 %14, i32* %4
%15 = call i32 @unlink(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%16 = load i32, i32* %4
%17 = bitcast %struct.sockaddr_un* %2 to %struct.sockaddr*
%18 = call i32 @bind(i32 %16, %struct.sockaddr* %17, i32 8)
br label %19
19: ; preds = %19, %0
%20 = load i32, i32* %4
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%22 = bitcast %struct.sockaddr_un* %2 to %struct.sockaddr*
%23 = call i32 @recvfrom(i32 %20, i8* %21, i32 1024, i32 0, %struct.sockaddr* %22, i32* %5)
store i32 %23, i32* %3
%24 = load i32, i32* @STDOUT_FILENO
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%26 = load i32, i32* %3
%27 = call i32 @write(i32 %24, i8* %25, i32 %26)
br label %19
}

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 i32
%3 = alloca [1024 x i8]
%4 = bitcast %struct.sockaddr_un* %1 to i8*
%5 = bitcast i32* %2 to i8*
store i32 8, i32* %2
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%7 = load i32, i32* @AF_UNIX
%8 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %1, i64 0, i32 1
store i32 %7, i32* %8
%9 = tail call i32 @strcpy(i32 undef, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* @PF_UNIX
%11 = load i32, i32* @SOCK_DGRAM
%12 = tail call i32 @socket(i32 %10, i32 %11, i32 0)
%13 = tail call i32 @unlink(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%14 = bitcast %struct.sockaddr_un* %1 to %struct.sockaddr*
%15 = call i32 @bind(i32 %12, %struct.sockaddr* %14, i32 8)
br label %16
16: ; preds = %16, %0
%17 = call i32 @recvfrom(i32 %12, i8* %6, i32 1024, i32 0, %struct.sockaddr* %14, i32* %2)
%18 = load i32, i32* @STDOUT_FILENO
%19 = call i32 @write(i32 %18, i8* %6, i32 %17)
br label %16
}