#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*/ socklen_t;
typedef int /*<<< orphan*/ sa;
typedef int /*<<< orphan*/ msgbuff;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int /*<<< orphan*/);
int /*<<< orphan*/ memset(struct sockaddr_un *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ send(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
int main() {
  int clientsocket;
  FILE *fp;
  char msgbuff[255];
  struct sockaddr_un sa;
  if ((clientsocket = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
    perror("Client: socket");
    return EXIT_FAILURE;
  }
  printf("Client: socket ready!\n");
  memset(&sa, 0, sizeof(sa));
  sa.sun_family = AF_UNIX;
  strcpy(sa.sun_path, "mysocketname");
  if (connect(clientsocket, (struct sockaddr *)&sa, (socklen_t)sizeof(sa)) <
      0) {
    perror("Client: connect");
    return EXIT_FAILURE;
  }
  printf("Client: connecting...\n");
  recv(clientsocket, msgbuff, sizeof(msgbuff), 0);
  printf("%s\n", msgbuff);
  send(clientsocket, "Client", 7, 0);
  close(clientsocket);
  printf("Client: exiting...\n");
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
mov    0x2e26(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    11e4 <main+0x54>
lea    0xe32(%rip),%rdi
call   1090 <perror@plt>
mov    0x2df6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12d2 <main+0x142>
lea    0xe24(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x118(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1070 <memset@plt>
mov    0x2ddc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x114(%rbp)
mov    -0x118(%rbp),%edi
lea    0xe05(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x8(%rbp),%edi
lea    -0x118(%rbp),%rsi
mov    $0x8,%edx
call   10a0 <connect@plt>
cmp    $0x0,%rax
jge    1261 <main+0xd1>
lea    0xde8(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d79(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12d2 <main+0x142>
lea    0xddb(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x8(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    $0xff,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
lea    -0x110(%rbp),%rsi
lea    0xdc7(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x8(%rbp),%edi
lea    0xdba(%rip),%rsi
mov    $0x7,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    -0x8(%rbp),%edi
call   1080 <close@plt>
lea    0xda6(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2cfb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x110,%rsp
mov    0x2e45(%rip),%r15
mov    (%r15),%edi
mov    0x2e2b(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
test   %eax,%eax
js     1273 <main+0xe3>
mov    %eax,%ebx
lea    0xe6c(%rip),%rdi
call   1050 <puts@plt>
lea    0x8(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1070 <memset@plt>
mov    (%r15),%eax
mov    %eax,0xc(%rsp)
mov    0x8(%rsp),%edi
lea    0xe1d(%rip),%rsi
call   1040 <strcpy@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x8,%edx
call   10a0 <connect@plt>
test   %rax,%rax
js     127c <main+0xec>
lea    0xe37(%rip),%rdi
call   1050 <puts@plt>
lea    0x10(%rsp),%r14
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xff,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %r14,%rdi
call   1050 <puts@plt>
lea    0xdf0(%rip),%rsi
mov    %ebx,%edi
mov    $0x7,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    %ebx,%edi
call   1080 <close@plt>
lea    0xe07(%rip),%rdi
call   1050 <puts@plt>
mov    0x2d64(%rip),%rax
mov    (%rax),%eax
add    $0x110,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xd86(%rip),%rdi
jmp    1283 <main+0xf3>
lea    0xd99(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d41(%rip),%rax
jmp    1264 <main+0xd4>

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str = [15 x i8] c"Client: socket\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [23 x i8] c"Client: socket ready!\0A\00"
@.str.2 = [13 x i8] c"mysocketname\00"
@.str.3 = [16 x i8] c"Client: connect\00"
@.str.4 = [23 x i8] c"Client: connecting...\0A\00"
@.str.5 = [4 x i8] c"%s\0A\00"
@.str.6 = [7 x i8] c"Client\00"
@.str.7 = [20 x i8] c"Client: exiting...\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
%4 = alloca [255 x i8]
%5 = alloca %struct.sockaddr_un
store i32 0, i32* %1
%6 = load i32, i32* @AF_UNIX
%7 = load i32, i32* @SOCK_STREAM
%8 = call i32 @socket(i32 %6, i32 %7, i32 0)
store i32 %8, i32* %2
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* @EXIT_FAILURE
store i32 %12, i32* %1
br label %41
13: ; preds = %0
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 @memset(%struct.sockaddr_un* %5, i32 0, i32 8)
%16 = load i32, i32* @AF_UNIX
%17 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %5, i32 0, i32 1
store i32 %16, i32* %17
%18 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %5, i32 0, i32 0
%19 = load i32, i32* %18
%20 = call i32 @strcpy(i32 %19, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%21 = load i32, i32* %2
%22 = bitcast %struct.sockaddr_un* %5 to %struct.sockaddr*
%23 = call i64 @connect(i32 %21, %struct.sockaddr* %22, i32 8)
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %13
%26 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%27 = load i32, i32* @EXIT_FAILURE
store i32 %27, i32* %1
br label %41
28: ; preds = %13
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
%30 = load i32, i32* %2
%31 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%32 = call i32 @recv(i32 %30, i8* %31, i32 255, i32 0)
%33 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %33)
%35 = load i32, i32* %2
%36 = call i32 @send(i32 %35, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32 7, i32 0)
%37 = load i32, i32* %2
%38 = call i32 @close(i32 %37)
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0))
%40 = load i32, i32* @EXIT_SUCCESS
store i32 %40, i32* %1
br label %41
41: ; preds = %28, %25, %10
%42 = load i32, i32* %1
ret i32 %42
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str = [15 x i8] c"Client: socket\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [13 x i8] c"mysocketname\00"
@.str.3 = [16 x i8] c"Client: connect\00"
@.str.6 = [7 x i8] c"Client\00"
@EXIT_SUCCESS = global i32 0
@str = [22 x i8] c"Client: socket ready!\00"
@str.8 = [22 x i8] c"Client: connecting...\00"
@str.9 = [19 x i8] c"Client: exiting...\00"
define i32 @main() {
%1 = alloca [255 x i8]
%2 = alloca %struct.sockaddr_un
%3 = getelementptr inbounds [255 x i8], [255 x i8]* %1, i64 0, i64 0
%4 = bitcast %struct.sockaddr_un* %2 to i8*
%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 slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = tail call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %31
11: ; preds = %0
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%13 = call i32 @memset(%struct.sockaddr_un* %2, i32 0, i32 8)
%14 = load i32, i32* @AF_UNIX
%15 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %2, i64 0, i32 1
store i32 %14, i32* %15
%16 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %2, i64 0, i32 0
%17 = load i32, i32* %16
%18 = call i32 @strcpy(i32 %17, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%19 = bitcast %struct.sockaddr_un* %2 to %struct.sockaddr*
%20 = call i64 @connect(i32 %7, %struct.sockaddr* %19, i32 8)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %11
%23 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
br label %31
24: ; preds = %11
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.8, i64 0, i64 0))
%26 = call i32 @recv(i32 %7, i8* %3, i32 255, i32 0)
%27 = call i32 @puts(i8* %3)
%28 = call i32 @send(i32 %7, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32 7, i32 0)
%29 = call i32 @close(i32 %7)
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.9, i64 0, i64 0))
br label %31
31: ; preds = %24, %22, %9
%32 = phi i32* [ @EXIT_FAILURE, %9 ], [ @EXIT_FAILURE, %22 ], [ @EXIT_SUCCESS, %24 ]
%33 = load i32, i32* %32
ret i32 %33
}