#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 scalar_t__ pid_t;

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ MSG_DONTROUTE;
int /*<<< orphan*/ MSG_WAITALL;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ assert(int const);
scalar_t__ close(int);
scalar_t__ fork();
int const recvfrom(int, char *, int const, int /*<<< orphan*/,
                   int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int const sendto(int, char *, int const, int /*<<< orphan*/,
                 int /*<<< orphan*/ *, int /*<<< orphan*/);
scalar_t__ socketpair(int /*<<< orphan*/, int /*<<< orphan*/,
                      int /*<<< orphan*/, int *);
int strlen(char *);
int /*<<< orphan*/ transpose(char *, int const);
scalar_t__ waitpid(scalar_t__, int *, int /*<<< orphan*/);
int main(int ac, char **av) {
  assert(ac == 2);
  const int len = strlen(av[1]);
  assert(len);
  (void)close(0);
  (void)close(1);
  int sv[2];
  assert(socketpair(AF_UNIX, SOCK_STREAM, 0, sv) == 0);
  assert(sv[0] == 0);
  assert(sv[1] == 1);
  pid_t pid = fork();
  assert(pid >= 0);
  if (pid) {
    assert(close(1) == 0);
    transpose(av[1], len);
    assert(sendto(0, av[1], len, MSG_DONTROUTE, NULL, 0) == len);
    assert(recvfrom(0, av[1], len, MSG_WAITALL, NULL, NULL) == len);
    assert(close(0) == 0);
    int status;
    assert(waitpid(pid, &status, 0) == pid);
    assert(status == 0);
  } else {
    assert(close(0) == 0);
    assert(recvfrom(1, av[1], len, MSG_WAITALL, NULL, NULL) == len);
    transpose(av[1], len);
    assert(sendto(1, av[1], len, MSG_DONTROUTE, NULL, 0) == len);
    assert(recvfrom(1, av[1], len, MSG_WAITALL, NULL, NULL) == 0);
    assert(close(1) == 0);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1060 <assert@plt>
xor    %edi,%edi
call   1050 <close@plt>
mov    $0x1,%edi
call   1050 <close@plt>
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
mov    0x2de0(%rip),%rax
mov    (%rax),%esi
lea    -0x1c(%rbp),%rcx
xor    %edx,%edx
call   1080 <socketpair@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
cmpl   $0x0,-0x1c(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
cmpl   $0x1,-0x18(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    $0x0,%al
call   10b0 <fork@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
cmpq   $0x0,-0x28(%rbp)
je     1338 <main+0x1a8>
mov    $0x1,%edi
call   1050 <close@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x14(%rbp),%esi
call   1070 <transpose@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x14(%rbp),%edx
mov    0x2d4b(%rip),%rax
mov    (%rax),%ecx
xor    %r9d,%r9d
xor    %eax,%eax
mov    %eax,%r8d
mov    %r9d,%edi
call   1040 <sendto@plt>
cmp    -0x14(%rbp),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x14(%rbp),%edx
mov    0x2cf7(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
xor    %eax,%eax
mov    %eax,%r9d
mov    %r9,%r8
call   1090 <recvfrom@plt>
cmp    -0x14(%rbp),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
xor    %edi,%edi
call   1050 <close@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x28(%rbp),%rdi
lea    -0x2c(%rbp),%rsi
xor    %edx,%edx
call   10a0 <waitpid@plt>
cmp    -0x28(%rbp),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
cmpl   $0x0,-0x2c(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
jmp    141d <main+0x28d>
xor    %edi,%edi
call   1050 <close@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x14(%rbp),%edx
mov    0x2c5e(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%edi
xor    %eax,%eax
mov    %eax,%r9d
mov    %r9,%r8
call   1090 <recvfrom@plt>
cmp    -0x14(%rbp),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x14(%rbp),%esi
call   1070 <transpose@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x14(%rbp),%edx
mov    0x2c38(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%edi
xor    %eax,%eax
mov    %eax,%r8d
xor    %r9d,%r9d
call   1040 <sendto@plt>
cmp    -0x14(%rbp),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x14(%rbp),%edx
mov    0x2be2(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%edi
xor    %eax,%eax
mov    %eax,%r9d
mov    %r9,%r8
call   1090 <recvfrom@plt>
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    $0x1,%edi
call   1050 <close@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
xor    %eax,%eax
cmp    $0x2,%edi
sete   %al
mov    %eax,%edi
call   1060 <assert@plt>
mov    0x8(%r14),%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1060 <assert@plt>
xor    %edi,%edi
call   1050 <close@plt>
mov    $0x1,%edi
call   1050 <close@plt>
mov    0x2e14(%rip),%rax
mov    (%rax),%edi
mov    0x2df3(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rcx
xor    %edx,%edx
call   1080 <socketpair@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1060 <assert@plt>
xor    %edi,%edi
cmpl   $0x0,0x8(%rsp)
sete   %dil
call   1060 <assert@plt>
xor    %edi,%edi
cmpl   $0x1,0xc(%rsp)
sete   %dil
call   1060 <assert@plt>
xor    %eax,%eax
call   10b0 <fork@plt>
mov    %rax,%rbx
mov    %rax,%rdi
shr    $0x3f,%rdi
xor    $0x1,%edi
call   1060 <assert@plt>
test   %rbx,%rbx
je     12ee <main+0x15e>
mov    $0x1,%edi
call   1050 <close@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1060 <assert@plt>
mov    0x8(%r14),%rdi
mov    %ebp,%esi
call   1070 <transpose@plt>
mov    0x8(%r14),%rsi
mov    0x2d77(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    %ebp,%edx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1040 <sendto@plt>
xor    %edi,%edi
cmp    %ebp,%eax
sete   %dil
call   1060 <assert@plt>
mov    0x8(%r14),%rsi
mov    0x2d2e(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    %ebp,%edx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1090 <recvfrom@plt>
xor    %edi,%edi
cmp    %ebp,%eax
sete   %dil
call   1060 <assert@plt>
xor    %edi,%edi
call   1050 <close@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1060 <assert@plt>
lea    0x4(%rsp),%rsi
mov    %rbx,%rdi
xor    %edx,%edx
call   10a0 <waitpid@plt>
xor    %edi,%edi
cmp    %rbx,%rax
sete   %dil
call   1060 <assert@plt>
xor    %edi,%edi
cmpl   $0x0,0x4(%rsp)
jmp    139a <main+0x20a>
xor    %edi,%edi
call   1050 <close@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1060 <assert@plt>
mov    0x8(%r14),%rsi
mov    0x2cb2(%rip),%rbx
mov    (%rbx),%ecx
mov    $0x1,%edi
mov    %ebp,%edx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1090 <recvfrom@plt>
xor    %edi,%edi
cmp    %ebp,%eax
sete   %dil
call   1060 <assert@plt>
mov    0x8(%r14),%rdi
mov    %ebp,%esi
call   1070 <transpose@plt>
mov    0x8(%r14),%rsi
mov    0x2c9b(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%edi
mov    %ebp,%edx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1040 <sendto@plt>
xor    %edi,%edi
cmp    %ebp,%eax
sete   %dil
call   1060 <assert@plt>
mov    0x8(%r14),%rsi
mov    (%rbx),%ecx
mov    $0x1,%edi
mov    %ebp,%edx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1090 <recvfrom@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1060 <assert@plt>
mov    $0x1,%edi
call   1050 <close@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1060 <assert@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@MSG_DONTROUTE = global i32 0
@MSG_WAITALL = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [2 x i32]
%8 = alloca i64
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp eq i32 %10, 2
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i32 @strlen(i8* %16)
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = call i32 @assert(i32 %18)
%20 = call i64 @close(i32 0)
%21 = call i64 @close(i32 1)
%22 = load i32, i32* @AF_UNIX
%23 = load i32, i32* @SOCK_STREAM
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%25 = call i64 @socketpair(i32 %22, i32 %23, i32 0, i32* %24)
%26 = icmp eq i64 %25, 0
%27 = zext i1 %26 to i32
%28 = call i32 @assert(i32 %27)
%29 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%30 = load i32, i32* %29
%31 = icmp eq i32 %30, 0
%32 = zext i1 %31 to i32
%33 = call i32 @assert(i32 %32)
%34 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%35 = load i32, i32* %34
%36 = icmp eq i32 %35, 1
%37 = zext i1 %36 to i32
%38 = call i32 @assert(i32 %37)
%39 = call i64 (...) @fork()
store i64 %39, i64* %8
%40 = load i64, i64* %8
%41 = icmp sge i64 %40, 0
%42 = zext i1 %41 to i32
%43 = call i32 @assert(i32 %42)
%44 = load i64, i64* %8
%45 = icmp ne i64 %44, 0
br i1 %45, label %46, label %90
46: ; preds = %2
%47 = call i64 @close(i32 1)
%48 = icmp eq i64 %47, 0
%49 = zext i1 %48 to i32
%50 = call i32 @assert(i32 %49)
%51 = load i8**, i8*** %5
%52 = getelementptr inbounds i8*, i8** %51, i64 1
%53 = load i8*, i8** %52
%54 = load i32, i32* %6
%55 = call i32 @transpose(i8* %53, i32 %54)
%56 = load i8**, i8*** %5
%57 = getelementptr inbounds i8*, i8** %56, i64 1
%58 = load i8*, i8** %57
%59 = load i32, i32* %6
%60 = load i32, i32* @MSG_DONTROUTE
%61 = call i32 @sendto(i32 0, i8* %58, i32 %59, i32 %60, i32* null, i32 0)
%62 = load i32, i32* %6
%63 = icmp eq i32 %61, %62
%64 = zext i1 %63 to i32
%65 = call i32 @assert(i32 %64)
%66 = load i8**, i8*** %5
%67 = getelementptr inbounds i8*, i8** %66, i64 1
%68 = load i8*, i8** %67
%69 = load i32, i32* %6
%70 = load i32, i32* @MSG_WAITALL
%71 = call i32 @recvfrom(i32 0, i8* %68, i32 %69, i32 %70, i32* null, i32* null)
%72 = load i32, i32* %6
%73 = icmp eq i32 %71, %72
%74 = zext i1 %73 to i32
%75 = call i32 @assert(i32 %74)
%76 = call i64 @close(i32 0)
%77 = icmp eq i64 %76, 0
%78 = zext i1 %77 to i32
%79 = call i32 @assert(i32 %78)
%80 = load i64, i64* %8
%81 = call i64 @waitpid(i64 %80, i32* %9, i32 0)
%82 = load i64, i64* %8
%83 = icmp eq i64 %81, %82
%84 = zext i1 %83 to i32
%85 = call i32 @assert(i32 %84)
%86 = load i32, i32* %9
%87 = icmp eq i32 %86, 0
%88 = zext i1 %87 to i32
%89 = call i32 @assert(i32 %88)
br label %133
90: ; preds = %2
%91 = call i64 @close(i32 0)
%92 = icmp eq i64 %91, 0
%93 = zext i1 %92 to i32
%94 = call i32 @assert(i32 %93)
%95 = load i8**, i8*** %5
%96 = getelementptr inbounds i8*, i8** %95, i64 1
%97 = load i8*, i8** %96
%98 = load i32, i32* %6
%99 = load i32, i32* @MSG_WAITALL
%100 = call i32 @recvfrom(i32 1, i8* %97, i32 %98, i32 %99, i32* null, i32* null)
%101 = load i32, i32* %6
%102 = icmp eq i32 %100, %101
%103 = zext i1 %102 to i32
%104 = call i32 @assert(i32 %103)
%105 = load i8**, i8*** %5
%106 = getelementptr inbounds i8*, i8** %105, i64 1
%107 = load i8*, i8** %106
%108 = load i32, i32* %6
%109 = call i32 @transpose(i8* %107, i32 %108)
%110 = load i8**, i8*** %5
%111 = getelementptr inbounds i8*, i8** %110, i64 1
%112 = load i8*, i8** %111
%113 = load i32, i32* %6
%114 = load i32, i32* @MSG_DONTROUTE
%115 = call i32 @sendto(i32 1, i8* %112, i32 %113, i32 %114, i32* null, i32 0)
%116 = load i32, i32* %6
%117 = icmp eq i32 %115, %116
%118 = zext i1 %117 to i32
%119 = call i32 @assert(i32 %118)
%120 = load i8**, i8*** %5
%121 = getelementptr inbounds i8*, i8** %120, i64 1
%122 = load i8*, i8** %121
%123 = load i32, i32* %6
%124 = load i32, i32* @MSG_WAITALL
%125 = call i32 @recvfrom(i32 1, i8* %122, i32 %123, i32 %124, i32* null, i32* null)
%126 = icmp eq i32 %125, 0
%127 = zext i1 %126 to i32
%128 = call i32 @assert(i32 %127)
%129 = call i64 @close(i32 1)
%130 = icmp eq i64 %129, 0
%131 = zext i1 %130 to i32
%132 = call i32 @assert(i32 %131)
br label %133
133: ; preds = %90, %46
ret i32 0
}

LLVM IR (-O2):
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@MSG_DONTROUTE = global i32 0
@MSG_WAITALL = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [2 x i32]
%4 = alloca i32
%5 = icmp eq i32 %0, 2
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @strlen(i8* %9)
%11 = tail call i32 @assert(i32 %10)
%12 = tail call i64 @close(i32 0)
%13 = tail call i64 @close(i32 1)
%14 = bitcast [2 x i32]* %3 to i8*
%15 = load i32, i32* @AF_UNIX
%16 = load i32, i32* @SOCK_STREAM
%17 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%18 = call i64 @socketpair(i32 %15, i32 %16, i32 0, i32* %17)
%19 = icmp eq i64 %18, 0
%20 = zext i1 %19 to i32
%21 = call i32 @assert(i32 %20)
%22 = load i32, i32* %17
%23 = icmp eq i32 %22, 0
%24 = zext i1 %23 to i32
%25 = call i32 @assert(i32 %24)
%26 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%27 = load i32, i32* %26
%28 = icmp eq i32 %27, 1
%29 = zext i1 %28 to i32
%30 = call i32 @assert(i32 %29)
%31 = call i64 (...) @fork()
%32 = lshr i64 %31, 63
%33 = trunc i64 %32 to i32
%34 = xor i32 %33, 1
%35 = call i32 @assert(i32 %34)
%36 = icmp eq i64 %31, 0
br i1 %36, label %69, label %37
37: ; preds = %2
%38 = call i64 @close(i32 1)
%39 = icmp eq i64 %38, 0
%40 = zext i1 %39 to i32
%41 = call i32 @assert(i32 %40)
%42 = load i8*, i8** %8
%43 = call i32 @transpose(i8* %42, i32 %10)
%44 = load i8*, i8** %8
%45 = load i32, i32* @MSG_DONTROUTE
%46 = call i32 @sendto(i32 0, i8* %44, i32 %10, i32 %45, i32* null, i32 0)
%47 = icmp eq i32 %46, %10
%48 = zext i1 %47 to i32
%49 = call i32 @assert(i32 %48)
%50 = load i8*, i8** %8
%51 = load i32, i32* @MSG_WAITALL
%52 = call i32 @recvfrom(i32 0, i8* %50, i32 %10, i32 %51, i32* null, i32* null)
%53 = icmp eq i32 %52, %10
%54 = zext i1 %53 to i32
%55 = call i32 @assert(i32 %54)
%56 = call i64 @close(i32 0)
%57 = icmp eq i64 %56, 0
%58 = zext i1 %57 to i32
%59 = call i32 @assert(i32 %58)
%60 = bitcast i32* %4 to i8*
%61 = call i64 @waitpid(i64 %31, i32* %4, i32 0)
%62 = icmp eq i64 %61, %31
%63 = zext i1 %62 to i32
%64 = call i32 @assert(i32 %63)
%65 = load i32, i32* %4
%66 = icmp eq i32 %65, 0
%67 = zext i1 %66 to i32
%68 = call i32 @assert(i32 %67)
br label %98
69: ; preds = %2
%70 = call i64 @close(i32 0)
%71 = icmp eq i64 %70, 0
%72 = zext i1 %71 to i32
%73 = call i32 @assert(i32 %72)
%74 = load i8*, i8** %8
%75 = load i32, i32* @MSG_WAITALL
%76 = call i32 @recvfrom(i32 1, i8* %74, i32 %10, i32 %75, i32* null, i32* null)
%77 = icmp eq i32 %76, %10
%78 = zext i1 %77 to i32
%79 = call i32 @assert(i32 %78)
%80 = load i8*, i8** %8
%81 = call i32 @transpose(i8* %80, i32 %10)
%82 = load i8*, i8** %8
%83 = load i32, i32* @MSG_DONTROUTE
%84 = call i32 @sendto(i32 1, i8* %82, i32 %10, i32 %83, i32* null, i32 0)
%85 = icmp eq i32 %84, %10
%86 = zext i1 %85 to i32
%87 = call i32 @assert(i32 %86)
%88 = load i8*, i8** %8
%89 = load i32, i32* @MSG_WAITALL
%90 = call i32 @recvfrom(i32 1, i8* %88, i32 %10, i32 %89, i32* null, i32* null)
%91 = icmp eq i32 %90, 0
%92 = zext i1 %91 to i32
%93 = call i32 @assert(i32 %92)
%94 = call i64 @close(i32 1)
%95 = icmp eq i64 %94, 0
%96 = zext i1 %95 to i32
%97 = call i32 @assert(i32 %96)
br label %98
98: ; preds = %69, %37
ret i32 0
}