#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*/ usa;
struct sockaddr_un {
  char *sun_path;
  int /*<<< orphan*/ sun_family;
};
struct sockaddr_storage {
  int ss_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ st;
typedef scalar_t__ ssize_t;
typedef int socklen_t;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ SOCK_DGRAM;
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ memset(struct sockaddr_storage *, int, int);
int /*<<< orphan*/ printf(char *, int);
scalar_t__ recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *,
                    int *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ unlink(char *);
int main(void) {
  int s[2] = {
      socket(AF_UNIX, SOCK_DGRAM, 0),
      socket(AF_UNIX, SOCK_DGRAM, 0),
  };
  if (s[0] == -1)
    return 1;
  if (s[1] == -1)
    return 2;
  struct sockaddr_un usa = {.sun_family = AF_UNIX,
                            .sun_path = "/tmp/test-it-out"};
  unlink("/tmp/test-it-out");
  int e = bind(s[0], (struct sockaddr *)&usa, sizeof(usa));
  if (e)
    return 3;
  for (;;) {
    char buf[256];
    struct sockaddr_storage st;
    memset(&st, 0xa5, sizeof(st));
    socklen_t sz = sizeof(st);
    ssize_t r =
        recvfrom(s[0], buf, sizeof(buf), 0, (struct sockaddr *)&st, &sz);
    if (r > 0)
      printf("> %d\n", st.ss_family);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e6f(%rip),%rax
mov    (%rax),%edi
mov    0x2e5e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %eax,-0xc(%rbp)
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
mov    0x2e42(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    11c0 <main+0x60>
movl   $0x1,-0x4(%rbp)
jmp    1298 <main+0x138>
cmpl   $0xffffffff,-0x8(%rbp)
jne    11d6 <main+0x76>
movl   $0x2,-0x4(%rbp)
jmp    1298 <main+0x138>
lea    0xe23(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e00(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
lea    0xe0c(%rip),%rdi
call   1030 <unlink@plt>
mov    -0xc(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x10,%edx
call   1070 <bind@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     1223 <main+0xc3>
movl   $0x3,-0x4(%rbp)
jmp    1298 <main+0x138>
jmp    1228 <main+0xc8>
lea    -0x138(%rbp),%rdi
mov    $0xa5,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
movl   $0x4,-0x13c(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x130(%rbp),%rsi
lea    -0x138(%rbp),%r8
mov    $0x100,%edx
xor    %ecx,%ecx
lea    -0x13c(%rbp),%r9
call   1060 <recvfrom@plt>
mov    %rax,-0x148(%rbp)
cmpq   $0x0,-0x148(%rbp)
jle    1293 <main+0x133>
mov    -0x138(%rbp),%esi
lea    0xd83(%rip),%rdi
call   1040 <printf@plt>
jmp    1228 <main+0xc8>
mov    -0x4(%rbp),%eax
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x120,%rsp
mov    0x2e72(%rip),%r14
mov    (%r14),%edi
mov    0x2e60(%rip),%rbx
mov    (%rbx),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %eax,%ebp
mov    (%r14),%edi
mov    (%rbx),%esi
xor    %edx,%edx
call   1080 <socket@plt>
cmp    $0xffffffff,%ebp
je     11d5 <main+0x75>
cmp    $0xffffffff,%eax
je     11dc <main+0x7c>
lea    0xe58(%rip),%rdi
mov    %rdi,0x10(%rsp)
mov    (%r14),%eax
mov    %eax,0x18(%rsp)
call   1030 <unlink@plt>
lea    0x10(%rsp),%rsi
mov    %ebp,%edi
mov    $0x10,%edx
call   1070 <bind@plt>
test   %eax,%eax
je     11f1 <main+0x91>
mov    $0x3,%eax
jmp    11e1 <main+0x81>
mov    $0x1,%eax
jmp    11e1 <main+0x81>
mov    $0x2,%eax
add    $0x120,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x8(%rsp),%rbx
lea    0x20(%rsp),%r14
lea    0xc(%rsp),%r15
lea    0xe0a(%rip),%r12
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0xa5,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
movl   $0x4,0xc(%rsp)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x100,%edx
xor    %ecx,%ecx
mov    %rbx,%r8
mov    %r15,%r9
call   1060 <recvfrom@plt>
test   %rax,%rax
jle    1210 <main+0xb0>
mov    0x8(%rsp),%esi
mov    %r12,%rdi
call   1040 <printf@plt>
jmp    1210 <main+0xb0>

LLVM IR (-O0):
%struct.sockaddr_un = type { i8*, i32 }
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [17 x i8] c"/tmp/test-it-out\00"
@.str.1 = [6 x i8] c"> %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i32]
%3 = alloca %struct.sockaddr_un
%4 = alloca i32
%5 = alloca [256 x i8]
%6 = alloca %struct.sockaddr_storage
%7 = alloca i32
%8 = alloca i64
store i32 0, i32* %1
%9 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%10 = load i32, i32* @AF_UNIX
%11 = load i32, i32* @SOCK_DGRAM
%12 = call i32 @socket(i32 %10, i32 %11, i32 0)
store i32 %12, i32* %9
%13 = getelementptr inbounds i32, i32* %9, i64 1
%14 = load i32, i32* @AF_UNIX
%15 = load i32, i32* @SOCK_DGRAM
%16 = call i32 @socket(i32 %14, i32 %15, i32 0)
store i32 %16, i32* %13
%17 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%18 = load i32, i32* %17
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %21
20: ; preds = %0
store i32 1, i32* %1
br label %53
21: ; preds = %0
%22 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%23 = load i32, i32* %22
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %26
25: ; preds = %21
store i32 2, i32* %1
br label %53
26: ; preds = %21
%27 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i32 0, i32 0
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8** %27
%28 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i32 0, i32 1
%29 = load i32, i32* @AF_UNIX
store i32 %29, i32* %28
%30 = call i32 @unlink(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%31 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%32 = load i32, i32* %31
%33 = bitcast %struct.sockaddr_un* %3 to %struct.sockaddr*
%34 = call i32 @bind(i32 %32, %struct.sockaddr* %33, i32 16)
store i32 %34, i32* %4
%35 = load i32, i32* %4
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %26
store i32 3, i32* %1
br label %53
38: ; preds = %26
br label %39
39: ; preds = %52, %38
%40 = call i32 @memset(%struct.sockaddr_storage* %6, i32 165, i32 4)
store i32 4, i32* %7
%41 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%42 = load i32, i32* %41
%43 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%44 = bitcast %struct.sockaddr_storage* %6 to %struct.sockaddr*
%45 = call i64 @recvfrom(i32 %42, i8* %43, i32 256, i32 0, %struct.sockaddr* %44, i32* %7)
store i64 %45, i64* %8
%46 = load i64, i64* %8
%47 = icmp sgt i64 %46, 0
br i1 %47, label %48, label %52
48: ; preds = %39
%49 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %6, i32 0, i32 0
%50 = load i32, i32* %49
%51 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %50)
br label %52
52: ; preds = %48, %39
br label %39
53: ; preds = %37, %25, %20
%54 = load i32, i32* %1
ret i32 %54
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i8*, i32 }
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [17 x i8] c"/tmp/test-it-out\00"
@.str.1 = [6 x i8] c"> %d\0A\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_un
%2 = alloca [256 x i8]
%3 = alloca %struct.sockaddr_storage
%4 = alloca i32
%5 = load i32, i32* @AF_UNIX
%6 = load i32, i32* @SOCK_DGRAM
%7 = tail call i32 @socket(i32 %5, i32 %6, i32 0)
%8 = load i32, i32* @AF_UNIX
%9 = load i32, i32* @SOCK_DGRAM
%10 = tail call i32 @socket(i32 %8, i32 %9, i32 0)
%11 = icmp eq i32 %7, -1
br i1 %11, label %38, label %12
12: ; preds = %0
%13 = icmp eq i32 %10, -1
br i1 %13, label %38, label %14
14: ; preds = %12
%15 = bitcast %struct.sockaddr_un* %1 to i8*
%16 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %1, i64 0, i32 0
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8** %16
%17 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %1, i64 0, i32 1
%18 = load i32, i32* @AF_UNIX
store i32 %18, i32* %17
%19 = tail call i32 @unlink(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%20 = bitcast %struct.sockaddr_un* %1 to %struct.sockaddr*
%21 = call i32 @bind(i32 %7, %struct.sockaddr* %20, i32 16)
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %29
23: ; preds = %14
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%25 = bitcast %struct.sockaddr_storage* %3 to i8*
%26 = bitcast i32* %4 to i8*
%27 = bitcast %struct.sockaddr_storage* %3 to %struct.sockaddr*
%28 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %3, i64 0, i32 0
br label %30
29: ; preds = %14
br label %38
30: ; preds = %23, %37
%31 = call i32 @memset(%struct.sockaddr_storage* %3, i32 165, i32 4)
store i32 4, i32* %4
%32 = call i64 @recvfrom(i32 %7, i8* %24, i32 256, i32 0, %struct.sockaddr* %27, i32* %4)
%33 = icmp sgt i64 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %30
%35 = load i32, i32* %28
%36 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %35)
br label %37
37: ; preds = %34, %30
br label %30
38: ; preds = %12, %0, %29
%39 = phi i32 [ 3, %29 ], [ 1, %0 ], [ 2, %12 ]
ret i32 %39
}