#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;
};

/* Variables and functions */
int /*<<< orphan*/ PF_LOCAL;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
scalar_t__ sendto(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
int main(int argc, char **argv) {
  int sock;
  struct sockaddr_un name;
  if (argc != 2) {
    perror("usage: send <socket>");
    exit(1);
  }
  sock = socket(PF_LOCAL, SOCK_DGRAM, 0);
  if (sock < 0) {
    perror("opening datagram socket");
    exit(1);
  }
  name.sun_family = PF_LOCAL;
  strcpy(name.sun_path, argv[1]);
  if (sendto(sock, "The sea is calm tonight, the tide is full . . .",
             sizeof("The sea is calm tonight, the tide is full . . ."), 0,
             (struct sockaddr *)&name, sizeof(struct sockaddr_un)) < 0) {
    perror("sending datagram message");
  }
  close(sock);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1196 <main+0x36>
lea    0xe79(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
mov    0x2e42(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11d2 <main+0x72>
lea    0xe52(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    0x2dff(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1030 <strcpy@plt>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%r8
lea    0xe31(%rip),%rsi
mov    $0x30,%edx
xor    %ecx,%ecx
mov    $0x8,%r9d
call   1040 <sendto@plt>
cmp    $0x0,%rax
jge    1224 <main+0xc4>
lea    0xe3e(%rip),%rdi
call   1060 <perror@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
cmp    $0x2,%edi
jne    11e7 <main+0x87>
mov    %rsi,%r14
mov    0x2e60(%rip),%r15
mov    (%r15),%edi
mov    0x2e66(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
test   %eax,%eax
js     11f0 <main+0x90>
mov    %eax,%ebx
mov    (%r15),%eax
mov    %eax,0xc(%rsp)
mov    0x8(%r14),%rsi
call   1030 <strcpy@plt>
lea    0xe85(%rip),%rsi
lea    0x8(%rsp),%r8
mov    %ebx,%edi
mov    $0x30,%edx
xor    %ecx,%ecx
mov    $0x8,%r9d
call   1040 <sendto@plt>
test   %rax,%rax
js     11d9 <main+0x79>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe7d(%rip),%rdi
call   1060 <perror@plt>
jmp    11c6 <main+0x66>
lea    0xe12(%rip),%rdi
jmp    11f7 <main+0x97>
lea    0xe1e(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [21 x i8] c"usage: send <socket>\00"
@PF_LOCAL = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [24 x i8] c"opening datagram socket\00"
@.str.2 = [48 x i8] c"The sea is calm tonight, the tide is full . . .\00"
@.str.3 = [25 x i8] c"sending datagram message\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.sockaddr_un
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = load i32, i32* @PF_LOCAL
%15 = load i32, i32* @SOCK_DGRAM
%16 = call i32 @socket(i32 %14, i32 %15, i32 0)
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %13
%20 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %13
%23 = load i32, i32* @PF_LOCAL
%24 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %7, i32 0, i32 1
store i32 %23, i32* %24
%25 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %7, i32 0, i32 0
%26 = load i32, i32* %25
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i32 @strcpy(i32 %26, i8* %29)
%31 = load i32, i32* %6
%32 = bitcast %struct.sockaddr_un* %7 to %struct.sockaddr*
%33 = call i64 @sendto(i32 %31, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0), i32 48, i32 0, %struct.sockaddr* %32, i32 8)
%34 = icmp slt i64 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %22
%36 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
br label %37
37: ; preds = %35, %22
%38 = load i32, i32* %6
%39 = call i32 @close(i32 %38)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [21 x i8] c"usage: send <socket>\00"
@PF_LOCAL = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [24 x i8] c"opening datagram socket\00"
@.str.2 = [48 x i8] c"The sea is calm tonight, the tide is full . . .\00"
@.str.3 = [25 x i8] c"sending datagram message\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_un
%4 = bitcast %struct.sockaddr_un* %3 to i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = tail call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = load i32, i32* @PF_LOCAL
%11 = load i32, i32* @SOCK_DGRAM
%12 = tail call i32 @socket(i32 %10, i32 %11, i32 0)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %9
%15 = tail call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %9
%18 = load i32, i32* @PF_LOCAL
%19 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 1
store i32 %18, i32* %19
%20 = getelementptr inbounds i8*, i8** %1, i64 1
%21 = load i8*, i8** %20
%22 = tail call i32 @strcpy(i32 undef, i8* %21)
%23 = bitcast %struct.sockaddr_un* %3 to %struct.sockaddr*
%24 = call i64 @sendto(i32 %12, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0), i32 48, i32 0, %struct.sockaddr* %23, i32 8)
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %17
%27 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
br label %28
28: ; preds = %26, %17
%29 = call i32 @close(i32 %12)
ret i32 0
}