#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 /*<<< orphan*/ addr;

/* Variables and functions */
int /*<<< orphan*/ AF_LOCAL;
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ SOCK_STREAM;
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ memset(struct sockaddr_un *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(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*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int strlen(char *);
int /*<<< orphan*/ strncpy(int /*<<< orphan*/, char *, int);
int main(int argc, char *argv[]) {
  int sockfd;
  struct sockaddr_un addr;
  char buf[1500];
  int n;
  if (argc != 2) {
    fprintf(stderr, "usage: %s <socket path>\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  sockfd = socket(AF_LOCAL, SOCK_STREAM, 0);
  if (-1 == sockfd) {
    perror("socket");
    exit(EXIT_FAILURE);
  }
  memset(&addr, 0, sizeof(addr));
  addr.sun_family = AF_LOCAL;
  strncpy(addr.sun_path, argv[1], sizeof(addr.sun_path) - 1);
  if (-1 == connect(sockfd, (struct sockaddr *)&addr, sizeof(addr))) {
    perror("connect");
    exit(EXIT_FAILURE);
  }
  while (1) {
    if (!fgets(buf, 1500, stdin))
      break;
    n = strlen(buf);
    if ((n = send(sockfd, buf, n, 0)) < 0) {
      perror("send");
      exit(EXIT_FAILURE);
    }
    if ((n = recv(sockfd, buf, 1500 - 1, 0)) < 0) {
      perror("recv");
      exit(EXIT_FAILURE);
    }
    buf[n] = '\0';
    fputs(buf, stdout);
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x610,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     120d <main+0x4d>
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe06(%rip),%rsi
call   10a0 <fprintf@plt>
mov    0x2dba(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    0x2dcc(%rip),%rax
mov    (%rax),%edi
mov    0x2dab(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x14(%rbp)
mov    $0xffffffff,%eax
cmp    -0x14(%rbp),%eax
jne    1251 <main+0x91>
lea    0xddb(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2d76(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1080 <memset@plt>
mov    0x2d78(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    $0x3,%edx
call   1040 <strncpy@plt>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x8,%edx
call   10d0 <connect@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    12bc <main+0xfc>
lea    0xd77(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2d0b(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
jmp    12c1 <main+0x101>
lea    -0x600(%rbp),%rdi
mov    0x2d19(%rip),%rax
mov    (%rax),%edx
mov    $0x5dc,%esi
call   1090 <fgets@plt>
cmp    $0x0,%eax
jne    12e9 <main+0x129>
jmp    13a3 <main+0x1e3>
lea    -0x600(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x604(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x600(%rbp),%rsi
mov    -0x604(%rbp),%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    %eax,-0x604(%rbp)
cmp    $0x0,%eax
jge    133b <main+0x17b>
lea    0xd00(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2c8c(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x600(%rbp),%rsi
mov    $0x5db,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x604(%rbp)
cmp    $0x0,%eax
jge    137a <main+0x1ba>
lea    0xcc6(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2c4d(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
movslq -0x604(%rbp),%rax
movb   $0x0,-0x600(%rbp,%rax,1)
lea    -0x600(%rbp),%rdi
mov    0x2c21(%rip),%rax
mov    (%rax),%esi
call   1070 <fputs@plt>
jmp    12c1 <main+0x101>
mov    0x2c06(%rip),%rax
mov    (%rax),%eax
add    $0x610,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x5f8,%rsp
mov    %rsi,%r14
cmp    $0x2,%edi
jne    12ff <main+0x13f>
mov    0x2e00(%rip),%r15
mov    (%r15),%edi
mov    0x2dde(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
cmp    $0xffffffff,%eax
je     1319 <main+0x159>
mov    %eax,%ebp
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1080 <memset@plt>
mov    (%r15),%eax
mov    %eax,0xc(%rsp)
mov    0x8(%rsp),%edi
mov    0x8(%r14),%rsi
mov    $0x3,%edx
call   1040 <strncpy@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x8,%edx
call   10d0 <connect@plt>
cmp    $0xffffffff,%eax
je     1322 <main+0x162>
mov    0x2d9e(%rip),%r14
mov    (%r14),%edx
lea    0x10(%rsp),%rdi
mov    $0x5dc,%esi
call   1090 <fgets@plt>
test   %eax,%eax
je     12c5 <main+0x105>
lea    0x10(%rsp),%rbx
mov    0x2d4c(%rip),%r15
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
test   %eax,%eax
js     12dc <main+0x11c>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x5db,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
js     12e5 <main+0x125>
mov    %eax,%eax
movb   $0x0,0x10(%rsp,%rax,1)
mov    (%r15),%esi
mov    %rbx,%rdi
call   1070 <fputs@plt>
mov    (%r14),%edx
mov    %rbx,%rdi
mov    $0x5dc,%esi
call   1090 <fgets@plt>
test   %eax,%eax
jne    1270 <main+0xb0>
mov    0x2ce4(%rip),%rax
mov    (%rax),%eax
add    $0x5f8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd45(%rip),%rdi
jmp    12ec <main+0x12c>
lea    0xd41(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2cc8(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    0x2cca(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xcee(%rip),%rsi
call   10a0 <fprintf@plt>
jmp    12f1 <main+0x131>
lea    0xcf9(%rip),%rdi
jmp    12ec <main+0x12c>
lea    0xcf7(%rip),%rdi
jmp    12ec <main+0x12c>

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

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [25 x i8] c"usage: %s <socket path>\0A\00"
@EXIT_FAILURE = global i32 0
@AF_LOCAL = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [7 x i8] c"socket\00"
@.str.2 = [8 x i8] c"connect\00"
@stdin = global i32 0
@.str.3 = [5 x i8] c"send\00"
@.str.4 = [5 x i8] c"recv\00"
@stdout = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_un
%4 = alloca [1500 x i8]
%5 = bitcast %struct.sockaddr_un* %3 to i8*
%6 = getelementptr inbounds [1500 x i8], [1500 x i8]* %4, i64 0, i64 0
%7 = icmp eq i32 %0, 2
br i1 %7, label %14, label %8
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %1
%11 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = load i32, i32* @EXIT_FAILURE
%13 = tail call i32 @exit(i32 %12)
unreachable
14: ; preds = %2
%15 = load i32, i32* @AF_LOCAL
%16 = load i32, i32* @SOCK_STREAM
%17 = tail call i32 @socket(i32 %15, i32 %16, i32 0)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %23
19: ; preds = %14
%20 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%21 = load i32, i32* @EXIT_FAILURE
%22 = tail call i32 @exit(i32 %21)
unreachable
23: ; preds = %14
%24 = call i32 @memset(%struct.sockaddr_un* %3, i32 0, i32 8)
%25 = load i32, i32* @AF_LOCAL
%26 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 1
store i32 %25, i32* %26
%27 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 0
%28 = load i32, i32* %27
%29 = getelementptr inbounds i8*, i8** %1, i64 1
%30 = load i8*, i8** %29
%31 = call i32 @strncpy(i32 %28, i8* %30, i32 3)
%32 = bitcast %struct.sockaddr_un* %3 to %struct.sockaddr*
%33 = call i32 @connect(i32 %17, %struct.sockaddr* %32, i32 8)
%34 = icmp eq i32 %33, -1
br i1 %34, label %39, label %35
35: ; preds = %23
%36 = load i32, i32* @stdin
%37 = call i32 @fgets(i8* %6, i32 1500, i32 %36)
%38 = icmp eq i32 %37, 0
br i1 %38, label %66, label %43
39: ; preds = %23
%40 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%41 = load i32, i32* @EXIT_FAILURE
%42 = call i32 @exit(i32 %41)
unreachable
43: ; preds = %35, %58
%44 = call i32 @strlen(i8* %6)
%45 = call i32 @send(i32 %17, i8* %6, i32 %44, i32 0)
%46 = icmp slt i32 %45, 0
br i1 %46, label %47, label %51
47: ; preds = %43
%48 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%49 = load i32, i32* @EXIT_FAILURE
%50 = call i32 @exit(i32 %49)
unreachable
51: ; preds = %43
%52 = call i32 @recv(i32 %17, i8* %6, i32 1499, i32 0)
%53 = icmp slt i32 %52, 0
br i1 %53, label %54, label %58
54: ; preds = %51
%55 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%56 = load i32, i32* @EXIT_FAILURE
%57 = call i32 @exit(i32 %56)
unreachable
58: ; preds = %51
%59 = zext i32 %52 to i64
%60 = getelementptr inbounds [1500 x i8], [1500 x i8]* %4, i64 0, i64 %59
store i8 0, i8* %60
%61 = load i32, i32* @stdout
%62 = call i32 @fputs(i8* %6, i32 %61)
%63 = load i32, i32* @stdin
%64 = call i32 @fgets(i8* %6, i32 1500, i32 %63)
%65 = icmp eq i32 %64, 0
br i1 %65, label %66, label %43
66: ; preds = %58, %35
%67 = load i32, i32* @EXIT_SUCCESS
ret i32 %67
}