#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 socklen_t;
typedef int /*<<< orphan*/ buff;

/* Variables and functions */
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *, ...);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int *);
char *strerror(int /*<<< orphan*/);
int uudplsn(char *);
int main(int argc, char **argv) {
  int sock;
  char *path = NULL;
  struct sockaddr_un addr;
  socklen_t addrlen = sizeof(struct sockaddr_un);
  char buff[4096];
  int bytes;
  int i = 0;
  if (argc != 2) {
    printf("Usage: %s <UNIX domain socket file path>\n", argv[0]);
    exit(1);
  }
  path = argv[1];
  sock = uudplsn(path);
  if (sock == -1) {
    printf("Create UNIX domain socket error\n");
    exit(1);
  }
  while (1) {
    bytes = recvfrom(sock, buff, sizeof(buff), 0, (struct sockaddr *)&addr,
                     &addrlen);
    if (bytes <= 0) {
      printf("%s\n", strerror(errno));
      break;
    }
    printf("%8d recv: %d\n", ++i, bytes);
  }
  close(sock);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1040,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x4,-0x2c(%rbp)
movl   $0x0,-0x1038(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11bb <main+0x5b>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <uudplsn@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11f5 <main+0x95>
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    11fa <main+0x9a>
mov    -0x14(%rbp),%edi
lea    -0x1030(%rbp),%rsi
lea    -0x28(%rbp),%r8
mov    $0x1000,%edx
xor    %ecx,%ecx
lea    -0x2c(%rbp),%r9
call   1060 <recvfrom@plt>
mov    %eax,-0x1034(%rbp)
cmpl   $0x0,-0x1034(%rbp)
jg     124f <main+0xef>
mov    0x2dae(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    %rax,%rsi
lea    0xe08(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1277 <main+0x117>
mov    -0x1038(%rbp),%esi
add    $0x1,%esi
mov    %esi,-0x1038(%rbp)
mov    -0x1034(%rbp),%edx
lea    0xde4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11fa <main+0x9a>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x1040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1018,%rsp
movl   $0x4,0x4(%rsp)
cmp    $0x2,%edi
jne    124d <main+0xdd>
mov    0x8(%rsi),%rdi
call   1040 <uudplsn@plt>
cmp    $0xffffffff,%eax
je     1268 <main+0xf8>
mov    %eax,%ebx
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%r8
lea    0x4(%rsp),%r9
mov    %eax,%edi
mov    $0x1000,%edx
xor    %ecx,%ecx
call   1070 <recvfrom@plt>
test   %eax,%eax
jle    121c <main+0xac>
mov    $0x1,%ebp
lea    0xe57(%rip),%r14
lea    0x10(%rsp),%r15
lea    0x8(%rsp),%r12
lea    0x4(%rsp),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %ebp,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x1000,%edx
xor    %ecx,%ecx
mov    %r12,%r8
mov    %r13,%r9
call   1070 <recvfrom@plt>
add    $0x1,%ebp
test   %eax,%eax
jg     11f0 <main+0x80>
mov    0x2dbd(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    %rax,%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x1018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%rsi),%rsi
lea    0xda9(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    0xdc9(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_un = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [42 x i8] c"Usage: %s <UNIX domain socket file path>\0A\00"
@.str.1 = [33 x i8] c"Create UNIX domain socket error\0A\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@errno = global i32 0
@.str.3 = [14 x i8] c"%8d recv: %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca %struct.sockaddr_un
%9 = alloca i32
%10 = alloca [4096 x i8]
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %7
store i32 4, i32* %9
store i32 0, i32* %12
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 2
br i1 %14, label %15, label %21
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
store i8* %24, i8** %7
%25 = load i8*, i8** %7
%26 = call i32 @uudplsn(i8* %25)
store i32 %26, i32* %6
%27 = load i32, i32* %6
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %32
29: ; preds = %21
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %21
br label %33
33: ; preds = %32, %44
%34 = load i32, i32* %6
%35 = getelementptr inbounds [4096 x i8], [4096 x i8]* %10, i64 0, i64 0
%36 = bitcast %struct.sockaddr_un* %8 to %struct.sockaddr*
%37 = call i32 @recvfrom(i32 %34, i8* %35, i32 4096, i32 0, %struct.sockaddr* %36, i32* %9)
store i32 %37, i32* %11
%38 = load i32, i32* %11
%39 = icmp sle i32 %38, 0
br i1 %39, label %40, label %44
40: ; preds = %33
%41 = load i32, i32* @errno
%42 = call i8* @strerror(i32 %41)
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %42)
br label %49
44: ; preds = %33
%45 = load i32, i32* %12
%46 = add nsw i32 %45, 1
store i32 %46, i32* %12
%47 = load i32, i32* %11
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %46, i32 %47)
br label %33
49: ; preds = %40
%50 = load i32, i32* %6
%51 = call i32 @close(i32 %50)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [42 x i8] c"Usage: %s <UNIX domain socket file path>\0A\00"
@errno = global i32 0
@.str.3 = [14 x i8] c"%8d recv: %d\0A\00"
@str = [32 x i8] c"Create UNIX domain socket error\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_un
%4 = alloca i32
%5 = alloca [4096 x i8]
%6 = bitcast %struct.sockaddr_un* %3 to i8*
%7 = bitcast i32* %4 to i8*
store i32 4, i32* %4
%8 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%9 = icmp eq i32 %0, 2
br i1 %9, label %14, label %10
10: ; preds = %2
%11 = load i8*, i8** %1
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = tail call i32 @uudplsn(i8* %16)
%18 = icmp eq i32 %17, -1
br i1 %18, label %23, label %19
19: ; preds = %14
%20 = bitcast %struct.sockaddr_un* %3 to %struct.sockaddr*
%21 = call i32 @recvfrom(i32 %17, i8* %8, i32 4096, i32 0, %struct.sockaddr* %20, i32* %4)
%22 = icmp slt i32 %21, 1
br i1 %22, label %26, label %31
23: ; preds = %14
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
%25 = tail call i32 @exit(i32 1)
unreachable
26: ; preds = %31, %19
%27 = load i32, i32* @errno
%28 = call i8* @strerror(i32 %27)
%29 = call i32 @puts(i8* dereferenceable(1) %28)
%30 = call i32 @close(i32 %17)
ret i32 0
31: ; preds = %19, %31
%32 = phi i32 [ %36, %31 ], [ %21, %19 ]
%33 = phi i32 [ %34, %31 ], [ 0, %19 ]
%34 = add nuw nsw i32 %33, 1
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %34, i32 %32)
%36 = call i32 @recvfrom(i32 %17, i8* %8, i32 4096, i32 0, %struct.sockaddr* %20, i32* %4)
%37 = icmp slt i32 %36, 1
br i1 %37, label %26, label %31
}