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

/* Variables and functions */
int /*<<< orphan*/ AF_LOCAL;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ perror(char *);
int recvfrom(int, char *, int, int /*<<< orphan*/, int /*<<< orphan*/ *,
             int /*<<< orphan*/);
int /*<<< orphan*/ remove(char *);
int sendto(int, char *, int, int /*<<< orphan*/, struct sockaddr *, size_t);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int main(void) {
  extern int make_named_socket(const char *name);
  int sock;
  char message[512];
  struct sockaddr_un name;
  size_t size;
  int nbytes;
  sock = make_named_socket("/tmp/mysocket");
  name.sun_family = AF_LOCAL;
  strcpy(name.sun_path, "/tmp/serversocket");
  size = strlen(name.sun_path) + sizeof(name.sun_family);
  nbytes = sendto(sock, "Yow!!! Are we having fun yet?!?",
                  strlen("Yow!!! Are we having fun yet?!?") + 1, 0,
                  (struct sockaddr *)&name, size);
  if (nbytes < 0) {
    perror("sendto (client)");
    exit(EXIT_FAILURE);
  }
  nbytes = recvfrom(sock, message, 512, 0, NULL, 0);
  if (nbytes < 0) {
    perror("recfrom (client)");
    exit(EXIT_FAILURE);
  }
  fprintf(stderr, "Client: got message: %s\n", message);
  remove("/tmp/mysocket");
  close(sock);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
lea    0xe4e(%rip),%rdi
call   10c0 <make_named_socket@plt>
mov    %eax,-0x4(%rbp)
mov    0x2e27(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x218(%rbp)
mov    -0x220(%rbp),%rdi
lea    0xe37(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x220(%rbp),%rdi
call   1050 <strlen@plt>
cltq
add    $0x4,%rax
mov    %rax,-0x228(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x230(%rbp)
lea    0xe1b(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x230(%rbp),%edi
mov    %eax,%edx
add    $0x1,%edx
lea    -0x220(%rbp),%r8
mov    -0x228(%rbp),%r9
lea    0xdf6(%rip),%rsi
xor    %ecx,%ecx
call   1060 <sendto@plt>
mov    %eax,-0x22c(%rbp)
cmpl   $0x0,-0x22c(%rbp)
jge    125e <main+0xbe>
lea    0xdf5(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2d79(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0x4(%rbp),%edi
lea    -0x210(%rbp),%rsi
mov    $0x200,%edx
xor    %r9d,%r9d
xor    %eax,%eax
mov    %eax,%r8d
mov    %r9d,%ecx
call   1090 <recvfrom@plt>
mov    %eax,-0x22c(%rbp)
cmpl   $0x0,-0x22c(%rbp)
jge    12aa <main+0x10a>
lea    0xdb9(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2d2d(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    0x2d27(%rip),%rax
mov    (%rax),%edi
lea    -0x210(%rbp),%rdx
lea    0xda0(%rip),%rsi
call   1080 <fprintf@plt>
lea    0xd33(%rip),%rdi
call   1030 <remove@plt>
mov    -0x4(%rbp),%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x210,%rsp
lea    0xe4e(%rip),%rdi
call   10c0 <make_named_socket@plt>
mov    %eax,%r14d
mov    0x2e27(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
lea    0xe40(%rip),%rsi
call   1040 <strcpy@plt>
call   1050 <strlen@plt>
movslq %eax,%rbx
add    $0x4,%rbx
lea    0xe3a(%rip),%rbp
mov    %rbp,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edx
mov    %rsp,%r8
mov    %r14d,%edi
mov    %rbp,%rsi
xor    %ecx,%ecx
mov    %rbx,%r9
call   1060 <sendto@plt>
test   %eax,%eax
js     1262 <main+0xc2>
lea    0x10(%rsp),%rsi
mov    %r14d,%edi
mov    $0x200,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1090 <recvfrom@plt>
test   %eax,%eax
js     126b <main+0xcb>
mov    0x2dab(%rip),%rax
mov    (%rax),%edi
lea    0xe2b(%rip),%rsi
lea    0x10(%rsp),%rdx
call   1080 <fprintf@plt>
lea    0xdb9(%rip),%rdi
call   1030 <remove@plt>
mov    %r14d,%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x210,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xdd7(%rip),%rdi
jmp    1272 <main+0xd2>
lea    0xdde(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2d52(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_un = type { i8*, i32 }
%struct.sockaddr = type { i32 }
@.str = [14 x i8] c"/tmp/mysocket\00"
@AF_LOCAL = global i32 0
@.str.1 = [18 x i8] c"/tmp/serversocket\00"
@.str.2 = [32 x i8] c"Yow!!! Are we having fun yet?!?\00"
@.str.3 = [16 x i8] c"sendto (client)\00"
@EXIT_FAILURE = global i32 0
@.str.4 = [17 x i8] c"recfrom (client)\00"
@stderr = global i32 0
@.str.5 = [25 x i8] c"Client: got message: %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [512 x i8]
%3 = alloca %struct.sockaddr_un
%4 = alloca i64
%5 = alloca i32
%6 = call i32 @make_named_socket(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store i32 %6, i32* %1
%7 = load i32, i32* @AF_LOCAL
%8 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i32 0, i32 1
store i32 %7, i32* %8
%9 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i32 0, i32 0
%10 = load i8*, i8** %9
%11 = call i32 @strcpy(i8* %10, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%12 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i32 0, i32 0
%13 = load i8*, i8** %12
%14 = call i32 @strlen(i8* %13)
%15 = sext i32 %14 to i64
%16 = add i64 %15, 4
store i64 %16, i64* %4
%17 = load i32, i32* %1
%18 = call i32 @strlen(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
%19 = add nsw i32 %18, 1
%20 = bitcast %struct.sockaddr_un* %3 to %struct.sockaddr*
%21 = load i64, i64* %4
%22 = call i32 @sendto(i32 %17, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %19, i32 0, %struct.sockaddr* %20, i64 %21)
store i32 %22, i32* %5
%23 = load i32, i32* %5
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %0
%26 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%27 = load i32, i32* @EXIT_FAILURE
%28 = call i32 @exit(i32 %27)
unreachable
29: ; preds = %0
%30 = load i32, i32* %1
%31 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%32 = call i32 @recvfrom(i32 %30, i8* %31, i32 512, i32 0, i32* null, i32 0)
store i32 %32, i32* %5
%33 = load i32, i32* %5
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %39
35: ; preds = %29
%36 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%37 = load i32, i32* @EXIT_FAILURE
%38 = call i32 @exit(i32 %37)
unreachable
39: ; preds = %29
%40 = load i32, i32* @stderr
%41 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%42 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i8* %41)
%43 = call i32 @remove(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%44 = load i32, i32* %1
%45 = call i32 @close(i32 %44)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i8*, i32 }
%struct.sockaddr = type { i32 }
@.str = [14 x i8] c"/tmp/mysocket\00"
@AF_LOCAL = global i32 0
@.str.1 = [18 x i8] c"/tmp/serversocket\00"
@.str.2 = [32 x i8] c"Yow!!! Are we having fun yet?!?\00"
@.str.3 = [16 x i8] c"sendto (client)\00"
@EXIT_FAILURE = global i32 0
@.str.4 = [17 x i8] c"recfrom (client)\00"
@stderr = global i32 0
@.str.5 = [25 x i8] c"Client: got message: %s\0A\00"
define i32 @main() {
%1 = alloca [512 x i8]
%2 = alloca %struct.sockaddr_un
%3 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 0
%4 = bitcast %struct.sockaddr_un* %2 to i8*
%5 = tail call i32 @make_named_socket(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @AF_LOCAL
%7 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %2, i64 0, i32 1
store i32 %6, i32* %7
%8 = tail call i32 @strcpy(i8* undef, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%9 = tail call i32 @strlen(i8* undef)
%10 = sext i32 %9 to i64
%11 = add nsw i64 %10, 4
%12 = tail call i32 @strlen(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
%13 = add nsw i32 %12, 1
%14 = bitcast %struct.sockaddr_un* %2 to %struct.sockaddr*
%15 = call i32 @sendto(i32 %5, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %13, i32 0, %struct.sockaddr* %14, i64 %11)
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %0
%18 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %0
%22 = call i32 @recvfrom(i32 %5, i8* %3, i32 512, i32 0, i32* null, i32 0)
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %21
%25 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%26 = load i32, i32* @EXIT_FAILURE
%27 = call i32 @exit(i32 %26)
unreachable
28: ; preds = %21
%29 = load i32, i32* @stderr
%30 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i8* %3)
%31 = call i32 @remove(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%32 = call i32 @close(i32 %5)
ret i32 0
}