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

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
int main() {
  int server_fd;
  struct sockaddr_un myaddr;
  myaddr.sun_family = AF_UNIX;
  strcpy(myaddr.sun_path, "sundysocketfile");
  char buf[100];
  server_fd = socket(AF_UNIX, SOCK_STREAM, 0);
  if (server_fd == -1) {
    perror("socket error");
    exit(1);
  }
  if (connect(server_fd, (struct sockaddr *)&myaddr, sizeof(myaddr)) == -1) {
    perror("connect error");
    exit(1);
  }
  read(server_fd, buf, 100);
  printf("get message : %s\n", buf);
  close(server_fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e4f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%edi
lea    0xe58(%rip),%rsi
call   1030 <strcpy@plt>
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
mov    0x2e1b(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    11e9 <main+0x69>
lea    0xe36(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0x8,%edx
call   1090 <connect@plt>
cmp    $0xffffffff,%eax
jne    1219 <main+0x99>
lea    0xe13(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x8(%rbp),%edi
lea    -0x80(%rbp),%rsi
mov    $0x64,%edx
call   1060 <read@plt>
lea    -0x80(%rbp),%rsi
lea    0xdf6(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x78,%rsp
mov    0x2e5a(%rip),%rbx
mov    (%rbx),%eax
mov    %eax,0xc(%rsp)
lea    0xe65(%rip),%rsi
call   1030 <strcpy@plt>
mov    (%rbx),%edi
mov    0x2e2f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
cmp    $0xffffffff,%eax
je     1203 <main+0x83>
mov    %eax,%ebx
lea    0x8(%rsp),%rsi
mov    %eax,%edi
mov    $0x8,%edx
call   1090 <connect@plt>
cmp    $0xffffffff,%eax
je     120c <main+0x8c>
lea    0x10(%rsp),%r14
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x64,%edx
call   1060 <read@plt>
lea    0xe41(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe06(%rip),%rdi
jmp    1213 <main+0x93>
lea    0xe0a(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@.str = [16 x i8] c"sundysocketfile\00"
@SOCK_STREAM = global i32 0
@.str.1 = [13 x i8] c"socket error\00"
@.str.2 = [14 x i8] c"connect error\00"
@.str.3 = [18 x i8] c"get message : %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_un
%4 = alloca [100 x i8]
store i32 0, i32* %1
%5 = load i32, i32* @AF_UNIX
%6 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i32 0, i32 1
store i32 %5, i32* %6
%7 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i32 0, i32 0
%8 = load i32, i32* %7
%9 = call i32 @strcpy(i32 %8, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* @AF_UNIX
%11 = load i32, i32* @SOCK_STREAM
%12 = call i32 @socket(i32 %10, i32 %11, i32 0)
store i32 %12, i32* %2
%13 = load i32, i32* %2
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %18
15: ; preds = %0
%16 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %0
%19 = load i32, i32* %2
%20 = bitcast %struct.sockaddr_un* %3 to %struct.sockaddr*
%21 = call i32 @connect(i32 %19, %struct.sockaddr* %20, i32 8)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %26
23: ; preds = %18
%24 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %18
%27 = load i32, i32* %2
%28 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%29 = call i32 @read(i32 %27, i8* %28, i32 100)
%30 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%31 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %30)
%32 = load i32, i32* %2
%33 = call i32 @close(i32 %32)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@.str = [16 x i8] c"sundysocketfile\00"
@SOCK_STREAM = global i32 0
@.str.1 = [13 x i8] c"socket error\00"
@.str.2 = [14 x i8] c"connect error\00"
@.str.3 = [18 x i8] c"get message : %s\0A\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_un
%2 = alloca [100 x i8]
%3 = bitcast %struct.sockaddr_un* %1 to i8*
%4 = load i32, i32* @AF_UNIX
%5 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %1, i64 0, i32 1
store i32 %4, i32* %5
%6 = tail call i32 @strcpy(i32 undef, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%8 = load i32, i32* @AF_UNIX
%9 = load i32, i32* @SOCK_STREAM
%10 = tail call i32 @socket(i32 %8, i32 %9, i32 0)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %15
12: ; preds = %0
%13 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %0
%16 = bitcast %struct.sockaddr_un* %1 to %struct.sockaddr*
%17 = call i32 @connect(i32 %10, %struct.sockaddr* %16, i32 8)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %22
19: ; preds = %15
%20 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %15
%23 = call i32 @read(i32 %10, i8* %7, i32 100)
%24 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %7)
%25 = call i32 @close(i32 %10)
ret i32 0
}