#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 {
  char *member_1;
  int /*<<< orphan*/ member_0;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ client_info;

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SUN_LEN(struct sockaddr_un *);
int accept(int, struct sockaddr *, int *);
int bind(int, struct sockaddr *, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int listen(int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ unlink(char *);
int main() {
  unlink("/tmp/my_socket");
  int sock_fd = 0;
  sock_fd = socket(AF_UNIX, SOCK_STREAM, 0);
  struct sockaddr_un our_addr = {AF_UNIX, "/tmp/my_socket"};
  int ret = bind(sock_fd, (struct sockaddr *)&our_addr, SUN_LEN(&our_addr));
  if (ret < 0) {
    perror("bind");
  };
  ret = listen(sock_fd, 100500);
  struct sockaddr_un client_info;
  int client_info_len = sizeof(client_info);
  int client_fd =
      accept(sock_fd, (struct sockaddr *)&client_info, &client_info_len);
  char message[10] = {0};
  ret = read(client_fd, message, 10);
  if (ret < 0) {
    perror("read");
    exit(1);
  }
  printf("Message received: %s\n", message);
  close(client_fd);
  close(sock_fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe2a(%rip),%rdi
call   1030 <unlink@plt>
movl   $0x0,-0x8(%rbp)
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
mov    0x2de6(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x8(%rbp)
mov    0x2de3(%rip),%rax
movslq (%rax),%rax
mov    %rax,-0x18(%rbp)
lea    0xded(%rip),%rax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x54(%rbp)
lea    -0x18(%rbp),%rax
mov    %rax,-0x50(%rbp)
lea    -0x18(%rbp),%rdi
call   10d0 <SUN_LEN@plt>
mov    -0x54(%rbp),%edi
mov    -0x50(%rbp),%rsi
mov    %eax,%edx
call   1090 <bind@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1254 <main+0x94>
lea    0xdc0(%rip),%rdi
call   10a0 <perror@plt>
mov    -0x8(%rbp),%edi
mov    $0x18894,%esi
call   1080 <listen@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x10,-0x34(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x30(%rbp),%rsi
lea    -0x34(%rbp),%rdx
call   10b0 <accept@plt>
mov    %eax,-0x38(%rbp)
lea    -0x42(%rbp),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1050 <memset@plt>
mov    -0x38(%rbp),%edi
lea    -0x42(%rbp),%rsi
mov    $0xa,%edx
call   1070 <read@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    12c2 <main+0x102>
lea    0xd61(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
lea    -0x42(%rbp),%rsi
lea    0xd4c(%rip),%rdi
call   1040 <printf@plt>
mov    -0x38(%rbp),%edi
call   1060 <close@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x40,%rsp
lea    0xe41(%rip),%r14
mov    %r14,%rdi
call   1030 <unlink@plt>
mov    0x2e1a(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2e00(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,%ebx
movslq 0x0(%rbp),%rax
mov    %rax,0x20(%rsp)
mov    %r14d,0x28(%rsp)
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
call   10c0 <SUN_LEN@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1080 <bind@plt>
test   %eax,%eax
js     1284 <main+0xd4>
mov    %ebx,%edi
mov    $0x18894,%esi
call   1070 <listen@plt>
movl   $0x10,0xc(%rsp)
lea    0x30(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %ebx,%edi
call   10a0 <accept@plt>
mov    %eax,%ebp
movw   $0x0,0x18(%rsp)
movq   $0x0,0x10(%rsp)
lea    0x10(%rsp),%rsi
mov    %eax,%edi
mov    $0xa,%edx
call   1060 <read@plt>
test   %eax,%eax
js     1295 <main+0xe5>
lea    0xdb8(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1040 <printf@plt>
mov    %ebp,%edi
call   1050 <close@plt>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xd84(%rip),%rdi
call   1090 <perror@plt>
jmp    120e <main+0x5e>
lea    0xd78(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_un = type { i8*, i32 }
%struct.sockaddr = type { i32 }
@.str = [15 x i8] c"/tmp/my_socket\00"
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [5 x i8] c"bind\00"
@.str.2 = [5 x i8] c"read\00"
@.str.3 = [22 x i8] c"Message received: %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_un
%4 = alloca i32
%5 = alloca %struct.sockaddr_un
%6 = alloca i32
%7 = alloca i32
%8 = alloca [10 x i8]
store i32 0, i32* %1
%9 = call i32 @unlink(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %2
%10 = load i32, i32* @AF_UNIX
%11 = load i32, i32* @SOCK_STREAM
%12 = call i32 @socket(i32 %10, i32 %11, i32 0)
store i32 %12, i32* %2
%13 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i32 0, i32 0
%14 = load i32, i32* @AF_UNIX
%15 = sext i32 %14 to i64
%16 = inttoptr i64 %15 to i8*
store i8* %16, i8** %13
%17 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i32 0, i32 1
store i32 ptrtoint ([15 x i8]* @.str to i32), i32* %17
%18 = load i32, i32* %2
%19 = bitcast %struct.sockaddr_un* %3 to %struct.sockaddr*
%20 = call i32 @SUN_LEN(%struct.sockaddr_un* %3)
%21 = call i32 @bind(i32 %18, %struct.sockaddr* %19, i32 %20)
store i32 %21, i32* %4
%22 = load i32, i32* %4
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %0
%25 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %26
26: ; preds = %24, %0
%27 = load i32, i32* %2
%28 = call i32 @listen(i32 %27, i32 100500)
store i32 %28, i32* %4
store i32 16, i32* %6
%29 = load i32, i32* %2
%30 = bitcast %struct.sockaddr_un* %5 to %struct.sockaddr*
%31 = call i32 @accept(i32 %29, %struct.sockaddr* %30, i32* %6)
store i32 %31, i32* %7
%32 = bitcast [10 x i8]* %8 to i8*
%33 = load i32, i32* %7
%34 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%35 = call i32 @read(i32 %33, i8* %34, i32 10)
store i32 %35, i32* %4
%36 = load i32, i32* %4
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %26
%39 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%40 = call i32 @exit(i32 1)
unreachable
41: ; preds = %26
%42 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%43 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %42)
%44 = load i32, i32* %7
%45 = call i32 @close(i32 %44)
%46 = load i32, i32* %2
%47 = call i32 @close(i32 %46)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i8*, i32 }
%struct.sockaddr = type { i32 }
@.str = [15 x i8] c"/tmp/my_socket\00"
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [5 x i8] c"bind\00"
@.str.2 = [5 x i8] c"read\00"
@.str.3 = [22 x i8] c"Message received: %s\0A\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_un
%2 = alloca %struct.sockaddr_un
%3 = alloca i32
%4 = alloca [10 x i8]
%5 = tail call i32 @unlink(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @AF_UNIX
%7 = load i32, i32* @SOCK_STREAM
%8 = tail call i32 @socket(i32 %6, i32 %7, i32 0)
%9 = bitcast %struct.sockaddr_un* %1 to i8*
%10 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %1, i64 0, i32 0
%11 = load i32, i32* @AF_UNIX
%12 = sext i32 %11 to i64
%13 = inttoptr i64 %12 to i8*
store i8* %13, i8** %10
%14 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %1, i64 0, i32 1
store i32 ptrtoint ([15 x i8]* @.str to i32), i32* %14
%15 = bitcast %struct.sockaddr_un* %1 to %struct.sockaddr*
%16 = call i32 @SUN_LEN(%struct.sockaddr_un* %1)
%17 = call i32 @bind(i32 %8, %struct.sockaddr* %15, i32 %16)
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %0
%20 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %19, %0
%22 = call i32 @listen(i32 %8, i32 100500)
%23 = bitcast %struct.sockaddr_un* %2 to i8*
%24 = bitcast i32* %3 to i8*
store i32 16, i32* %3
%25 = bitcast %struct.sockaddr_un* %2 to %struct.sockaddr*
%26 = call i32 @accept(i32 %8, %struct.sockaddr* %25, i32* %3)
%27 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%28 = call i32 @read(i32 %26, i8* %27, i32 10)
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %21
%31 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %21
%34 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %27)
%35 = call i32 @close(i32 %26)
%36 = call i32 @close(i32 %8)
ret i32 0
}