#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*/ 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*/ memcpy(char *, char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ pipe(int *);
int /*<<< orphan*/ printf(char *, long double);
unsigned long long rdtsc();
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) {
  unsigned long long x;
  unsigned long long y;
  int pid, status;
  int fd1[2];
  int fd2[2];
  int bytes = 4;
  char buf[bytes];
  int n2;
  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 = "k";
  FILE *fp2;
  if ((fp2 = fopen("/home/george/Documents/C/pipe64K.txt", "wt+")) == NULL) {
    perror("/home/george/Documents/C/pipe64K.txt");
    exit(1);
  }
  int i = 0;
  for (i; i < 100; i++) {
    pipe(fd1);
    pipe(fd2);
    x = rdtsc();
    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);
    }
    y = rdtsc();
    printf("total cycles for round trip: %lld\n", y - x);
    long double time = (long double)(y - x) / 2600000000;
    printf("time spend (half of bi-direction): %Lf\n", time);
    fprintf(fp2, "%Lf\n", time);
    fflush(fp2);
  }
  fclose(fp2);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x4,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0xd0(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x50(%rbp)
mov    -0x3c(%rbp),%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0xc8(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x68(%rbp)
mov    -0x3c(%rbp),%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0xc0(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x70(%rbp)
lea    0xd68(%rip),%rdi
lea    0xd6b(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,-0x60(%rbp)
cmpq   $0x0,-0x60(%rbp)
jne    12e1 <main+0xd1>
lea    0xd52(%rip),%rdi
call   1100 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret
mov    -0xc8(%rbp),%rdi
mov    -0x3c(%rbp),%esi
mov    -0x60(%rbp),%rdx
call   10b0 <fgets@plt>
cmp    $0x0,%rax
je     1323 <main+0x113>
mov    -0xc0(%rbp),%rdi
mov    -0xc8(%rbp),%rsi
mov    -0x3c(%rbp),%edx
call   10d0 <memcpy@plt>
mov    -0xc0(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x60(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0xc0(%rbp),%rax
mov    %rax,-0x78(%rbp)
lea    0xd3d(%rip),%rax
mov    %rax,-0x80(%rbp)
lea    0xce2(%rip),%rdi
lea    0xd00(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,-0x88(%rbp)
cmp    $0x0,%rax
jne    137c <main+0x16c>
lea    0xcbe(%rip),%rdi
call   1100 <perror@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
movl   $0x0,-0x8c(%rbp)
cmpl   $0x64,-0x8c(%rbp)
jge    15c3 <main+0x3b3>
lea    -0x30(%rbp),%rdi
call   1090 <pipe@plt>
lea    -0x38(%rbp),%rdi
call   1090 <pipe@plt>
xor    %eax,%eax
mov    %al,-0xd5(%rbp)
call   1070 <rdtsc@plt>
mov    %rax,%rcx
mov    -0xd5(%rbp),%al
mov    %rcx,-0x18(%rbp)
call   1130 <fork@plt>
mov    %eax,-0x24(%rbp)
mov    %eax,%ecx
mov    %ecx,-0xd4(%rbp)
sub    $0xffffffff,%eax
je     14b9 <main+0x2a9>
jmp    13dd <main+0x1cd>
mov    -0xd4(%rbp),%eax
test   %eax,%eax
jne    1413 <main+0x203>
jmp    13f0 <main+0x1e0>
mov    -0xd0(%rbp),%r8
lea    -0x30(%rbp),%rdi
lea    -0x38(%rbp),%rsi
mov    -0x78(%rbp),%rdx
mov    -0x80(%rbp),%rcx
call   1060 <runpipe@plt>
xor    %edi,%edi
call   1110 <exit@plt>
jmp    1418 <main+0x208>
lea    -0x28(%rbp),%rdi
call   1120 <wait@plt>
mov    %eax,-0x24(%rbp)
cmp    $0xffffffff,%eax
je     1432 <main+0x222>
jmp    1418 <main+0x208>
mov    -0x34(%rbp),%edi
call   1080 <close@plt>
mov    -0x38(%rbp),%eax
mov    %eax,-0xdc(%rbp)
mov    -0x80(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0xdc(%rbp),%edi
mov    -0xd0(%rbp),%rsi
mov    %eax,%edx
call   10a0 <read@plt>
mov    %eax,-0x54(%rbp)
cmp    $0x0,%eax
jl     14a8 <main+0x298>
mov    -0xd0(%rbp),%rax
movslq -0x54(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x54(%rbp),%eax
mov    %eax,-0xa4(%rbp)
fildl  -0xa4(%rbp)
sub    $0x10,%rsp
mov    %rsp,%rax
fstpt  (%rax)
lea    0xbba(%rip),%rdi
call   1050 <printf@plt>
add    $0x10,%rsp
jmp    14b4 <main+0x2a4>
lea    0xbc4(%rip),%rdi
call   1100 <perror@plt>
jmp    14cf <main+0x2bf>
lea    0xbb8(%rip),%rdi
call   1100 <perror@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
xor    %eax,%eax
call   1070 <rdtsc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0xb8(%rbp)
sets   %al
movzbl %al,%eax
mov    %eax,%ecx
fildll -0xb8(%rbp)
lea    0xaff(%rip),%rax
mov    %rax,-0xe8(%rbp)
flds   (%rax,%rcx,4)
faddp  %st,%st(1)
sub    $0x10,%rsp
mov    %rsp,%rax
fstpt  (%rax)
lea    0xb60(%rip),%rdi
call   1050 <printf@plt>
add    $0x10,%rsp
mov    -0xe8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    -0x18(%rbp),%rdx
sub    %rdx,%rcx
mov    %rcx,-0xb0(%rbp)
sets   %cl
movzbl %cl,%ecx
fildll -0xb0(%rbp)
flds   (%rax,%rcx,4)
faddp  %st,%st(1)
flds   0xab2(%rip)
fdivrp %st,%st(1)
fstpt  -0xa0(%rbp)
fldt   -0xa0(%rbp)
sub    $0x10,%rsp
mov    %rsp,%rax
fstpt  (%rax)
lea    0xb2c(%rip),%rdi
call   1050 <printf@plt>
add    $0x10,%rsp
mov    -0x88(%rbp),%rdi
fldt   -0xa0(%rbp)
sub    $0x10,%rsp
mov    %rsp,%rax
fstpt  (%rax)
lea    0xb29(%rip),%rsi
call   10c0 <fprintf@plt>
add    $0x10,%rsp
mov    -0x88(%rbp),%rdi
call   10e0 <fflush@plt>
mov    -0x8c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8c(%rbp)
jmp    1386 <main+0x176>
mov    -0x88(%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    $0x68,%rsp
mov    %rsp,%rbp
lea    0xde4(%rip),%rdi
lea    0xde7(%rip),%rsi
call   10f0 <fopen@plt>
test   %rax,%rax
jne    125c <main+0x4c>
lea    0xdd8(%rip),%rdi
call   1100 <perror@plt>
mov    %rbp,%rsp
mov    $0xffffffff,%eax
add    $0x68,%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     128f <main+0x7f>
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    0xd8d(%rip),%rdi
lea    0xdab(%rip),%rsi
call   10f0 <fopen@plt>
test   %rax,%rax
jne    12bb <main+0xab>
lea    0xd75(%rip),%rdi
jmp    1415 <main+0x205>
mov    %rax,%r12
lea    0x64(%rsp),%rbx
lea    0xdf9(%rip),%r13
xor    %r15d,%r15d
jmp    137c <main+0x16c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %eax,%ecx
movb   $0x0,0x20(%rsp,%rcx,1)
mov    %eax,0x38(%rsp)
fildl  0x38(%rsp)
fstpt  (%rsp)
lea    0xd5b(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
call   1070 <rdtsc@plt>
xor    %ecx,%ecx
sub    %rbp,%rax
mov    %rax,0x50(%rsp)
sets   %cl
fildll 0x50(%rsp)
lea    0xce3(%rip),%rax
fadds  (%rax,%rcx,4)
fld    %st(0)
fstpt  0x44(%rsp)
fstpt  (%rsp)
lea    0xd4d(%rip),%rdi
call   1050 <printf@plt>
fldt   0x44(%rsp)
fdivs  0xcc9(%rip)
fld    %st(0)
fstpt  0x44(%rsp)
fstpt  (%rsp)
lea    0xd51(%rip),%rdi
call   1050 <printf@plt>
fldt   0x44(%rsp)
fstpt  (%rsp)
mov    %r12,%rdi
mov    %r13,%rsi
call   10c0 <fprintf@plt>
mov    %r12,%rdi
call   10e0 <fflush@plt>
add    $0x1,%r15d
cmp    $0x64,%r15d
je     13ff <main+0x1ef>
lea    0x5c(%rsp),%rdi
call   1090 <pipe@plt>
lea    0x3c(%rsp),%rdi
call   1090 <pipe@plt>
xor    %eax,%eax
call   1070 <rdtsc@plt>
mov    %rax,%rbp
xor    %eax,%eax
call   1130 <fork@plt>
cmp    $0xffffffff,%eax
je     140e <main+0x1fe>
test   %eax,%eax
je     1424 <main+0x214>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1120 <wait@plt>
cmp    $0xffffffff,%eax
jne    13b0 <main+0x1a0>
mov    0x40(%rsp),%edi
call   1080 <close@plt>
mov    0x3c(%rsp),%r14d
lea    0xca9(%rip),%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    0xc7e(%rip),%rdi
call   1100 <perror@plt>
jmp    12fe <main+0xee>
mov    %r12,%rdi
call   1030 <fclose@plt>
xor    %edi,%edi
call   1110 <exit@plt>
lea    0xc63(%rip),%rdi
call   1100 <perror@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
lea    0xc50(%rip),%rcx
lea    0x5c(%rsp),%rdi
lea    0x3c(%rsp),%rsi
lea    0x10(%rsp),%rdx
lea    0x20(%rsp),%r8
call   1060 <runpipe@plt>
xor    %edi,%edi
call   1110 <exit@plt>

LLVM IR (-O0):
@.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 = [2 x i8] c"k\00"
@.str.4 = [37 x i8] c"/home/george/Documents/C/pipe64K.txt\00"
@.str.5 = [4 x i8] c"wt+\00"
@.str.6 = [31 x i8] c"read %d bytes from the pipe2 \0A\00"
@.str.7 = [5 x i8] c"read\00"
@.str.8 = [5 x i8] c"fork\00"
@.str.9 = [35 x i8] c"total cycles for round trip: %lld\0A\00"
@.str.10 = [40 x i8] c"time spend (half of bi-direction): %Lf\0A\00"
@.str.11 = [5 x i8] c"%Lf\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
%10 = alloca [2 x i32]
%11 = alloca [2 x i32]
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i64
%15 = alloca i32
%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* %12
%24 = load i32, i32* %12
%25 = zext i32 %24 to i64
%26 = call i8* @llvm.stacksave()
store i8* %26, i8** %13
%27 = alloca i8, i64 %25
store i64 %25, i64* %14
%28 = load i32, i32* %12
%29 = zext i32 %28 to i64
%30 = alloca i8, i64 %29
store i64 %29, i64* %17
%31 = load i32, i32* %12
%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** %13
%40 = load i32, i32* %3
ret i32 %40
41: ; preds = %2
%42 = load i32, i32* %12
%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* %12
%48 = call i32 @memcpy(i8* %33, i8* %30, i32 %47)
%49 = load i32, i32* %12
%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* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8** %20
%55 = call i32* @fopen(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, 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 ([37 x i8], [37 x i8]* @.str.4, 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 = %126, %60
%63 = load i32, i32* %22
%64 = icmp slt i32 %63, 100
br i1 %64, label %65, label %129
65: ; preds = %62
%66 = getelementptr inbounds [2 x i32], [2 x i32]* %10, i64 0, i64 0
%67 = call i32 @pipe(i32* %66)
%68 = getelementptr inbounds [2 x i32], [2 x i32]* %11, i64 0, i64 0
%69 = call i32 @pipe(i32* %68)
%70 = call i64 (...) @rdtsc()
store i64 %70, i64* %6
%71 = call i32 (...) @fork()
store i32 %71, i32* %8
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]* %10, i64 0, i64 0
%74 = getelementptr inbounds [2 x i32], [2 x i32]* %11, 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* %9)
store i32 %81, i32* %8
%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]* %11, i64 0, i64 1
%86 = load i32, i32* %85
%87 = call i32 @close(i32 %86)
%88 = getelementptr inbounds [2 x i32], [2 x i32]* %11, 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* %15
%93 = icmp sge i32 %92, 0
br i1 %93, label %94, label %101
94: ; preds = %84
%95 = load i32, i32* %15
%96 = sext i32 %95 to i64
%97 = getelementptr inbounds i8, i8* %27, i64 %96
store i8 0, i8* %97
%98 = load i32, i32* %15
%99 = sitofp i32 %98 to x86_fp80
%100 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, 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.7, 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.8, i64 0, i64 0))
%106 = call i32 @exit(i32 1)
unreachable
107: ; preds = %103
%108 = call i64 (...) @rdtsc()
store i64 %108, i64* %7
%109 = load i64, i64* %7
%110 = load i64, i64* %6
%111 = sub i64 %109, %110
%112 = uitofp i64 %111 to x86_fp80
%113 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.9, i64 0, i64 0), x86_fp80 %112)
%114 = load i64, i64* %7
%115 = load i64, i64* %6
%116 = sub i64 %114, %115
%117 = uitofp i64 %116 to x86_fp80
%118 = fdiv x86_fp80 %117, 0xK401E9AF8DA0000000000
store x86_fp80 %118, x86_fp80* %23
%119 = load x86_fp80, x86_fp80* %23
%120 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.10, i64 0, i64 0), x86_fp80 %119)
%121 = load i32*, i32** %21
%122 = load x86_fp80, x86_fp80* %23
%123 = call i32 @fprintf(i32* %121, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0), x86_fp80 %122)
%124 = load i32*, i32** %21
%125 = call i32 @fflush(i32* %124)
br label %126
126: ; preds = %107
%127 = load i32, i32* %22
%128 = add nsw i32 %127, 1
store i32 %128, i32* %22
br label %62
129: ; preds = %62
%130 = load i32*, i32** %21
%131 = call i32 @fclose(i32* %130)
%132 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.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 = [2 x i8] c"k\00"
@.str.4 = [37 x i8] c"/home/george/Documents/C/pipe64K.txt\00"
@.str.5 = [4 x i8] c"wt+\00"
@.str.6 = [31 x i8] c"read %d bytes from the pipe2 \0A\00"
@.str.7 = [5 x i8] c"read\00"
@.str.8 = [5 x i8] c"fork\00"
@.str.9 = [35 x i8] c"total cycles for round trip: %lld\0A\00"
@.str.10 = [40 x i8] c"time spend (half of bi-direction): %Lf\0A\00"
@.str.11 = [5 x i8] c"%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 = bitcast i32* %3 to i8*
%7 = bitcast [2 x i32]* %4 to i8*
%8 = bitcast [2 x i32]* %5 to i8*
%9 = tail call i8* @llvm.stacksave()
%10 = alloca [4 x i8]
%11 = alloca [4 x i8]
%12 = alloca [4 x i8]
%13 = getelementptr inbounds [4 x i8], [4 x i8]* %12, i64 0, i64 0
%14 = getelementptr inbounds [4 x i8], [4 x i8]* %11, i64 0, i64 0
%15 = getelementptr inbounds [4 x i8], [4 x i8]* %10, i64 0, i64 0
%16 = 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))
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %20
18: ; preds = %2
%19 = 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* %9)
ret i32 -1
20: ; preds = %2
%21 = call i32* @fgets(i8* %14, i32 4, i32* %16)
%22 = icmp eq i32* %21, null
br i1 %22, label %26, label %23
23: ; preds = %20
%24 = call i32 @memcpy(i8* %13, i8* %14, i32 4)
%25 = getelementptr inbounds [4 x i8], [4 x i8]* %12, i64 0, i64 4
store i8 0, i8* %25
br label %26
26: ; preds = %23, %20
%27 = call i32 @fclose(i32* %16)
%28 = call i32* @fopen(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%29 = icmp eq i32* %28, null
br i1 %29, label %34, label %30
30: ; preds = %26
%31 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%32 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%33 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
br label %37
34: ; preds = %26
%35 = call i32 @perror(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %30, %66
%38 = phi i32 [ 0, %30 ], [ %75, %66 ]
%39 = call i32 @pipe(i32* %31)
%40 = call i32 @pipe(i32* %32)
%41 = call i64 (...) @rdtsc()
%42 = call i32 (...) @fork()
switch i32 %42, label %46 [
i32 0, label %43
i32 -1, label %63
]
43: ; preds = %37
%44 = call i32 @runpipe(i32* %31, i32* %32, i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8* %15)
%45 = call i32 @exit(i32 0)
unreachable
46: ; preds = %37, %46
%47 = call i32 @wait(i32* %3)
%48 = icmp eq i32 %47, -1
br i1 %48, label %49, label %46
49: ; preds = %46
%50 = load i32, i32* %33
%51 = call i32 @close(i32 %50)
%52 = load i32, i32* %32
%53 = call i32 @strlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%54 = call i32 @read(i32 %52, i8* %15, i32 %53)
%55 = icmp sgt i32 %54, -1
br i1 %55, label %56, label %61
56: ; preds = %49
%57 = zext i32 %54 to i64
%58 = getelementptr inbounds [4 x i8], [4 x i8]* %10, i64 0, i64 %57
store i8 0, i8* %58
%59 = sitofp i32 %54 to x86_fp80
%60 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0), x86_fp80 %59)
br label %66
61: ; preds = %49
%62 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
br label %66
63: ; preds = %37
%64 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%65 = call i32 @exit(i32 1)
unreachable
66: ; preds = %56, %61
%67 = call i64 (...) @rdtsc()
%68 = sub i64 %67, %41
%69 = uitofp i64 %68 to x86_fp80
%70 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.9, i64 0, i64 0), x86_fp80 %69)
%71 = fdiv x86_fp80 %69, 0xK401E9AF8DA0000000000
%72 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.10, i64 0, i64 0), x86_fp80 %71)
%73 = call i32 @fprintf(i32* %28, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0), x86_fp80 %71)
%74 = call i32 @fflush(i32* %28)
%75 = add nuw nsw i32 %38, 1
%76 = icmp eq i32 %75, 100
br i1 %76, label %77, label %37
77: ; preds = %66
%78 = call i32 @fclose(i32* %28)
%79 = call i32 @exit(i32 0)
unreachable
}