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

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ PF_UNIX;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ STDOUT_FILENO;
int accept(int, int /*<<< orphan*/ *, int *);
int /*<<< orphan*/ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ listen(int, int);
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, cd;
  socklen_t alen = sizeof(struct sockaddr_un);
  char message[1024];
  uaddr.sun_family = AF_UNIX;
  strcpy(uaddr.sun_path, "/tmp/mysock");
  sd = socket(PF_UNIX, SOCK_STREAM, 0);
  unlink("/tmp/mysock");
  bind(sd, (struct sockaddr *)&uaddr, sizeof(uaddr));
  listen(sd, 5);
  for (;;) {
    cd = accept(sd, NULL, &alen);
    rc = read(cd, message, sizeof(message));
    write(STDOUT_FILENO, message, rc);
    close(cd);
  }
  close(sd);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x8,-0x20(%rbp)
mov    0x2e28(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%edi
lea    0xe41(%rip),%rsi
call   1040 <strcpy@plt>
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
mov    0x2df4(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x18(%rbp)
lea    0xe19(%rip),%rdi
call   1030 <unlink@plt>
mov    -0x18(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0x8,%edx
call   1090 <bind@plt>
mov    -0x18(%rbp),%edi
mov    $0x5,%esi
call   1080 <listen@plt>
mov    -0x18(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
lea    -0x20(%rbp),%rdx
call   10a0 <accept@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1070 <read@plt>
mov    %eax,-0x14(%rbp)
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
lea    -0x420(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1050 <write@plt>
mov    -0x1c(%rbp),%edi
call   1060 <close@plt>
jmp    120a <main+0x7a>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x410,%rsp
movl   $0x8,0x4(%rsp)
mov    0x2e2a(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
lea    0xe45(%rip),%rbx
mov    %rbx,%rsi
call   1040 <strcpy@plt>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
mov    0x2df5(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,%r15d
mov    %rbx,%rdi
call   1030 <unlink@plt>
lea    0x8(%rsp),%rsi
mov    %r15d,%edi
mov    $0x8,%edx
call   1090 <bind@plt>
mov    %r15d,%edi
mov    $0x5,%esi
call   1080 <listen@plt>
lea    0x4(%rsp),%r14
lea    0x10(%rsp),%rbx
mov    0x2dd1(%rip),%r12
nopw   0x0(%rax,%rax,1)
mov    %r15d,%edi
xor    %esi,%esi
mov    %r14,%rdx
call   10a0 <accept@plt>
mov    %eax,%ebp
mov    %eax,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1070 <read@plt>
mov    (%r12),%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <write@plt>
mov    %ebp,%edi
call   1060 <close@plt>
jmp    1220 <main+0x90>

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

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_STREAM = 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_STREAM
%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)
%16 = call i32 @listen(i32 %12, i32 5)
br label %17
17: ; preds = %17, %0
%18 = call i32 @accept(i32 %12, i32* null, i32* %2)
%19 = call i32 @read(i32 %18, i8* %6, i32 1024)
%20 = load i32, i32* @STDOUT_FILENO
%21 = call i32 @write(i32 %20, i8* %6, i32 %19)
%22 = call i32 @close(i32 %18)
br label %17
}