#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 msghdr {
  char *iov_base;
  int iov_len;
  int msg_iovlen;
  char *msg_control;
  int msg_controllen;
  struct msghdr *msg_iov;
};
struct iovec {
  char *iov_base;
  int iov_len;
  int msg_iovlen;
  char *msg_control;
  int msg_controllen;
  struct iovec *msg_iov;
};
struct cmsghdr {
  int cmsg_len;
  int /*<<< orphan*/ cmsg_type;
  int /*<<< orphan*/ cmsg_level;
};
typedef int /*<<< orphan*/ msg;
typedef int /*<<< orphan*/ iov;
typedef int /*<<< orphan*/ control_buf;

/* Variables and functions */
scalar_t__ CMSG_DATA(struct cmsghdr *);
struct cmsghdr *CMSG_FIRSTHDR(struct msghdr *);
void *CMSG_LEN(int);
int /*<<< orphan*/ SCM_RIGHTS;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ abort();
scalar_t__ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ memset(struct msghdr *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
scalar_t__ pipe(int *);
int send(int, char *, int, int /*<<< orphan*/);
int sendmsg(int, struct msghdr *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
void sender(int fd) {
  char str[] = "0123456789012345678901234567890123456789";
  struct msghdr msg;
  struct iovec iov;
  struct cmsghdr *cmsg;
  char control_buf[256];
  int new_fds[4];
  int n;
  if (pipe(new_fds) || pipe(new_fds + 2)) {
    perror("pipe");
    abort();
  }
  n = send(fd, str, 20, 0);
  fprintf(stderr, "send: %d (%m)\n", n);
  memset(&msg, 0, sizeof(msg));
  memset(&iov, 0, sizeof(iov));
  iov.iov_base = str;
  iov.iov_len = 7;
  msg.msg_iov = &iov;
  msg.msg_iovlen = 1;
  msg.msg_control = control_buf;
  msg.msg_controllen = sizeof(control_buf);
  cmsg = CMSG_FIRSTHDR(&msg);
  cmsg->cmsg_level = SOL_SOCKET;
  cmsg->cmsg_type = SCM_RIGHTS;
  msg.msg_controllen = cmsg->cmsg_len = CMSG_LEN(sizeof(int) * 2);
  ((int *)CMSG_DATA(cmsg))[0] = new_fds[0];
  ((int *)CMSG_DATA(cmsg))[1] = new_fds[1];
  n = sendmsg(fd, &msg, 0);
  fprintf(stderr, "sendmsg: %d (%m)\n", n);
  msg.msg_controllen = cmsg->cmsg_len;
  msg.msg_controllen = cmsg->cmsg_len = CMSG_LEN(sizeof(int) * 1);
  ((int *)CMSG_DATA(cmsg))[0] = new_fds[2];
  n = sendmsg(fd, &msg, 0);
  fprintf(stderr, "sendmsg: %d (%m)\n", n);
  n = send(fd, str, 10, 0);
  fprintf(stderr, "send: %d (%m)\n", n);
  msg.msg_controllen = cmsg->cmsg_len = CMSG_LEN(sizeof(int) * 5);
  ((int *)CMSG_DATA(cmsg))[0] = new_fds[0];
  ((int *)CMSG_DATA(cmsg))[1] = new_fds[1];
  ((int *)CMSG_DATA(cmsg))[2] = new_fds[2];
  ((int *)CMSG_DATA(cmsg))[3] = new_fds[3];
  ((int *)CMSG_DATA(cmsg))[4] = 0;
  n = sendmsg(fd, &msg, 0);
  fprintf(stderr, "sendmsg: %d (%m)\n", n);
  if (close(fd)) {
    perror("close");
    abort();
  }
  fprintf(stderr, "sender exiting\n");
}


x86 assembly (clang, -O0):
<sender>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1c0,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x30(%rbp),%rdi
lea    0xe27(%rip),%rsi
mov    $0x29,%edx
call   10c0 <memcpy@plt>
lea    -0x1a0(%rbp),%rdi
call   1090 <pipe@plt>
cmp    $0x0,%rax
jne    1213 <sender+0x53>
lea    -0x1a0(%rbp),%rdi
add    $0x8,%rdi
call   1090 <pipe@plt>
cmp    $0x0,%rax
je     1226 <sender+0x66>
lea    0xe0f(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x4(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x14,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    %eax,-0x1a4(%rbp)
mov    0x2d92(%rip),%rax
mov    (%rax),%edi
mov    -0x1a4(%rbp),%edx
lea    0xdd9(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
lea    -0x58(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1070 <memset@plt>
lea    -0x80(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1070 <memset@plt>
lea    -0x30(%rbp),%rax
mov    %rax,-0x80(%rbp)
movl   $0x7,-0x78(%rbp)
lea    -0x80(%rbp),%rax
mov    %rax,-0x38(%rbp)
movl   $0x1,-0x4c(%rbp)
lea    -0x190(%rbp),%rax
mov    %rax,-0x48(%rbp)
movl   $0x100,-0x40(%rbp)
lea    -0x58(%rbp),%rdi
call   10e0 <CMSG_FIRSTHDR@plt>
mov    %rax,-0x88(%rbp)
mov    0x2d25(%rip),%rax
mov    (%rax),%ecx
mov    -0x88(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    0x2cfa(%rip),%rax
mov    (%rax),%ecx
mov    -0x88(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    $0x8,%edi
call   10a0 <CMSG_LEN@plt>
mov    -0x88(%rbp),%rcx
mov    %eax,(%rcx)
mov    %eax,-0x40(%rbp)
mov    -0x1a0(%rbp),%eax
mov    %eax,-0x1c0(%rbp)
mov    -0x88(%rbp),%rdi
call   1050 <CMSG_DATA@plt>
mov    -0x1c0(%rbp),%ecx
mov    %ecx,(%rax)
mov    -0x19c(%rbp),%eax
mov    %eax,-0x1bc(%rbp)
mov    -0x88(%rbp),%rdi
call   1050 <CMSG_DATA@plt>
mov    -0x1bc(%rbp),%ecx
mov    %ecx,0x4(%rax)
mov    -0x4(%rbp),%edi
lea    -0x58(%rbp),%rsi
xor    %edx,%edx
call   1040 <sendmsg@plt>
mov    %eax,-0x1a4(%rbp)
mov    0x2c84(%rip),%rax
mov    (%rax),%edi
mov    -0x1a4(%rbp),%edx
lea    0xcda(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x88(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
mov    $0x4,%edi
call   10a0 <CMSG_LEN@plt>
mov    -0x88(%rbp),%rcx
mov    %eax,(%rcx)
mov    %eax,-0x40(%rbp)
mov    -0x198(%rbp),%eax
mov    %eax,-0x1b8(%rbp)
mov    -0x88(%rbp),%rdi
call   1050 <CMSG_DATA@plt>
mov    -0x1b8(%rbp),%ecx
mov    %ecx,(%rax)
mov    -0x4(%rbp),%edi
lea    -0x58(%rbp),%rsi
xor    %edx,%edx
call   1040 <sendmsg@plt>
mov    %eax,-0x1a4(%rbp)
mov    0x2c11(%rip),%rax
mov    (%rax),%edi
mov    -0x1a4(%rbp),%edx
lea    0xc67(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x4(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0xa,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    %eax,-0x1a4(%rbp)
mov    0x2bdb(%rip),%rax
mov    (%rax),%edi
mov    -0x1a4(%rbp),%edx
lea    0xc22(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    $0x14,%edi
call   10a0 <CMSG_LEN@plt>
mov    -0x88(%rbp),%rcx
mov    %eax,(%rcx)
mov    %eax,-0x40(%rbp)
mov    -0x1a0(%rbp),%eax
mov    %eax,-0x1b4(%rbp)
mov    -0x88(%rbp),%rdi
call   1050 <CMSG_DATA@plt>
mov    -0x1b4(%rbp),%ecx
mov    %ecx,(%rax)
mov    -0x19c(%rbp),%eax
mov    %eax,-0x1b0(%rbp)
mov    -0x88(%rbp),%rdi
call   1050 <CMSG_DATA@plt>
mov    -0x1b0(%rbp),%ecx
mov    %ecx,0x4(%rax)
mov    -0x198(%rbp),%eax
mov    %eax,-0x1ac(%rbp)
mov    -0x88(%rbp),%rdi
call   1050 <CMSG_DATA@plt>
mov    -0x1ac(%rbp),%ecx
mov    %ecx,0x8(%rax)
mov    -0x194(%rbp),%eax
mov    %eax,-0x1a8(%rbp)
mov    -0x88(%rbp),%rdi
call   1050 <CMSG_DATA@plt>
mov    -0x1a8(%rbp),%ecx
mov    %ecx,0xc(%rax)
mov    -0x88(%rbp),%rdi
call   1050 <CMSG_DATA@plt>
movl   $0x0,0x10(%rax)
mov    -0x4(%rbp),%edi
lea    -0x58(%rbp),%rsi
xor    %edx,%edx
call   1040 <sendmsg@plt>
mov    %eax,-0x1a4(%rbp)
mov    0x2afe(%rip),%rax
mov    (%rax),%edi
mov    -0x1a4(%rbp),%edx
lea    0xb54(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x4(%rbp),%edi
call   1080 <close@plt>
cmp    $0x0,%rax
je     1515 <sender+0x355>
lea    0xb46(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    0x2abc(%rip),%rax
mov    (%rax),%edi
lea    0xb30(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
add    $0x1c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sender>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1a8,%rsp
mov    %edi,%r15d
movups 0xe4e(%rip),%xmm0
movups %xmm0,0x59(%rsp)
movaps 0xe39(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xe1d(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
mov    %rsp,%rdi
call   1090 <pipe@plt>
test   %rax,%rax
jne    141b <sender+0x26b>
lea    0x8(%rsp),%rdi
call   1090 <pipe@plt>
test   %rax,%rax
jne    141b <sender+0x26b>
lea    0x40(%rsp),%rsi
mov    %r15d,%edi
mov    %rsi,%rbp
mov    $0x14,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    0x2dae(%rip),%r12
mov    (%r12),%edi
lea    0xdf9(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   10b0 <fprintf@plt>
lea    0x18(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1070 <memset@plt>
lea    0x78(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1070 <memset@plt>
mov    %rbp,0x78(%rsp)
movl   $0x7,0x80(%rsp)
mov    %rbx,0x38(%rsp)
movl   $0x1,0x24(%rsp)
lea    0xa0(%rsp),%rax
mov    %rax,0x28(%rsp)
movl   $0x100,0x30(%rsp)
mov    %r14,%rdi
call   10d0 <CMSG_FIRSTHDR@plt>
mov    %rax,%rbx
mov    0x2d3e(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rbx)
mov    0x2d1a(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rbx)
mov    $0x8,%edi
call   10a0 <CMSG_LEN@plt>
mov    %eax,(%rbx)
mov    %eax,0x30(%rsp)
mov    (%rsp),%ebp
mov    %rbx,%rdi
call   1050 <CMSG_DATA@plt>
mov    %ebp,(%rax)
mov    0x4(%rsp),%ebp
mov    %rbx,%rdi
call   1050 <CMSG_DATA@plt>
mov    %ebp,0x4(%rax)
mov    %r15d,%edi
mov    %r14,%rsi
xor    %edx,%edx
call   1040 <sendmsg@plt>
mov    (%r12),%edi
lea    0xd3e(%rip),%r13
mov    %r13,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    (%rbx),%eax
mov    %eax,0x30(%rsp)
mov    $0x4,%edi
call   10a0 <CMSG_LEN@plt>
mov    %eax,(%rbx)
mov    %eax,0x30(%rsp)
mov    0x8(%rsp),%ebp
mov    %rbx,%rdi
call   1050 <CMSG_DATA@plt>
mov    %ebp,(%rax)
mov    %r15d,%edi
mov    %r14,%rsi
xor    %edx,%edx
call   1040 <sendmsg@plt>
mov    (%r12),%edi
mov    %r13,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    %r15d,%edi
lea    0x40(%rsp),%rsi
mov    $0xa,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    (%r12),%edi
lea    0xcc3(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    $0x14,%edi
call   10a0 <CMSG_LEN@plt>
mov    %eax,(%rbx)
mov    %eax,0x30(%rsp)
mov    (%rsp),%ebp
mov    %rbx,%rdi
call   1050 <CMSG_DATA@plt>
mov    %ebp,(%rax)
mov    0x4(%rsp),%ebp
mov    %rbx,%rdi
call   1050 <CMSG_DATA@plt>
mov    %ebp,0x4(%rax)
mov    0x8(%rsp),%ebp
mov    %rbx,%rdi
call   1050 <CMSG_DATA@plt>
mov    %ebp,0x8(%rax)
mov    0xc(%rsp),%ebp
mov    %rbx,%rdi
call   1050 <CMSG_DATA@plt>
mov    %ebp,0xc(%rax)
mov    %rbx,%rdi
call   1050 <CMSG_DATA@plt>
movl   $0x0,0x10(%rax)
mov    %r15d,%edi
mov    %r14,%rsi
xor    %edx,%edx
call   1040 <sendmsg@plt>
mov    (%r12),%edi
mov    %r13,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    %r15d,%edi
call   1080 <close@plt>
test   %rax,%rax
jne    1424 <sender+0x274>
mov    (%r12),%edi
lea    0xc53(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
add    $0x1a8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc07(%rip),%rdi
jmp    142b <sender+0x27b>
lea    0xc24(%rip),%rdi
call   10c0 <perror@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
%struct.msghdr = type { i8*, i32, i32, i8*, i32, %struct.msghdr* }
%struct.iovec = type { i8*, i32, i32, i8*, i32, %struct.iovec* }
%struct.cmsghdr = type { i32, i32, i32 }
@__const.sender.str = [41 x i8] c"0123456789012345678901234567890123456789\00"
@.str = [5 x i8] c"pipe\00"
@stderr = global i32 0
@.str.1 = [15 x i8] c"send: %d (%m)\0A\00"
@SOL_SOCKET = global i32 0
@SCM_RIGHTS = global i32 0
@.str.2 = [18 x i8] c"sendmsg: %d (%m)\0A\00"
@.str.3 = [6 x i8] c"close\00"
@.str.4 = [16 x i8] c"sender exiting\0A\00"
define void @sender(i32 %0) {
%2 = alloca i32
%3 = alloca [41 x i8]
%4 = alloca %struct.msghdr
%5 = alloca %struct.iovec
%6 = alloca %struct.cmsghdr*
%7 = alloca [256 x i8]
%8 = alloca [4 x i32]
%9 = alloca i32
store i32 %0, i32* %2
%10 = bitcast [41 x i8]* %3 to i8*
%11 = getelementptr inbounds [4 x i32], [4 x i32]* %8, i64 0, i64 0
%12 = call i64 @pipe(i32* %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %19, label %14
14: ; preds = %1
%15 = getelementptr inbounds [4 x i32], [4 x i32]* %8, i64 0, i64 0
%16 = getelementptr inbounds i32, i32* %15, i64 2
%17 = call i64 @pipe(i32* %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %14, %1
%20 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%21 = call i32 (...) @abort()
unreachable
22: ; preds = %14
%23 = load i32, i32* %2
%24 = getelementptr inbounds [41 x i8], [41 x i8]* %3, i64 0, i64 0
%25 = call i32 @send(i32 %23, i8* %24, i32 20, i32 0)
store i32 %25, i32* %9
%26 = load i32, i32* @stderr
%27 = load i32, i32* %9
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %27)
%29 = call i32 @memset(%struct.msghdr* %4, i32 0, i32 40)
%30 = bitcast %struct.iovec* %5 to %struct.msghdr*
%31 = call i32 @memset(%struct.msghdr* %30, i32 0, i32 40)
%32 = getelementptr inbounds [41 x i8], [41 x i8]* %3, i64 0, i64 0
%33 = getelementptr inbounds %struct.iovec, %struct.iovec* %5, i32 0, i32 0
store i8* %32, i8** %33
%34 = getelementptr inbounds %struct.iovec, %struct.iovec* %5, i32 0, i32 1
store i32 7, i32* %34
%35 = bitcast %struct.iovec* %5 to %struct.msghdr*
%36 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %4, i32 0, i32 5
store %struct.msghdr* %35, %struct.msghdr** %36
%37 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %4, i32 0, i32 2
store i32 1, i32* %37
%38 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%39 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %4, i32 0, i32 3
store i8* %38, i8** %39
%40 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %4, i32 0, i32 4
store i32 256, i32* %40
%41 = call %struct.cmsghdr* @CMSG_FIRSTHDR(%struct.msghdr* %4)
store %struct.cmsghdr* %41, %struct.cmsghdr** %6
%42 = load i32, i32* @SOL_SOCKET
%43 = load %struct.cmsghdr*, %struct.cmsghdr** %6
%44 = getelementptr inbounds %struct.cmsghdr, %struct.cmsghdr* %43, i32 0, i32 2
store i32 %42, i32* %44
%45 = load i32, i32* @SCM_RIGHTS
%46 = load %struct.cmsghdr*, %struct.cmsghdr** %6
%47 = getelementptr inbounds %struct.cmsghdr, %struct.cmsghdr* %46, i32 0, i32 1
store i32 %45, i32* %47
%48 = call i8* @CMSG_LEN(i32 8)
%49 = ptrtoint i8* %48 to i32
%50 = load %struct.cmsghdr*, %struct.cmsghdr** %6
%51 = getelementptr inbounds %struct.cmsghdr, %struct.cmsghdr* %50, i32 0, i32 0
store i32 %49, i32* %51
%52 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %4, i32 0, i32 4
store i32 %49, i32* %52
%53 = getelementptr inbounds [4 x i32], [4 x i32]* %8, i64 0, i64 0
%54 = load i32, i32* %53
%55 = load %struct.cmsghdr*, %struct.cmsghdr** %6
%56 = call i64 @CMSG_DATA(%struct.cmsghdr* %55)
%57 = inttoptr i64 %56 to i32*
%58 = getelementptr inbounds i32, i32* %57, i64 0
store i32 %54, i32* %58
%59 = getelementptr inbounds [4 x i32], [4 x i32]* %8, i64 0, i64 1
%60 = load i32, i32* %59
%61 = load %struct.cmsghdr*, %struct.cmsghdr** %6
%62 = call i64 @CMSG_DATA(%struct.cmsghdr* %61)
%63 = inttoptr i64 %62 to i32*
%64 = getelementptr inbounds i32, i32* %63, i64 1
store i32 %60, i32* %64
%65 = load i32, i32* %2
%66 = call i32 @sendmsg(i32 %65, %struct.msghdr* %4, i32 0)
store i32 %66, i32* %9
%67 = load i32, i32* @stderr
%68 = load i32, i32* %9
%69 = call i32 (i32, i8*, ...) @fprintf(i32 %67, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %68)
%70 = load %struct.cmsghdr*, %struct.cmsghdr** %6
%71 = getelementptr inbounds %struct.cmsghdr, %struct.cmsghdr* %70, i32 0, i32 0
%72 = load i32, i32* %71
%73 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %4, i32 0, i32 4
store i32 %72, i32* %73
%74 = call i8* @CMSG_LEN(i32 4)
%75 = ptrtoint i8* %74 to i32
%76 = load %struct.cmsghdr*, %struct.cmsghdr** %6
%77 = getelementptr inbounds %struct.cmsghdr, %struct.cmsghdr* %76, i32 0, i32 0
store i32 %75, i32* %77
%78 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %4, i32 0, i32 4
store i32 %75, i32* %78
%79 = getelementptr inbounds [4 x i32], [4 x i32]* %8, i64 0, i64 2
%80 = load i32, i32* %79
%81 = load %struct.cmsghdr*, %struct.cmsghdr** %6
%82 = call i64 @CMSG_DATA(%struct.cmsghdr* %81)
%83 = inttoptr i64 %82 to i32*
%84 = getelementptr inbounds i32, i32* %83, i64 0
store i32 %80, i32* %84
%85 = load i32, i32* %2
%86 = call i32 @sendmsg(i32 %85, %struct.msghdr* %4, i32 0)
store i32 %86, i32* %9
%87 = load i32, i32* @stderr
%88 = load i32, i32* %9
%89 = call i32 (i32, i8*, ...) @fprintf(i32 %87, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %88)
%90 = load i32, i32* %2
%91 = getelementptr inbounds [41 x i8], [41 x i8]* %3, i64 0, i64 0
%92 = call i32 @send(i32 %90, i8* %91, i32 10, i32 0)
store i32 %92, i32* %9
%93 = load i32, i32* @stderr
%94 = load i32, i32* %9
%95 = call i32 (i32, i8*, ...) @fprintf(i32 %93, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %94)
%96 = call i8* @CMSG_LEN(i32 20)
%97 = ptrtoint i8* %96 to i32
%98 = load %struct.cmsghdr*, %struct.cmsghdr** %6
%99 = getelementptr inbounds %struct.cmsghdr, %struct.cmsghdr* %98, i32 0, i32 0
store i32 %97, i32* %99
%100 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %4, i32 0, i32 4
store i32 %97, i32* %100
%101 = getelementptr inbounds [4 x i32], [4 x i32]* %8, i64 0, i64 0
%102 = load i32, i32* %101
%103 = load %struct.cmsghdr*, %struct.cmsghdr** %6
%104 = call i64 @CMSG_DATA(%struct.cmsghdr* %103)
%105 = inttoptr i64 %104 to i32*
%106 = getelementptr inbounds i32, i32* %105, i64 0
store i32 %102, i32* %106
%107 = getelementptr inbounds [4 x i32], [4 x i32]* %8, i64 0, i64 1
%108 = load i32, i32* %107
%109 = load %struct.cmsghdr*, %struct.cmsghdr** %6
%110 = call i64 @CMSG_DATA(%struct.cmsghdr* %109)
%111 = inttoptr i64 %110 to i32*
%112 = getelementptr inbounds i32, i32* %111, i64 1
store i32 %108, i32* %112
%113 = getelementptr inbounds [4 x i32], [4 x i32]* %8, i64 0, i64 2
%114 = load i32, i32* %113
%115 = load %struct.cmsghdr*, %struct.cmsghdr** %6
%116 = call i64 @CMSG_DATA(%struct.cmsghdr* %115)
%117 = inttoptr i64 %116 to i32*
%118 = getelementptr inbounds i32, i32* %117, i64 2
store i32 %114, i32* %118
%119 = getelementptr inbounds [4 x i32], [4 x i32]* %8, i64 0, i64 3
%120 = load i32, i32* %119
%121 = load %struct.cmsghdr*, %struct.cmsghdr** %6
%122 = call i64 @CMSG_DATA(%struct.cmsghdr* %121)
%123 = inttoptr i64 %122 to i32*
%124 = getelementptr inbounds i32, i32* %123, i64 3
store i32 %120, i32* %124
%125 = load %struct.cmsghdr*, %struct.cmsghdr** %6
%126 = call i64 @CMSG_DATA(%struct.cmsghdr* %125)
%127 = inttoptr i64 %126 to i32*
%128 = getelementptr inbounds i32, i32* %127, i64 4
store i32 0, i32* %128
%129 = load i32, i32* %2
%130 = call i32 @sendmsg(i32 %129, %struct.msghdr* %4, i32 0)
store i32 %130, i32* %9
%131 = load i32, i32* @stderr
%132 = load i32, i32* %9
%133 = call i32 (i32, i8*, ...) @fprintf(i32 %131, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %132)
%134 = load i32, i32* %2
%135 = call i64 @close(i32 %134)
%136 = icmp ne i64 %135, 0
br i1 %136, label %137, label %140
137: ; preds = %22
%138 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%139 = call i32 (...) @abort()
unreachable
140: ; preds = %22
%141 = load i32, i32* @stderr
%142 = call i32 (i32, i8*, ...) @fprintf(i32 %141, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
%struct.msghdr = type { i8*, i32, i32, i8*, i32, %struct.msghdr* }
%struct.iovec = type { i8*, i32, i32, i8*, i32, %struct.iovec* }
%struct.cmsghdr = type { i32, i32, i32 }
@__const.sender.str = [41 x i8] c"0123456789012345678901234567890123456789\00"
@.str = [5 x i8] c"pipe\00"
@stderr = global i32 0
@.str.1 = [15 x i8] c"send: %d (%m)\0A\00"
@SOL_SOCKET = global i32 0
@SCM_RIGHTS = global i32 0
@.str.2 = [18 x i8] c"sendmsg: %d (%m)\0A\00"
@.str.3 = [6 x i8] c"close\00"
@.str.4 = [16 x i8] c"sender exiting\0A\00"
define void @sender(i32 %0) {
%2 = alloca [41 x i8]
%3 = alloca %struct.msghdr
%4 = alloca %struct.iovec
%5 = alloca [256 x i8]
%6 = alloca [4 x i32]
%7 = getelementptr inbounds [41 x i8], [41 x i8]* %2, i64 0, i64 0
%8 = bitcast %struct.msghdr* %3 to i8*
%9 = bitcast %struct.iovec* %4 to i8*
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%11 = bitcast [4 x i32]* %6 to i8*
%12 = getelementptr inbounds [4 x i32], [4 x i32]* %6, i64 0, i64 0
%13 = call i64 @pipe(i32* %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %1
%16 = getelementptr inbounds [4 x i32], [4 x i32]* %6, i64 0, i64 2
%17 = call i64 @pipe(i32* %16)
%18 = icmp eq i64 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %15, %1
%20 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%21 = call i32 (...) @abort()
unreachable
22: ; preds = %15
%23 = call i32 @send(i32 %0, i8* %7, i32 20, i32 0)
%24 = load i32, i32* @stderr
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %23)
%26 = call i32 @memset(%struct.msghdr* %3, i32 0, i32 40)
%27 = bitcast %struct.iovec* %4 to %struct.msghdr*
%28 = call i32 @memset(%struct.msghdr* %27, i32 0, i32 40)
%29 = getelementptr inbounds %struct.iovec, %struct.iovec* %4, i64 0, i32 0
store i8* %7, i8** %29
%30 = getelementptr inbounds %struct.iovec, %struct.iovec* %4, i64 0, i32 1
store i32 7, i32* %30
%31 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %3, i64 0, i32 5
%32 = bitcast %struct.msghdr** %31 to %struct.iovec**
store %struct.iovec* %4, %struct.iovec** %32
%33 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %3, i64 0, i32 2
store i32 1, i32* %33
%34 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %3, i64 0, i32 3
store i8* %10, i8** %34
%35 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %3, i64 0, i32 4
store i32 256, i32* %35
%36 = call %struct.cmsghdr* @CMSG_FIRSTHDR(%struct.msghdr* %3)
%37 = load i32, i32* @SOL_SOCKET
%38 = getelementptr inbounds %struct.cmsghdr, %struct.cmsghdr* %36, i64 0, i32 2
store i32 %37, i32* %38
%39 = load i32, i32* @SCM_RIGHTS
%40 = getelementptr inbounds %struct.cmsghdr, %struct.cmsghdr* %36, i64 0, i32 1
store i32 %39, i32* %40
%41 = call i8* @CMSG_LEN(i32 8)
%42 = ptrtoint i8* %41 to i64
%43 = trunc i64 %42 to i32
%44 = getelementptr inbounds %struct.cmsghdr, %struct.cmsghdr* %36, i64 0, i32 0
store i32 %43, i32* %44
store i32 %43, i32* %35
%45 = load i32, i32* %12
%46 = call i64 @CMSG_DATA(%struct.cmsghdr* %36)
%47 = inttoptr i64 %46 to i32*
store i32 %45, i32* %47
%48 = getelementptr inbounds [4 x i32], [4 x i32]* %6, i64 0, i64 1
%49 = load i32, i32* %48
%50 = call i64 @CMSG_DATA(%struct.cmsghdr* %36)
%51 = inttoptr i64 %50 to i32*
%52 = getelementptr inbounds i32, i32* %51, i64 1
store i32 %49, i32* %52
%53 = call i32 @sendmsg(i32 %0, %struct.msghdr* %3, i32 0)
%54 = load i32, i32* @stderr
%55 = call i32 (i32, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %53)
%56 = load i32, i32* %44
store i32 %56, i32* %35
%57 = call i8* @CMSG_LEN(i32 4)
%58 = ptrtoint i8* %57 to i64
%59 = trunc i64 %58 to i32
store i32 %59, i32* %44
store i32 %59, i32* %35
%60 = load i32, i32* %16
%61 = call i64 @CMSG_DATA(%struct.cmsghdr* %36)
%62 = inttoptr i64 %61 to i32*
store i32 %60, i32* %62
%63 = call i32 @sendmsg(i32 %0, %struct.msghdr* %3, i32 0)
%64 = load i32, i32* @stderr
%65 = call i32 (i32, i8*, ...) @fprintf(i32 %64, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %63)
%66 = call i32 @send(i32 %0, i8* %7, i32 10, i32 0)
%67 = load i32, i32* @stderr
%68 = call i32 (i32, i8*, ...) @fprintf(i32 %67, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %66)
%69 = call i8* @CMSG_LEN(i32 20)
%70 = ptrtoint i8* %69 to i64
%71 = trunc i64 %70 to i32
store i32 %71, i32* %44
store i32 %71, i32* %35
%72 = load i32, i32* %12
%73 = call i64 @CMSG_DATA(%struct.cmsghdr* %36)
%74 = inttoptr i64 %73 to i32*
store i32 %72, i32* %74
%75 = load i32, i32* %48
%76 = call i64 @CMSG_DATA(%struct.cmsghdr* %36)
%77 = inttoptr i64 %76 to i32*
%78 = getelementptr inbounds i32, i32* %77, i64 1
store i32 %75, i32* %78
%79 = load i32, i32* %16
%80 = call i64 @CMSG_DATA(%struct.cmsghdr* %36)
%81 = inttoptr i64 %80 to i32*
%82 = getelementptr inbounds i32, i32* %81, i64 2
store i32 %79, i32* %82
%83 = getelementptr inbounds [4 x i32], [4 x i32]* %6, i64 0, i64 3
%84 = load i32, i32* %83
%85 = call i64 @CMSG_DATA(%struct.cmsghdr* %36)
%86 = inttoptr i64 %85 to i32*
%87 = getelementptr inbounds i32, i32* %86, i64 3
store i32 %84, i32* %87
%88 = call i64 @CMSG_DATA(%struct.cmsghdr* %36)
%89 = inttoptr i64 %88 to i32*
%90 = getelementptr inbounds i32, i32* %89, i64 4
store i32 0, i32* %90
%91 = call i32 @sendmsg(i32 %0, %struct.msghdr* %3, i32 0)
%92 = load i32, i32* @stderr
%93 = call i32 (i32, i8*, ...) @fprintf(i32 %92, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %91)
%94 = call i64 @close(i32 %0)
%95 = icmp eq i64 %94, 0
br i1 %95, label %99, label %96
96: ; preds = %22
%97 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%98 = call i32 (...) @abort()
unreachable
99: ; preds = %22
%100 = load i32, i32* @stderr
%101 = call i32 (i32, i8*, ...) @fprintf(i32 %100, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
ret void
}