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

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ feof(int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
scalar_t__ printf(char *, ...);
int recv(int, char *, int, int /*<<< orphan*/);
int send(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int main(void) {
  int s;
  if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
    perror("socket");
    exit(EXIT_FAILURE);
  }
  printf("Trying to connect...\n");
  struct sockaddr_un remote;
  remote.sun_family = AF_UNIX;
  strcpy(remote.sun_path, "unix-stream-server.temp");
  int len = strlen(remote.sun_path) + sizeof(remote.sun_family);
  if (connect(s, (struct sockaddr *)&remote, len) == -1) {
    perror("connect");
    exit(EXIT_FAILURE);
  }
  printf("Connected.\n");
  char str[100];
  while (printf("> "), fgets(str, 100, stdin), !feof(stdin)) {
    if (send(s, str, strlen(str), 0) == -1) {
      perror("send");
      exit(EXIT_FAILURE);
    }
    int t;
    if ((t = recv(s, str, 100, 0)) > 0) {
      str[t] = '\0';
      printf("echo> %s", str);
    } else {
      if (t < 0)
        perror("recv");
      else
        printf("Server closed connection\n");
      exit(EXIT_FAILURE);
    }
  }
  close(s);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
mov    0x2dee(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    1211 <main+0x51>
lea    0xe02(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2dbe(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
lea    0xdef(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    0x2dc2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xde7(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
cltq
add    $0x4,%rax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   10d0 <connect@plt>
cmp    $0xffffffff,%eax
jne    127f <main+0xbf>
lea    0xdc9(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2d50(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
lea    0xdb7(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xdb5(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x80(%rbp),%rdi
mov    0x2d3a(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   1090 <fgets@plt>
mov    0x2d27(%rip),%rax
mov    (%rax),%edi
call   10a0 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    12d5 <main+0x115>
jmp    13af <main+0x1ef>
mov    -0x8(%rbp),%eax
mov    %eax,-0x94(%rbp)
lea    -0x80(%rbp),%rax
mov    %rax,-0x90(%rbp)
lea    -0x80(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x94(%rbp),%edi
mov    -0x90(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
cmp    $0xffffffff,%eax
jne    132b <main+0x16b>
lea    0xd34(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2ca4(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x8(%rbp),%edi
lea    -0x80(%rbp),%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x84(%rbp)
cmp    $0x0,%eax
jle    1370 <main+0x1b0>
movslq -0x84(%rbp),%rax
movb   $0x0,-0x80(%rbp,%rax,1)
lea    -0x80(%rbp),%rsi
lea    0xced(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    13aa <main+0x1ea>
cmpl   $0x0,-0x84(%rbp)
jge    138e <main+0x1ce>
lea    0xcd6(%rip),%rdi
call   10b0 <perror@plt>
jmp    139c <main+0x1dc>
lea    0xcca(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    0x2c25(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
jmp    128d <main+0xcd>
mov    -0x8(%rbp),%edi
call   1080 <close@plt>
mov    0x2c02(%rip),%rax
mov    (%rax),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x80,%rsp
mov    0x2e02(%rip),%rbx
mov    (%rbx),%edi
mov    0x2de1(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
cmp    $0xffffffff,%eax
je     1351 <main+0x181>
mov    %eax,%ebp
lea    0xe33(%rip),%rdi
call   1050 <puts@plt>
mov    (%rbx),%eax
mov    %eax,0x8(%rsp)
lea    0xdeb(%rip),%rsi
call   1040 <strcpy@plt>
call   1060 <strlen@plt>
lea    0x4(%rax),%edx
mov    %rsp,%rsi
mov    %ebp,%edi
call   10e0 <connect@plt>
cmp    $0xffffffff,%eax
je     135a <main+0x18a>
lea    0xe0f(%rip),%rdi
call   1050 <puts@plt>
lea    0xdd8(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x2d83(%rip),%r12
mov    (%r12),%edx
lea    0x10(%rsp),%rdi
mov    $0x64,%esi
call   10a0 <fgets@plt>
mov    (%r12),%edi
call   10b0 <feof@plt>
test   %eax,%eax
jne    130c <main+0x13c>
lea    0x10(%rsp),%rbx
lea    0xda2(%rip),%r14
lea    0xd93(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
cmp    $0xffffffff,%eax
je     132c <main+0x15c>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jle    1335 <main+0x165>
mov    %eax,%eax
movb   $0x0,0x10(%rsp,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %r15,%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    (%r12),%edx
mov    %rbx,%rdi
mov    $0x64,%esi
call   10a0 <fgets@plt>
mov    (%r12),%edi
call   10b0 <feof@plt>
test   %eax,%eax
je     12a0 <main+0xd0>
mov    %ebp,%edi
call   1090 <close@plt>
mov    0x2ca6(%rip),%rax
mov    (%rax),%eax
add    $0x80,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcf7(%rip),%rdi
jmp    133e <main+0x16e>
jns    1363 <main+0x193>
lea    0xcfa(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2c7e(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
lea    0xca8(%rip),%rdi
jmp    133e <main+0x16e>
lea    0xcbe(%rip),%rdi
jmp    133e <main+0x16e>
lea    0xcf3(%rip),%rdi
call   1050 <puts@plt>
jmp    1343 <main+0x173>

LLVM IR (-O0):
%struct.sockaddr_un = type { i8*, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str = [7 x i8] c"socket\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [22 x i8] c"Trying to connect...\0A\00"
@.str.2 = [24 x i8] c"unix-stream-server.temp\00"
@.str.3 = [8 x i8] c"connect\00"
@.str.4 = [12 x i8] c"Connected.\0A\00"
@.str.5 = [3 x i8] c"> \00"
@stdin = global i32 0
@.str.6 = [5 x i8] c"send\00"
@.str.7 = [9 x i8] c"echo> %s\00"
@.str.8 = [5 x i8] c"recv\00"
@.str.9 = [26 x i8] c"Server closed connection\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_un
%4 = alloca i32
%5 = alloca [100 x i8]
%6 = alloca i32
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* %2
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %15
11: ; preds = %0
%12 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @exit(i32 %13)
unreachable
15: ; preds = %0
%16 = call i64 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%17 = load i32, i32* @AF_UNIX
%18 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i32 0, i32 1
store i32 %17, i32* %18
%19 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i32 0, i32 0
%20 = load i8*, i8** %19
%21 = call i32 @strcpy(i8* %20, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%22 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i32 0, i32 0
%23 = load i8*, i8** %22
%24 = call i32 @strlen(i8* %23)
%25 = sext i32 %24 to i64
%26 = add i64 %25, 4
%27 = trunc i64 %26 to i32
store i32 %27, i32* %4
%28 = load i32, i32* %2
%29 = bitcast %struct.sockaddr_un* %3 to %struct.sockaddr*
%30 = load i32, i32* %4
%31 = call i32 @connect(i32 %28, %struct.sockaddr* %29, i32 %30)
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %37
33: ; preds = %15
%34 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%35 = load i32, i32* @EXIT_FAILURE
%36 = call i32 @exit(i32 %35)
unreachable
37: ; preds = %15
%38 = call i64 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
br label %39
39: ; preds = %80, %37
%40 = call i64 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%41 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%42 = load i32, i32* @stdin
%43 = call i32 @fgets(i8* %41, i32 100, i32 %42)
%44 = load i32, i32* @stdin
%45 = call i32 @feof(i32 %44)
%46 = icmp ne i32 %45, 0
%47 = xor i1 %46, true
br i1 %47, label %48, label %81
48: ; preds = %39
%49 = load i32, i32* %2
%50 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%51 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%52 = call i32 @strlen(i8* %51)
%53 = call i32 @send(i32 %49, i8* %50, i32 %52, i32 0)
%54 = icmp eq i32 %53, -1
br i1 %54, label %55, label %59
55: ; preds = %48
%56 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%57 = load i32, i32* @EXIT_FAILURE
%58 = call i32 @exit(i32 %57)
unreachable
59: ; preds = %48
%60 = load i32, i32* %2
%61 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%62 = call i32 @recv(i32 %60, i8* %61, i32 100, i32 0)
store i32 %62, i32* %6
%63 = icmp sgt i32 %62, 0
br i1 %63, label %64, label %70
64: ; preds = %59
%65 = load i32, i32* %6
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 %66
store i8 0, i8* %67
%68 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%69 = call i64 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), i8* %68)
br label %80
70: ; preds = %59
%71 = load i32, i32* %6
%72 = icmp slt i32 %71, 0
br i1 %72, label %73, label %75
73: ; preds = %70
%74 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
br label %77
75: ; preds = %70
%76 = call i64 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.9, i64 0, i64 0))
br label %77
77: ; preds = %75, %73
%78 = load i32, i32* @EXIT_FAILURE
%79 = call i32 @exit(i32 %78)
unreachable
80: ; preds = %64
br label %39
81: ; preds = %39
%82 = load i32, i32* %2
%83 = call i32 @close(i32 %82)
%84 = load i32, i32* @EXIT_SUCCESS
ret i32 %84
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i8*, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str = [7 x i8] c"socket\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [24 x i8] c"unix-stream-server.temp\00"
@.str.3 = [8 x i8] c"connect\00"
@.str.5 = [3 x i8] c"> \00"
@stdin = global i32 0
@.str.6 = [5 x i8] c"send\00"
@.str.7 = [9 x i8] c"echo> %s\00"
@.str.8 = [5 x i8] c"recv\00"
@EXIT_SUCCESS = global i32 0
@str = [21 x i8] c"Trying to connect...\00"
@str.10 = [11 x i8] c"Connected.\00"
@str.11 = [25 x i8] c"Server closed connection\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_un
%2 = alloca [100 x i8]
%3 = load i32, i32* @AF_UNIX
%4 = load i32, i32* @SOCK_STREAM
%5 = tail call i32 @socket(i32 %3, i32 %4, i32 0)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %11
7: ; preds = %0
%8 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @EXIT_FAILURE
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %0
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%13 = bitcast %struct.sockaddr_un* %1 to i8*
%14 = load i32, i32* @AF_UNIX
%15 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %1, i64 0, i32 1
store i32 %14, i32* %15
%16 = tail call i32 @strcpy(i8* undef, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%17 = tail call i32 @strlen(i8* undef)
%18 = add i32 %17, 4
%19 = bitcast %struct.sockaddr_un* %1 to %struct.sockaddr*
%20 = call i32 @connect(i32 %5, %struct.sockaddr* %19, i32 %18)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %26
22: ; preds = %11
%23 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%24 = load i32, i32* @EXIT_FAILURE
%25 = call i32 @exit(i32 %24)
unreachable
26: ; preds = %11
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.10, i64 0, i64 0))
%28 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%29 = call i64 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%30 = load i32, i32* @stdin
%31 = call i32 @fgets(i8* %28, i32 100, i32 %30)
%32 = load i32, i32* @stdin
%33 = call i32 @feof(i32 %32)
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %65
35: ; preds = %26, %46
%36 = call i32 @strlen(i8* %28)
%37 = call i32 @send(i32 %5, i8* %28, i32 %36, i32 0)
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %43
39: ; preds = %35
%40 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%41 = load i32, i32* @EXIT_FAILURE
%42 = call i32 @exit(i32 %41)
unreachable
43: ; preds = %35
%44 = call i32 @recv(i32 %5, i8* %28, i32 100, i32 0)
%45 = icmp sgt i32 %44, 0
br i1 %45, label %46, label %56
46: ; preds = %43
%47 = zext i32 %44 to i64
%48 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %47
store i8 0, i8* %48
%49 = call i64 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), i8* %28)
%50 = call i64 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%51 = load i32, i32* @stdin
%52 = call i32 @fgets(i8* %28, i32 100, i32 %51)
%53 = load i32, i32* @stdin
%54 = call i32 @feof(i32 %53)
%55 = icmp eq i32 %54, 0
br i1 %55, label %35, label %65
56: ; preds = %43
%57 = icmp slt i32 %44, 0
br i1 %57, label %58, label %60
58: ; preds = %56
%59 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
br label %62
60: ; preds = %56
%61 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.11, i64 0, i64 0))
br label %62
62: ; preds = %60, %58
%63 = load i32, i32* @EXIT_FAILURE
%64 = call i32 @exit(i32 %63)
unreachable
65: ; preds = %46, %26
%66 = call i32 @close(i32 %5)
%67 = load i32, i32* @EXIT_SUCCESS
ret i32 %67
}