#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;
};
typedef int /*<<< orphan*/ sa_family_t;
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char **argv) {
  int sockfd;
  int len;
  struct sockaddr_un address;
  int result;
  if (argc != 3) {
    fprintf(stderr, "Usage %s [ <socket_name> | @<socket_name> ] <message>\n",
            *argv);
    return 1;
  }
  if (!(sockfd = socket(AF_UNIX, SOCK_STREAM, 0))) {
    perror("socket() error\n");
    return 1;
  }
  address.sun_family = AF_UNIX;
  strcpy(address.sun_path, *(argv + 1));
  if (address.sun_path[0] == '@')
    address.sun_path[0] = 0;
  len = sizeof(sa_family_t) + strlen(*(argv + 1));
  result = connect(sockfd, (struct sockaddr *)&address, len);
  if (result == -1) {
    perror("oops:  client1");
    return 1;
  }
  write(sockfd, *(argv + 2), strlen(*(argv + 2)));
  char buffer[1024];
  len = read(sockfd, buffer, sizeof(buffer));
  buffer[len] = 0;
  printf("%s", buffer);
  close(sockfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11eb <main+0x4b>
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe26(%rip),%rsi
call   1090 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1324 <main+0x184>
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
mov    0x2dd5(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jne    1228 <main+0x88>
lea    0xe20(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1324 <main+0x184>
mov    0x2db9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1030 <strcpy@plt>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x40,%eax
jne    125c <main+0xbc>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <strlen@plt>
cltq
add    $0x4,%rax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   10b0 <connect@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    12a6 <main+0x106>
lea    0xdb2(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1324 <main+0x184>
mov    -0x14(%rbp),%eax
mov    %eax,-0x43c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x438(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1050 <strlen@plt>
mov    -0x43c(%rbp),%edi
mov    -0x438(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    -0x14(%rbp),%edi
lea    -0x430(%rbp),%rsi
mov    $0x400,%edx
call   1080 <read@plt>
mov    %eax,-0x18(%rbp)
movslq -0x18(%rbp),%rax
movb   $0x0,-0x430(%rbp,%rax,1)
lea    -0x430(%rbp),%rsi
lea    0xd46(%rip),%rdi
call   1060 <printf@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    %rsi,%rbx
cmp    $0x3,%edi
je     1168 <main+0x28>
mov    0x2e88(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xea4(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%eax
pop    %rbx
ret
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
mov    0x2e58(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <socket@plt>
test   %eax,%eax
jne    1193 <main+0x53>
lea    0xeab(%rip),%rdi
call   1050 <perror@plt>
jmp    1161 <main+0x21>
mov    0x8(%rbx),%rsi
call   1030 <strcpy@plt>

LLVM IR (-O0):
%struct.sockaddr_un = type { i8*, i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [55 x i8] c"Usage %s [ <socket_name> | @<socket_name> ] <message>\0A\00"
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [16 x i8] c"socket() error\0A\00"
@.str.2 = [15 x i8] c"oops: client1\00"
@.str.3 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.sockaddr_un
%9 = alloca i32
%10 = alloca [1024 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 3
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i8**, i8*** %5
%16 = load i8*, i8** %15
%17 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i8* %16)
store i32 1, i32* %3
br label %80
18: ; preds = %2
%19 = load i32, i32* @AF_UNIX
%20 = load i32, i32* @SOCK_STREAM
%21 = call i32 @socket(i32 %19, i32 %20, i32 0)
store i32 %21, i32* %6
%22 = icmp ne i32 %21, 0
br i1 %22, label %25, label %23
23: ; preds = %18
%24 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %80
25: ; preds = %18
%26 = load i32, i32* @AF_UNIX
%27 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %8, i32 0, i32 1
store i32 %26, i32* %27
%28 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %8, i32 0, i32 0
%29 = load i8*, i8** %28
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = call i32 @strcpy(i8* %29, i8* %32)
%34 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %8, i32 0, i32 0
%35 = load i8*, i8** %34
%36 = getelementptr inbounds i8, i8* %35, i64 0
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp eq i32 %38, 64
br i1 %39, label %40, label %44
40: ; preds = %25
%41 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %8, i32 0, i32 0
%42 = load i8*, i8** %41
%43 = getelementptr inbounds i8, i8* %42, i64 0
store i8 0, i8* %43
br label %44
44: ; preds = %40, %25
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 1
%47 = load i8*, i8** %46
%48 = call i32 @strlen(i8* %47)
%49 = sext i32 %48 to i64
%50 = add i64 4, %49
%51 = trunc i64 %50 to i32
store i32 %51, i32* %7
%52 = load i32, i32* %6
%53 = bitcast %struct.sockaddr_un* %8 to %struct.sockaddr*
%54 = load i32, i32* %7
%55 = call i32 @connect(i32 %52, %struct.sockaddr* %53, i32 %54)
store i32 %55, i32* %9
%56 = load i32, i32* %9
%57 = icmp eq i32 %56, -1
br i1 %57, label %58, label %60
58: ; preds = %44
%59 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %80
60: ; preds = %44
%61 = load i32, i32* %6
%62 = load i8**, i8*** %5
%63 = getelementptr inbounds i8*, i8** %62, i64 2
%64 = load i8*, i8** %63
%65 = load i8**, i8*** %5
%66 = getelementptr inbounds i8*, i8** %65, i64 2
%67 = load i8*, i8** %66
%68 = call i32 @strlen(i8* %67)
%69 = call i32 @write(i32 %61, i8* %64, i32 %68)
%70 = load i32, i32* %6
%71 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%72 = call i32 @read(i32 %70, i8* %71, i32 1024)
store i32 %72, i32* %7
%73 = load i32, i32* %7
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 %74
store i8 0, i8* %75
%76 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%77 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %76)
%78 = load i32, i32* %6
%79 = call i32 @close(i32 %78)
store i32 0, i32* %3
br label %80
80: ; preds = %60, %58, %23, %13
%81 = load i32, i32* %3
ret i32 %81
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [55 x i8] c"Usage %s [ <socket_name> | @<socket_name> ] <message>\0A\00"
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [16 x i8] c"socket() error\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %19
8: ; preds = %2
%9 = load i32, i32* @AF_UNIX
%10 = load i32, i32* @SOCK_STREAM
%11 = tail call i32 @socket(i32 %9, i32 %10, i32 0)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = tail call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %19
15: ; preds = %8
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = tail call i32 @strcpy(i8* undef, i8* %17)
unreachable
19: ; preds = %13, %4
ret i32 1
}