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

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ write(int, char *, int);
int main(int nargs, char *argv[]) {
  if (nargs != 2) {
    printf("Give the sun path number\n");
    return -1;
  }
  int sockfd, servlen, n;
  struct sockaddr_un serv_addr;
  char buffer[82];
  bzero((char *)&serv_addr, sizeof(serv_addr));
  serv_addr.sun_family = AF_UNIX;
  strcpy(serv_addr.sun_path, argv[1]);
  servlen = strlen(serv_addr.sun_path) + sizeof(serv_addr.sun_family);
  if ((sockfd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
    error("Creating socket");
  if (connect(sockfd, (struct sockaddr *)&serv_addr, servlen) < 0)
    error("Connecting");
  printf("Please enter your message: ");
  bzero(buffer, 82);
  fgets(buffer, 80, stdin);
  write(sockfd, buffer, strlen(buffer));
  n = read(sockfd, buffer, 80);
  printf("The return message was\n");
  write(1, buffer, n);
  close(sockfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11eb <main+0x3b>
lea    0xe26(%rip),%rdi
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1332 <main+0x182>
lea    -0x30(%rbp),%rdi
mov    $0x10,%esi
call   10b0 <bzero@plt>
mov    0x2de8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1030 <strcpy@plt>
mov    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
cltq
add    $0x4,%rax
mov    %eax,-0x18(%rbp)
mov    0x2db9(%rip),%rax
mov    (%rax),%edi
mov    0x2d98(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1259 <main+0xa9>
lea    0xdc6(%rip),%rdi
call   10a0 <error@plt>
mov    -0x14(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   10c0 <connect@plt>
cmp    $0x0,%rax
jge    127e <main+0xce>
lea    0xdb1(%rip),%rdi
call   10a0 <error@plt>
lea    0xdb0(%rip),%rdi
call   1060 <printf@plt>
lea    -0x90(%rbp),%rdi
mov    $0x52,%esi
call   10b0 <bzero@plt>
lea    -0x90(%rbp),%rdi
mov    0x2d37(%rip),%rax
mov    (%rax),%edx
mov    $0x50,%esi
call   1090 <fgets@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x9c(%rbp)
lea    -0x90(%rbp),%rax
mov    %rax,-0x98(%rbp)
lea    -0x90(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x9c(%rbp),%edi
mov    -0x98(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    -0x14(%rbp),%edi
lea    -0x90(%rbp),%rsi
mov    $0x50,%edx
call   1080 <read@plt>
mov    %eax,-0x1c(%rbp)
lea    0xd47(%rip),%rdi
call   1060 <printf@plt>
lea    -0x90(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    $0x1,%edi
call   1040 <write@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x70,%rsp
cmp    $0x2,%edi
jne    12cd <main+0x10d>
mov    %rsi,%rbx
mov    %rsp,%rdi
mov    $0x10,%esi
call   10c0 <bzero@plt>
mov    0x2e00(%rip),%r14
mov    (%r14),%eax
mov    %eax,0x8(%rsp)
mov    (%rsp),%rbp
mov    0x8(%rbx),%rsi
mov    %rbp,%rdi
call   1030 <strcpy@plt>
mov    %rbp,%rdi
call   1060 <strlen@plt>
mov    %eax,%ebp
add    $0x4,%ebp
mov    (%r14),%edi
mov    0x2dba(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    1231 <main+0x71>
lea    0xdd4(%rip),%rdi
call   10b0 <error@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    %ebp,%edx
call   10d0 <connect@plt>
test   %rax,%rax
jns    124e <main+0x8e>
lea    0xdc7(%rip),%rdi
call   10b0 <error@plt>
lea    0xdc6(%rip),%rdi
call   1070 <printf@plt>
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0x52,%esi
call   10c0 <bzero@plt>
mov    0x2d6d(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
mov    $0x50,%esi
call   10a0 <fgets@plt>
mov    %r14,%rdi
call   1060 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1050 <write@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x50,%edx
call   1090 <read@plt>
mov    %eax,%ebp
lea    0xd89(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
mov    %r14,%rsi
mov    %ebp,%edx
call   1050 <write@plt>
mov    %ebx,%edi
call   1080 <close@plt>
xor    %eax,%eax
jmp    12de <main+0x11e>
lea    0xd7a(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%eax
add    $0x70,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_un = type { i8*, i32 }
%struct.sockaddr = type { i32 }
@.str = [26 x i8] c"Give the sun path number\0A\00"
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [16 x i8] c"Creating socket\00"
@.str.2 = [11 x i8] c"Connecting\00"
@.str.3 = [28 x i8] c"Please enter your message: \00"
@stdin = global i32 0
@.str.4 = [24 x i8] c"The return message was\0A\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 i32
%9 = alloca %struct.sockaddr_un
%10 = alloca [82 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, 2
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %67
15: ; preds = %2
%16 = bitcast %struct.sockaddr_un* %9 to i8*
%17 = call i32 @bzero(i8* %16, i32 16)
%18 = load i32, i32* @AF_UNIX
%19 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %9, i32 0, i32 1
store i32 %18, i32* %19
%20 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %9, i32 0, i32 0
%21 = load i8*, i8** %20
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32 @strcpy(i8* %21, i8* %24)
%26 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %9, i32 0, i32 0
%27 = load i8*, i8** %26
%28 = call i32 @strlen(i8* %27)
%29 = sext i32 %28 to i64
%30 = add i64 %29, 4
%31 = trunc i64 %30 to i32
store i32 %31, i32* %7
%32 = load i32, i32* @AF_UNIX
%33 = load i32, i32* @SOCK_STREAM
%34 = call i32 @socket(i32 %32, i32 %33, i32 0)
store i32 %34, i32* %6
%35 = icmp slt i32 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %15
%37 = call i32 @error(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %38
38: ; preds = %36, %15
%39 = load i32, i32* %6
%40 = bitcast %struct.sockaddr_un* %9 to %struct.sockaddr*
%41 = load i32, i32* %7
%42 = call i64 @connect(i32 %39, %struct.sockaddr* %40, i32 %41)
%43 = icmp slt i64 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %38
%45 = call i32 @error(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %46
46: ; preds = %44, %38
%47 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
%48 = getelementptr inbounds [82 x i8], [82 x i8]* %10, i64 0, i64 0
%49 = call i32 @bzero(i8* %48, i32 82)
%50 = getelementptr inbounds [82 x i8], [82 x i8]* %10, i64 0, i64 0
%51 = load i32, i32* @stdin
%52 = call i32 @fgets(i8* %50, i32 80, i32 %51)
%53 = load i32, i32* %6
%54 = getelementptr inbounds [82 x i8], [82 x i8]* %10, i64 0, i64 0
%55 = getelementptr inbounds [82 x i8], [82 x i8]* %10, i64 0, i64 0
%56 = call i32 @strlen(i8* %55)
%57 = call i32 @write(i32 %53, i8* %54, i32 %56)
%58 = load i32, i32* %6
%59 = getelementptr inbounds [82 x i8], [82 x i8]* %10, i64 0, i64 0
%60 = call i32 @read(i32 %58, i8* %59, i32 80)
store i32 %60, i32* %8
%61 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
%62 = getelementptr inbounds [82 x i8], [82 x i8]* %10, i64 0, i64 0
%63 = load i32, i32* %8
%64 = call i32 @write(i32 1, i8* %62, i32 %63)
%65 = load i32, i32* %6
%66 = call i32 @close(i32 %65)
store i32 0, i32* %3
br label %67
67: ; preds = %46, %13
%68 = load i32, i32* %3
ret i32 %68
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i8*, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [16 x i8] c"Creating socket\00"
@.str.2 = [11 x i8] c"Connecting\00"
@.str.3 = [28 x i8] c"Please enter your message: \00"
@stdin = global i32 0
@str = [23 x i8] c"The return message was\00"
@str.5 = [25 x i8] c"Give the sun path number\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_un
%4 = alloca [82 x i8]
%5 = icmp eq i32 %0, 2
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.5, i64 0, i64 0))
br label %44
8: ; preds = %2
%9 = bitcast %struct.sockaddr_un* %3 to i8*
%10 = getelementptr inbounds [82 x i8], [82 x i8]* %4, i64 0, i64 0
%11 = call i32 @bzero(i8* %9, i32 16)
%12 = load i32, i32* @AF_UNIX
%13 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 1
store i32 %12, i32* %13
%14 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 0
%15 = load i8*, i8** %14
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = tail call i32 @strcpy(i8* %15, i8* %17)
%19 = tail call i32 @strlen(i8* %15)
%20 = add i32 %19, 4
%21 = load i32, i32* @AF_UNIX
%22 = load i32, i32* @SOCK_STREAM
%23 = tail call i32 @socket(i32 %21, i32 %22, i32 0)
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %8
%26 = tail call i32 @error(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %27
27: ; preds = %25, %8
%28 = bitcast %struct.sockaddr_un* %3 to %struct.sockaddr*
%29 = call i64 @connect(i32 %23, %struct.sockaddr* %28, i32 %20)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %27
%32 = call i32 @error(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %33
33: ; preds = %31, %27
%34 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
%35 = call i32 @bzero(i8* %10, i32 82)
%36 = load i32, i32* @stdin
%37 = call i32 @fgets(i8* %10, i32 80, i32 %36)
%38 = call i32 @strlen(i8* %10)
%39 = call i32 @write(i32 %23, i8* %10, i32 %38)
%40 = call i32 @read(i32 %23, i8* %10, i32 80)
%41 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%42 = call i32 @write(i32 1, i8* %10, i32 %40)
%43 = call i32 @close(i32 %23)
br label %44
44: ; preds = %33, %6
%45 = phi i32 [ -1, %6 ], [ 0, %33 ]
ret i32 %45
}