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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int make_named_socket(char *);
int /*<<< orphan*/ perror(char *);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *, size_t *);
int sendto(int, char *, int, int /*<<< orphan*/, struct sockaddr *, size_t);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ unlink(char *);
int main(void) {
  int sock;
  char message[512];
  struct sockaddr_un name;
  size_t size;
  int nbytes;
  unlink("/tmp/serversocket");
  sock = make_named_socket("/tmp/serversocket");
  while (1) {
    size = sizeof(name);
    nbytes = recvfrom(sock, message, 512, 0, (struct sockaddr *)&name, &size);
    if (nbytes < 0) {
      perror("recfrom (server)");
      exit(EXIT_FAILURE);
    }
    fprintf(stderr, "Server: got message: %s\n", message);
    nbytes = sendto(sock, message, nbytes, 0, (struct sockaddr *)&name, size);
    if (nbytes < 0) {
      perror("sendto (server)");
      exit(EXIT_FAILURE);
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe77(%rip),%rdi
call   1030 <unlink@plt>
lea    0xe6b(%rip),%rdi
call   1090 <make_named_socket@plt>
mov    %eax,-0x8(%rbp)
movq   $0x4,-0x220(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x210(%rbp),%rsi
lea    -0x218(%rbp),%r8
mov    $0x200,%edx
xor    %ecx,%ecx
lea    -0x220(%rbp),%r9
call   1060 <recvfrom@plt>
mov    %eax,-0x224(%rbp)
cmpl   $0x0,-0x224(%rbp)
jge    11f9 <main+0x89>
lea    0xe2c(%rip),%rdi
call   1070 <perror@plt>
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    0x2de0(%rip),%rax
mov    (%rax),%edi
lea    -0x210(%rbp),%rdx
lea    0xe13(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x8(%rbp),%edi
lea    -0x210(%rbp),%rsi
mov    -0x224(%rbp),%edx
lea    -0x218(%rbp),%r8
mov    -0x220(%rbp),%r9
xor    %ecx,%ecx
call   1040 <sendto@plt>
mov    %eax,-0x224(%rbp)
cmpl   $0x0,-0x224(%rbp)
jge    1267 <main+0xf7>
lea    0xde8(%rip),%rdi
call   1070 <perror@plt>
mov    0x2d78(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    119d <main+0x2d>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x218,%rsp
lea    0xe78(%rip),%rbx
mov    %rbx,%rdi
call   1030 <unlink@plt>
mov    %rbx,%rdi
call   1090 <make_named_socket@plt>
mov    %eax,%ebx
lea    0x10(%rsp),%r14
lea    0x8(%rsp),%r15
mov    0x2e35(%rip),%r12
lea    0xe71(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movq   $0x4,(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
mov    %r15,%r8
mov    %rsp,%r9
call   1060 <recvfrom@plt>
test   %eax,%eax
js     1216 <main+0xa6>
mov    %eax,%ebp
mov    (%r12),%edi
mov    %r13,%rsi
mov    %r14,%rdx
call   1050 <fprintf@plt>
mov    (%rsp),%r9
mov    %ebx,%edi
mov    %r14,%rsi
mov    %ebp,%edx
xor    %ecx,%ecx
mov    %r15,%r8
call   1040 <sendto@plt>
test   %eax,%eax
jns    11c0 <main+0x50>
lea    0xe28(%rip),%rdi
jmp    121d <main+0xad>
lea    0xdf5(%rip),%rdi
call   1070 <perror@plt>
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_un = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [18 x i8] c"/tmp/serversocket\00"
@.str.1 = [17 x i8] c"recfrom (server)\00"
@EXIT_FAILURE = global i32 0
@stderr = global i32 0
@.str.2 = [25 x i8] c"Server: got message: %s\0A\00"
@.str.3 = [16 x i8] c"sendto (server)\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [512 x i8]
%4 = alloca %struct.sockaddr_un
%5 = alloca i64
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32 @unlink(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @make_named_socket(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
store i32 %8, i32* %2
br label %9
9: ; preds = %0, %36
store i64 4, i64* %5
%10 = load i32, i32* %2
%11 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%12 = bitcast %struct.sockaddr_un* %4 to %struct.sockaddr*
%13 = call i32 @recvfrom(i32 %10, i8* %11, i32 512, i32 0, %struct.sockaddr* %12, i64* %5)
store i32 %13, i32* %6
%14 = load i32, i32* %6
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %9
%17 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %9
%21 = load i32, i32* @stderr
%22 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%23 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %22)
%24 = load i32, i32* %2
%25 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%26 = load i32, i32* %6
%27 = bitcast %struct.sockaddr_un* %4 to %struct.sockaddr*
%28 = load i64, i64* %5
%29 = call i32 @sendto(i32 %24, i8* %25, i32 %26, i32 0, %struct.sockaddr* %27, i64 %28)
store i32 %29, i32* %6
%30 = load i32, i32* %6
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %20
%33 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%34 = load i32, i32* @EXIT_FAILURE
%35 = call i32 @exit(i32 %34)
unreachable
36: ; preds = %20
br label %9
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [18 x i8] c"/tmp/serversocket\00"
@.str.1 = [17 x i8] c"recfrom (server)\00"
@EXIT_FAILURE = global i32 0
@stderr = global i32 0
@.str.2 = [25 x i8] c"Server: got message: %s\0A\00"
@.str.3 = [16 x i8] c"sendto (server)\00"
define i32 @main() {
%1 = alloca [512 x i8]
%2 = alloca %struct.sockaddr_un
%3 = alloca i64
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 0
%5 = bitcast %struct.sockaddr_un* %2 to i8*
%6 = bitcast i64* %3 to i8*
%7 = tail call i32 @unlink(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @make_named_socket(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%9 = bitcast %struct.sockaddr_un* %2 to %struct.sockaddr*
br label %10
10: ; preds = %17, %0
store i64 4, i64* %3
%11 = call i32 @recvfrom(i32 %8, i8* %4, i32 512, i32 0, %struct.sockaddr* %9, i64* %3)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %10
%14 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %10
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%20 = load i64, i64* %3
%21 = call i32 @sendto(i32 %8, i8* %4, i32 %11, i32 0, %struct.sockaddr* %9, i64 %20)
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %10
23: ; preds = %17
%24 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%25 = load i32, i32* @EXIT_FAILURE
%26 = call i32 @exit(i32 %25)
unreachable
}