#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;
};
typedef int socklen_t;

/* Variables and functions */
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, char *);
int socket_unix_bind(char *, int);
int socket_unix_recv(int, struct sockaddr_un *, char *, int,
                     int /*<<< orphan*/);
int socket_unix_send(int, struct sockaddr_un *, char *, int,
                     int /*<<< orphan*/);
int /*<<< orphan*/ unlink(char *);
int main(int argc, char **argv) {
  struct sockaddr_un addr;
  socklen_t addrlen;
  char buffer[64];
  int sock;
  int i, n;
  if ((sock = socket_unix_bind("server-dgram.sock", 1)) < 0)
    return (1);
  for (i = 0; i < 3; ++i) {
    memset(buffer, 0, 64);
    addrlen = sizeof(struct sockaddr_un);
    if ((n = socket_unix_recv(sock, &addr, buffer, 64, 0)) < 0) {
      perror("recvfrom()");
      continue;
    }
    printf("Recv %s: %s\n", addr.sun_path, buffer);
    if ((n = socket_unix_send(sock, &addr, "Hello Client\n", 13, 0)) < 0) {
      perror("recvfrom()");
      continue;
    }
  }
  close(sock);
  unlink("server-dgram.sock");
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe63(%rip),%rdi
mov    $0x1,%esi
call   1080 <socket_unix_bind@plt>
mov    %eax,-0x64(%rbp)
cmp    $0x0,%eax
jge    11bf <main+0x3f>
movl   $0x1,-0x4(%rbp)
jmp    1296 <main+0x116>
movl   $0x0,-0x68(%rbp)
cmpl   $0x3,-0x68(%rbp)
jge    127b <main+0xfb>
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1050 <memset@plt>
movl   $0x8,-0x1c(%rbp)
mov    -0x64(%rbp),%edi
lea    -0x60(%rbp),%rdx
lea    -0x18(%rbp),%rsi
mov    $0x40,%ecx
xor    %r8d,%r8d
call   10a0 <socket_unix_recv@plt>
mov    %eax,-0x6c(%rbp)
cmp    $0x0,%eax
jge    121c <main+0x9c>
lea    0xe00(%rip),%rdi
call   1070 <perror@plt>
jmp    126d <main+0xed>
mov    -0x18(%rbp),%rsi
lea    -0x60(%rbp),%rdx
lea    0xdf2(%rip),%rdi
call   1040 <printf@plt>
mov    -0x64(%rbp),%edi
lea    -0x18(%rbp),%rsi
lea    0xdec(%rip),%rdx
mov    $0xd,%ecx
xor    %r8d,%r8d
call   1090 <socket_unix_send@plt>
mov    %eax,-0x6c(%rbp)
cmp    $0x0,%eax
jge    1268 <main+0xe8>
lea    0xdb4(%rip),%rdi
call   1070 <perror@plt>
jmp    126d <main+0xed>
jmp    126d <main+0xed>
mov    -0x68(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x68(%rbp)
jmp    11c6 <main+0x46>
mov    -0x64(%rbp),%edi
call   1060 <close@plt>
lea    0xd76(%rip),%rdi
call   1030 <unlink@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x58,%rsp
lea    0xe73(%rip),%rdi
mov    $0x1,%ebp
mov    $0x1,%esi
call   1080 <socket_unix_bind@plt>
test   %eax,%eax
js     12f7 <main+0x177>
mov    %eax,%ebx
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1050 <memset@plt>
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    %rbp,%rdx
mov    $0x40,%ecx
xor    %r8d,%r8d
call   10a0 <socket_unix_recv@plt>
test   %eax,%eax
js     1300 <main+0x180>
mov    0x8(%rsp),%rsi
lea    0xe38(%rip),%rdi
lea    0x10(%rsp),%rdx
call   1040 <printf@plt>
lea    0xe34(%rip),%rdx
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0xd,%ecx
xor    %r8d,%r8d
call   1090 <socket_unix_send@plt>
test   %eax,%eax
js     1300 <main+0x180>
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1050 <memset@plt>
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    %rbp,%rdx
mov    $0x40,%ecx
xor    %r8d,%r8d
call   10a0 <socket_unix_recv@plt>
test   %eax,%eax
js     1311 <main+0x191>
mov    0x8(%rsp),%rsi
lea    0xdcc(%rip),%rdi
lea    0x10(%rsp),%rdx
call   1040 <printf@plt>
lea    0xdc8(%rip),%rdx
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0xd,%ecx
xor    %r8d,%r8d
call   1090 <socket_unix_send@plt>
test   %eax,%eax
js     1311 <main+0x191>
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1050 <memset@plt>
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    %rbp,%rdx
mov    $0x40,%ecx
xor    %r8d,%r8d
call   10a0 <socket_unix_recv@plt>
test   %eax,%eax
js     1322 <main+0x1a2>
mov    0x8(%rsp),%rsi
lea    0xd64(%rip),%rdi
lea    0x10(%rsp),%rdx
call   1040 <printf@plt>
lea    0xd60(%rip),%rdx
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0xd,%ecx
xor    %r8d,%r8d
call   1090 <socket_unix_send@plt>
test   %eax,%eax
js     1322 <main+0x1a2>
mov    %ebx,%edi
call   1060 <close@plt>
lea    0xd10(%rip),%rdi
call   1030 <unlink@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x58,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xd0b(%rip),%rdi
call   1070 <perror@plt>
jmp    1212 <main+0x92>
lea    0xcfa(%rip),%rdi
call   1070 <perror@plt>
jmp    127e <main+0xfe>
lea    0xce9(%rip),%rdi
call   1070 <perror@plt>
jmp    12e2 <main+0x162>

LLVM IR (-O0):
%struct.sockaddr_un = type { i8* }
@.str = [18 x i8] c"server-dgram.sock\00"
@.str.1 = [11 x i8] c"recvfrom()\00"
@.str.2 = [13 x i8] c"Recv %s: %s\0A\00"
@.str.3 = [14 x i8] c"Hello Client\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.sockaddr_un
%7 = alloca i32
%8 = alloca [64 x i8]
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = call i32 @socket_unix_bind(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 1)
store i32 %12, i32* %9
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %2
store i32 1, i32* %3
br label %46
15: ; preds = %2
store i32 0, i32* %10
br label %16
16: ; preds = %39, %15
%17 = load i32, i32* %10
%18 = icmp slt i32 %17, 3
br i1 %18, label %19, label %42
19: ; preds = %16
%20 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%21 = call i32 @memset(i8* %20, i32 0, i32 64)
store i32 8, i32* %7
%22 = load i32, i32* %9
%23 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%24 = call i32 @socket_unix_recv(i32 %22, %struct.sockaddr_un* %6, i8* %23, i32 64, i32 0)
store i32 %24, i32* %11
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %19
%27 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
br label %39
28: ; preds = %19
%29 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %6, i32 0, i32 0
%30 = load i8*, i8** %29
%31 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%32 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %30, i8* %31)
%33 = load i32, i32* %9
%34 = call i32 @socket_unix_send(i32 %33, %struct.sockaddr_un* %6, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 13, i32 0)
store i32 %34, i32* %11
%35 = icmp slt i32 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %28
%37 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
br label %39
38: ; preds = %28
br label %39
39: ; preds = %38, %36, %26
%40 = load i32, i32* %10
%41 = add nsw i32 %40, 1
store i32 %41, i32* %10
br label %16
42: ; preds = %16
%43 = load i32, i32* %9
%44 = call i32 @close(i32 %43)
%45 = call i32 @unlink(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %46
46: ; preds = %42, %14
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i8* }
@.str = [18 x i8] c"server-dgram.sock\00"
@.str.1 = [11 x i8] c"recvfrom()\00"
@.str.2 = [13 x i8] c"Recv %s: %s\0A\00"
@.str.3 = [14 x i8] c"Hello Client\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_un
%4 = alloca [64 x i8]
%5 = bitcast %struct.sockaddr_un* %3 to i8*
%6 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%7 = tail call i32 @socket_unix_bind(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 1)
%8 = icmp slt i32 %7, 0
br i1 %8, label %46, label %9
9: ; preds = %2
%10 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 0
%11 = call i32 @memset(i8* %6, i32 0, i32 64)
%12 = call i32 @socket_unix_recv(i32 %7, %struct.sockaddr_un* %3, i8* %6, i32 64, i32 0)
%13 = icmp slt i32 %12, 0
br i1 %13, label %19, label %14
14: ; preds = %9
%15 = load i8*, i8** %10
%16 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %15, i8* %6)
%17 = call i32 @socket_unix_send(i32 %7, %struct.sockaddr_un* %3, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 13, i32 0)
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %14, %9
%20 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %19, %14
%22 = call i32 @memset(i8* %6, i32 0, i32 64)
%23 = call i32 @socket_unix_recv(i32 %7, %struct.sockaddr_un* %3, i8* %6, i32 64, i32 0)
%24 = icmp slt i32 %23, 0
br i1 %24, label %30, label %25
25: ; preds = %21
%26 = load i8*, i8** %10
%27 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %26, i8* %6)
%28 = call i32 @socket_unix_send(i32 %7, %struct.sockaddr_un* %3, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 13, i32 0)
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %21, %25
%31 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
br label %32
32: ; preds = %30, %25
%33 = call i32 @memset(i8* %6, i32 0, i32 64)
%34 = call i32 @socket_unix_recv(i32 %7, %struct.sockaddr_un* %3, i8* %6, i32 64, i32 0)
%35 = icmp slt i32 %34, 0
br i1 %35, label %41, label %36
36: ; preds = %32
%37 = load i8*, i8** %10
%38 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %37, i8* %6)
%39 = call i32 @socket_unix_send(i32 %7, %struct.sockaddr_un* %3, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 13, i32 0)
%40 = icmp slt i32 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %32, %36
%42 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
br label %43
43: ; preds = %41, %36
%44 = call i32 @close(i32 %7)
%45 = call i32 @unlink(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %46
46: ; preds = %2, %43
%47 = phi i32 [ 0, %43 ], [ 1, %2 ]
ret i32 %47
}