#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 {
  char *sun_path;
  int /*<<< orphan*/ sun_family;
};
struct sockaddr {
  int dummy;
};
struct msghdr {
  int msg_iovlen;
  char *msg_control;
  int msg_controllen;
  struct iovec *msg_iov;
  scalar_t__ msg_namelen;
  scalar_t__ msg_name;
  int /*<<< orphan*/ member_0;
};
struct iovec {
  char *iov_base;
  int iov_len;
};
struct cmsghdr {
  int cmsg_len;
  int /*<<< orphan*/ cmsg_type;
  int /*<<< orphan*/ cmsg_level;
};
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
scalar_t__ CMSG_DATA(struct cmsghdr *);
struct cmsghdr *CMSG_FIRSTHDR(struct msghdr *);
int CMSG_LEN(int);
int CMSG_SPACE(int);
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ SCM_RIGHTS;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(char);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ memcpy(int *, int *, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int recv(int, char *, int, int /*<<< orphan*/);
int sendmsg(int, struct msghdr *, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int main(int argc, char **argv) {
  struct sockaddr_un sun;
  char buf[1024];
  int s, sunlen, ret, buflen;
  struct msghdr msg = {0};
  struct iovec iov;
  struct cmsghdr *cmsg;
  int myfd = 0;
  char cmsgbuf[CMSG_SPACE(sizeof myfd)];
  int *fdptr;
  if (argc != 3) {
    fprintf(stderr, "usage:  %s testfile address\n", argv[0]);
    exit(-1);
  }
  myfd = open(argv[1], O_RDWR);
  if (myfd < 0) {
    perror(argv[1]);
    exit(-1);
  }
  s = socket(AF_UNIX, SOCK_STREAM, 0);
  if (s < 0) {
    perror("socket");
    exit(-1);
  }
  sun.sun_family = AF_UNIX;
  strcpy(sun.sun_path, argv[2]);
  sunlen = strlen(sun.sun_path) + 1 + sizeof(short);
  ret = connect(s, (struct sockaddr *)&sun, sunlen);
  if (ret < 0) {
    perror("connect");
    exit(-1);
  }
  printf("client: Connected to server via %s\n", sun.sun_path);
  strcpy(buf, "hello world");
  buflen = strlen(buf) + 1;
  iov.iov_base = buf;
  iov.iov_len = buflen;
  msg.msg_name = 0;
  msg.msg_namelen = 0;
  msg.msg_iov = &iov;
  msg.msg_iovlen = 1;
  msg.msg_control = cmsgbuf;
  msg.msg_controllen = sizeof cmsgbuf;
  cmsg = CMSG_FIRSTHDR(&msg);
  cmsg->cmsg_level = SOL_SOCKET;
  cmsg->cmsg_type = SCM_RIGHTS;
  cmsg->cmsg_len = CMSG_LEN(sizeof(int));
  fdptr = (int *)CMSG_DATA(cmsg);
  memcpy(fdptr, &myfd, sizeof(int));
  msg.msg_controllen = cmsg->cmsg_len;
  ret = sendmsg(s, &msg, 0);
  if (ret < 0) {
    perror("sendmsg");
    exit(-1);
  }
  printf("client: Sent descriptor, waiting for reply\n");
  buf[0] = 0;
  ret = recv(s, buf, sizeof(buf), 0);
  if (ret < 0) {
    perror("recv");
    exit(-1);
  }
  printf("client: Received reply, code=%d\n", buf[0]);
  if (buf[0])
    printf("client: ...This implies the descriptor was not received\n");
  else
    printf("client: ...This implies the descriptor was received\n");
  exit(buf[0]);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4c0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xorps  %xmm0,%xmm0
movaps %xmm0,-0x450(%rbp)
movaps %xmm0,-0x460(%rbp)
movaps %xmm0,-0x470(%rbp)
movq   $0x0,-0x440(%rbp)
movl   $0x0,-0x48c(%rbp)
mov    $0x4,%edi
call   10a0 <CMSG_SPACE@plt>
mov    %eax,%eax
mov    %rax,-0x4b8(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x498(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x4b0(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x4a0(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     12b5 <main+0xb5>
mov    0x2d32(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xd5a(%rip),%rsi
call   10b0 <fprintf@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2d24(%rip),%rax
mov    (%rax),%esi
call   10d0 <open@plt>
mov    %eax,-0x48c(%rbp)
cmpl   $0x0,-0x48c(%rbp)
jge    12f5 <main+0xf5>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10e0 <perror@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
mov    0x2cdc(%rip),%rax
mov    (%rax),%edi
mov    0x2cbb(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1120 <socket@plt>
mov    %eax,-0x424(%rbp)
cmpl   $0x0,-0x424(%rbp)
jge    1337 <main+0x137>
lea    0xcf5(%rip),%rdi
call   10e0 <perror@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
mov    0x2c9a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1040 <strcpy@plt>
mov    -0x20(%rbp),%rdi
call   1070 <strlen@plt>
add    $0x1,%eax
cltq
add    $0x2,%rax
mov    %eax,-0x428(%rbp)
mov    -0x424(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    -0x428(%rbp),%edx
call   1100 <connect@plt>
mov    %eax,-0x42c(%rbp)
cmpl   $0x0,-0x42c(%rbp)
jge    13aa <main+0x1aa>
lea    0xc89(%rip),%rdi
call   10e0 <perror@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
mov    -0x20(%rbp),%rsi
lea    0xc77(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    -0x420(%rbp),%rdi
lea    0xc86(%rip),%rsi
call   1040 <strcpy@plt>
lea    -0x420(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x4b0(%rbp),%rcx
mov    %eax,%edx
mov    -0x4b8(%rbp),%rax
add    $0x1,%edx
mov    %edx,-0x430(%rbp)
lea    -0x420(%rbp),%rdx
mov    %rdx,-0x480(%rbp)
mov    -0x430(%rbp),%edx
mov    %edx,-0x478(%rbp)
movq   $0x0,-0x448(%rbp)
movq   $0x0,-0x450(%rbp)
lea    -0x480(%rbp),%rdx
mov    %rdx,-0x458(%rbp)
movl   $0x1,-0x470(%rbp)
mov    %rcx,-0x468(%rbp)
mov    %eax,-0x460(%rbp)
lea    -0x470(%rbp),%rdi
call   1110 <CMSG_FIRSTHDR@plt>
mov    %rax,-0x488(%rbp)
mov    0x2b7d(%rip),%rax
mov    (%rax),%ecx
mov    -0x488(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    0x2b42(%rip),%rax
mov    (%rax),%ecx
mov    -0x488(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    $0x4,%edi
call   1090 <CMSG_LEN@plt>
mov    %eax,%ecx
mov    -0x488(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x488(%rbp),%rdi
call   1060 <CMSG_DATA@plt>
mov    %rax,-0x4a8(%rbp)
mov    -0x4a8(%rbp),%rdi
lea    -0x48c(%rbp),%rsi
mov    $0x4,%edx
call   10c0 <memcpy@plt>
mov    -0x488(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x460(%rbp)
mov    -0x424(%rbp),%edi
lea    -0x470(%rbp),%rsi
xor    %edx,%edx
call   1050 <sendmsg@plt>
mov    %eax,-0x42c(%rbp)
cmpl   $0x0,-0x42c(%rbp)
jge    150e <main+0x30e>
lea    0xb5d(%rip),%rdi
call   10e0 <perror@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
lea    0xb4f(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movb   $0x0,-0x420(%rbp)
mov    -0x424(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x42c(%rbp)
cmpl   $0x0,-0x42c(%rbp)
jge    1565 <main+0x365>
lea    0xb3a(%rip),%rdi
call   10e0 <perror@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
movsbl -0x420(%rbp),%esi
lea    0xb22(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
cmpb   $0x0,-0x420(%rbp)
je     159a <main+0x39a>
lea    0xb28(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
jmp    15a8 <main+0x3a8>
lea    0xb4e(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movsbl -0x420(%rbp),%edi
call   10f0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x468,%rsp
mov    %rsi,%r12
mov    %edi,%ebx
xorps  %xmm0,%xmm0
movaps %xmm0,-0x50(%rbp)
movaps %xmm0,-0x60(%rbp)
movaps %xmm0,-0x70(%rbp)
movq   $0x0,-0x40(%rbp)
mov    $0x4,%edi
call   10b0 <CMSG_SPACE@plt>
mov    %eax,%r15d
mov    %eax,%eax
mov    %rsp,%r13
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
cmp    $0x3,%ebx
jne    1289 <main+0x79>
mov    0x8(%r12),%rdi
mov    0x2d77(%rip),%rax
mov    (%rax),%esi
call   10e0 <open@plt>
mov    %eax,-0x2c(%rbp)
test   %eax,%eax
jns    12ac <main+0x9c>
mov    0x8(%r12),%rdi
jmp    140b <main+0x1fb>
mov    0x2d38(%rip),%rax
mov    (%rax),%edi
mov    (%r12),%rdx
lea    0xd63(%rip),%rsi
call   10c0 <fprintf@plt>
mov    $0xffffffff,%edi
call   1100 <exit@plt>
mov    0x2d25(%rip),%rbx
mov    (%rbx),%edi
mov    0x2d04(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1130 <socket@plt>
test   %eax,%eax
jns    12d5 <main+0xc5>
lea    0xd4d(%rip),%rdi
jmp    140b <main+0x1fb>
mov    %eax,%r14d
mov    (%rbx),%eax
mov    %eax,-0x88(%rbp)
mov    0x10(%r12),%rsi
call   1040 <strcpy@plt>
call   1080 <strlen@plt>
lea    0x3(%rax),%edx
lea    -0x90(%rbp),%rsi
mov    %r14d,%edi
call   1110 <connect@plt>
test   %eax,%eax
jns    1311 <main+0x101>
lea    0xd18(%rip),%rdi
jmp    140b <main+0x1fb>
mov    -0x90(%rbp),%rsi
lea    0xd0d(%rip),%rdi
xor    %eax,%eax
call   1090 <printf@plt>
lea    0xd23(%rip),%rsi
lea    -0x490(%rbp),%rbx
mov    %rbx,%rdi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
call   1080 <strlen@plt>
add    $0x1,%eax
mov    %rbx,-0x80(%rbp)
mov    %eax,-0x78(%rbp)
xorps  %xmm0,%xmm0
movaps %xmm0,-0x50(%rbp)
lea    -0x80(%rbp),%rax
mov    %rax,-0x58(%rbp)
movl   $0x1,-0x70(%rbp)
mov    %r13,-0x68(%rbp)
mov    %r15d,-0x60(%rbp)
lea    -0x70(%rbp),%r15
mov    %r15,%rdi
call   1120 <CMSG_FIRSTHDR@plt>
mov    %rax,%rbx
mov    0x2c5e(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rbx)
mov    0x2c2a(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rbx)
mov    $0x4,%edi
call   10a0 <CMSG_LEN@plt>
mov    %eax,(%rbx)
mov    %rbx,%rdi
call   1070 <CMSG_DATA@plt>
lea    -0x2c(%rbp),%rsi
mov    %rax,%rdi
mov    $0x4,%edx
call   10d0 <memcpy@plt>
mov    (%rbx),%eax
mov    %eax,-0x60(%rbp)
mov    %r14d,%edi
mov    %r15,%rsi
xor    %edx,%edx
call   1050 <sendmsg@plt>
test   %eax,%eax
jns    13d7 <main+0x1c7>
lea    0xc87(%rip),%rdi
jmp    140b <main+0x1fb>
lea    0xcac(%rip),%rdi
call   1060 <puts@plt>
movb   $0x0,-0x490(%rbp)
lea    -0x490(%rbp),%rsi
mov    %r14d,%edi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jns    141a <main+0x20a>
lea    0xc59(%rip),%rdi
call   10f0 <perror@plt>
mov    $0xffffffff,%edi
call   1100 <exit@plt>
movsbl -0x490(%rbp),%esi
lea    0xc41(%rip),%rdi
xor    %eax,%eax
call   1090 <printf@plt>
cmpb   $0x0,-0x490(%rbp)
lea    0xc78(%rip),%rax
lea    0xca5(%rip),%rdi
cmove  %rax,%rdi
call   1060 <puts@plt>
movsbl -0x490(%rbp),%edi
call   1100 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_un = type { i8*, i32 }
%struct.msghdr = type { i32, i8*, i32, %struct.iovec*, i64, i64, i32 }
%struct.iovec = type { i8*, i32 }
%struct.cmsghdr = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [29 x i8] c"usage: %s testfile address\0A\00"
@O_RDWR = global i32 0
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [7 x i8] c"socket\00"
@.str.2 = [8 x i8] c"connect\00"
@.str.3 = [36 x i8] c"client: Connected to server via %s\0A\00"
@.str.4 = [12 x i8] c"hello world\00"
@SOL_SOCKET = global i32 0
@SCM_RIGHTS = global i32 0
@.str.5 = [8 x i8] c"sendmsg\00"
@.str.6 = [44 x i8] c"client: Sent descriptor, waiting for reply\0A\00"
@.str.7 = [5 x i8] c"recv\00"
@.str.8 = [33 x i8] c"client: Received reply, code=%d\0A\00"
@.str.9 = [57 x i8] c"client: ...This implies the descriptor was not received\0A\00"
@.str.10 = [53 x i8] c"client: ...This implies the descriptor was received\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.sockaddr_un
%7 = alloca [1024 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca %struct.msghdr
%13 = alloca %struct.iovec
%14 = alloca %struct.cmsghdr*
%15 = alloca i32
%16 = alloca i8*
%17 = alloca i64
%18 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%19 = bitcast %struct.msghdr* %12 to i8*
store i32 0, i32* %15
%20 = call i32 @CMSG_SPACE(i32 4)
%21 = zext i32 %20 to i64
%22 = call i8* @llvm.stacksave()
store i8* %22, i8** %16
%23 = alloca i8, i64 %21
store i64 %21, i64* %17
%24 = load i32, i32* %4
%25 = icmp ne i32 %24, 3
br i1 %25, label %26, label %33
26: ; preds = %2
%27 = load i32, i32* @stderr
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 0
%30 = load i8*, i8** %29
%31 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %30)
%32 = call i32 @exit(i8 signext -1)
unreachable
33: ; preds = %2
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = load i32, i32* @O_RDWR
%38 = call i32 @open(i8* %36, i32 %37)
store i32 %38, i32* %15
%39 = load i32, i32* %15
%40 = icmp slt i32 %39, 0
br i1 %40, label %41, label %47
41: ; preds = %33
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 1
%44 = load i8*, i8** %43
%45 = call i32 @perror(i8* %44)
%46 = call i32 @exit(i8 signext -1)
unreachable
47: ; preds = %33
%48 = load i32, i32* @AF_UNIX
%49 = load i32, i32* @SOCK_STREAM
%50 = call i32 @socket(i32 %48, i32 %49, i32 0)
store i32 %50, i32* %8
%51 = load i32, i32* %8
%52 = icmp slt i32 %51, 0
br i1 %52, label %53, label %56
53: ; preds = %47
%54 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%55 = call i32 @exit(i8 signext -1)
unreachable
56: ; preds = %47
%57 = load i32, i32* @AF_UNIX
%58 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %6, i32 0, i32 1
store i32 %57, i32* %58
%59 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %6, i32 0, i32 0
%60 = load i8*, i8** %59
%61 = load i8**, i8*** %5
%62 = getelementptr inbounds i8*, i8** %61, i64 2
%63 = load i8*, i8** %62
%64 = call i32 @strcpy(i8* %60, i8* %63)
%65 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %6, i32 0, i32 0
%66 = load i8*, i8** %65
%67 = call i32 @strlen(i8* %66)
%68 = add nsw i32 %67, 1
%69 = sext i32 %68 to i64
%70 = add i64 %69, 2
%71 = trunc i64 %70 to i32
store i32 %71, i32* %9
%72 = load i32, i32* %8
%73 = bitcast %struct.sockaddr_un* %6 to %struct.sockaddr*
%74 = load i32, i32* %9
%75 = call i32 @connect(i32 %72, %struct.sockaddr* %73, i32 %74)
store i32 %75, i32* %10
%76 = load i32, i32* %10
%77 = icmp slt i32 %76, 0
br i1 %77, label %78, label %81
78: ; preds = %56
%79 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%80 = call i32 @exit(i8 signext -1)
unreachable
81: ; preds = %56
%82 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %6, i32 0, i32 0
%83 = load i8*, i8** %82
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i8* %83)
%85 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%86 = call i32 @strcpy(i8* %85, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
%87 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%88 = call i32 @strlen(i8* %87)
%89 = add nsw i32 %88, 1
store i32 %89, i32* %11
%90 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%91 = getelementptr inbounds %struct.iovec, %struct.iovec* %13, i32 0, i32 0
store i8* %90, i8** %91
%92 = load i32, i32* %11
%93 = getelementptr inbounds %struct.iovec, %struct.iovec* %13, i32 0, i32 1
store i32 %92, i32* %93
%94 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %12, i32 0, i32 5
store i64 0, i64* %94
%95 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %12, i32 0, i32 4
store i64 0, i64* %95
%96 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %12, i32 0, i32 3
store %struct.iovec* %13, %struct.iovec** %96
%97 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %12, i32 0, i32 0
store i32 1, i32* %97
%98 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %12, i32 0, i32 1
store i8* %23, i8** %98
%99 = trunc i64 %21 to i32
%100 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %12, i32 0, i32 2
store i32 %99, i32* %100
%101 = call %struct.cmsghdr* @CMSG_FIRSTHDR(%struct.msghdr* %12)
store %struct.cmsghdr* %101, %struct.cmsghdr** %14
%102 = load i32, i32* @SOL_SOCKET
%103 = load %struct.cmsghdr*, %struct.cmsghdr** %14
%104 = getelementptr inbounds %struct.cmsghdr, %struct.cmsghdr* %103, i32 0, i32 2
store i32 %102, i32* %104
%105 = load i32, i32* @SCM_RIGHTS
%106 = load %struct.cmsghdr*, %struct.cmsghdr** %14
%107 = getelementptr inbounds %struct.cmsghdr, %struct.cmsghdr* %106, i32 0, i32 1
store i32 %105, i32* %107
%108 = call i32 @CMSG_LEN(i32 4)
%109 = load %struct.cmsghdr*, %struct.cmsghdr** %14
%110 = getelementptr inbounds %struct.cmsghdr, %struct.cmsghdr* %109, i32 0, i32 0
store i32 %108, i32* %110
%111 = load %struct.cmsghdr*, %struct.cmsghdr** %14
%112 = call i64 @CMSG_DATA(%struct.cmsghdr* %111)
%113 = inttoptr i64 %112 to i32*
store i32* %113, i32** %18
%114 = load i32*, i32** %18
%115 = call i32 @memcpy(i32* %114, i32* %15, i32 4)
%116 = load %struct.cmsghdr*, %struct.cmsghdr** %14
%117 = getelementptr inbounds %struct.cmsghdr, %struct.cmsghdr* %116, i32 0, i32 0
%118 = load i32, i32* %117
%119 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %12, i32 0, i32 2
store i32 %118, i32* %119
%120 = load i32, i32* %8
%121 = call i32 @sendmsg(i32 %120, %struct.msghdr* %12, i32 0)
store i32 %121, i32* %10
%122 = load i32, i32* %10
%123 = icmp slt i32 %122, 0
br i1 %123, label %124, label %127
124: ; preds = %81
%125 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
%126 = call i32 @exit(i8 signext -1)
unreachable
127: ; preds = %81
%128 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.6, i64 0, i64 0))
%129 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
store i8 0, i8* %129
%130 = load i32, i32* %8
%131 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%132 = call i32 @recv(i32 %130, i8* %131, i32 1024, i32 0)
store i32 %132, i32* %10
%133 = load i32, i32* %10
%134 = icmp slt i32 %133, 0
br i1 %134, label %135, label %138
135: ; preds = %127
%136 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%137 = call i32 @exit(i8 signext -1)
unreachable
138: ; preds = %127
%139 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%140 = load i8, i8* %139
%141 = sext i8 %140 to i32
%142 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0), i32 %141)
%143 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%144 = load i8, i8* %143
%145 = icmp ne i8 %144, 0
br i1 %145, label %146, label %148
146: ; preds = %138
%147 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.9, i64 0, i64 0))
br label %150
148: ; preds = %138
%149 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.10, i64 0, i64 0))
br label %150
150: ; preds = %148, %146
%151 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%152 = load i8, i8* %151
%153 = call i32 @exit(i8 signext %152)
unreachable
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i8*, i32 }
%struct.msghdr = type { i32, i8*, i32, %struct.iovec*, i64, i64, i32 }
%struct.iovec = type { i8*, i32 }
%struct.sockaddr = type { i32 }
%struct.cmsghdr = type { i32, i32, i32 }
@stderr = global i32 0
@.str = [29 x i8] c"usage: %s testfile address\0A\00"
@O_RDWR = global i32 0
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [7 x i8] c"socket\00"
@.str.2 = [8 x i8] c"connect\00"
@.str.3 = [36 x i8] c"client: Connected to server via %s\0A\00"
@.str.4 = [12 x i8] c"hello world\00"
@SOL_SOCKET = global i32 0
@SCM_RIGHTS = global i32 0
@.str.5 = [8 x i8] c"sendmsg\00"
@.str.7 = [5 x i8] c"recv\00"
@.str.8 = [33 x i8] c"client: Received reply, code=%d\0A\00"
@str = [43 x i8] c"client: Sent descriptor, waiting for reply\00"
@str.11 = [52 x i8] c"client: ...This implies the descriptor was received\00"
@str.12 = [56 x i8] c"client: ...This implies the descriptor was not received\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_un
%4 = alloca [1024 x i8]
%5 = alloca %struct.msghdr
%6 = alloca %struct.iovec
%7 = alloca i32
%8 = bitcast %struct.sockaddr_un* %3 to i8*
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%10 = bitcast %struct.msghdr* %5 to i8*
%11 = bitcast %struct.iovec* %6 to i8*
%12 = bitcast i32* %7 to i8*
%13 = tail call i32 @CMSG_SPACE(i32 4)
%14 = zext i32 %13 to i64
%15 = alloca i8, i64 %14
%16 = icmp eq i32 %0, 3
br i1 %16, label %22, label %17
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %1
%20 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = tail call i32 @exit(i8 signext -1)
unreachable
22: ; preds = %2
%23 = getelementptr inbounds i8*, i8** %1, i64 1
%24 = load i8*, i8** %23
%25 = load i32, i32* @O_RDWR
%26 = tail call i32 @open(i8* %24, i32 %25)
store i32 %26, i32* %7
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %22
%29 = load i8*, i8** %23
%30 = tail call i32 @perror(i8* %29)
%31 = tail call i32 @exit(i8 signext -1)
unreachable
32: ; preds = %22
%33 = load i32, i32* @AF_UNIX
%34 = load i32, i32* @SOCK_STREAM
%35 = tail call i32 @socket(i32 %33, i32 %34, i32 0)
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %32
%38 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%39 = tail call i32 @exit(i8 signext -1)
unreachable
40: ; preds = %32
%41 = load i32, i32* @AF_UNIX
%42 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 1
store i32 %41, i32* %42
%43 = getelementptr inbounds i8*, i8** %1, i64 2
%44 = load i8*, i8** %43
%45 = tail call i32 @strcpy(i8* undef, i8* %44)
%46 = tail call i32 @strlen(i8* undef)
%47 = add i32 %46, 3
%48 = bitcast %struct.sockaddr_un* %3 to %struct.sockaddr*
%49 = call i32 @connect(i32 %35, %struct.sockaddr* %48, i32 %47)
%50 = icmp slt i32 %49, 0
br i1 %50, label %51, label %54
51: ; preds = %40
%52 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%53 = call i32 @exit(i8 signext -1)
unreachable
54: ; preds = %40
%55 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 0
%56 = load i8*, i8** %55
%57 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i8* %56)
%58 = call i32 @strcpy(i8* %9, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
%59 = call i32 @strlen(i8* %9)
%60 = add nsw i32 %59, 1
%61 = getelementptr inbounds %struct.iovec, %struct.iovec* %6, i64 0, i32 0
store i8* %9, i8** %61
%62 = getelementptr inbounds %struct.iovec, %struct.iovec* %6, i64 0, i32 1
store i32 %60, i32* %62
%63 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %5, i64 0, i32 4
%64 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %5, i64 0, i32 3
%65 = bitcast i64* %63 to i8*
store %struct.iovec* %6, %struct.iovec** %64
%66 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %5, i64 0, i32 0
store i32 1, i32* %66
%67 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %5, i64 0, i32 1
store i8* %15, i8** %67
%68 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %5, i64 0, i32 2
store i32 %13, i32* %68
%69 = call %struct.cmsghdr* @CMSG_FIRSTHDR(%struct.msghdr* %5)
%70 = load i32, i32* @SOL_SOCKET
%71 = getelementptr inbounds %struct.cmsghdr, %struct.cmsghdr* %69, i64 0, i32 2
store i32 %70, i32* %71
%72 = load i32, i32* @SCM_RIGHTS
%73 = getelementptr inbounds %struct.cmsghdr, %struct.cmsghdr* %69, i64 0, i32 1
store i32 %72, i32* %73
%74 = call i32 @CMSG_LEN(i32 4)
%75 = getelementptr inbounds %struct.cmsghdr, %struct.cmsghdr* %69, i64 0, i32 0
store i32 %74, i32* %75
%76 = call i64 @CMSG_DATA(%struct.cmsghdr* %69)
%77 = inttoptr i64 %76 to i32*
%78 = call i32 @memcpy(i32* %77, i32* %7, i32 4)
%79 = load i32, i32* %75
store i32 %79, i32* %68
%80 = call i32 @sendmsg(i32 %35, %struct.msghdr* %5, i32 0)
%81 = icmp slt i32 %80, 0
br i1 %81, label %82, label %85
82: ; preds = %54
%83 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
%84 = call i32 @exit(i8 signext -1)
unreachable
85: ; preds = %54
%86 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str, i64 0, i64 0))
store i8 0, i8* %9
%87 = call i32 @recv(i32 %35, i8* %9, i32 1024, i32 0)
%88 = icmp slt i32 %87, 0
br i1 %88, label %89, label %92
89: ; preds = %85
%90 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%91 = call i32 @exit(i8 signext -1)
unreachable
92: ; preds = %85
%93 = load i8, i8* %9
%94 = sext i8 %93 to i32
%95 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0), i32 %94)
%96 = load i8, i8* %9
%97 = icmp eq i8 %96, 0
%98 = select i1 %97, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @str.11, i64 0, i64 0), i8* getelementptr inbounds ([56 x i8], [56 x i8]* @str.12, i64 0, i64 0)
%99 = call i32 @puts(i8* dereferenceable(1) %98)
%100 = load i8, i8* %9
%101 = call i32 @exit(i8 signext %100)
unreachable
}