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

/* Forward declarations */

/* Type definitions */
struct timeval {
  scalar_t__ tv_usec;
  scalar_t__ tv_sec;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, long double);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ pipe(int *);
int /*<<< orphan*/ printf(char *, long double);
int read(int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ runpipe(int *, int *, char *, char *, char *);
int /*<<< orphan*/ strlen(char *);
int wait(int *);
int main(int argc, char **argv) {
  int pid, status;
  int fd1[2];
  int fd2[2];
  int bytes = 4;
  char buf[bytes];
  int n2;
  struct timeval start, end;
  FILE *fp;
  char str[bytes];
  char string[bytes];
  fp = fopen("512KB.txt", "r");
  if (fp == NULL) {
    perror("Error opening file");
    return (-1);
  }
  if (fgets(str, bytes, fp) != NULL) {
    memcpy(string, str, bytes);
    string[bytes] = '\0';
  }
  fclose(fp);
  char *data1 = string;
  char *data2 = string;
  FILE *fp2;
  if ((fp2 = fopen("/home/george/Documents/C/pipe.txt", "wt+")) == NULL) {
    perror("/home/george/Documents/C/pipe.txt");
    exit(1);
  }
  int iter = 0;
  for (iter; iter < 100; iter++) {
    pipe(fd1);
    pipe(fd2);
    gettimeofday(&start, NULL);
    switch (pid = fork()) {
    case 0:
      runpipe(fd1, fd2, data1, data2, buf);
      exit(0);
    default:
      while ((pid = wait(&status)) != -1)
        ;
      close(fd2[1]);
      if ((n2 = read(fd2[0], buf, strlen(data2))) >= 0) {
        buf[n2] = 0;
        printf("read %d bytes from the pipe2 \n", n2);
      } else
        perror("read");
      break;
    case -1:
      perror("fork");
      exit(1);
    }
    gettimeofday(&end, NULL);
    long double time =
        ((long double)(end.tv_sec - start.tv_sec) +
         ((long double)(end.tv_usec - start.tv_usec) / 1000000.0));
    printf("%Lf\n", time / 2);
    printf("time spend (half of bi-direction): %Lf\n", time / 2);
    fprintf(fp2, "%Lf\n", time / 2);
    fflush(fp2);
  }
  fclose(fp2);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x4,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0xe0(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x40(%rbp)
mov    -0x2c(%rbp),%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0xd8(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x78(%rbp)
mov    -0x2c(%rbp),%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0xd0(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x80(%rbp)
lea    0xd64(%rip),%rdi
lea    0xd67(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,-0x70(%rbp)
cmpq   $0x0,-0x70(%rbp)
jne    12e1 <main+0xd1>
lea    0xd4e(%rip),%rdi
call   1100 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret
mov    -0xd8(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    -0x70(%rbp),%rdx
call   10b0 <fgets@plt>
cmp    $0x0,%rax
je     1323 <main+0x113>
mov    -0xd0(%rbp),%rdi
mov    -0xd8(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   10d0 <memcpy@plt>
mov    -0xd0(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x70(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0xd0(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    %rax,-0x90(%rbp)
lea    0xcdf(%rip),%rdi
lea    0xcfa(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,-0x98(%rbp)
cmp    $0x0,%rax
jne    137b <main+0x16b>
lea    0xcbb(%rip),%rdi
call   1100 <perror@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
movl   $0x0,-0x9c(%rbp)
cmpl   $0x64,-0x9c(%rbp)
jge    15c7 <main+0x3b7>
lea    -0x20(%rbp),%rdi
call   1090 <pipe@plt>
lea    -0x28(%rbp),%rdi
call   1090 <pipe@plt>
xor    %eax,%eax
mov    %eax,-0xe8(%rbp)
mov    %eax,%esi
lea    -0x58(%rbp),%rdi
call   1070 <gettimeofday@plt>
mov    -0xe8(%rbp),%eax
call   1130 <fork@plt>
mov    %eax,-0x14(%rbp)
mov    %eax,%ecx
mov    %ecx,-0xe4(%rbp)
sub    $0xffffffff,%eax
je     14c0 <main+0x2b0>
jmp    13db <main+0x1cb>
mov    -0xe4(%rbp),%eax
test   %eax,%eax
jne    1417 <main+0x207>
jmp    13ee <main+0x1de>
mov    -0xe0(%rbp),%r8
lea    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
mov    -0x88(%rbp),%rdx
mov    -0x90(%rbp),%rcx
call   1060 <runpipe@plt>
xor    %edi,%edi
call   1110 <exit@plt>
jmp    141c <main+0x20c>
lea    -0x18(%rbp),%rdi
call   1120 <wait@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     1436 <main+0x226>
jmp    141c <main+0x20c>
mov    -0x24(%rbp),%edi
call   1080 <close@plt>
mov    -0x28(%rbp),%eax
mov    %eax,-0xec(%rbp)
mov    -0x90(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0xec(%rbp),%edi
mov    -0xe0(%rbp),%rsi
mov    %eax,%edx
call   10a0 <read@plt>
mov    %eax,-0x44(%rbp)
cmp    $0x0,%eax
jl     14af <main+0x29f>
mov    -0xe0(%rbp),%rax
movslq -0x44(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x44(%rbp),%eax
mov    %eax,-0xb4(%rbp)
fildl  -0xb4(%rbp)
sub    $0x10,%rsp
mov    %rsp,%rax
fstpt  (%rax)
lea    0xbac(%rip),%rdi
call   1050 <printf@plt>
add    $0x10,%rsp
jmp    14bb <main+0x2ab>
lea    0xbb6(%rip),%rdi
call   1100 <perror@plt>
jmp    14d6 <main+0x2c6>
lea    0xbaa(%rip),%rdi
call   1100 <perror@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
xor    %eax,%eax
mov    %eax,%esi
lea    -0x68(%rbp),%rdi
call   1070 <gettimeofday@plt>
mov    -0x68(%rbp),%rax
mov    -0x60(%rbp),%rdx
mov    -0x58(%rbp),%rcx
mov    -0x50(%rbp),%rsi
sub    %rsi,%rdx
mov    %rdx,-0xc0(%rbp)
fildll -0xc0(%rbp)
sub    %rcx,%rax
mov    %rax,-0xc8(%rbp)
fildll -0xc8(%rbp)
flds   0xae7(%rip)
fdivrp %st,%st(1)
faddp  %st,%st(1)
fstpt  -0xb0(%rbp)
fldt   -0xb0(%rbp)
flds   0xad5(%rip)
fld    %st(0)
fstpt  -0xf8(%rbp)
fdivrp %st,%st(1)
sub    $0x10,%rsp
mov    %rsp,%rax
fstpt  (%rax)
lea    0xb50(%rip),%rdi
call   1050 <printf@plt>
fldt   -0xf8(%rbp)
add    $0x10,%rsp
fldt   -0xb0(%rbp)
fdivp  %st,%st(1)
sub    $0x10,%rsp
mov    %rsp,%rax
fstpt  (%rax)
lea    0xb06(%rip),%rdi
call   1050 <printf@plt>
fldt   -0xf8(%rbp)
add    $0x10,%rsp
mov    -0x98(%rbp),%rdi
fldt   -0xb0(%rbp)
fdivp  %st,%st(1)
sub    $0x10,%rsp
mov    %rsp,%rax
fstpt  (%rax)
lea    0xafb(%rip),%rsi
call   10c0 <fprintf@plt>
add    $0x10,%rsp
mov    -0x98(%rbp),%rdi
call   10e0 <fflush@plt>
mov    -0x9c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x9c(%rbp)
jmp    1385 <main+0x175>
mov    -0x98(%rbp),%rdi
call   1030 <fclose@plt>
xor    %edi,%edi
call   1110 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
mov    %rsp,%rbp
lea    0xddd(%rip),%rdi
lea    0xde0(%rip),%rsi
call   10f0 <fopen@plt>
test   %rax,%rax
jne    1262 <main+0x52>
lea    0xdd1(%rip),%rdi
call   1100 <perror@plt>
mov    %rbp,%rsp
mov    $0xffffffff,%eax
add    $0x98,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rax,%rbx
lea    0x30(%rsp),%rdi
mov    $0x4,%esi
mov    %rax,%rdx
call   10b0 <fgets@plt>
test   %rax,%rax
je     1295 <main+0x85>
lea    0x10(%rsp),%rdi
lea    0x30(%rsp),%rsi
mov    $0x4,%edx
call   10d0 <memcpy@plt>
movb   $0x0,0x14(%rsp)
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0xd83(%rip),%rdi
lea    0xd9e(%rip),%rsi
call   10f0 <fopen@plt>
test   %rax,%rax
jne    12c1 <main+0xb1>
lea    0xd6b(%rip),%rdi
jmp    1433 <main+0x223>
mov    %rax,%r13
lea    0x74(%rsp),%rbx
lea    0xdc9(%rip),%r12
lea    0xd9f(%rip),%rbp
xor    %r15d,%r15d
jmp    138f <main+0x17f>
nop
mov    %eax,%ecx
movb   $0x0,0x20(%rsp,%rcx,1)
mov    %eax,0x40(%rsp)
fildl  0x40(%rsp)
fstpt  (%rsp)
lea    0xd54(%rip),%rdi
call   1050 <printf@plt>
lea    0x78(%rsp),%rdi
xor    %esi,%esi
call   1070 <gettimeofday@plt>
mov    0x78(%rsp),%rax
mov    0x80(%rsp),%rcx
sub    0x90(%rsp),%rcx
mov    %rcx,0x58(%rsp)
fildll 0x58(%rsp)
sub    0x88(%rsp),%rax
mov    %rax,0x60(%rsp)
fildll 0x60(%rsp)
fdivs  0xcc1(%rip)
faddp  %st,%st(1)
fmuls  0xcbd(%rip)
fld    %st(0)
fstpt  0x4c(%rsp)
fstpt  (%rsp)
mov    %r12,%rdi
call   1050 <printf@plt>
fldt   0x4c(%rsp)
fstpt  (%rsp)
mov    %rbp,%rdi
call   1050 <printf@plt>
fldt   0x4c(%rsp)
fstpt  (%rsp)
mov    %r13,%rdi
mov    %r12,%rsi
call   10c0 <fprintf@plt>
mov    %r13,%rdi
call   10e0 <fflush@plt>
add    $0x1,%r15d
cmp    $0x64,%r15d
je     141d <main+0x20d>
lea    0x6c(%rsp),%rdi
call   1090 <pipe@plt>
lea    0x44(%rsp),%rdi
call   1090 <pipe@plt>
lea    0x88(%rsp),%rdi
xor    %esi,%esi
call   1070 <gettimeofday@plt>
xor    %eax,%eax
call   1130 <fork@plt>
cmp    $0xffffffff,%eax
je     142c <main+0x21c>
test   %eax,%eax
je     1442 <main+0x232>
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1120 <wait@plt>
cmp    $0xffffffff,%eax
jne    13d0 <main+0x1c0>
mov    0x48(%rsp),%edi
call   1080 <close@plt>
mov    0x44(%rsp),%r14d
lea    0x10(%rsp),%rdi
call   1040 <strlen@plt>
mov    %r14d,%edi
lea    0x20(%rsp),%rsi
mov    %eax,%edx
call   10a0 <read@plt>
test   %eax,%eax
jns    12e0 <main+0xd0>
lea    0xc59(%rip),%rdi
call   1100 <perror@plt>
jmp    12fe <main+0xee>
mov    %r13,%rdi
call   1030 <fclose@plt>
xor    %edi,%edi
call   1110 <exit@plt>
lea    0xc3e(%rip),%rdi
call   1100 <perror@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
lea    0x6c(%rsp),%rdi
lea    0x44(%rsp),%rsi
lea    0x10(%rsp),%rcx
lea    0x20(%rsp),%r8
mov    %rcx,%rdx
call   1060 <runpipe@plt>
xor    %edi,%edi
call   1110 <exit@plt>

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
@.str = [10 x i8] c"512KB.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [19 x i8] c"Error opening file\00"
@.str.3 = [34 x i8] c"/home/george/Documents/C/pipe.txt\00"
@.str.4 = [4 x i8] c"wt+\00"
@.str.5 = [31 x i8] c"read %d bytes from the pipe2 \0A\00"
@.str.6 = [5 x i8] c"read\00"
@.str.7 = [5 x i8] c"fork\00"
@.str.8 = [5 x i8] c"%Lf\0A\00"
@.str.9 = [40 x i8] c"time spend (half of bi-direction): %Lf\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 [2 x i32]
%9 = alloca [2 x i32]
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i64
%13 = alloca i32
%14 = alloca %struct.timeval
%15 = alloca %struct.timeval
%16 = alloca i32*
%17 = alloca i64
%18 = alloca i64
%19 = alloca i8*
%20 = alloca i8*
%21 = alloca i32*
%22 = alloca i32
%23 = alloca x86_fp80
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 4, i32* %10
%24 = load i32, i32* %10
%25 = zext i32 %24 to i64
%26 = call i8* @llvm.stacksave()
store i8* %26, i8** %11
%27 = alloca i8, i64 %25
store i64 %25, i64* %12
%28 = load i32, i32* %10
%29 = zext i32 %28 to i64
%30 = alloca i8, i64 %29
store i64 %29, i64* %17
%31 = load i32, i32* %10
%32 = zext i32 %31 to i64
%33 = alloca i8, i64 %32
store i64 %32, i64* %18
%34 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %34, i32** %16
%35 = load i32*, i32** %16
%36 = icmp eq i32* %35, null
br i1 %36, label %37, label %41
37: ; preds = %2
%38 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
%39 = load i8*, i8** %11
%40 = load i32, i32* %3
ret i32 %40
41: ; preds = %2
%42 = load i32, i32* %10
%43 = load i32*, i32** %16
%44 = call i32* @fgets(i8* %30, i32 %42, i32* %43)
%45 = icmp ne i32* %44, null
br i1 %45, label %46, label %52
46: ; preds = %41
%47 = load i32, i32* %10
%48 = call i32 @memcpy(i8* %33, i8* %30, i32 %47)
%49 = load i32, i32* %10
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %33, i64 %50
store i8 0, i8* %51
br label %52
52: ; preds = %46, %41
%53 = load i32*, i32** %16
%54 = call i32 @fclose(i32* %53)
store i8* %33, i8** %19
store i8* %33, i8** %20
%55 = call i32* @fopen(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
store i32* %55, i32** %21
%56 = icmp eq i32* %55, null
br i1 %56, label %57, label %60
57: ; preds = %52
%58 = call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0))
%59 = call i32 @exit(i32 1)
unreachable
60: ; preds = %52
store i32 0, i32* %22
%61 = load i32, i32* %22
br label %62
62: ; preds = %135, %60
%63 = load i32, i32* %22
%64 = icmp slt i32 %63, 100
br i1 %64, label %65, label %138
65: ; preds = %62
%66 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 0
%67 = call i32 @pipe(i32* %66)
%68 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 0
%69 = call i32 @pipe(i32* %68)
%70 = call i32 @gettimeofday(%struct.timeval* %14, i32* null)
%71 = call i32 (...) @fork()
store i32 %71, i32* %6
switch i32 %71, label %79 [
i32 0, label %72
i32 -1, label %104
]
72: ; preds = %65
%73 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 0
%74 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 0
%75 = load i8*, i8** %19
%76 = load i8*, i8** %20
%77 = call i32 @runpipe(i32* %73, i32* %74, i8* %75, i8* %76, i8* %27)
%78 = call i32 @exit(i32 0)
unreachable
79: ; preds = %65
br label %80
80: ; preds = %83, %79
%81 = call i32 @wait(i32* %7)
store i32 %81, i32* %6
%82 = icmp ne i32 %81, -1
br i1 %82, label %83, label %84
83: ; preds = %80
br label %80
84: ; preds = %80
%85 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 1
%86 = load i32, i32* %85
%87 = call i32 @close(i32 %86)
%88 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 0
%89 = load i32, i32* %88
%90 = load i8*, i8** %20
%91 = call i32 @strlen(i8* %90)
%92 = call i32 @read(i32 %89, i8* %27, i32 %91)
store i32 %92, i32* %13
%93 = icmp sge i32 %92, 0
br i1 %93, label %94, label %101
94: ; preds = %84
%95 = load i32, i32* %13
%96 = sext i32 %95 to i64
%97 = getelementptr inbounds i8, i8* %27, i64 %96
store i8 0, i8* %97
%98 = load i32, i32* %13
%99 = sitofp i32 %98 to x86_fp80
%100 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0), x86_fp80 %99)
br label %103
101: ; preds = %84
%102 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
br label %103
103: ; preds = %101, %94
br label %107
104: ; preds = %65
%105 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%106 = call i32 @exit(i32 1)
unreachable
107: ; preds = %103
%108 = call i32 @gettimeofday(%struct.timeval* %15, i32* null)
%109 = getelementptr inbounds %struct.timeval, %struct.timeval* %15, i32 0, i32 1
%110 = load i64, i64* %109
%111 = getelementptr inbounds %struct.timeval, %struct.timeval* %14, i32 0, i32 1
%112 = load i64, i64* %111
%113 = sub nsw i64 %110, %112
%114 = sitofp i64 %113 to x86_fp80
%115 = getelementptr inbounds %struct.timeval, %struct.timeval* %15, i32 0, i32 0
%116 = load i64, i64* %115
%117 = getelementptr inbounds %struct.timeval, %struct.timeval* %14, i32 0, i32 0
%118 = load i64, i64* %117
%119 = sub nsw i64 %116, %118
%120 = sitofp i64 %119 to x86_fp80
%121 = fdiv x86_fp80 %120, 0xK4012F424000000000000
%122 = fadd x86_fp80 %114, %121
store x86_fp80 %122, x86_fp80* %23
%123 = load x86_fp80, x86_fp80* %23
%124 = fdiv x86_fp80 %123, 0xK40008000000000000000
%125 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), x86_fp80 %124)
%126 = load x86_fp80, x86_fp80* %23
%127 = fdiv x86_fp80 %126, 0xK40008000000000000000
%128 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.9, i64 0, i64 0), x86_fp80 %127)
%129 = load i32*, i32** %21
%130 = load x86_fp80, x86_fp80* %23
%131 = fdiv x86_fp80 %130, 0xK40008000000000000000
%132 = call i32 @fprintf(i32* %129, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), x86_fp80 %131)
%133 = load i32*, i32** %21
%134 = call i32 @fflush(i32* %133)
br label %135
135: ; preds = %107
%136 = load i32, i32* %22
%137 = add nsw i32 %136, 1
store i32 %137, i32* %22
br label %62
138: ; preds = %62
%139 = load i32*, i32** %21
%140 = call i32 @fclose(i32* %139)
%141 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
@.str = [10 x i8] c"512KB.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [19 x i8] c"Error opening file\00"
@.str.3 = [34 x i8] c"/home/george/Documents/C/pipe.txt\00"
@.str.4 = [4 x i8] c"wt+\00"
@.str.5 = [31 x i8] c"read %d bytes from the pipe2 \0A\00"
@.str.6 = [5 x i8] c"read\00"
@.str.7 = [5 x i8] c"fork\00"
@.str.8 = [5 x i8] c"%Lf\0A\00"
@.str.9 = [40 x i8] c"time spend (half of bi-direction): %Lf\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca [2 x i32]
%5 = alloca [2 x i32]
%6 = alloca %struct.timeval
%7 = alloca %struct.timeval
%8 = bitcast i32* %3 to i8*
%9 = bitcast [2 x i32]* %4 to i8*
%10 = bitcast [2 x i32]* %5 to i8*
%11 = tail call i8* @llvm.stacksave()
%12 = alloca [4 x i8]
%13 = getelementptr inbounds [4 x i8], [4 x i8]* %12, i64 0, i64 0
%14 = bitcast %struct.timeval* %6 to i8*
%15 = bitcast %struct.timeval* %7 to i8*
%16 = alloca [4 x i8]
%17 = alloca [4 x i8]
%18 = getelementptr inbounds [4 x i8], [4 x i8]* %17, i64 0, i64 0
%19 = getelementptr inbounds [4 x i8], [4 x i8]* %16, i64 0, i64 0
%20 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %24
22: ; preds = %2
%23 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
tail call void @llvm.stackrestore(i8* %11)
ret i32 -1
24: ; preds = %2
%25 = call i32* @fgets(i8* %19, i32 4, i32* %20)
%26 = icmp eq i32* %25, null
br i1 %26, label %30, label %27
27: ; preds = %24
%28 = call i32 @memcpy(i8* %18, i8* %19, i32 4)
%29 = getelementptr inbounds [4 x i8], [4 x i8]* %17, i64 0, i64 4
store i8 0, i8* %29
br label %30
30: ; preds = %27, %24
%31 = call i32 @fclose(i32* %20)
%32 = call i32* @fopen(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%33 = icmp eq i32* %32, null
br i1 %33, label %42, label %34
34: ; preds = %30
%35 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%36 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%37 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%38 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i64 0, i32 1
%39 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i64 0, i32 1
%40 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i64 0, i32 0
%41 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i64 0, i32 0
br label %45
42: ; preds = %30
%43 = call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0))
%44 = call i32 @exit(i32 1)
unreachable
45: ; preds = %34, %74
%46 = phi i32 [ 0, %34 ], [ %91, %74 ]
%47 = call i32 @pipe(i32* %35)
%48 = call i32 @pipe(i32* %36)
%49 = call i32 @gettimeofday(%struct.timeval* %6, i32* null)
%50 = call i32 (...) @fork()
switch i32 %50, label %54 [
i32 0, label %51
i32 -1, label %71
]
51: ; preds = %45
%52 = call i32 @runpipe(i32* %35, i32* %36, i8* %18, i8* %18, i8* %13)
%53 = call i32 @exit(i32 0)
unreachable
54: ; preds = %45, %54
%55 = call i32 @wait(i32* %3)
%56 = icmp eq i32 %55, -1
br i1 %56, label %57, label %54
57: ; preds = %54
%58 = load i32, i32* %37
%59 = call i32 @close(i32 %58)
%60 = load i32, i32* %36
%61 = call i32 @strlen(i8* %18)
%62 = call i32 @read(i32 %60, i8* %13, i32 %61)
%63 = icmp sgt i32 %62, -1
br i1 %63, label %64, label %69
64: ; preds = %57
%65 = zext i32 %62 to i64
%66 = getelementptr inbounds [4 x i8], [4 x i8]* %12, i64 0, i64 %65
store i8 0, i8* %66
%67 = sitofp i32 %62 to x86_fp80
%68 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0), x86_fp80 %67)
br label %74
69: ; preds = %57
%70 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
br label %74
71: ; preds = %45
%72 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%73 = call i32 @exit(i32 1)
unreachable
74: ; preds = %64, %69
%75 = call i32 @gettimeofday(%struct.timeval* %7, i32* null)
%76 = load i64, i64* %38
%77 = load i64, i64* %39
%78 = sub nsw i64 %76, %77
%79 = sitofp i64 %78 to x86_fp80
%80 = load i64, i64* %40
%81 = load i64, i64* %41
%82 = sub nsw i64 %80, %81
%83 = sitofp i64 %82 to x86_fp80
%84 = fdiv x86_fp80 %83, 0xK4012F424000000000000
%85 = fadd x86_fp80 %84, %79
%86 = fmul x86_fp80 %85, 0xK3FFE8000000000000000
%87 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), x86_fp80 %86)
%88 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.9, i64 0, i64 0), x86_fp80 %86)
%89 = call i32 @fprintf(i32* %32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), x86_fp80 %86)
%90 = call i32 @fflush(i32* %32)
%91 = add nuw nsw i32 %46, 1
%92 = icmp eq i32 %91, 100
br i1 %92, label %93, label %45
93: ; preds = %74
%94 = call i32 @fclose(i32* %32)
%95 = call i32 @exit(i32 0)
unreachable
}