#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 ssize_t;
typedef int /*<<< orphan*/ name;

/* Variables and functions */
int /*<<< orphan*/ AF_LOCAL;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int make_named_socket(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ remove(char *);
int sendto(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
int strlen(char *);
int main(int argc, char *argv[]) {
  int sock;
  struct sockaddr_un name;
  ssize_t size;
  int nbytes;
  char *message = argv[1];
  nbytes = strlen(message);
  sock = make_named_socket("/tmp/mysocket");
  name.sun_family = AF_LOCAL;
  strcpy(name.sun_path, "/tmp/serversocket");
  size = sizeof(name);
  nbytes = sendto(sock, message, nbytes + 1, 0, (struct sockaddr *)&name, size);
  if (nbytes < 0) {
    perror("client send error");
    exit(EXIT_FAILURE);
  }
  fprintf(stderr, "Client: sent message: %s\n", message);
  remove("/tmp/mysocket");
  close(sock);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x28(%rbp)
lea    0xe42(%rip),%rdi
call   10b0 <make_named_socket@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e1b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%edi
lea    0xe32(%rip),%rsi
call   1040 <strcpy@plt>
movl   $0x8,-0x24(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%edx
add    $0x1,%edx
lea    -0x20(%rbp),%r8
mov    -0x24(%rbp),%r9d
xor    %ecx,%ecx
call   1060 <sendto@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    122b <main+0x9b>
lea    0xe08(%rip),%rdi
call   1090 <perror@plt>
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    0x2da6(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%rdx
lea    0xdf3(%rip),%rsi
call   1080 <fprintf@plt>
lea    0xdb5(%rip),%rdi
call   1030 <remove@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x8(%rsi),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
lea    0xe53(%rip),%rdi
call   10b0 <make_named_socket@plt>
mov    %eax,%r14d
mov    0x2e2c(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
lea    0xe45(%rip),%rsi
call   1040 <strcpy@plt>
add    $0x1,%ebp
lea    0x8(%rsp),%r8
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
xor    %ecx,%ecx
mov    $0x8,%r9d
call   1060 <sendto@plt>
test   %eax,%eax
js     1226 <main+0x96>
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
lea    0xe33(%rip),%rsi
mov    %rbx,%rdx
call   1080 <fprintf@plt>
lea    0xdf2(%rip),%rdi
call   1030 <remove@plt>
mov    %r14d,%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xdf3(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d97(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [14 x i8] c"/tmp/mysocket\00"
@AF_LOCAL = global i32 0
@.str.1 = [18 x i8] c"/tmp/serversocket\00"
@.str.2 = [18 x i8] c"client send error\00"
@EXIT_FAILURE = global i32 0
@stderr = global i32 0
@.str.3 = [26 x i8] c"Client: sent message: %s\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 i32
%8 = alloca i32
%9 = alloca i8*
store i32 %0, i32* %3
store i8** %1, i8*** %4
%10 = load i8**, i8*** %4
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
store i8* %12, i8** %9
%13 = load i8*, i8** %9
%14 = call i32 @strlen(i8* %13)
store i32 %14, i32* %8
%15 = call i32 @make_named_socket(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store i32 %15, i32* %5
%16 = load i32, i32* @AF_LOCAL
%17 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %6, i32 0, i32 1
store i32 %16, i32* %17
%18 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %6, i32 0, i32 0
%19 = load i32, i32* %18
%20 = call i32 @strcpy(i32 %19, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
store i32 8, i32* %7
%21 = load i32, i32* %5
%22 = load i8*, i8** %9
%23 = load i32, i32* %8
%24 = add nsw i32 %23, 1
%25 = bitcast %struct.sockaddr_un* %6 to %struct.sockaddr*
%26 = load i32, i32* %7
%27 = call i32 @sendto(i32 %21, i8* %22, i32 %24, i32 0, %struct.sockaddr* %25, i32 %26)
store i32 %27, i32* %8
%28 = load i32, i32* %8
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %2
%31 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%32 = load i32, i32* @EXIT_FAILURE
%33 = call i32 @exit(i32 %32)
unreachable
34: ; preds = %2
%35 = load i32, i32* @stderr
%36 = load i8*, i8** %9
%37 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %36)
%38 = call i32 @remove(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%39 = load i32, i32* %5
%40 = call i32 @close(i32 %39)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [14 x i8] c"/tmp/mysocket\00"
@AF_LOCAL = global i32 0
@.str.1 = [18 x i8] c"/tmp/serversocket\00"
@.str.2 = [18 x i8] c"client send error\00"
@EXIT_FAILURE = global i32 0
@stderr = global i32 0
@.str.3 = [26 x i8] c"Client: sent message: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_un
%4 = bitcast %struct.sockaddr_un* %3 to i8*
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32 @strlen(i8* %6)
%8 = tail call i32 @make_named_socket(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @AF_LOCAL
%10 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 1
store i32 %9, i32* %10
%11 = tail call i32 @strcpy(i32 undef, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%12 = add nsw i32 %7, 1
%13 = bitcast %struct.sockaddr_un* %3 to %struct.sockaddr*
%14 = call i32 @sendto(i32 %8, i8* %6, i32 %12, i32 0, %struct.sockaddr* %13, i32 8)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %2
%17 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %2
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %6)
%23 = call i32 @remove(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%24 = call i32 @close(i32 %8)
ret i32 0
}