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

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
scalar_t__ ENOENT;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ STDOUT_FILENO;
int accept(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int bind(int, struct sockaddr *, int);
int close(int);
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int listen(int, int);
int /*<<< orphan*/ memset(struct sockaddr_un *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strncpy(int /*<<< orphan*/, char *, int);
int unlink(char *);
int write(int /*<<< orphan*/, char *, int);
int main(void) {
  struct sockaddr_un addr;
  int sfd, cfd;
  ssize_t numRead;
  char buf[100];
  sfd = socket(AF_UNIX, SOCK_STREAM, 0);
  if (sfd == -1)
    exit(-1);
  if (unlink("/tmp/us_xfr") == -1 && errno != ENOENT)
    exit(-2);
  memset(&addr, 0, sizeof(struct sockaddr_un));
  addr.sun_family = AF_UNIX;
  strncpy(addr.sun_path, "/tmp/us_xfr", sizeof(addr.sun_path) - 1);
  if (bind(sfd, (struct sockaddr *)&addr, sizeof(struct sockaddr_un)) == -1)
    exit(-3);
  if (listen(sfd, 5) == -1)
    exit(-4);
  for (;;) {
    cfd = accept(sfd, NULL, NULL);
    if (cfd == -1)
      exit(-5);
    while ((numRead = read(cfd, buf, 100)) > 0)
      if (write(STDOUT_FILENO, buf, numRead) != numRead)
        perror("partial/failed write ");
    if (numRead == -1)
      exit(-6);
    if (close(cfd) == -1)
      perror("close ");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
mov    0x2dee(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1202 <main+0x42>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
lea    0xdf7(%rip),%rdi
call   1030 <unlink@plt>
cmp    $0xffffffff,%eax
jne    123b <main+0x7b>
mov    0x2daa(%rip),%rax
mov    (%rax),%rax
mov    0x2d90(%rip),%rcx
cmp    (%rcx),%rax
je     123b <main+0x7b>
mov    $0xfffffffe,%edi
call   10d0 <exit@plt>
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1060 <memset@plt>
mov    0x2d8e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%edi
lea    0xd9f(%rip),%rsi
mov    $0x3,%edx
call   1040 <strncpy@plt>
mov    -0x14(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0x8,%edx
call   10a0 <bind@plt>
cmp    $0xffffffff,%eax
jne    128f <main+0xcf>
mov    $0xfffffffd,%edi
call   10d0 <exit@plt>
mov    -0x14(%rbp),%edi
mov    $0x5,%esi
call   1090 <listen@plt>
cmp    $0xffffffff,%eax
jne    12af <main+0xef>
mov    $0xfffffffc,%edi
call   10d0 <exit@plt>
jmp    12b4 <main+0xf4>
mov    -0x14(%rbp),%edi
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rsi
call   10c0 <accept@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    12da <main+0x11a>
mov    $0xfffffffb,%edi
call   10d0 <exit@plt>
jmp    12df <main+0x11f>
mov    -0x18(%rbp),%edi
lea    -0x80(%rbp),%rsi
mov    $0x64,%edx
call   1080 <read@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jle    132b <main+0x16b>
mov    0x2ced(%rip),%rax
mov    (%rax),%edi
lea    -0x80(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1050 <write@plt>
cmp    -0x1c(%rbp),%eax
je     1326 <main+0x166>
lea    0xceb(%rip),%rdi
call   10b0 <perror@plt>
jmp    12df <main+0x11f>
cmpl   $0xffffffff,-0x1c(%rbp)
jne    133f <main+0x17f>
mov    $0xfffffffa,%edi
call   10d0 <exit@plt>
mov    -0x18(%rbp),%edi
call   1070 <close@plt>
cmp    $0xffffffff,%eax
jne    135c <main+0x19c>
lea    0xccb(%rip),%rdi
call   10b0 <perror@plt>
jmp    12b4 <main+0xf4>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    0x2e0b(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2df1(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
cmp    $0xffffffff,%eax
jne    11f7 <main+0x37>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
mov    %eax,%r14d
lea    0xdff(%rip),%rdi
call   1030 <unlink@plt>
cmp    $0xffffffff,%eax
jne    1221 <main+0x61>
mov    0x2db6(%rip),%rax
mov    (%rax),%rax
mov    0x2d9c(%rip),%rcx
cmp    (%rcx),%rax
jne    128c <main+0xcc>
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1060 <memset@plt>
mov    0x0(%rbp),%eax
mov    %eax,0xc(%rsp)
mov    0x8(%rsp),%edi
lea    0xdb9(%rip),%rsi
mov    $0x3,%edx
call   1040 <strncpy@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x8,%edx
call   10a0 <bind@plt>
cmp    $0xffffffff,%eax
jne    1270 <main+0xb0>
mov    $0xfffffffd,%edi
call   10d0 <exit@plt>
mov    %r14d,%edi
mov    $0x5,%esi
call   1090 <listen@plt>
cmp    $0xffffffff,%eax
jne    1296 <main+0xd6>
mov    $0xfffffffc,%edi
call   10d0 <exit@plt>
mov    $0xfffffffe,%edi
call   10d0 <exit@plt>
mov    %r14d,%edi
xor    %esi,%esi
xor    %edx,%edx
call   10c0 <accept@plt>
cmp    $0xffffffff,%eax
jne    12b1 <main+0xf1>
mov    $0xfffffffb,%edi
call   10d0 <exit@plt>
mov    %eax,%ebp
lea    0x10(%rsp),%r13
mov    0x2d31(%rip),%r15
lea    0xd46(%rip),%r12
jmp    12e0 <main+0x120>
mov    %r14d,%edi
xor    %esi,%esi
xor    %edx,%edx
call   10c0 <accept@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
je     12a7 <main+0xe7>
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %r13,%rsi
mov    $0x64,%edx
call   1080 <read@plt>
mov    %eax,%ebx
test   %eax,%eax
jle    1310 <main+0x150>
mov    (%r15),%edi
mov    %r13,%rsi
mov    %ebx,%edx
call   1050 <write@plt>
cmp    %ebx,%eax
je     12e0 <main+0x120>
mov    %r12,%rdi
call   10b0 <perror@plt>
jmp    12e0 <main+0x120>
cmp    $0xffffffff,%ebx
je     132f <main+0x16f>
mov    %ebp,%edi
call   1070 <close@plt>
cmp    $0xffffffff,%eax
jne    12c8 <main+0x108>
lea    0xcfa(%rip),%rdi
call   10b0 <perror@plt>
jmp    12c8 <main+0x108>
mov    $0xfffffffa,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str = [12 x i8] c"/tmp/us_xfr\00"
@errno = global i64 0
@ENOENT = global i64 0
@STDOUT_FILENO = global i32 0
@.str.1 = [22 x i8] c"partial/failed write \00"
@.str.2 = [7 x i8] c"close \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.sockaddr_un
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [100 x i8]
store i32 0, i32* %1
%7 = load i32, i32* @AF_UNIX
%8 = load i32, i32* @SOCK_STREAM
%9 = call i32 @socket(i32 %7, i32 %8, i32 0)
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = call i32 @exit(i32 -1)
unreachable
14: ; preds = %0
%15 = call i32 @unlink(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %23
17: ; preds = %14
%18 = load i64, i64* @errno
%19 = load i64, i64* @ENOENT
%20 = icmp ne i64 %18, %19
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = call i32 @exit(i32 -2)
unreachable
23: ; preds = %17, %14
%24 = call i32 @memset(%struct.sockaddr_un* %2, i32 0, i32 8)
%25 = load i32, i32* @AF_UNIX
%26 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %2, i32 0, i32 1
store i32 %25, i32* %26
%27 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %2, i32 0, i32 0
%28 = load i32, i32* %27
%29 = call i32 @strncpy(i32 %28, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 3)
%30 = load i32, i32* %3
%31 = bitcast %struct.sockaddr_un* %2 to %struct.sockaddr*
%32 = call i32 @bind(i32 %30, %struct.sockaddr* %31, i32 8)
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %36
34: ; preds = %23
%35 = call i32 @exit(i32 -3)
unreachable
36: ; preds = %23
%37 = load i32, i32* %3
%38 = call i32 @listen(i32 %37, i32 5)
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %42
40: ; preds = %36
%41 = call i32 @exit(i32 -4)
unreachable
42: ; preds = %36
br label %43
43: ; preds = %77, %42
%44 = load i32, i32* %3
%45 = call i32 @accept(i32 %44, i32* null, i32* null)
store i32 %45, i32* %4
%46 = load i32, i32* %4
%47 = icmp eq i32 %46, -1
br i1 %47, label %48, label %50
48: ; preds = %43
%49 = call i32 @exit(i32 -5)
unreachable
50: ; preds = %43
br label %51
51: ; preds = %65, %50
%52 = load i32, i32* %4
%53 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%54 = call i32 @read(i32 %52, i8* %53, i32 100)
store i32 %54, i32* %5
%55 = icmp sgt i32 %54, 0
br i1 %55, label %56, label %66
56: ; preds = %51
%57 = load i32, i32* @STDOUT_FILENO
%58 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%59 = load i32, i32* %5
%60 = call i32 @write(i32 %57, i8* %58, i32 %59)
%61 = load i32, i32* %5
%62 = icmp ne i32 %60, %61
br i1 %62, label %63, label %65
63: ; preds = %56
%64 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %65
65: ; preds = %63, %56
br label %51
66: ; preds = %51
%67 = load i32, i32* %5
%68 = icmp eq i32 %67, -1
br i1 %68, label %69, label %71
69: ; preds = %66
%70 = call i32 @exit(i32 -6)
unreachable
71: ; preds = %66
%72 = load i32, i32* %4
%73 = call i32 @close(i32 %72)
%74 = icmp eq i32 %73, -1
br i1 %74, label %75, label %77
75: ; preds = %71
%76 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %77
77: ; preds = %75, %71
br label %43
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str = [12 x i8] c"/tmp/us_xfr\00"
@errno = global i64 0
@ENOENT = global i64 0
@STDOUT_FILENO = global i32 0
@.str.1 = [22 x i8] c"partial/failed write \00"
@.str.2 = [7 x i8] c"close \00"
define i32 @main() {
%1 = alloca %struct.sockaddr_un
%2 = alloca [100 x i8]
%3 = bitcast %struct.sockaddr_un* %1 to i8*
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%5 = load i32, i32* @AF_UNIX
%6 = load i32, i32* @SOCK_STREAM
%7 = tail call i32 @socket(i32 %5, i32 %6, i32 0)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = tail call i32 @exit(i32 -1)
unreachable
11: ; preds = %0
%12 = tail call i32 @unlink(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %20
14: ; preds = %11
%15 = load i64, i64* @errno
%16 = load i64, i64* @ENOENT
%17 = icmp eq i64 %15, %16
br i1 %17, label %20, label %18
18: ; preds = %14
%19 = tail call i32 @exit(i32 -2)
unreachable
20: ; preds = %14, %11
%21 = call i32 @memset(%struct.sockaddr_un* %1, i32 0, i32 8)
%22 = load i32, i32* @AF_UNIX
%23 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %1, i64 0, i32 1
store i32 %22, i32* %23
%24 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %1, i64 0, i32 0
%25 = load i32, i32* %24
%26 = call i32 @strncpy(i32 %25, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 3)
%27 = bitcast %struct.sockaddr_un* %1 to %struct.sockaddr*
%28 = call i32 @bind(i32 %7, %struct.sockaddr* %27, i32 8)
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %32
30: ; preds = %20
%31 = call i32 @exit(i32 -3)
unreachable
32: ; preds = %20
%33 = call i32 @listen(i32 %7, i32 5)
%34 = icmp eq i32 %33, -1
br i1 %34, label %38, label %35
35: ; preds = %32
%36 = call i32 @accept(i32 %7, i32* null, i32* null)
%37 = icmp eq i32 %36, -1
br i1 %37, label %44, label %40
38: ; preds = %32
%39 = call i32 @exit(i32 -4)
unreachable
40: ; preds = %35, %66
%41 = phi i32 [ %67, %66 ], [ %36, %35 ]
%42 = call i32 @read(i32 %41, i8* %4, i32 100)
%43 = icmp sgt i32 %42, 0
br i1 %43, label %46, label %56
44: ; preds = %66, %35
%45 = call i32 @exit(i32 -5)
unreachable
46: ; preds = %40, %53
%47 = phi i32 [ %54, %53 ], [ %42, %40 ]
%48 = load i32, i32* @STDOUT_FILENO
%49 = call i32 @write(i32 %48, i8* %4, i32 %47)
%50 = icmp eq i32 %49, %47
br i1 %50, label %53, label %51
51: ; preds = %46
%52 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %53
53: ; preds = %51, %46
%54 = call i32 @read(i32 %41, i8* %4, i32 100)
%55 = icmp sgt i32 %54, 0
br i1 %55, label %46, label %56
56: ; preds = %53, %40
%57 = phi i32 [ %42, %40 ], [ %54, %53 ]
%58 = icmp eq i32 %57, -1
br i1 %58, label %59, label %61
59: ; preds = %56
%60 = call i32 @exit(i32 -6)
unreachable
61: ; preds = %56
%62 = call i32 @close(i32 %41)
%63 = icmp eq i32 %62, -1
br i1 %63, label %64, label %66
64: ; preds = %61
%65 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %66
66: ; preds = %64, %61
%67 = call i32 @accept(i32 %7, i32* null, i32* null)
%68 = icmp eq i32 %67, -1
br i1 %68, label %44, label %40
}