#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_UNIX;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ fsync(int);
int /*<<< orphan*/ send(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strncpy(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char **argv) {
  int fd;
  struct sockaddr_un addr;
  addr.sun_family = AF_UNIX;
  char *socket_path = "/tmp/mysocket";
  strncpy(addr.sun_path, socket_path, sizeof(addr.sun_path) - 1);
  fd = socket(AF_UNIX, SOCK_STREAM, 0);
  connect(fd, (struct sockaddr *)&addr, sizeof(addr));
  write(fd, "write-hello\n", 12);
  send(fd, "send-hello\n", 11, 0);
  fsync(fd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e72(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
lea    0xe7e(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    $0x3,%edx
call   1030 <strncpy@plt>
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
mov    0x2e31(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x8,%edx
call   1070 <connect@plt>
mov    -0x14(%rbp),%edi
lea    0xe40(%rip),%rsi
mov    $0xc,%edx
call   1040 <write@plt>
mov    -0x14(%rbp),%edi
lea    0xe39(%rip),%rsi
mov    $0xb,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    -0x14(%rbp),%edi
call   1060 <fsync@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e7c(%rip),%rbx
mov    (%rbx),%eax
mov    %eax,0xc(%rsp)
lea    0xe87(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncpy@plt>
mov    (%rbx),%edi
mov    0x2e4c(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %eax,%ebx
lea    0x8(%rsp),%rsi
mov    %eax,%edi
mov    $0x8,%edx
call   1070 <connect@plt>
lea    0xe5f(%rip),%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   1040 <write@plt>
lea    0xe59(%rip),%rsi
mov    %ebx,%edi
mov    $0xb,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    %ebx,%edi
call   1060 <fsync@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@.str = [14 x i8] c"/tmp/mysocket\00"
@SOCK_STREAM = global i32 0
@.str.1 = [13 x i8] c"write-hello\0A\00"
@.str.2 = [12 x i8] c"send-hello\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca %struct.sockaddr_un
%7 = alloca i8*
store i32 %0, i32* %3
store i8** %1, i8*** %4
%8 = load i32, i32* @AF_UNIX
%9 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %6, i32 0, i32 1
store i32 %8, i32* %9
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8** %7
%10 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %6, i32 0, i32 0
%11 = load i32, i32* %10
%12 = load i8*, i8** %7
%13 = call i32 @strncpy(i32 %11, i8* %12, i32 3)
%14 = load i32, i32* @AF_UNIX
%15 = load i32, i32* @SOCK_STREAM
%16 = call i32 @socket(i32 %14, i32 %15, i32 0)
store i32 %16, i32* %5
%17 = load i32, i32* %5
%18 = bitcast %struct.sockaddr_un* %6 to %struct.sockaddr*
%19 = call i32 @connect(i32 %17, %struct.sockaddr* %18, i32 8)
%20 = load i32, i32* %5
%21 = call i32 @write(i32 %20, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 12)
%22 = load i32, i32* %5
%23 = call i32 @send(i32 %22, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 11, i32 0)
%24 = load i32, i32* %5
%25 = call i32 @fsync(i32 %24)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@.str = [14 x i8] c"/tmp/mysocket\00"
@SOCK_STREAM = global i32 0
@.str.1 = [13 x i8] c"write-hello\0A\00"
@.str.2 = [12 x i8] c"send-hello\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_un
%4 = bitcast %struct.sockaddr_un* %3 to i8*
%5 = load i32, i32* @AF_UNIX
%6 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 1
store i32 %5, i32* %6
%7 = tail call i32 @strncpy(i32 undef, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 3)
%8 = load i32, i32* @AF_UNIX
%9 = load i32, i32* @SOCK_STREAM
%10 = tail call i32 @socket(i32 %8, i32 %9, i32 0)
%11 = bitcast %struct.sockaddr_un* %3 to %struct.sockaddr*
%12 = call i32 @connect(i32 %10, %struct.sockaddr* %11, i32 8)
%13 = call i32 @write(i32 %10, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 12)
%14 = call i32 @send(i32 %10, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 11, i32 0)
%15 = call i32 @fsync(i32 %10)
ret i32 0
}