#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 */
typedef int /*<<< orphan*/ uaddr;
struct sockaddr_un {
  int /*<<< orphan*/ sun_path;
  int /*<<< orphan*/ sun_family;
};
struct sockaddr {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ PF_UNIX;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ sendto(int, char *, int, int /*<<< orphan*/,
                          struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
int strlen(int /*<<< orphan*/);
int main(void) {
  struct sockaddr_un uaddr;
  int msg_len, sd;
  char message[1024];
  uaddr.sun_family = AF_UNIX;
  strcpy(uaddr.sun_path, "/tmp/mysock");
  sd = socket(PF_UNIX, SOCK_DGRAM, 0);
  msg_len = strlen(fgets(message, 1024, stdin));
  sendto(sd, message, msg_len, 0, (struct sockaddr *)&uaddr, sizeof(uaddr));
  close(sd);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e57(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%edi
lea    0xe68(%rip),%rsi
call   1030 <strcpy@plt>
mov    0x2e54(%rip),%rax
mov    (%rax),%edi
mov    0x2e23(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,-0x18(%rbp)
lea    -0x420(%rbp),%rdi
mov    0x2e11(%rip),%rax
mov    (%rax),%edx
mov    $0x400,%esi
call   1070 <fgets@plt>
mov    %eax,%edi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    -0x14(%rbp),%edx
lea    -0x10(%rbp),%r8
xor    %ecx,%ecx
mov    $0x8,%r9d
call   1050 <sendto@plt>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
mov    0x2db6(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x418,%rsp
mov    0x2e5f(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
lea    0xe72(%rip),%rsi
call   1030 <strcpy@plt>
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
mov    0x2e2d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,%ebx
mov    0x2e23(%rip),%rax
mov    (%rax),%edx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0x400,%esi
call   1070 <fgets@plt>
mov    %eax,%edi
call   1040 <strlen@plt>
lea    0x8(%rsp),%r8
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    $0x8,%r9d
call   1050 <sendto@plt>
mov    %ebx,%edi
call   1060 <close@plt>
mov    0x2dc9(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@.str = [12 x i8] c"/tmp/mysock\00"
@PF_UNIX = global i32 0
@SOCK_DGRAM = global i32 0
@stdin = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.sockaddr_un
%3 = alloca i32
%4 = alloca i32
%5 = alloca [1024 x i8]
store i32 0, i32* %1
%6 = load i32, i32* @AF_UNIX
%7 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %2, i32 0, i32 1
store i32 %6, i32* %7
%8 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %2, i32 0, i32 0
%9 = load i32, i32* %8
%10 = call i32 @strcpy(i32 %9, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* @PF_UNIX
%12 = load i32, i32* @SOCK_DGRAM
%13 = call i32 @socket(i32 %11, i32 %12, i32 0)
store i32 %13, i32* %4
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%15 = load i32, i32* @stdin
%16 = call i32 @fgets(i8* %14, i32 1024, i32 %15)
%17 = call i32 @strlen(i32 %16)
store i32 %17, i32* %3
%18 = load i32, i32* %4
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%20 = load i32, i32* %3
%21 = bitcast %struct.sockaddr_un* %2 to %struct.sockaddr*
%22 = call i32 @sendto(i32 %18, i8* %19, i32 %20, i32 0, %struct.sockaddr* %21, i32 8)
%23 = load i32, i32* %4
%24 = call i32 @close(i32 %23)
%25 = load i32, i32* @EXIT_SUCCESS
%26 = call i32 @exit(i32 %25)
unreachable
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@.str = [12 x i8] c"/tmp/mysock\00"
@PF_UNIX = global i32 0
@SOCK_DGRAM = global i32 0
@stdin = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca %struct.sockaddr_un
%2 = alloca [1024 x i8]
%3 = bitcast %struct.sockaddr_un* %1 to i8*
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%5 = load i32, i32* @AF_UNIX
%6 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %1, i64 0, i32 1
store i32 %5, i32* %6
%7 = tail call i32 @strcpy(i32 undef, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* @PF_UNIX
%9 = load i32, i32* @SOCK_DGRAM
%10 = tail call i32 @socket(i32 %8, i32 %9, i32 0)
%11 = load i32, i32* @stdin
%12 = call i32 @fgets(i8* %4, i32 1024, i32 %11)
%13 = call i32 @strlen(i32 %12)
%14 = bitcast %struct.sockaddr_un* %1 to %struct.sockaddr*
%15 = call i32 @sendto(i32 %10, i8* %4, i32 %13, i32 0, %struct.sockaddr* %14, i32 8)
%16 = call i32 @close(i32 %10)
%17 = load i32, i32* @EXIT_SUCCESS
%18 = call i32 @exit(i32 %17)
unreachable
}