#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ sync;

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ assert(int);
int atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fork();
int /*<<< orphan*/ free(int *);
int /*<<< orphan*/ internal_recv(int, ...);
int /*<<< orphan*/ internal_send(int, void *, int);
double log_perf(char *, ...);
int *malloc(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, double);
int socketpair(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/,
               int *);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  int size, length, i;
  int *data;
  int *target;
  char sync[10];
  int fds[2];
  double bs, as, br, ar;
  if (argc > 1) {
    size = atoi(argv[1]);
    length = size / sizeof(int);
    size = sizeof(int) * length;
  } else
    exit(1);
  int block_size = size;
  if (argc > 2) {
    block_size = atoi(argv[2]);
  }
  if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds) == -1) {
    perror("socketpair");
    exit(1);
  }
  log_perf("before init, size=%d", size);
  data = malloc(size);
  for (i = 0; i < length; i++)
    data[i] = i;
  log_perf("after init");
  if (!fork()) {
    free(data);
    target = malloc(size);
    internal_send(fds[1], &sync, sizeof(char));
    br = log_perf("start read");
    int count = 0;
    while (count < size) {
      int copy_size = (size - count) > block_size ? block_size : (size - count);
      internal_recv(fds[1], ((void *)target) + count, copy_size);
      internal_send(fds[1], &sync, sizeof(sync));
      count += copy_size;
    }
    ar = log_perf("done read");
    internal_send(fds[1], &br, sizeof(double));
    internal_send(fds[1], &ar, sizeof(double));
    for (i = 0; i < length; i++)
      assert(target[i] == i);
  } else {
    internal_recv(fds[0], &sync, sizeof(char));
    bs = log_perf("start write");
    int count = 0;
    while (count < size) {
      int copy_size = (size - count) > block_size ? block_size : (size - count);
      internal_send(fds[0], ((void *)data) + count, copy_size);
      internal_recv(fds[0], &sync, sizeof(sync));
      count += copy_size;
    }
    as = log_perf("done write");
    internal_recv(fds[0], &br, sizeof(double));
    internal_recv(fds[0], &ar, sizeof(double));
    printf("TIME: %f\n",
           (((as) > (ar)) ? (as) : (ar)) - (((bs) < (br)) ? (bs) : (br)));
    wait(NULL);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    121e <main+0x4e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x14(%rbp)
movslq -0x14(%rbp),%rax
shr    $0x2,%rax
mov    %eax,-0x18(%rbp)
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
mov    %eax,-0x14(%rbp)
jmp    1228 <main+0x58>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x6c(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    1248 <main+0x78>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x6c(%rbp)
mov    0x2d99(%rip),%rax
mov    (%rax),%edi
mov    0x2d80(%rip),%rax
mov    (%rax),%esi
lea    -0x44(%rbp),%rcx
xor    %edx,%edx
call   1060 <socketpair@plt>
cmp    $0xffffffff,%eax
jne    1284 <main+0xb4>
lea    0xd8b(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x14(%rbp),%esi
lea    0xd7d(%rip),%rdi
mov    $0x0,%al
call   1090 <log_perf@plt>
mov    -0x14(%rbp),%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    12d0 <main+0x100>
mov    -0x1c(%rbp),%edx
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    12a8 <main+0xd8>
lea    0xd49(%rip),%rdi
mov    $0x0,%al
call   1090 <log_perf@plt>
mov    $0x0,%al
call   10e0 <fork@plt>
cmp    $0x0,%eax
jne    1410 <main+0x240>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x14(%rbp),%edi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x40(%rbp),%edi
lea    -0x3a(%rbp),%rsi
mov    $0x1,%edx
call   10f0 <internal_send@plt>
lea    0xd10(%rip),%rdi
mov    $0x0,%al
call   1090 <log_perf@plt>
movsd  %xmm0,-0x60(%rbp)
movl   $0x0,-0x70(%rbp)
mov    -0x70(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    139a <main+0x1ca>
mov    -0x14(%rbp),%eax
sub    -0x70(%rbp),%eax
cmp    -0x6c(%rbp),%eax
jle    1354 <main+0x184>
mov    -0x6c(%rbp),%eax
mov    %eax,-0x80(%rbp)
jmp    135d <main+0x18d>
mov    -0x14(%rbp),%eax
sub    -0x70(%rbp),%eax
mov    %eax,-0x80(%rbp)
mov    -0x80(%rbp),%eax
mov    %eax,-0x74(%rbp)
mov    -0x40(%rbp),%edi
mov    -0x30(%rbp),%rsi
movslq -0x70(%rbp),%rax
add    %rax,%rsi
mov    -0x74(%rbp),%edx
mov    $0x0,%al
call   1080 <internal_recv@plt>
mov    -0x40(%rbp),%edi
lea    -0x3a(%rbp),%rsi
mov    $0xa,%edx
call   10f0 <internal_send@plt>
mov    -0x74(%rbp),%eax
add    -0x70(%rbp),%eax
mov    %eax,-0x70(%rbp)
jmp    132e <main+0x15e>
lea    0xc95(%rip),%rdi
mov    $0x0,%al
call   1090 <log_perf@plt>
movsd  %xmm0,-0x68(%rbp)
mov    -0x40(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    $0x8,%edx
call   10f0 <internal_send@plt>
mov    -0x40(%rbp),%edi
lea    -0x68(%rbp),%rsi
mov    $0x8,%edx
call   10f0 <internal_send@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    140b <main+0x23b>
mov    -0x30(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x1c(%rbp),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    13d6 <main+0x206>
jmp    1586 <main+0x3b6>
mov    -0x44(%rbp),%edi
lea    -0x3a(%rbp),%rsi
mov    $0x1,%edx
mov    $0x0,%al
call   1080 <internal_recv@plt>
lea    0xc16(%rip),%rdi
mov    $0x0,%al
call   1090 <log_perf@plt>
movsd  %xmm0,-0x50(%rbp)
movl   $0x0,-0x78(%rbp)
mov    -0x78(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    14b2 <main+0x2e2>
mov    -0x14(%rbp),%eax
sub    -0x78(%rbp),%eax
cmp    -0x6c(%rbp),%eax
jle    1466 <main+0x296>
mov    -0x6c(%rbp),%eax
mov    %eax,-0x84(%rbp)
jmp    1472 <main+0x2a2>
mov    -0x14(%rbp),%eax
sub    -0x78(%rbp),%eax
mov    %eax,-0x84(%rbp)
mov    -0x84(%rbp),%eax
mov    %eax,-0x7c(%rbp)
mov    -0x44(%rbp),%edi
mov    -0x28(%rbp),%rsi
movslq -0x78(%rbp),%rax
add    %rax,%rsi
mov    -0x7c(%rbp),%edx
call   10f0 <internal_send@plt>
mov    -0x44(%rbp),%edi
lea    -0x3a(%rbp),%rsi
mov    $0xa,%edx
mov    $0x0,%al
call   1080 <internal_recv@plt>
mov    -0x7c(%rbp),%eax
add    -0x78(%rbp),%eax
mov    %eax,-0x78(%rbp)
jmp    143d <main+0x26d>
lea    0xb93(%rip),%rdi
mov    $0x0,%al
call   1090 <log_perf@plt>
movsd  %xmm0,-0x58(%rbp)
mov    -0x44(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    $0x8,%edx
mov    $0x0,%al
call   1080 <internal_recv@plt>
mov    -0x44(%rbp),%edi
lea    -0x68(%rbp),%rsi
mov    $0x8,%edx
mov    $0x0,%al
call   1080 <internal_recv@plt>
movsd  -0x58(%rbp),%xmm0
ucomisd -0x68(%rbp),%xmm0
jbe    150d <main+0x33d>
movsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
jmp    151a <main+0x34a>
movsd  -0x68(%rbp),%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
movsd  -0x90(%rbp),%xmm0
ff
movsd  %xmm0,-0x98(%rbp)
ff
movsd  -0x50(%rbp),%xmm1
movsd  -0x60(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1550 <main+0x380>
movsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0xa0(%rbp)
ff
jmp    155d <main+0x38d>
movsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0xa0(%rbp)
ff
movsd  -0x98(%rbp),%xmm0
ff
movsd  -0xa0(%rbp),%xmm1
ff
subsd  %xmm1,%xmm0
lea    0xadf(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10d0 <wait@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
cmp    $0x2,%edi
jl     15fc <main+0x42c>
mov    %rsi,%r12
mov    %edi,%ebp
mov    0x8(%rsi),%rdi
call   10b0 <atoi@plt>
mov    %eax,%ebx
mov    %eax,%r13d
and    $0xfffffffc,%r13d
mov    %r13d,%r15d
cmp    $0x2,%ebp
je     1213 <main+0x43>
mov    0x10(%r12),%rdi
call   10b0 <atoi@plt>
mov    %eax,%r15d
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
mov    0x2db5(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rcx
xor    %edx,%edx
call   1060 <socketpair@plt>
cmp    $0xffffffff,%eax
je     1606 <main+0x436>
mov    %ebx,%ebp
sar    $0x2,%ebp
lea    0xe57(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1090 <log_perf@plt>
mov    %r13d,%edi
call   1070 <malloc@plt>
mov    %rax,%r12
cmp    $0x4,%ebx
jl     13ed <main+0x21d>
cmp    $0x2,%ebp
mov    $0x1,%eax
cmovge %ebp,%eax
cmp    $0x8,%eax
jae    1279 <main+0xa9>
xor    %ecx,%ecx
jmp    13e0 <main+0x210>
mov    %eax,%ecx
and    $0x7ffffff8,%ecx
lea    -0x8(%rcx),%rdi
mov    %rdi,%rsi
shr    $0x3,%rsi
add    $0x1,%rsi
mov    %esi,%edx
and    $0x3,%edx
cmp    $0x18,%rdi
jae    12aa <main+0xda>
movdqa 0xd5d(%rip),%xmm0
xor    %edi,%edi
jmp    1380 <main+0x1b0>
and    $0xfffffffffffffffc,%rsi
movdqa 0xd4a(%rip),%xmm0
xor    %edi,%edi
movdqa 0xd4f(%rip),%xmm8
movdqa 0xd56(%rip),%xmm9
movdqa 0xd5d(%rip),%xmm10
movdqa 0xd65(%rip),%xmm4
movdqa 0xd6d(%rip),%xmm5
movdqa 0xd75(%rip),%xmm6
movdqa 0xd7d(%rip),%xmm7
movdqa 0xd85(%rip),%xmm1
nopl   0x0(%rax,%rax,1)
movdqa %xmm0,%xmm2
paddd  %xmm8,%xmm2
movdqu %xmm0,(%r12,%rdi,4)
movdqu %xmm2,0x10(%r12,%rdi,4)
movdqa %xmm0,%xmm2
paddd  %xmm9,%xmm2
movdqa %xmm0,%xmm3
paddd  %xmm10,%xmm3
movdqu %xmm2,0x20(%r12,%rdi,4)
movdqu %xmm3,0x30(%r12,%rdi,4)
movdqa %xmm0,%xmm2
paddd  %xmm4,%xmm2
movdqa %xmm0,%xmm3
paddd  %xmm5,%xmm3
movdqu %xmm2,0x40(%r12,%rdi,4)
movdqu %xmm3,0x50(%r12,%rdi,4)
movdqa %xmm0,%xmm2
paddd  %xmm6,%xmm2
movdqa %xmm0,%xmm3
paddd  %xmm7,%xmm3
movdqu %xmm2,0x60(%r12,%rdi,4)
movdqu %xmm3,0x70(%r12,%rdi,4)
add    $0x20,%rdi
paddd  %xmm1,%xmm0
add    $0xfffffffffffffffc,%rsi
jne    1300 <main+0x130>
test   %rdx,%rdx
je     13d0 <main+0x200>
lea    (%r12,%rdi,4),%rsi
add    $0x10,%rsi
shl    $0x5,%rdx
xor    %edi,%edi
movdqa 0xc75(%rip),%xmm1
movdqa 0xc7d(%rip),%xmm2
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movdqa %xmm0,%xmm3
paddd  %xmm1,%xmm3
movdqu %xmm0,-0x10(%rsi,%rdi,1)
movdqu %xmm3,(%rsi,%rdi,1)
paddd  %xmm2,%xmm0
add    $0x20,%rdi
cmp    %rdi,%rdx
jne    13b0 <main+0x1e0>
cmp    %rax,%rcx
je     13ed <main+0x21d>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ecx,(%r12,%rcx,4)
add    $0x1,%rcx
cmp    %rcx,%rax
jne    13e0 <main+0x210>
lea    0xcbc(%rip),%rdi
xor    %eax,%eax
call   1090 <log_perf@plt>
xor    %eax,%eax
call   10e0 <fork@plt>
test   %eax,%eax
je     14ea <main+0x31a>
mov    (%rsp),%edi
lea    0x2e(%rsp),%rsi
mov    $0x1,%edx
xor    %eax,%eax
call   1080 <internal_recv@plt>
lea    0xcab(%rip),%rdi
xor    %eax,%eax
call   1090 <log_perf@plt>
movq   %xmm0,0x10(%rsp)
test   %r13d,%r13d
jle    1476 <main+0x2a6>
lea    0x2e(%rsp),%r14
xor    %ebp,%ebp
xchg   %ax,%ax
mov    %r13d,%ebx
sub    %ebp,%ebx
cmp    %r15d,%ebx
cmovg  %r15d,%ebx
mov    (%rsp),%edi
movslq %ebp,%rbp
lea    (%r12,%rbp,1),%rsi
mov    %ebx,%edx
call   10f0 <internal_send@plt>
mov    (%rsp),%edi
mov    $0xa,%edx
mov    %r14,%rsi
xor    %eax,%eax
call   1080 <internal_recv@plt>
add    %ebx,%ebp
cmp    %ebp,%r13d
jg     1440 <main+0x270>
lea    0xc5f(%rip),%rdi
xor    %eax,%eax
call   1090 <log_perf@plt>
movq   %xmm0,0x8(%rsp)
mov    (%rsp),%edi
lea    0x20(%rsp),%rsi
mov    $0x8,%edx
xor    %eax,%eax
call   1080 <internal_recv@plt>
mov    (%rsp),%edi
lea    0x18(%rsp),%rsi
mov    $0x8,%edx
xor    %eax,%eax
call   1080 <internal_recv@plt>
movsd  0x8(%rsp),%xmm1
maxsd  0x18(%rsp),%xmm1
movsd  0x10(%rsp),%xmm0
minsd  0x20(%rsp),%xmm0
subsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
lea    0xc0e(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   10d0 <wait@plt>
jmp    15eb <main+0x41b>
mov    %ebp,0x8(%rsp)
mov    %ebx,0x10(%rsp)
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r13d,%edi
call   1070 <malloc@plt>
mov    %rax,%r12
mov    0x4(%rsp),%edi
lea    0x2e(%rsp),%rsi
mov    $0x1,%edx
call   10f0 <internal_send@plt>
lea    0xb9c(%rip),%rdi
xor    %eax,%eax
call   1090 <log_perf@plt>
movq   %xmm0,0x20(%rsp)
test   %r13d,%r13d
jle    157a <main+0x3aa>
lea    0x2e(%rsp),%rbp
xor    %r14d,%r14d
nopl   0x0(%rax)
mov    %r13d,%ebx
sub    %r14d,%ebx
cmp    %r15d,%ebx
cmovg  %r15d,%ebx
mov    0x4(%rsp),%edi
movslq %r14d,%r14
lea    (%r12,%r14,1),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1080 <internal_recv@plt>
mov    0x4(%rsp),%edi
mov    %rbp,%rsi
mov    $0xa,%edx
call   10f0 <internal_send@plt>
add    %ebx,%r14d
cmp    %r14d,%r13d
jg     1540 <main+0x370>
lea    0xb45(%rip),%rdi
xor    %eax,%eax
call   1090 <log_perf@plt>
movq   %xmm0,0x18(%rsp)
mov    0x4(%rsp),%edi
lea    0x20(%rsp),%rsi
mov    $0x8,%edx
call   10f0 <internal_send@plt>
mov    0x4(%rsp),%edi
lea    0x18(%rsp),%rsi
mov    $0x8,%edx
call   10f0 <internal_send@plt>
cmpl   $0x4,0x10(%rsp)
jl     15eb <main+0x41b>
mov    0x8(%rsp),%eax
cmp    $0x2,%eax
mov    $0x1,%ebx
cmovge %eax,%ebx
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    (%r12,%rbp,4),%eax
xor    %edi,%edi
cmp    %rax,%rbp
sete   %dil
call   1050 <assert@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    15d0 <main+0x400>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%edi
call   10c0 <exit@plt>
lea    0xa83(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str = [11 x i8] c"socketpair\00"
@.str.1 = [21 x i8] c"before init, size=%d\00"
@.str.2 = [11 x i8] c"after init\00"
@.str.3 = [11 x i8] c"start read\00"
@.str.4 = [10 x i8] c"done read\00"
@.str.5 = [12 x i8] c"start write\00"
@.str.6 = [11 x i8] c"done write\00"
@.str.7 = [10 x i8] c"TIME: %f\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca [10 x i8]
%12 = alloca [2 x i32]
%13 = alloca double
%14 = alloca double
%15 = alloca double
%16 = alloca double
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%22 = load i32, i32* %4
%23 = icmp sgt i32 %22, 1
br i1 %23, label %24, label %37
24: ; preds = %2
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32 @atoi(i8* %27)
store i32 %28, i32* %6
%29 = load i32, i32* %6
%30 = sext i32 %29 to i64
%31 = udiv i64 %30, 4
%32 = trunc i64 %31 to i32
store i32 %32, i32* %7
%33 = load i32, i32* %7
%34 = sext i32 %33 to i64
%35 = mul i64 4, %34
%36 = trunc i64 %35 to i32
store i32 %36, i32* %6
br label %39
37: ; preds = %2
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %24
%40 = load i32, i32* %6
store i32 %40, i32* %17
%41 = load i32, i32* %4
%42 = icmp sgt i32 %41, 2
br i1 %42, label %43, label %48
43: ; preds = %39
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 2
%46 = load i8*, i8** %45
%47 = call i32 @atoi(i8* %46)
store i32 %47, i32* %17
br label %48
48: ; preds = %43, %39
%49 = load i32, i32* @AF_UNIX
%50 = load i32, i32* @SOCK_STREAM
%51 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 0
%52 = call i32 @socketpair(i32 %49, i32 %50, i32 0, i32* %51)
%53 = icmp eq i32 %52, -1
br i1 %53, label %54, label %57
54: ; preds = %48
%55 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%56 = call i32 @exit(i32 1)
unreachable
57: ; preds = %48
%58 = load i32, i32* %6
%59 = call double (i8*, ...) @log_perf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %58)
%60 = load i32, i32* %6
%61 = call i32* @malloc(i32 %60)
store i32* %61, i32** %9
store i32 0, i32* %8
br label %62
62: ; preds = %72, %57
%63 = load i32, i32* %8
%64 = load i32, i32* %7
%65 = icmp slt i32 %63, %64
br i1 %65, label %66, label %75
66: ; preds = %62
%67 = load i32, i32* %8
%68 = load i32*, i32** %9
%69 = load i32, i32* %8
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i32, i32* %68, i64 %70
store i32 %67, i32* %71
br label %72
72: ; preds = %66
%73 = load i32, i32* %8
%74 = add nsw i32 %73, 1
store i32 %74, i32* %8
br label %62
75: ; preds = %62
%76 = call double (i8*, ...) @log_perf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%77 = call i32 (...) @fork()
%78 = icmp ne i32 %77, 0
br i1 %78, label %151, label %79
79: ; preds = %75
%80 = load i32*, i32** %9
%81 = call i32 @free(i32* %80)
%82 = load i32, i32* %6
%83 = call i32* @malloc(i32 %82)
store i32* %83, i32** %10
%84 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 1
%85 = load i32, i32* %84
%86 = bitcast [10 x i8]* %11 to i8*
%87 = call i32 @internal_send(i32 %85, i8* %86, i32 1)
%88 = call double (i8*, ...) @log_perf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
store double %88, double* %15
store i32 0, i32* %18
br label %89
89: ; preds = %105, %79
%90 = load i32, i32* %18
%91 = load i32, i32* %6
%92 = icmp slt i32 %90, %91
br i1 %92, label %93, label %123
93: ; preds = %89
%94 = load i32, i32* %6
%95 = load i32, i32* %18
%96 = sub nsw i32 %94, %95
%97 = load i32, i32* %17
%98 = icmp sgt i32 %96, %97
br i1 %98, label %99, label %101
99: ; preds = %93
%100 = load i32, i32* %17
br label %105
101: ; preds = %93
%102 = load i32, i32* %6
%103 = load i32, i32* %18
%104 = sub nsw i32 %102, %103
br label %105
105: ; preds = %101, %99
%106 = phi i32 [ %100, %99 ], [ %104, %101 ]
store i32 %106, i32* %19
%107 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 1
%108 = load i32, i32* %107
%109 = load i32*, i32** %10
%110 = bitcast i32* %109 to i8*
%111 = load i32, i32* %18
%112 = sext i32 %111 to i64
%113 = getelementptr i8, i8* %110, i64 %112
%114 = load i32, i32* %19
%115 = call i32 (i32, ...) @internal_recv(i32 %108, i8* %113, i32 %114)
%116 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 1
%117 = load i32, i32* %116
%118 = bitcast [10 x i8]* %11 to i8*
%119 = call i32 @internal_send(i32 %117, i8* %118, i32 10)
%120 = load i32, i32* %19
%121 = load i32, i32* %18
%122 = add nsw i32 %121, %120
store i32 %122, i32* %18
br label %89
123: ; preds = %89
%124 = call double (i8*, ...) @log_perf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
store double %124, double* %16
%125 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 1
%126 = load i32, i32* %125
%127 = bitcast double* %15 to i8*
%128 = call i32 @internal_send(i32 %126, i8* %127, i32 8)
%129 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 1
%130 = load i32, i32* %129
%131 = bitcast double* %16 to i8*
%132 = call i32 @internal_send(i32 %130, i8* %131, i32 8)
store i32 0, i32* %8
br label %133
133: ; preds = %147, %123
%134 = load i32, i32* %8
%135 = load i32, i32* %7
%136 = icmp slt i32 %134, %135
br i1 %136, label %137, label %150
137: ; preds = %133
%138 = load i32*, i32** %10
%139 = load i32, i32* %8
%140 = sext i32 %139 to i64
%141 = getelementptr inbounds i32, i32* %138, i64 %140
%142 = load i32, i32* %141
%143 = load i32, i32* %8
%144 = icmp eq i32 %142, %143
%145 = zext i1 %144 to i32
%146 = call i32 @assert(i32 %145)
br label %147
147: ; preds = %137
%148 = load i32, i32* %8
%149 = add nsw i32 %148, 1
store i32 %149, i32* %8
br label %133
150: ; preds = %133
br label %218
151: ; preds = %75
%152 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 0
%153 = load i32, i32* %152
%154 = call i32 (i32, ...) @internal_recv(i32 %153, [10 x i8]* %11, i64 1)
%155 = call double (i8*, ...) @log_perf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
store double %155, double* %13
store i32 0, i32* %20
br label %156
156: ; preds = %172, %151
%157 = load i32, i32* %20
%158 = load i32, i32* %6
%159 = icmp slt i32 %157, %158
br i1 %159, label %160, label %189
160: ; preds = %156
%161 = load i32, i32* %6
%162 = load i32, i32* %20
%163 = sub nsw i32 %161, %162
%164 = load i32, i32* %17
%165 = icmp sgt i32 %163, %164
br i1 %165, label %166, label %168
166: ; preds = %160
%167 = load i32, i32* %17
br label %172
168: ; preds = %160
%169 = load i32, i32* %6
%170 = load i32, i32* %20
%171 = sub nsw i32 %169, %170
br label %172
172: ; preds = %168, %166
%173 = phi i32 [ %167, %166 ], [ %171, %168 ]
store i32 %173, i32* %21
%174 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 0
%175 = load i32, i32* %174
%176 = load i32*, i32** %9
%177 = bitcast i32* %176 to i8*
%178 = load i32, i32* %20
%179 = sext i32 %178 to i64
%180 = getelementptr i8, i8* %177, i64 %179
%181 = load i32, i32* %21
%182 = call i32 @internal_send(i32 %175, i8* %180, i32 %181)
%183 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 0
%184 = load i32, i32* %183
%185 = call i32 (i32, ...) @internal_recv(i32 %184, [10 x i8]* %11, i64 10)
%186 = load i32, i32* %21
%187 = load i32, i32* %20
%188 = add nsw i32 %187, %186
store i32 %188, i32* %20
br label %156
189: ; preds = %156
%190 = call double (i8*, ...) @log_perf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
store double %190, double* %14
%191 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 0
%192 = load i32, i32* %191
%193 = call i32 (i32, ...) @internal_recv(i32 %192, double* %15, i64 8)
%194 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 0
%195 = load i32, i32* %194
%196 = call i32 (i32, ...) @internal_recv(i32 %195, double* %16, i64 8)
%197 = load double, double* %14
%198 = load double, double* %16
%199 = fcmp ogt double %197, %198
br i1 %199, label %200, label %202
200: ; preds = %189
%201 = load double, double* %14
br label %204
202: ; preds = %189
%203 = load double, double* %16
br label %204
204: ; preds = %202, %200
%205 = phi double [ %201, %200 ], [ %203, %202 ]
%206 = load double, double* %13
%207 = load double, double* %15
%208 = fcmp olt double %206, %207
br i1 %208, label %209, label %211
209: ; preds = %204
%210 = load double, double* %13
br label %213
211: ; preds = %204
%212 = load double, double* %15
br label %213
213: ; preds = %211, %209
%214 = phi double [ %210, %209 ], [ %212, %211 ]
%215 = fsub double %205, %214
%216 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), double %215)
%217 = call i32 @wait(i32* null)
br label %218
218: ; preds = %213, %150
ret i32 0
}

LLVM IR (-O2):
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str = [11 x i8] c"socketpair\00"
@.str.1 = [21 x i8] c"before init, size=%d\00"
@.str.2 = [11 x i8] c"after init\00"
@.str.3 = [11 x i8] c"start read\00"
@.str.4 = [10 x i8] c"done read\00"
@.str.5 = [12 x i8] c"start write\00"
@.str.6 = [11 x i8] c"done write\00"
@.str.7 = [10 x i8] c"TIME: %f\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [10 x i8]
%4 = alloca [2 x i32]
%5 = alloca double
%6 = alloca double
%7 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%8 = bitcast [2 x i32]* %4 to i8*
%9 = bitcast double* %5 to i8*
%10 = bitcast double* %6 to i8*
%11 = icmp sgt i32 %0, 1
br i1 %11, label %12, label %19
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call i32 @atoi(i8* %14)
%16 = ashr i32 %15, 2
%17 = and i32 %15, -4
%18 = icmp eq i32 %0, 2
br i1 %18, label %25, label %21
19: ; preds = %2
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %12
%22 = getelementptr inbounds i8*, i8** %1, i64 2
%23 = load i8*, i8** %22
%24 = tail call i32 @atoi(i8* %23)
br label %25
25: ; preds = %21, %12
%26 = phi i32 [ %24, %21 ], [ %17, %12 ]
%27 = load i32, i32* @AF_UNIX
%28 = load i32, i32* @SOCK_STREAM
%29 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%30 = call i32 @socketpair(i32 %27, i32 %28, i32 0, i32* %29)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %35
32: ; preds = %25
%33 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %25
%36 = call double (i8*, ...) @log_perf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %17)
%37 = call i32* @malloc(i32 %17)
%38 = icmp sgt i32 %15, 3
br i1 %38, label %39, label %113
39: ; preds = %35
%40 = call i32 @llvm.smax.i32(i32 %16, i32 1)
%41 = zext i32 %40 to i64
%42 = icmp ult i32 %40, 8
br i1 %42, label %105, label %43
43: ; preds = %39
%44 = and i64 %41, 2147483640
%45 = add nsw i64 %44, -8
%46 = lshr exact i64 %45, 3
%47 = add nuw nsw i64 %46, 1
%48 = and i64 %47, 3
%49 = icmp ult i64 %45, 24
br i1 %49, label %86, label %50
50: ; preds = %43
%51 = and i64 %47, 4611686018427387900
br label %52
52: ; preds = %52, %50
%53 = phi i64 [ 0, %50 ], [ %82, %52 ]
%54 = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, %50 ], [ %83, %52 ]
%55 = phi i64 [ 0, %50 ], [ %84, %52 ]
%56 = add <4 x i32> %54, <i32 4, i32 4, i32 4, i32 4>
%57 = getelementptr inbounds i32, i32* %37, i64 %53
%58 = bitcast i32* %57 to <4 x i32>*
store <4 x i32> %54, <4 x i32>* %58
%59 = getelementptr inbounds i32, i32* %57, i64 4
%60 = bitcast i32* %59 to <4 x i32>*
store <4 x i32> %56, <4 x i32>* %60
%61 = or i64 %53, 8
%62 = add <4 x i32> %54, <i32 8, i32 8, i32 8, i32 8>
%63 = add <4 x i32> %54, <i32 12, i32 12, i32 12, i32 12>
%64 = getelementptr inbounds i32, i32* %37, i64 %61
%65 = bitcast i32* %64 to <4 x i32>*
store <4 x i32> %62, <4 x i32>* %65
%66 = getelementptr inbounds i32, i32* %64, i64 4
%67 = bitcast i32* %66 to <4 x i32>*
store <4 x i32> %63, <4 x i32>* %67
%68 = or i64 %53, 16
%69 = add <4 x i32> %54, <i32 16, i32 16, i32 16, i32 16>
%70 = add <4 x i32> %54, <i32 20, i32 20, i32 20, i32 20>
%71 = getelementptr inbounds i32, i32* %37, i64 %68
%72 = bitcast i32* %71 to <4 x i32>*
store <4 x i32> %69, <4 x i32>* %72
%73 = getelementptr inbounds i32, i32* %71, i64 4
%74 = bitcast i32* %73 to <4 x i32>*
store <4 x i32> %70, <4 x i32>* %74
%75 = or i64 %53, 24
%76 = add <4 x i32> %54, <i32 24, i32 24, i32 24, i32 24>
%77 = add <4 x i32> %54, <i32 28, i32 28, i32 28, i32 28>
%78 = getelementptr inbounds i32, i32* %37, i64 %75
%79 = bitcast i32* %78 to <4 x i32>*
store <4 x i32> %76, <4 x i32>* %79
%80 = getelementptr inbounds i32, i32* %78, i64 4
%81 = bitcast i32* %80 to <4 x i32>*
store <4 x i32> %77, <4 x i32>* %81
%82 = add nuw i64 %53, 32
%83 = add <4 x i32> %54, <i32 32, i32 32, i32 32, i32 32>
%84 = add i64 %55, 4
%85 = icmp eq i64 %84, %51
br i1 %85, label %86, label %52
86: ; preds = %52, %43
%87 = phi i64 [ 0, %43 ], [ %82, %52 ]
%88 = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, %43 ], [ %83, %52 ]
%89 = icmp eq i64 %48, 0
br i1 %89, label %103, label %90
90: ; preds = %86, %90
%91 = phi i64 [ %99, %90 ], [ %87, %86 ]
%92 = phi <4 x i32> [ %100, %90 ], [ %88, %86 ]
%93 = phi i64 [ %101, %90 ], [ 0, %86 ]
%94 = add <4 x i32> %92, <i32 4, i32 4, i32 4, i32 4>
%95 = getelementptr inbounds i32, i32* %37, i64 %91
%96 = bitcast i32* %95 to <4 x i32>*
store <4 x i32> %92, <4 x i32>* %96
%97 = getelementptr inbounds i32, i32* %95, i64 4
%98 = bitcast i32* %97 to <4 x i32>*
store <4 x i32> %94, <4 x i32>* %98
%99 = add nuw i64 %91, 8
%100 = add <4 x i32> %92, <i32 8, i32 8, i32 8, i32 8>
%101 = add i64 %93, 1
%102 = icmp eq i64 %101, %48
br i1 %102, label %103, label %90
103: ; preds = %90, %86
%104 = icmp eq i64 %44, %41
br i1 %104, label %113, label %105
105: ; preds = %39, %103
%106 = phi i64 [ 0, %39 ], [ %44, %103 ]
br label %107
107: ; preds = %105, %107
%108 = phi i64 [ %111, %107 ], [ %106, %105 ]
%109 = getelementptr inbounds i32, i32* %37, i64 %108
%110 = trunc i64 %108 to i32
store i32 %110, i32* %109
%111 = add nuw nsw i64 %108, 1
%112 = icmp eq i64 %111, %41
br i1 %112, label %113, label %107
113: ; preds = %107, %103, %35
%114 = call double (i8*, ...) @log_perf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%115 = call i32 (...) @fork()
%116 = icmp eq i32 %115, 0
br i1 %116, label %117, label %159
117: ; preds = %113
%118 = call i32 @free(i32* %37)
%119 = call i32* @malloc(i32 %17)
%120 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%121 = load i32, i32* %120
%122 = call i32 @internal_send(i32 %121, i8* %7, i32 1)
%123 = call double (i8*, ...) @log_perf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
store double %123, double* %5
%124 = icmp sgt i32 %17, 0
br i1 %124, label %125, label %140
125: ; preds = %117
%126 = bitcast i32* %119 to i8*
br label %127
127: ; preds = %125, %127
%128 = phi i32 [ 0, %125 ], [ %138, %127 ]
%129 = sub nsw i32 %17, %128
%130 = icmp sgt i32 %129, %26
%131 = select i1 %130, i32 %26, i32 %129
%132 = load i32, i32* %120
%133 = sext i32 %128 to i64
%134 = getelementptr i8, i8* %126, i64 %133
%135 = call i32 (i32, ...) @internal_recv(i32 %132, i8* %134, i32 %131)
%136 = load i32, i32* %120
%137 = call i32 @internal_send(i32 %136, i8* %7, i32 10)
%138 = add nsw i32 %131, %128
%139 = icmp sgt i32 %17, %138
br i1 %139, label %127, label %140
140: ; preds = %127, %117
%141 = call double (i8*, ...) @log_perf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
store double %141, double* %6
%142 = load i32, i32* %120
%143 = call i32 @internal_send(i32 %142, i8* %9, i32 8)
%144 = load i32, i32* %120
%145 = call i32 @internal_send(i32 %144, i8* %10, i32 8)
br i1 %38, label %146, label %194
146: ; preds = %140
%147 = call i32 @llvm.smax.i32(i32 %16, i32 1)
%148 = zext i32 %147 to i64
br label %149
149: ; preds = %146, %149
%150 = phi i64 [ 0, %146 ], [ %157, %149 ]
%151 = getelementptr inbounds i32, i32* %119, i64 %150
%152 = load i32, i32* %151
%153 = zext i32 %152 to i64
%154 = icmp eq i64 %150, %153
%155 = zext i1 %154 to i32
%156 = call i32 @assert(i32 %155)
%157 = add nuw nsw i64 %150, 1
%158 = icmp eq i64 %157, %148
br i1 %158, label %194, label %149
159: ; preds = %113
%160 = load i32, i32* %29
%161 = call i32 (i32, ...) @internal_recv(i32 %160, [10 x i8]* %3, i64 1)
%162 = call double (i8*, ...) @log_perf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
%163 = icmp sgt i32 %17, 0
br i1 %163, label %164, label %179
164: ; preds = %159
%165 = bitcast i32* %37 to i8*
br label %166
166: ; preds = %164, %166
%167 = phi i32 [ 0, %164 ], [ %177, %166 ]
%168 = sub nsw i32 %17, %167
%169 = icmp sgt i32 %168, %26
%170 = select i1 %169, i32 %26, i32 %168
%171 = load i32, i32* %29
%172 = sext i32 %167 to i64
%173 = getelementptr i8, i8* %165, i64 %172
%174 = call i32 @internal_send(i32 %171, i8* %173, i32 %170)
%175 = load i32, i32* %29
%176 = call i32 (i32, ...) @internal_recv(i32 %175, [10 x i8]* %3, i64 10)
%177 = add nsw i32 %170, %167
%178 = icmp sgt i32 %17, %177
br i1 %178, label %166, label %179
179: ; preds = %166, %159
%180 = call double (i8*, ...) @log_perf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
%181 = load i32, i32* %29
%182 = call i32 (i32, ...) @internal_recv(i32 %181, double* %5, i64 8)
%183 = load i32, i32* %29
%184 = call i32 (i32, ...) @internal_recv(i32 %183, double* %6, i64 8)
%185 = load double, double* %6
%186 = fcmp ogt double %180, %185
%187 = select i1 %186, double %180, double %185
%188 = load double, double* %5
%189 = fcmp olt double %162, %188
%190 = select i1 %189, double %162, double %188
%191 = fsub double %187, %190
%192 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), double %191)
%193 = call i32 @wait(i32* null)
br label %194
194: ; preds = %149, %140, %179
ret i32 0
}