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

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int BUFSIZ;
scalar_t__ CMSG_DATA(struct cmsghdr *);
struct cmsghdr *CMSG_FIRSTHDR(struct msghdr *);
int CMSG_LEN(int);
int CMSG_SPACE(int);
int /*<<< orphan*/ SCM_RIGHTS;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
void *htonl(int);
int /*<<< orphan*/ memcpy(int *, int *, int);
int /*<<< orphan*/ memset(struct sockaddr_un *, int /*<<< orphan*/, int);
int ntohl(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int recv(int, char **, int, int /*<<< orphan*/);
int send(int, ...);
int sendmsg(int, struct msghdr *, int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(int /*<<< orphan*/, int, char *, char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ socketpair(int /*<<< orphan*/, int /*<<< orphan*/,
                      int /*<<< orphan*/, int *);
int sprintf(char *, char *, char *);
int /*<<< orphan*/ write(int, char **, int);
int main(int argc, char **argv) {
  struct msghdr msg = {0};
  struct cmsghdr *cmsg;
  int myfds[2] = {0};
  char buf[CMSG_SPACE(sizeof myfds)];
  int *fdptr;
  int rc, mux_socket;
  struct iovec iov = {.iov_len = 1};
  struct sockaddr_un addr;
  char buffer[BUFSIZ];
  uint32_t *p, num;
  memset(&addr, 0, sizeof(addr));
  addr.sun_family = AF_UNIX;
  snprintf(addr.sun_path, 100, "%s", argv[1]);
  mux_socket = socket(AF_UNIX, SOCK_STREAM, 0);
  if (connect(mux_socket, (struct sockaddr *)&addr, sizeof(addr))) {
    perror("connect");
    return 1;
  }
  rc = recv(mux_socket, &buffer, BUFSIZ, 0);
  if (rc < 0) {
    perror("recv");
    return 1;
  }
  p = (uint32_t *)buffer;
  num = ntohl(*p);
  printf("Message has %d bytes\n", num);
  if (num < 8) {
    printf("Message too short\n");
    return 1;
  }
  num = ntohl(*++p);
  if (num != 0x00000001) {
    printf("Message not a Hello\n");
    return 1;
  }
  num = ntohl(*++p);
  if (num != 4) {
    printf("Protocol version not 4\n");
    return 1;
  }
  if (rc != send(mux_socket, &buffer, rc, 0)) {
    perror("send");
    return 1;
  }
  p = (uint32_t *)buffer;
  p++;
  *p++ = htonl(0x10000008);
  *p++ = htonl(1);
  *p++ = htonl(0);
  num = sprintf((char *)(p + 1), "%s", "localhost");
  *p++ = htonl(num);
  p = (uint32_t *)((char *)p + num);
  *p++ = htonl(5555);
  num = ((char *)p) - buffer;
  p = (uint32_t *)buffer;
  *p = htonl(num - sizeof(*p));
  printf("Message has %d bytes\n", num);
  if (send(mux_socket, buffer, num, 0) != num) {
    perror("send");
    return 1;
  }
  if (socketpair(AF_UNIX, SOCK_STREAM, 0, myfds)) {
    perror("socketpair");
    return 1;
  }
  msg.msg_control = buf;
  msg.msg_controllen = sizeof buf;
  msg.msg_iovlen = 1;
  msg.msg_iov = &iov;
  num = 0;
  iov.iov_base = &num;
  iov.iov_len = 1;
  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, &myfds[0], sizeof(int));
  msg.msg_controllen = cmsg->cmsg_len;
  if (sendmsg(mux_socket, &msg, 0) != 1) {
    perror("sendmsg");
    return 1;
  }
  if (sendmsg(mux_socket, &msg, 0) != 1) {
    perror("sendmsg");
    return 1;
  }
  rc = recv(mux_socket, &buffer, BUFSIZ, 0);
  if (rc <= 0) {
    perror("recv");
    return 1;
  }
  p = (uint32_t *)buffer;
  num = ntohl(*p++);
  printf("Message has %d bytes\n", num);
  if (ntohl(*p) != 0x80000006) {
    printf("Forwarding request failed\n");
    return 1;
  }
  close(mux_socket);
  while ((rc = recv(myfds[1], &buffer, BUFSIZ, 0))) {
    write(1, &buffer, rc);
    if (send(myfds[1], &buffer, rc, 0) != rc) {
      perror("send");
      return 1;
    }
  }
  printf("Connection finished\n");
  rc = recv(mux_socket, &buffer, BUFSIZ, 0);
  if (rc <= 0) {
    perror("recv");
    return 1;
  }
  p = (uint32_t *)buffer;
  num = ntohl(*p++);
  printf("Message has %d bytes\n", num);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xorps  %xmm0,%xmm0
movaps %xmm0,-0x20(%rbp)
movaps %xmm0,-0x30(%rbp)
movq   $0x0,-0x40(%rbp)
mov    $0x8,%edi
call   10e0 <CMSG_SPACE@plt>
mov    %eax,%eax
mov    %rax,-0xa8(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0xa0(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x50(%rbp)
movups 0xd54(%rip),%xmm0
movaps %xmm0,-0x70(%rbp)
mov    0x2d11(%rip),%rax
mov    (%rax),%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x98(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x80(%rbp)
lea    -0x78(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   10b0 <memset@plt>
mov    0x2cf1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x74(%rbp)
mov    -0x78(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
mov    $0x64,%esi
lea    0xd05(%rip),%rdx
call   1090 <snprintf@plt>
mov    0x2cc9(%rip),%rax
mov    (%rax),%edi
mov    0x2cb0(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1160 <socket@plt>
mov    %eax,-0x60(%rbp)
mov    -0x60(%rbp),%edi
lea    -0x78(%rbp),%rsi
mov    $0x8,%edx
call   1130 <connect@plt>
cmp    $0x0,%rax
je     1369 <main+0x129>
lea    0xcc5(%rip),%rdi
call   1110 <perror@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x90(%rbp)
jmp    1a14 <main+0x7d4>
mov    -0x98(%rbp),%rsi
mov    -0x60(%rbp),%edi
mov    0x2c4e(%rip),%rax
mov    (%rax),%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x5c(%rbp)
cmpl   $0x0,-0x5c(%rbp)
jge    13b2 <main+0x172>
lea    0xc84(%rip),%rdi
call   1110 <perror@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x90(%rbp)
jmp    1a14 <main+0x7d4>
mov    -0x98(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    -0x88(%rbp),%rax
mov    (%rax),%edi
call   1150 <ntohl@plt>
mov    %eax,-0x8c(%rbp)
mov    -0x8c(%rbp),%esi
lea    0xc3f(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
cmpl   $0x8,-0x8c(%rbp)
jge    1419 <main+0x1d9>
lea    0xc3a(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x90(%rbp)
jmp    1a14 <main+0x7d4>
mov    -0x88(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x88(%rbp)
mov    0x4(%rax),%edi
call   1150 <ntohl@plt>
mov    %eax,-0x8c(%rbp)
cmpl   $0x1,-0x8c(%rbp)
je     146d <main+0x22d>
lea    0xbf9(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x90(%rbp)
jmp    1a14 <main+0x7d4>
mov    -0x88(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x88(%rbp)
mov    0x4(%rax),%edi
call   1150 <ntohl@plt>
mov    %eax,-0x8c(%rbp)
cmpl   $0x4,-0x8c(%rbp)
je     14c1 <main+0x281>
lea    0xbba(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x90(%rbp)
jmp    1a14 <main+0x7d4>
mov    -0x98(%rbp),%rsi
mov    -0x5c(%rbp),%eax
mov    %eax,-0xac(%rbp)
mov    -0x60(%rbp),%edi
mov    -0x5c(%rbp),%edx
xor    %ecx,%ecx
mov    $0x0,%al
call   1070 <send@plt>
mov    %eax,%ecx
mov    -0xac(%rbp),%eax
cmp    %ecx,%eax
je     1512 <main+0x2d2>
lea    0xb7f(%rip),%rdi
call   1110 <perror@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x90(%rbp)
jmp    1a14 <main+0x7d4>
mov    -0x98(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    -0x88(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x88(%rbp)
mov    $0x10000008,%edi
call   10a0 <htonl@plt>
mov    %eax,%ecx
mov    -0x88(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x88(%rbp)
mov    %ecx,(%rax)
mov    $0x1,%edi
call   10a0 <htonl@plt>
mov    %eax,%ecx
mov    -0x88(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x88(%rbp)
mov    %ecx,(%rax)
xor    %edi,%edi
call   10a0 <htonl@plt>
mov    %eax,%ecx
mov    -0x88(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x88(%rbp)
mov    %ecx,(%rax)
mov    -0x88(%rbp),%rdi
add    $0x4,%rdi
lea    0xa66(%rip),%rsi
lea    0xaca(%rip),%rdx
call   1120 <sprintf@plt>
mov    %eax,-0x8c(%rbp)
mov    -0x8c(%rbp),%edi
call   10a0 <htonl@plt>
mov    %eax,%ecx
mov    -0x88(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x88(%rbp)
mov    %ecx,(%rax)
mov    -0x88(%rbp),%rax
movslq -0x8c(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x88(%rbp)
mov    $0x15b3,%edi
call   10a0 <htonl@plt>
mov    %rax,%rcx
mov    -0x98(%rbp),%rax
mov    %ecx,%edx
mov    -0x88(%rbp),%rcx
mov    %rcx,%rsi
add    $0x4,%rsi
mov    %rsi,-0x88(%rbp)
mov    %edx,(%rcx)
mov    -0x88(%rbp),%rcx
sub    %rax,%rcx
mov    %ecx,-0x8c(%rbp)
mov    %rax,-0x88(%rbp)
movslq -0x8c(%rbp),%rax
sub    $0x4,%rax
mov    %eax,%edi
call   10a0 <htonl@plt>
mov    %eax,%ecx
mov    -0x88(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8c(%rbp),%esi
lea    0x9ba(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x98(%rbp),%rsi
mov    -0x60(%rbp),%edi
mov    -0x8c(%rbp),%edx
xor    %ecx,%ecx
mov    $0x0,%al
call   1070 <send@plt>
cmp    -0x8c(%rbp),%eax
je     16b4 <main+0x474>
lea    0x9dd(%rip),%rdi
call   1110 <perror@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x90(%rbp)
jmp    1a14 <main+0x7d4>
mov    0x2925(%rip),%rax
mov    (%rax),%edi
mov    0x290c(%rip),%rax
mov    (%rax),%esi
lea    -0x40(%rbp),%rcx
xor    %edx,%edx
call   1100 <socketpair@plt>
cmp    $0x0,%rax
je     16fd <main+0x4bd>
lea    0x9a3(%rip),%rdi
call   1110 <perror@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x90(%rbp)
jmp    1a14 <main+0x7d4>
mov    -0xa8(%rbp),%rax
mov    -0xa0(%rbp),%rcx
mov    %rcx,-0x30(%rbp)
mov    %eax,-0x28(%rbp)
movl   $0x1,-0x24(%rbp)
lea    -0x70(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x8c(%rbp)
lea    -0x8c(%rbp),%rax
mov    %rax,-0x68(%rbp)
movl   $0x1,-0x70(%rbp)
lea    -0x30(%rbp),%rdi
call   1140 <CMSG_FIRSTHDR@plt>
mov    %rax,-0x38(%rbp)
mov    0x2897(%rip),%rax
mov    (%rax),%ecx
mov    -0x38(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    0x285f(%rip),%rax
mov    (%rax),%ecx
mov    -0x38(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    $0x4,%edi
call   10d0 <CMSG_LEN@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x38(%rbp),%rdi
call   1050 <CMSG_DATA@plt>
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rdi
lea    -0x40(%rbp),%rsi
mov    $0x4,%edx
call   10f0 <memcpy@plt>
mov    -0x38(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x60(%rbp),%edi
lea    -0x30(%rbp),%rsi
xor    %edx,%edx
call   1040 <sendmsg@plt>
cmp    $0x1,%eax
je     17dd <main+0x59d>
lea    0x8ce(%rip),%rdi
call   1110 <perror@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x90(%rbp)
jmp    1a14 <main+0x7d4>
mov    -0x60(%rbp),%edi
lea    -0x30(%rbp),%rsi
xor    %edx,%edx
call   1040 <sendmsg@plt>
cmp    $0x1,%eax
je     1816 <main+0x5d6>
lea    0x895(%rip),%rdi
call   1110 <perror@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x90(%rbp)
jmp    1a14 <main+0x7d4>
mov    -0x98(%rbp),%rsi
mov    -0x60(%rbp),%edi
mov    0x27a1(%rip),%rax
mov    (%rax),%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x5c(%rbp)
cmpl   $0x0,-0x5c(%rbp)
jg     185f <main+0x61f>
lea    0x7d7(%rip),%rdi
call   1110 <perror@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x90(%rbp)
jmp    1a14 <main+0x7d4>
mov    -0x98(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    -0x88(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x88(%rbp)
mov    (%rax),%edi
call   1150 <ntohl@plt>
mov    %eax,-0x8c(%rbp)
mov    -0x8c(%rbp),%esi
lea    0x784(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x88(%rbp),%rax
mov    (%rax),%edi
call   1150 <ntohl@plt>
cmp    $0x80000006,%eax
je     18e0 <main+0x6a0>
lea    0x7d5(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x90(%rbp)
jmp    1a14 <main+0x7d4>
mov    -0x60(%rbp),%edi
call   10c0 <close@plt>
mov    -0x98(%rbp),%rsi
mov    -0x3c(%rbp),%edi
mov    0x26cf(%rip),%rax
mov    (%rax),%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x5c(%rbp)
cmp    $0x0,%eax
je     1968 <main+0x728>
mov    -0x98(%rbp),%rsi
mov    -0x5c(%rbp),%edx
mov    $0x1,%edi
call   1060 <write@plt>
mov    -0x98(%rbp),%rsi
mov    -0x3c(%rbp),%edi
mov    -0x5c(%rbp),%edx
xor    %ecx,%ecx
mov    $0x0,%al
call   1070 <send@plt>
cmp    -0x5c(%rbp),%eax
je     1963 <main+0x723>
lea    0x72e(%rip),%rdi
call   1110 <perror@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x90(%rbp)
jmp    1a14 <main+0x7d4>
jmp    18e8 <main+0x6a8>
lea    0x744(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x98(%rbp),%rsi
mov    -0x60(%rbp),%edi
mov    0x2641(%rip),%rax
mov    (%rax),%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x5c(%rbp)
cmpl   $0x0,-0x5c(%rbp)
jg     19bf <main+0x77f>
lea    0x677(%rip),%rdi
call   1110 <perror@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x90(%rbp)
jmp    1a14 <main+0x7d4>
mov    -0x98(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    -0x88(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x88(%rbp)
mov    (%rax),%edi
call   1150 <ntohl@plt>
mov    %eax,-0x8c(%rbp)
mov    -0x8c(%rbp),%esi
lea    0x624(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x90(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %rsi,%r14
xorps  %xmm0,%xmm0
movaps %xmm0,-0x60(%rbp)
movaps %xmm0,-0x70(%rbp)
movq   $0x0,-0x40(%rbp)
mov    $0x8,%edi
call   10f0 <CMSG_SPACE@plt>
mov    %rsp,-0x30(%rbp)
mov    %eax,-0x44(%rbp)
mov    %eax,%eax
mov    %rsp,%rcx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rcx
mov    %rcx,-0x88(%rbp)
mov    %rcx,%rsp
movups 0xd67(%rip),%xmm0
movaps %xmm0,-0x80(%rbp)
mov    0x2d24(%rip),%rbx
mov    (%rbx),%eax
mov    %rsp,%r13
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
lea    -0x50(%rbp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   10c0 <memset@plt>
mov    0x2d0f(%rip),%r12
mov    (%r12),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x50(%rbp),%edi
mov    0x8(%r14),%rcx
lea    0xd2a(%rip),%rdx
mov    $0x64,%esi
call   10a0 <snprintf@plt>
mov    (%r12),%edi
mov    0x2cd5(%rip),%r12
mov    (%r12),%esi
xor    %edx,%edx
call   1160 <socket@plt>
mov    %eax,%r14d
mov    %eax,%edi
mov    %r15,%rsi
mov    $0x8,%edx
call   1130 <connect@plt>
test   %rax,%rax
jne    15fb <main+0x3bb>
mov    (%rbx),%edx
mov    %r14d,%edi
mov    %r13,%rsi
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
js     1654 <main+0x414>
mov    %eax,%r15d
mov    0x0(%r13),%edi
call   1150 <ntohl@plt>
mov    %eax,%ebx
lea    0xcd3(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1090 <printf@plt>
cmp    $0x7,%ebx
jg     1367 <main+0x127>
lea    0xd4f(%rip),%rdi
jmp    15d7 <main+0x397>
mov    0x4(%r13),%edi
call   1150 <ntohl@plt>
cmp    $0x1,%eax
jne    15c7 <main+0x387>
mov    0x8(%r13),%edi
call   1150 <ntohl@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x4,%eax
jne    15d0 <main+0x390>
mov    %r14d,%edi
mov    %r13,%rsi
mov    %r15d,%edx
xor    %ecx,%ecx
xor    %eax,%eax
call   1080 <send@plt>
cmp    %eax,%r15d
jne    15bb <main+0x37b>
mov    $0x10000008,%edi
call   10b0 <htonl@plt>
mov    %eax,0x4(%r13)
mov    $0x1,%r15d
mov    $0x1,%edi
call   10b0 <htonl@plt>
mov    %eax,0x8(%r13)
xor    %edi,%edi
call   10b0 <htonl@plt>
mov    %eax,0xc(%r13)
movabs $0x736f686c61636f6c,%rax
68 6f 73
mov    %rax,0x14(%r13)
movw   $0x74,0x1c(%r13)
mov    $0x9,%edi
call   10b0 <htonl@plt>
mov    %eax,0x10(%r13)
mov    $0x15b3,%edi
call   10b0 <htonl@plt>
mov    %eax,0x1d(%r13)
mov    $0x1d,%edi
call   10b0 <htonl@plt>
mov    %eax,0x0(%r13)
lea    0xc04(%rip),%rdi
mov    $0x21,%esi
xor    %eax,%eax
call   1090 <printf@plt>
mov    %r14d,%edi
mov    %r13,%rsi
mov    $0x21,%edx
xor    %ecx,%ecx
xor    %eax,%eax
call   1080 <send@plt>
cmp    $0x21,%eax
jne    1676 <main+0x436>
mov    0x2b94(%rip),%rax
mov    (%rax),%edi
mov    (%r12),%esi
lea    -0x40(%rbp),%rcx
xor    %edx,%edx
call   1110 <socketpair@plt>
test   %rax,%rax
jne    1687 <main+0x447>
mov    -0x88(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x44(%rbp),%eax
mov    %eax,-0x68(%rbp)
movl   $0x1,-0x64(%rbp)
lea    -0x80(%rbp),%rax
mov    %rax,-0x60(%rbp)
movl   $0x0,-0x34(%rbp)
lea    -0x34(%rbp),%rax
mov    %rax,-0x78(%rbp)
movl   $0x1,-0x80(%rbp)
lea    -0x70(%rbp),%r12
mov    %r12,%rdi
call   1140 <CMSG_FIRSTHDR@plt>
mov    %rax,%rbx
mov    0x2b36(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rbx)
mov    0x2b02(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rbx)
mov    $0x4,%edi
call   10e0 <CMSG_LEN@plt>
mov    %eax,(%rbx)
mov    %rbx,%rdi
call   1060 <CMSG_DATA@plt>
lea    -0x40(%rbp),%rsi
mov    %rax,%rdi
mov    $0x4,%edx
call   1100 <memcpy@plt>
mov    (%rbx),%eax
mov    %eax,-0x68(%rbp)
mov    %r14d,%edi
mov    %r12,%rsi
xor    %edx,%edx
call   1040 <sendmsg@plt>
cmp    $0x1,%eax
jne    1665 <main+0x425>
lea    -0x70(%rbp),%rsi
mov    %r14d,%edi
xor    %edx,%edx
call   1040 <sendmsg@plt>
cmp    $0x1,%eax
jne    1665 <main+0x425>
mov    0x2aa7(%rip),%r12
mov    (%r12),%edx
mov    %r14d,%edi
mov    %r13,%rsi
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jle    1698 <main+0x458>
mov    0x0(%r13),%edi
call   1150 <ntohl@plt>
mov    %eax,-0x34(%rbp)
lea    0xad3(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1090 <printf@plt>
mov    0x4(%r13),%edi
call   1150 <ntohl@plt>
cmp    $0x80000006,%eax
jne    1604 <main+0x3c4>
mov    %r14d,%edi
call   10d0 <close@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    -0x3c(%rbp),%edi
mov    (%r12),%edx
mov    %r13,%rsi
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
je     1612 <main+0x3d2>
mov    %eax,%ebx
mov    $0x1,%edi
mov    %r13,%rsi
mov    %eax,%edx
call   1070 <write@plt>
mov    -0x3c(%rbp),%edi
mov    %r13,%rsi
mov    %ebx,%edx
xor    %ecx,%ecx
xor    %eax,%eax
call   1080 <send@plt>
cmp    %ebx,%eax
je     1580 <main+0x340>
lea    0xa74(%rip),%rdi
jmp    165b <main+0x41b>
lea    0xacf(%rip),%rdi
jmp    15d7 <main+0x397>
lea    0xaaf(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%r15d
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    %r15d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xa11(%rip),%rdi
jmp    165b <main+0x41b>
lea    0xa61(%rip),%rdi
call   1050 <puts@plt>
jmp    15e2 <main+0x3a2>
lea    0xa3f(%rip),%rdi
call   1050 <puts@plt>
mov    (%r12),%edx
xor    %r15d,%r15d
mov    %r14d,%edi
mov    %r13,%rsi
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jle    1654 <main+0x414>
mov    0x0(%r13),%edi
call   1150 <ntohl@plt>
mov    %eax,-0x34(%rbp)
lea    0x9d7(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1090 <printf@plt>
jmp    15e2 <main+0x3a2>
lea    0x9c0(%rip),%rdi
call   1120 <perror@plt>
jmp    15dc <main+0x39c>
lea    0x9e4(%rip),%rdi
call   1120 <perror@plt>
jmp    15e2 <main+0x3a2>
lea    0x9b9(%rip),%rdi
call   1120 <perror@plt>
jmp    15e2 <main+0x3a2>
lea    0x9b7(%rip),%rdi
call   1120 <perror@plt>
jmp    15e2 <main+0x3a2>
lea    0x97c(%rip),%rdi
call   1120 <perror@plt>
jmp    15e2 <main+0x3a2>

LLVM IR (-O0):
%struct.iovec = type { i32, i32* }
%struct.msghdr = type { i8*, i32, i32, %struct.iovec*, i32 }
%struct.cmsghdr = type { i32, i32, i32 }
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@__const.main.iov = %struct.iovec { i32 1, i32* null }
@BUFSIZ = global i32 0
@AF_UNIX = global i32 0
@.str = [3 x i8] c"%s\00"
@SOCK_STREAM = global i32 0
@.str.1 = [8 x i8] c"connect\00"
@.str.2 = [5 x i8] c"recv\00"
@.str.3 = [22 x i8] c"Message has %d bytes\0A\00"
@.str.4 = [19 x i8] c"Message too short\0A\00"
@.str.5 = [21 x i8] c"Message not a Hello\0A\00"
@.str.6 = [24 x i8] c"Protocol version not 4\0A\00"
@.str.7 = [5 x i8] c"send\00"
@.str.8 = [10 x i8] c"localhost\00"
@.str.9 = [11 x i8] c"socketpair\00"
@SOL_SOCKET = global i32 0
@SCM_RIGHTS = global i32 0
@.str.10 = [8 x i8] c"sendmsg\00"
@.str.11 = [27 x i8] c"Forwarding request failed\0A\00"
@.str.12 = [21 x i8] c"Connection finished\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.msghdr
%7 = alloca %struct.cmsghdr*
%8 = alloca [2 x i32]
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i32*
%12 = alloca i32
%13 = alloca i32
%14 = alloca %struct.iovec
%15 = alloca %struct.sockaddr_un
%16 = alloca i64
%17 = alloca i32*
%18 = alloca i32
%19 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%20 = bitcast %struct.msghdr* %6 to i8*
%21 = bitcast [2 x i32]* %8 to i8*
%22 = call i32 @CMSG_SPACE(i32 8)
%23 = zext i32 %22 to i64
%24 = call i8* @llvm.stacksave()
store i8* %24, i8** %9
%25 = alloca i8, i64 %23
store i64 %23, i64* %10
%26 = bitcast %struct.iovec* %14 to i8*
%27 = load i32, i32* @BUFSIZ
%28 = zext i32 %27 to i64
%29 = alloca i8, i64 %28
store i64 %28, i64* %16
%30 = call i32 @memset(%struct.sockaddr_un* %15, i32 0, i32 8)
%31 = load i32, i32* @AF_UNIX
%32 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %15, i32 0, i32 1
store i32 %31, i32* %32
%33 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %15, i32 0, i32 0
%34 = load i32, i32* %33
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 1
%37 = load i8*, i8** %36
%38 = call i32 @snprintf(i32 %34, i32 100, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %37)
%39 = load i32, i32* @AF_UNIX
%40 = load i32, i32* @SOCK_STREAM
%41 = call i32 @socket(i32 %39, i32 %40, i32 0)
store i32 %41, i32* %13
%42 = load i32, i32* %13
%43 = bitcast %struct.sockaddr_un* %15 to %struct.sockaddr*
%44 = call i64 @connect(i32 %42, %struct.sockaddr* %43, i32 8)
%45 = icmp ne i64 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %2
%47 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
store i32 1, i32* %19
br label %263
48: ; preds = %2
%49 = load i32, i32* %13
%50 = bitcast i8* %29 to i8**
%51 = load i32, i32* @BUFSIZ
%52 = call i32 @recv(i32 %49, i8** %50, i32 %51, i32 0)
store i32 %52, i32* %12
%53 = load i32, i32* %12
%54 = icmp slt i32 %53, 0
br i1 %54, label %55, label %57
55: ; preds = %48
%56 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
store i32 1, i32* %19
br label %263
57: ; preds = %48
%58 = bitcast i8* %29 to i32*
store i32* %58, i32** %17
%59 = load i32*, i32** %17
%60 = load i32, i32* %59
%61 = call i32 @ntohl(i32 %60)
store i32 %61, i32* %18
%62 = load i32, i32* %18
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %62)
%64 = load i32, i32* %18
%65 = icmp slt i32 %64, 8
br i1 %65, label %66, label %68
66: ; preds = %57
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %3
store i32 1, i32* %19
br label %263
68: ; preds = %57
%69 = load i32*, i32** %17
%70 = getelementptr inbounds i32, i32* %69, i32 1
store i32* %70, i32** %17
%71 = load i32, i32* %70
%72 = call i32 @ntohl(i32 %71)
store i32 %72, i32* %18
%73 = load i32, i32* %18
%74 = icmp ne i32 %73, 1
br i1 %74, label %75, label %77
75: ; preds = %68
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %3
store i32 1, i32* %19
br label %263
77: ; preds = %68
%78 = load i32*, i32** %17
%79 = getelementptr inbounds i32, i32* %78, i32 1
store i32* %79, i32** %17
%80 = load i32, i32* %79
%81 = call i32 @ntohl(i32 %80)
store i32 %81, i32* %18
%82 = load i32, i32* %18
%83 = icmp ne i32 %82, 4
br i1 %83, label %84, label %86
84: ; preds = %77
%85 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %3
store i32 1, i32* %19
br label %263
86: ; preds = %77
%87 = load i32, i32* %12
%88 = load i32, i32* %13
%89 = load i32, i32* %12
%90 = call i32 (i32, ...) @send(i32 %88, i8* %29, i32 %89, i32 0)
%91 = icmp ne i32 %87, %90
br i1 %91, label %92, label %94
92: ; preds = %86
%93 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
store i32 1, i32* %3
store i32 1, i32* %19
br label %263
94: ; preds = %86
%95 = bitcast i8* %29 to i32*
store i32* %95, i32** %17
%96 = load i32*, i32** %17
%97 = getelementptr inbounds i32, i32* %96, i32 1
store i32* %97, i32** %17
%98 = call i8* @htonl(i32 268435464)
%99 = ptrtoint i8* %98 to i32
%100 = load i32*, i32** %17
%101 = getelementptr inbounds i32, i32* %100, i32 1
store i32* %101, i32** %17
store i32 %99, i32* %100
%102 = call i8* @htonl(i32 1)
%103 = ptrtoint i8* %102 to i32
%104 = load i32*, i32** %17
%105 = getelementptr inbounds i32, i32* %104, i32 1
store i32* %105, i32** %17
store i32 %103, i32* %104
%106 = call i8* @htonl(i32 0)
%107 = ptrtoint i8* %106 to i32
%108 = load i32*, i32** %17
%109 = getelementptr inbounds i32, i32* %108, i32 1
store i32* %109, i32** %17
store i32 %107, i32* %108
%110 = load i32*, i32** %17
%111 = getelementptr inbounds i32, i32* %110, i64 1
%112 = bitcast i32* %111 to i8*
%113 = call i32 @sprintf(i8* %112, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0))
store i32 %113, i32* %18
%114 = load i32, i32* %18
%115 = call i8* @htonl(i32 %114)
%116 = ptrtoint i8* %115 to i32
%117 = load i32*, i32** %17
%118 = getelementptr inbounds i32, i32* %117, i32 1
store i32* %118, i32** %17
store i32 %116, i32* %117
%119 = load i32*, i32** %17
%120 = bitcast i32* %119 to i8*
%121 = load i32, i32* %18
%122 = sext i32 %121 to i64
%123 = getelementptr inbounds i8, i8* %120, i64 %122
%124 = bitcast i8* %123 to i32*
store i32* %124, i32** %17
%125 = call i8* @htonl(i32 5555)
%126 = ptrtoint i8* %125 to i32
%127 = load i32*, i32** %17
%128 = getelementptr inbounds i32, i32* %127, i32 1
store i32* %128, i32** %17
store i32 %126, i32* %127
%129 = load i32*, i32** %17
%130 = bitcast i32* %129 to i8*
%131 = ptrtoint i8* %130 to i64
%132 = ptrtoint i8* %29 to i64
%133 = sub i64 %131, %132
%134 = trunc i64 %133 to i32
store i32 %134, i32* %18
%135 = bitcast i8* %29 to i32*
store i32* %135, i32** %17
%136 = load i32, i32* %18
%137 = sext i32 %136 to i64
%138 = sub i64 %137, 4
%139 = trunc i64 %138 to i32
%140 = call i8* @htonl(i32 %139)
%141 = ptrtoint i8* %140 to i32
%142 = load i32*, i32** %17
store i32 %141, i32* %142
%143 = load i32, i32* %18
%144 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %143)
%145 = load i32, i32* %13
%146 = load i32, i32* %18
%147 = call i32 (i32, ...) @send(i32 %145, i8* %29, i32 %146, i32 0)
%148 = load i32, i32* %18
%149 = icmp ne i32 %147, %148
br i1 %149, label %150, label %152
150: ; preds = %94
%151 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
store i32 1, i32* %3
store i32 1, i32* %19
br label %263
152: ; preds = %94
%153 = load i32, i32* @AF_UNIX
%154 = load i32, i32* @SOCK_STREAM
%155 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 0
%156 = call i64 @socketpair(i32 %153, i32 %154, i32 0, i32* %155)
%157 = icmp ne i64 %156, 0
br i1 %157, label %158, label %160
158: ; preds = %152
%159 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0))
store i32 1, i32* %3
store i32 1, i32* %19
br label %263
160: ; preds = %152
%161 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %6, i32 0, i32 0
store i8* %25, i8** %161
%162 = trunc i64 %23 to i32
%163 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %6, i32 0, i32 1
store i32 %162, i32* %163
%164 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %6, i32 0, i32 2
store i32 1, i32* %164
%165 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %6, i32 0, i32 3
store %struct.iovec* %14, %struct.iovec** %165
store i32 0, i32* %18
%166 = getelementptr inbounds %struct.iovec, %struct.iovec* %14, i32 0, i32 1
store i32* %18, i32** %166
%167 = getelementptr inbounds %struct.iovec, %struct.iovec* %14, i32 0, i32 0
store i32 1, i32* %167
%168 = call %struct.cmsghdr* @CMSG_FIRSTHDR(%struct.msghdr* %6)
store %struct.cmsghdr* %168, %struct.cmsghdr** %7
%169 = load i32, i32* @SOL_SOCKET
%170 = load %struct.cmsghdr*, %struct.cmsghdr** %7
%171 = getelementptr inbounds %struct.cmsghdr, %struct.cmsghdr* %170, i32 0, i32 2
store i32 %169, i32* %171
%172 = load i32, i32* @SCM_RIGHTS
%173 = load %struct.cmsghdr*, %struct.cmsghdr** %7
%174 = getelementptr inbounds %struct.cmsghdr, %struct.cmsghdr* %173, i32 0, i32 1
store i32 %172, i32* %174
%175 = call i32 @CMSG_LEN(i32 4)
%176 = load %struct.cmsghdr*, %struct.cmsghdr** %7
%177 = getelementptr inbounds %struct.cmsghdr, %struct.cmsghdr* %176, i32 0, i32 0
store i32 %175, i32* %177
%178 = load %struct.cmsghdr*, %struct.cmsghdr** %7
%179 = call i64 @CMSG_DATA(%struct.cmsghdr* %178)
%180 = inttoptr i64 %179 to i32*
store i32* %180, i32** %11
%181 = load i32*, i32** %11
%182 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 0
%183 = call i32 @memcpy(i32* %181, i32* %182, i32 4)
%184 = load %struct.cmsghdr*, %struct.cmsghdr** %7
%185 = getelementptr inbounds %struct.cmsghdr, %struct.cmsghdr* %184, i32 0, i32 0
%186 = load i32, i32* %185
%187 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %6, i32 0, i32 1
store i32 %186, i32* %187
%188 = load i32, i32* %13
%189 = call i32 @sendmsg(i32 %188, %struct.msghdr* %6, i32 0)
%190 = icmp ne i32 %189, 1
br i1 %190, label %191, label %193
191: ; preds = %160
%192 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.10, i64 0, i64 0))
store i32 1, i32* %3
store i32 1, i32* %19
br label %263
193: ; preds = %160
%194 = load i32, i32* %13
%195 = call i32 @sendmsg(i32 %194, %struct.msghdr* %6, i32 0)
%196 = icmp ne i32 %195, 1
br i1 %196, label %197, label %199
197: ; preds = %193
%198 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.10, i64 0, i64 0))
store i32 1, i32* %3
store i32 1, i32* %19
br label %263
199: ; preds = %193
%200 = load i32, i32* %13
%201 = bitcast i8* %29 to i8**
%202 = load i32, i32* @BUFSIZ
%203 = call i32 @recv(i32 %200, i8** %201, i32 %202, i32 0)
store i32 %203, i32* %12
%204 = load i32, i32* %12
%205 = icmp sle i32 %204, 0
br i1 %205, label %206, label %208
206: ; preds = %199
%207 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
store i32 1, i32* %19
br label %263
208: ; preds = %199
%209 = bitcast i8* %29 to i32*
store i32* %209, i32** %17
%210 = load i32*, i32** %17
%211 = getelementptr inbounds i32, i32* %210, i32 1
store i32* %211, i32** %17
%212 = load i32, i32* %210
%213 = call i32 @ntohl(i32 %212)
store i32 %213, i32* %18
%214 = load i32, i32* %18
%215 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %214)
%216 = load i32*, i32** %17
%217 = load i32, i32* %216
%218 = call i32 @ntohl(i32 %217)
%219 = icmp ne i32 %218, -2147483642
br i1 %219, label %220, label %222
220: ; preds = %208
%221 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.11, i64 0, i64 0))
store i32 1, i32* %3
store i32 1, i32* %19
br label %263
222: ; preds = %208
%223 = load i32, i32* %13
%224 = call i32 @close(i32 %223)
br label %225
225: ; preds = %244, %222
%226 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 1
%227 = load i32, i32* %226
%228 = bitcast i8* %29 to i8**
%229 = load i32, i32* @BUFSIZ
%230 = call i32 @recv(i32 %227, i8** %228, i32 %229, i32 0)
store i32 %230, i32* %12
%231 = icmp ne i32 %230, 0
br i1 %231, label %232, label %245
232: ; preds = %225
%233 = bitcast i8* %29 to i8**
%234 = load i32, i32* %12
%235 = call i32 @write(i32 1, i8** %233, i32 %234)
%236 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 1
%237 = load i32, i32* %236
%238 = load i32, i32* %12
%239 = call i32 (i32, ...) @send(i32 %237, i8* %29, i32 %238, i32 0)
%240 = load i32, i32* %12
%241 = icmp ne i32 %239, %240
br i1 %241, label %242, label %244
242: ; preds = %232
%243 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
store i32 1, i32* %3
store i32 1, i32* %19
br label %263
244: ; preds = %232
br label %225
245: ; preds = %225
%246 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.12, i64 0, i64 0))
%247 = load i32, i32* %13
%248 = bitcast i8* %29 to i8**
%249 = load i32, i32* @BUFSIZ
%250 = call i32 @recv(i32 %247, i8** %248, i32 %249, i32 0)
store i32 %250, i32* %12
%251 = load i32, i32* %12
%252 = icmp sle i32 %251, 0
br i1 %252, label %253, label %255
253: ; preds = %245
%254 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
store i32 1, i32* %19
br label %263
255: ; preds = %245
%256 = bitcast i8* %29 to i32*
store i32* %256, i32** %17
%257 = load i32*, i32** %17
%258 = getelementptr inbounds i32, i32* %257, i32 1
store i32* %258, i32** %17
%259 = load i32, i32* %257
%260 = call i32 @ntohl(i32 %259)
store i32 %260, i32* %18
%261 = load i32, i32* %18
%262 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %261)
store i32 0, i32* %3
store i32 1, i32* %19
br label %263
263: ; preds = %255, %253, %242, %220, %206, %197, %191, %158, %150, %92, %84, %75, %66, %55, %46
%264 = load i8*, i8** %9
%265 = load i32, i32* %3
ret i32 %265
}

LLVM IR (-O2):
%struct.iovec = type { i32, i32* }
%struct.msghdr = type { i8*, i32, i32, %struct.iovec*, i32 }
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
%struct.cmsghdr = type { i32, i32, i32 }
@__const.main.iov = %struct.iovec { i32 1, i32* null }
@BUFSIZ = global i32 0
@AF_UNIX = global i32 0
@.str = [3 x i8] c"%s\00"
@SOCK_STREAM = global i32 0
@.str.1 = [8 x i8] c"connect\00"
@.str.2 = [5 x i8] c"recv\00"
@.str.3 = [22 x i8] c"Message has %d bytes\0A\00"
@.str.7 = [5 x i8] c"send\00"
@.str.8 = [10 x i8] c"localhost\00"
@.str.9 = [11 x i8] c"socketpair\00"
@SOL_SOCKET = global i32 0
@SCM_RIGHTS = global i32 0
@.str.10 = [8 x i8] c"sendmsg\00"
@str = [20 x i8] c"Connection finished\00"
@str.13 = [26 x i8] c"Forwarding request failed\00"
@str.14 = [23 x i8] c"Protocol version not 4\00"
@str.15 = [20 x i8] c"Message not a Hello\00"
@str.16 = [18 x i8] c"Message too short\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.msghdr
%4 = alloca i64
%5 = bitcast i64* %4 to [2 x i32]*
%6 = alloca %struct.iovec
%7 = alloca %struct.sockaddr_un
%8 = alloca i32
%9 = bitcast %struct.msghdr* %3 to i8*
%10 = bitcast i64* %4 to i8*
store i64 0, i64* %4
%11 = tail call i32 @CMSG_SPACE(i32 8)
%12 = zext i32 %11 to i64
%13 = tail call i8* @llvm.stacksave()
%14 = alloca i8, i64 %12
%15 = bitcast %struct.iovec* %6 to i8*
%16 = bitcast %struct.sockaddr_un* %7 to i8*
%17 = load i32, i32* @BUFSIZ
%18 = zext i32 %17 to i64
%19 = alloca i8, i64 %18
%20 = bitcast i32* %8 to i8*
%21 = call i32 @memset(%struct.sockaddr_un* %7, i32 0, i32 8)
%22 = load i32, i32* @AF_UNIX
%23 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %7, i64 0, i32 1
store i32 %22, i32* %23
%24 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %7, i64 0, i32 0
%25 = load i32, i32* %24
%26 = getelementptr inbounds i8*, i8** %1, i64 1
%27 = load i8*, i8** %26
%28 = call i32 @snprintf(i32 %25, i32 100, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %27)
%29 = load i32, i32* @AF_UNIX
%30 = load i32, i32* @SOCK_STREAM
%31 = call i32 @socket(i32 %29, i32 %30, i32 0)
%32 = bitcast %struct.sockaddr_un* %7 to %struct.sockaddr*
%33 = call i64 @connect(i32 %31, %struct.sockaddr* %32, i32 8)
%34 = icmp eq i64 %33, 0
br i1 %34, label %37, label %35
35: ; preds = %2
%36 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %180
37: ; preds = %2
%38 = bitcast i8* %19 to i8**
%39 = load i32, i32* @BUFSIZ
%40 = call i32 @recv(i32 %31, i8** %38, i32 %39, i32 0)
%41 = icmp slt i32 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %37
%43 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %180
44: ; preds = %37
%45 = bitcast i8* %19 to i32*
%46 = load i32, i32* %45
%47 = call i32 @ntohl(i32 %46)
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %47)
%49 = icmp slt i32 %47, 8
br i1 %49, label %50, label %52
50: ; preds = %44
%51 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.16, i64 0, i64 0))
br label %180
52: ; preds = %44
%53 = getelementptr inbounds i8, i8* %19, i64 4
%54 = bitcast i8* %53 to i32*
%55 = load i32, i32* %54
%56 = call i32 @ntohl(i32 %55)
%57 = icmp eq i32 %56, 1
br i1 %57, label %60, label %58
58: ; preds = %52
%59 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.15, i64 0, i64 0))
br label %180
60: ; preds = %52
%61 = getelementptr inbounds i8, i8* %19, i64 8
%62 = bitcast i8* %61 to i32*
%63 = load i32, i32* %62
%64 = call i32 @ntohl(i32 %63)
store i32 %64, i32* %8
%65 = icmp eq i32 %64, 4
br i1 %65, label %68, label %66
66: ; preds = %60
%67 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.14, i64 0, i64 0))
br label %180
68: ; preds = %60
%69 = call i32 (i32, ...) @send(i32 %31, i8* %19, i32 %40, i32 0)
%70 = icmp eq i32 %40, %69
br i1 %70, label %73, label %71
71: ; preds = %68
%72 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
br label %180
73: ; preds = %68
%74 = call i8* @htonl(i32 268435464)
%75 = ptrtoint i8* %74 to i64
%76 = trunc i64 %75 to i32
store i32 %76, i32* %54
%77 = call i8* @htonl(i32 1)
%78 = ptrtoint i8* %77 to i64
%79 = trunc i64 %78 to i32
%80 = getelementptr inbounds i8, i8* %19, i64 12
%81 = bitcast i8* %80 to i32*
store i32 %79, i32* %62
%82 = call i8* @htonl(i32 0)
%83 = ptrtoint i8* %82 to i64
%84 = trunc i64 %83 to i32
%85 = getelementptr inbounds i8, i8* %19, i64 16
%86 = bitcast i8* %85 to i32*
store i32 %84, i32* %81
%87 = getelementptr inbounds i8, i8* %19, i64 20
%88 = call i8* @htonl(i32 9)
%89 = ptrtoint i8* %88 to i64
%90 = trunc i64 %89 to i32
store i32 %90, i32* %86
%91 = getelementptr inbounds i8, i8* %19, i64 29
%92 = bitcast i8* %91 to i32*
%93 = call i8* @htonl(i32 5555)
%94 = ptrtoint i8* %93 to i64
%95 = trunc i64 %94 to i32
store i32 %95, i32* %92
%96 = call i8* @htonl(i32 29)
%97 = ptrtoint i8* %96 to i64
%98 = trunc i64 %97 to i32
store i32 %98, i32* %45
%99 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 33)
%100 = call i32 (i32, ...) @send(i32 %31, i8* %19, i32 33, i32 0)
%101 = icmp eq i32 %100, 33
br i1 %101, label %104, label %102
102: ; preds = %73
%103 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
br label %180
104: ; preds = %73
%105 = load i32, i32* @AF_UNIX
%106 = load i32, i32* @SOCK_STREAM
%107 = bitcast i64* %4 to i32*
%108 = call i64 @socketpair(i32 %105, i32 %106, i32 0, i32* %107)
%109 = icmp eq i64 %108, 0
br i1 %109, label %112, label %110
110: ; preds = %104
%111 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0))
br label %180
112: ; preds = %104
%113 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %3, i64 0, i32 0
store i8* %14, i8** %113
%114 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %3, i64 0, i32 1
store i32 %11, i32* %114
%115 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %3, i64 0, i32 2
store i32 1, i32* %115
%116 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %3, i64 0, i32 3
store %struct.iovec* %6, %struct.iovec** %116
store i32 0, i32* %8
%117 = getelementptr inbounds %struct.iovec, %struct.iovec* %6, i64 0, i32 1
store i32* %8, i32** %117
%118 = getelementptr inbounds %struct.iovec, %struct.iovec* %6, i64 0, i32 0
store i32 1, i32* %118
%119 = call %struct.cmsghdr* @CMSG_FIRSTHDR(%struct.msghdr* %3)
%120 = load i32, i32* @SOL_SOCKET
%121 = getelementptr inbounds %struct.cmsghdr, %struct.cmsghdr* %119, i64 0, i32 2
store i32 %120, i32* %121
%122 = load i32, i32* @SCM_RIGHTS
%123 = getelementptr inbounds %struct.cmsghdr, %struct.cmsghdr* %119, i64 0, i32 1
store i32 %122, i32* %123
%124 = call i32 @CMSG_LEN(i32 4)
%125 = getelementptr inbounds %struct.cmsghdr, %struct.cmsghdr* %119, i64 0, i32 0
store i32 %124, i32* %125
%126 = call i64 @CMSG_DATA(%struct.cmsghdr* %119)
%127 = inttoptr i64 %126 to i32*
%128 = call i32 @memcpy(i32* %127, i32* %107, i32 4)
%129 = load i32, i32* %125
store i32 %129, i32* %114
%130 = call i32 @sendmsg(i32 %31, %struct.msghdr* %3, i32 0)
%131 = icmp eq i32 %130, 1
br i1 %131, label %134, label %132
132: ; preds = %112
%133 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.10, i64 0, i64 0))
br label %180
134: ; preds = %112
%135 = call i32 @sendmsg(i32 %31, %struct.msghdr* %3, i32 0)
%136 = icmp eq i32 %135, 1
br i1 %136, label %139, label %137
137: ; preds = %134
%138 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.10, i64 0, i64 0))
br label %180
139: ; preds = %134
%140 = load i32, i32* @BUFSIZ
%141 = call i32 @recv(i32 %31, i8** %38, i32 %140, i32 0)
%142 = icmp slt i32 %141, 1
br i1 %142, label %143, label %145
143: ; preds = %139
%144 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %180
145: ; preds = %139
%146 = load i32, i32* %45
%147 = call i32 @ntohl(i32 %146)
store i32 %147, i32* %8
%148 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %147)
%149 = load i32, i32* %54
%150 = call i32 @ntohl(i32 %149)
%151 = icmp eq i32 %150, -2147483642
br i1 %151, label %154, label %152
152: ; preds = %145
%153 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.13, i64 0, i64 0))
br label %180
154: ; preds = %145
%155 = call i32 @close(i32 %31)
%156 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
br label %157
157: ; preds = %162, %154
%158 = load i32, i32* %156
%159 = load i32, i32* @BUFSIZ
%160 = call i32 @recv(i32 %158, i8** %38, i32 %159, i32 0)
%161 = icmp eq i32 %160, 0
br i1 %161, label %169, label %162
162: ; preds = %157
%163 = call i32 @write(i32 1, i8** %38, i32 %160)
%164 = load i32, i32* %156
%165 = call i32 (i32, ...) @send(i32 %164, i8* %19, i32 %160, i32 0)
%166 = icmp eq i32 %165, %160
br i1 %166, label %157, label %167
167: ; preds = %162
%168 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
br label %180
169: ; preds = %157
%170 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%171 = load i32, i32* @BUFSIZ
%172 = call i32 @recv(i32 %31, i8** %38, i32 %171, i32 0)
%173 = icmp slt i32 %172, 1
br i1 %173, label %174, label %176
174: ; preds = %169
%175 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %180
176: ; preds = %169
%177 = load i32, i32* %45
%178 = call i32 @ntohl(i32 %177)
store i32 %178, i32* %8
%179 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %178)
br label %180
180: ; preds = %176, %174, %167, %152, %143, %137, %132, %110, %102, %71, %66, %58, %50, %42, %35
%181 = phi i32 [ 1, %35 ], [ 1, %42 ], [ 1, %50 ], [ 1, %58 ], [ 1, %66 ], [ 1, %71 ], [ 1, %102 ], [ 1, %110 ], [ 1, %132 ], [ 1, %137 ], [ 1, %143 ], [ 1, %152 ], [ 1, %167 ], [ 1, %174 ], [ 0, %176 ]
ret i32 %181
}