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

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ bzero(struct sockaddr_un *, int);
int /*<<< orphan*/ die(char *);
int /*<<< orphan*/ exit(int);
scalar_t__ fgets(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int sendto(int, int /*<<< orphan*/ *, int /*<<< orphan*/, int /*<<< orphan*/,
           struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strlen(int /*<<< orphan*/ *);
int /*<<< orphan*/ strncpy(int /*<<< orphan*/, char *, int);
main(int argc, char **argv) {
  struct sockaddr_un mysun;
  int sock;
  u_char buf[1024];
  int n;
  if (argc != 2) {
    fprintf(stderr, "Usage: %s file\n", argv[0]);
    exit(1);
  }
  bzero(&mysun, sizeof(mysun));
  mysun.sun_family = AF_UNIX;
  strncpy(mysun.sun_path, argv[1], sizeof(mysun.sun_path));
  if ((sock = socket(AF_UNIX, SOCK_DGRAM, 0)) < 0) {
    die("socket");
  }
  while (fgets(buf, sizeof(buf), stdin)) {
    int sent;
    if ((sent = sendto(sock, buf, strlen(buf), 0, (struct sockaddr *)&mysun,
                       sizeof(mysun))) < 0)
      die("sendto");
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1040,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11d9 <main+0x49>
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe36(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    -0x18(%rbp),%rdi
mov    $0x8,%esi
call   1090 <bzero@plt>
mov    0x2dfa(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
mov    0x2dd9(%rip),%rax
mov    (%rax),%edi
mov    0x2dc0(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    1239 <main+0xa9>
lea    0xddc(%rip),%rdi
call   1080 <die@plt>
jmp    123e <main+0xae>
lea    -0x1020(%rbp),%rdi
mov    0x2d94(%rip),%rax
mov    (%rax),%edx
mov    $0x1000,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     12c5 <main+0x135>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x1034(%rbp)
lea    -0x1020(%rbp),%rax
mov    %rax,-0x1030(%rbp)
lea    -0x1020(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x1034(%rbp),%edi
mov    -0x1030(%rbp),%rsi
mov    %eax,%edx
lea    -0x18(%rbp),%r8
xor    %ecx,%ecx
mov    $0x8,%r9d
call   1050 <sendto@plt>
mov    %eax,-0x1028(%rbp)
cmp    $0x0,%eax
jge    12c0 <main+0x130>
lea    0xd5c(%rip),%rdi
call   1080 <die@plt>
jmp    123e <main+0xae>
mov    -0x4(%rbp),%eax
add    $0x1040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x1010,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    1295 <main+0x105>
lea    0x8(%rsp),%rdi
mov    $0x8,%esi
call   1090 <bzero@plt>
mov    0x2e27(%rip),%rbp
mov    0x0(%rbp),%eax
mov    %eax,0xc(%rsp)
mov    0x8(%rsp),%edi
mov    0x8(%rbx),%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
mov    0x0(%rbp),%edi
mov    0x2df4(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    11ff <main+0x6f>
lea    0xe16(%rip),%rdi
call   1080 <die@plt>
mov    0x2dda(%rip),%r12
mov    (%r12),%edx
lea    0x10(%rsp),%rdi
mov    $0x1000,%esi
call   1060 <fgets@plt>
test   %rax,%rax
je     1283 <main+0xf3>
lea    0x10(%rsp),%rbx
lea    0x8(%rsp),%r14
lea    0xde8(%rip),%r15
jmp    1256 <main+0xc6>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%r12),%edx
mov    %rbx,%rdi
mov    $0x1000,%esi
call   1060 <fgets@plt>
test   %rax,%rax
je     1283 <main+0xf3>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    $0x8,%r9d
call   1050 <sendto@plt>
test   %eax,%eax
jns    1240 <main+0xb0>
mov    %r15,%rdi
call   1080 <die@plt>
jmp    1240 <main+0xb0>
xor    %eax,%eax
add    $0x1010,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d2c(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xd58(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [16 x i8] c"Usage: %s file\0A\00"
@AF_UNIX = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [7 x i8] c"socket\00"
@stdin = global i32 0
@.str.2 = [7 x i8] c"sendto\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.sockaddr_un
%7 = alloca i32
%8 = alloca [1024 x i32]
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 2
br i1 %12, label %13, label %20
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %2
%21 = call i32 @bzero(%struct.sockaddr_un* %6, i32 8)
%22 = load i32, i32* @AF_UNIX
%23 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %6, i32 0, i32 1
store i32 %22, i32* %23
%24 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %6, i32 0, i32 0
%25 = load i32, i32* %24
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32 @strncpy(i32 %25, i8* %28, i32 4)
%30 = load i32, i32* @AF_UNIX
%31 = load i32, i32* @SOCK_DGRAM
%32 = call i32 @socket(i32 %30, i32 %31, i32 0)
store i32 %32, i32* %7
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %20
%35 = call i32 @die(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %36
36: ; preds = %34, %20
br label %37
37: ; preds = %52, %36
%38 = getelementptr inbounds [1024 x i32], [1024 x i32]* %8, i64 0, i64 0
%39 = load i32, i32* @stdin
%40 = call i64 @fgets(i32* %38, i32 4096, i32 %39)
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %53
42: ; preds = %37
%43 = load i32, i32* %7
%44 = getelementptr inbounds [1024 x i32], [1024 x i32]* %8, i64 0, i64 0
%45 = getelementptr inbounds [1024 x i32], [1024 x i32]* %8, i64 0, i64 0
%46 = call i32 @strlen(i32* %45)
%47 = bitcast %struct.sockaddr_un* %6 to %struct.sockaddr*
%48 = call i32 @sendto(i32 %43, i32* %44, i32 %46, i32 0, %struct.sockaddr* %47, i32 8)
store i32 %48, i32* %10
%49 = icmp slt i32 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %42
%51 = call i32 @die(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %52
52: ; preds = %50, %42
br label %37
53: ; preds = %37
%54 = load i32, i32* %3
ret i32 %54
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [16 x i8] c"Usage: %s file\0A\00"
@AF_UNIX = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [7 x i8] c"socket\00"
@stdin = global i32 0
@.str.2 = [7 x i8] c"sendto\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_un
%4 = alloca [1024 x i32]
%5 = bitcast %struct.sockaddr_un* %3 to i8*
%6 = bitcast [1024 x i32]* %4 to i8*
%7 = icmp eq i32 %0, 2
br i1 %7, label %13, label %8
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %1
%11 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = call i32 @bzero(%struct.sockaddr_un* %3, i32 8)
%15 = load i32, i32* @AF_UNIX
%16 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 1
store i32 %15, i32* %16
%17 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 0
%18 = load i32, i32* %17
%19 = getelementptr inbounds i8*, i8** %1, i64 1
%20 = load i8*, i8** %19
%21 = tail call i32 @strncpy(i32 %18, i8* %20, i32 4)
%22 = load i32, i32* @AF_UNIX
%23 = load i32, i32* @SOCK_DGRAM
%24 = tail call i32 @socket(i32 %22, i32 %23, i32 0)
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %13
%27 = tail call i32 @die(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %28
28: ; preds = %26, %13
%29 = getelementptr inbounds [1024 x i32], [1024 x i32]* %4, i64 0, i64 0
%30 = load i32, i32* @stdin
%31 = call i64 @fgets(i32* %29, i32 4096, i32 %30)
%32 = icmp eq i64 %31, 0
br i1 %32, label %45, label %33
33: ; preds = %28
%34 = bitcast %struct.sockaddr_un* %3 to %struct.sockaddr*
br label %35
35: ; preds = %33, %41
%36 = call i32 @strlen(i32* %29)
%37 = call i32 @sendto(i32 %24, i32* %29, i32 %36, i32 0, %struct.sockaddr* %34, i32 8)
%38 = icmp slt i32 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %35
%40 = call i32 @die(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %41
41: ; preds = %39, %35
%42 = load i32, i32* @stdin
%43 = call i64 @fgets(i32* %29, i32 4096, i32 %42)
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %35
45: ; preds = %41, %28
ret i32 0
}