#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 timespec {
  int tv_sec;
  int tv_nsec;
};
typedef int pid_t;

/* Variables and functions */
int /*<<< orphan*/ CLOCK_MONOTONIC;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
unsigned int Readn(int, char *, unsigned int);
int /*<<< orphan*/ Writen(int, char *, unsigned int);
int /*<<< orphan*/ _exit(int /*<<< orphan*/);
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ pipe(int *);
int /*<<< orphan*/ printf(char *, unsigned int);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
long unsigned pipe_latency(unsigned expected_size, bool debug) {
  int pipe_go[2], pipe_come[2];
  pid_t child_pid;
  char buf[(512 * 1024 + 1)];
  unsigned transferred;
  struct timespec start;
  struct timespec end;
  memset(buf, 0, (512 * 1024 + 1));
  pipe(pipe_go);
  pipe(pipe_come);
  child_pid = fork();
  if (child_pid == -1) {
    perror("fork");
    exit(EXIT_FAILURE);
  } else if (child_pid == 0) {
    close(pipe_go[1]);
    close(pipe_come[0]);
    if (debug)
      printf("child is reading %u...\n", expected_size);
    if ((transferred = Readn(pipe_go[0], buf, expected_size)) < expected_size) {
      perror("read less than expected");
    }
    if (debug)
      printf("child is sending %u...\n", expected_size);
    Writen(pipe_come[1], buf, expected_size);
    close(pipe_go[0]);
    close(pipe_come[1]);
    if (debug)
      printf("child is exiting %u...\n", expected_size);
    _exit(EXIT_SUCCESS);
  } else {
    close(pipe_go[0]);
    close(pipe_come[1]);
    clock_gettime(CLOCK_MONOTONIC, &start);
    if (debug)
      printf("parent is writing %u...\n", expected_size);
    Writen(pipe_go[1], buf, expected_size);
    if (debug)
      printf("parent is reading %u...\n", expected_size);
    if ((transferred = Readn(pipe_come[0], buf, expected_size)) <
        expected_size) {
      perror("read less than expected");
    }
    clock_gettime(CLOCK_MONOTONIC, &end);
    close(pipe_go[1]);
    close(pipe_come[0]);
    if (debug)
      printf("parent is waiting after %u...\n", expected_size);
    wait(NULL);
    if (debug)
      printf("parent is returning after %u...\n", expected_size);
    return ((end.tv_sec - start.tv_sec) * 1000000000 + end.tv_nsec -
            start.tv_nsec) /
           2;
  }
}


x86 assembly (clang, -O0):
<pipe_latency>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80040,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
lea    -0x80020(%rbp),%rdi
xor    %esi,%esi
mov    $0x80001,%edx
call   1070 <memset@plt>
lea    -0x10(%rbp),%rdi
call   1090 <pipe@plt>
lea    -0x18(%rbp),%rdi
call   1090 <pipe@plt>
mov    $0x0,%al
call   10e0 <fork@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1224 <pipe_latency+0x64>
lea    0xdef(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2dbb(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
cmpl   $0x0,-0x1c(%rbp)
jne    12e6 <pipe_latency+0x126>
mov    -0xc(%rbp),%edi
call   1080 <close@plt>
mov    -0x18(%rbp),%edi
call   1080 <close@plt>
cmpl   $0x0,-0x8(%rbp)
je     1257 <pipe_latency+0x97>
mov    -0x4(%rbp),%esi
lea    0xdb3(%rip),%rdi
call   1060 <printf@plt>
mov    -0x10(%rbp),%edi
lea    -0x80020(%rbp),%rsi
mov    -0x4(%rbp),%edx
call   1050 <Readn@plt>
mov    %eax,-0x80024(%rbp)
cmp    -0x4(%rbp),%eax
jae    1284 <pipe_latency+0xc4>
lea    0xd9e(%rip),%rdi
call   10a0 <perror@plt>
cmpl   $0x0,-0x8(%rbp)
je     129d <pipe_latency+0xdd>
mov    -0x4(%rbp),%esi
lea    0xd9d(%rip),%rdi
call   1060 <printf@plt>
mov    -0x14(%rbp),%edi
lea    -0x80020(%rbp),%rsi
mov    -0x4(%rbp),%edx
call   10b0 <Writen@plt>
mov    -0x10(%rbp),%edi
call   1080 <close@plt>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
cmpl   $0x0,-0x8(%rbp)
je     12d8 <pipe_latency+0x118>
mov    -0x4(%rbp),%esi
lea    0xd7a(%rip),%rdi
call   1060 <printf@plt>
mov    0x2cf1(%rip),%rax
mov    (%rax),%edi
call   1030 <_exit@plt>
mov    -0x10(%rbp),%edi
call   1080 <close@plt>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
mov    0x2ceb(%rip),%rax
mov    (%rax),%edi
lea    -0x80030(%rbp),%rsi
call   1040 <clock_gettime@plt>
cmpl   $0x0,-0x8(%rbp)
je     1324 <pipe_latency+0x164>
mov    -0x4(%rbp),%esi
lea    0xd46(%rip),%rdi
call   1060 <printf@plt>
mov    -0xc(%rbp),%edi
lea    -0x80020(%rbp),%rsi
mov    -0x4(%rbp),%edx
call   10b0 <Writen@plt>
cmpl   $0x0,-0x8(%rbp)
je     134f <pipe_latency+0x18f>
mov    -0x4(%rbp),%esi
lea    0xd34(%rip),%rdi
call   1060 <printf@plt>
mov    -0x18(%rbp),%edi
lea    -0x80020(%rbp),%rsi
mov    -0x4(%rbp),%edx
call   1050 <Readn@plt>
mov    %eax,-0x80024(%rbp)
cmp    -0x4(%rbp),%eax
jae    137c <pipe_latency+0x1bc>
lea    0xca6(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2c65(%rip),%rax
mov    (%rax),%edi
lea    -0x80038(%rbp),%rsi
call   1040 <clock_gettime@plt>
mov    -0xc(%rbp),%edi
call   1080 <close@plt>
mov    -0x18(%rbp),%edi
call   1080 <close@plt>
cmpl   $0x0,-0x8(%rbp)
je     13ba <pipe_latency+0x1fa>
mov    -0x4(%rbp),%esi
lea    0xce2(%rip),%rdi
call   1060 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10d0 <wait@plt>
cmpl   $0x0,-0x8(%rbp)
je     13dc <pipe_latency+0x21c>
mov    -0x4(%rbp),%esi
lea    0xcdf(%rip),%rdi
call   1060 <printf@plt>
mov    -0x80038(%rbp),%eax
sub    -0x80030(%rbp),%eax
imul   $0x3b9aca00,%eax,%eax
add    -0x80034(%rbp),%eax
sub    -0x8002c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cltq
add    $0x80040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pipe_latency>:
push   %rbp
push   %r14
push   %rbx
sub    $0x80030,%rsp
mov    %esi,%r14d
mov    %edi,%ebx
lea    0x20(%rsp),%rdi
xor    %esi,%esi
mov    $0x80001,%edx
call   1070 <memset@plt>
lea    0x8(%rsp),%rdi
call   1090 <pipe@plt>
mov    %rsp,%rdi
call   1090 <pipe@plt>
xor    %eax,%eax
call   10e0 <fork@plt>
test   %eax,%eax
je     1315 <pipe_latency+0x155>
cmp    $0xffffffff,%eax
je     1382 <pipe_latency+0x1c2>
mov    0x8(%rsp),%edi
call   1080 <close@plt>
mov    0x4(%rsp),%edi
call   1080 <close@plt>
mov    0x2dc4(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0x18(%rsp),%rsi
call   1040 <clock_gettime@plt>
test   %r14d,%r14d
je     1264 <pipe_latency+0xa4>
lea    0xe28(%rip),%rdi
mov    %ebx,%esi
call   1060 <printf@plt>
mov    0xc(%rsp),%edi
lea    0x20(%rsp),%rsi
mov    %ebx,%edx
call   10b0 <Writen@plt>
lea    0xe23(%rip),%rdi
mov    %ebx,%esi
call   1060 <printf@plt>
jmp    1274 <pipe_latency+0xb4>
mov    0xc(%rsp),%edi
lea    0x20(%rsp),%rsi
mov    %ebx,%edx
call   10b0 <Writen@plt>
mov    (%rsp),%edi
lea    0x20(%rsp),%rsi
mov    %ebx,%edx
call   1050 <Readn@plt>
cmp    %ebx,%eax
jb     1304 <pipe_latency+0x144>
mov    0x0(%rbp),%edi
lea    0x10(%rsp),%rsi
call   1040 <clock_gettime@plt>
mov    0xc(%rsp),%edi
call   1080 <close@plt>
mov    (%rsp),%edi
call   1080 <close@plt>
test   %r14d,%r14d
je     12cf <pipe_latency+0x10f>
lea    0xde6(%rip),%rdi
mov    %ebx,%esi
call   1060 <printf@plt>
xor    %edi,%edi
call   10d0 <wait@plt>
lea    0xdf0(%rip),%rdi
mov    %ebx,%esi
call   1060 <printf@plt>
jmp    12d6 <pipe_latency+0x116>
xor    %edi,%edi
call   10d0 <wait@plt>
mov    0x10(%rsp),%eax
sub    0x18(%rsp),%eax
imul   $0x3b9aca00,%eax,%eax
add    0x14(%rsp),%eax
sub    0x1c(%rsp),%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
movslq %ecx,%rax
add    $0x80030,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xd12(%rip),%rdi
call   10a0 <perror@plt>
jmp    1287 <pipe_latency+0xc7>
mov    0xc(%rsp),%edi
call   1080 <close@plt>
mov    (%rsp),%edi
call   1080 <close@plt>
test   %r14d,%r14d
je     1339 <pipe_latency+0x179>
lea    0xcd3(%rip),%rdi
mov    %ebx,%esi
call   1060 <printf@plt>
mov    0x8(%rsp),%edi
lea    0x20(%rsp),%rsi
mov    %ebx,%edx
call   1050 <Readn@plt>
cmp    %ebx,%eax
jae    1359 <pipe_latency+0x199>
lea    0xcc9(%rip),%rdi
call   10a0 <perror@plt>
test   %r14d,%r14d
jne    139c <pipe_latency+0x1dc>
mov    0x4(%rsp),%edi
lea    0x20(%rsp),%rsi
mov    %ebx,%edx
call   10b0 <Writen@plt>
mov    0x8(%rsp),%edi
call   1080 <close@plt>
mov    0x4(%rsp),%edi
call   1080 <close@plt>
jmp    13da <pipe_latency+0x21a>
lea    0xc77(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2c43(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
lea    0xc92(%rip),%rdi
mov    %ebx,%esi
call   1060 <printf@plt>
mov    0x4(%rsp),%edi
lea    0x20(%rsp),%rsi
mov    %ebx,%edx
call   10b0 <Writen@plt>
mov    0x8(%rsp),%edi
call   1080 <close@plt>
mov    0x4(%rsp),%edi
call   1080 <close@plt>
lea    0xc7a(%rip),%rdi
mov    %ebx,%esi
call   1060 <printf@plt>
mov    0x2bef(%rip),%rax
mov    (%rax),%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
@.str = [5 x i8] c"fork\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [24 x i8] c"child is reading %u...\0A\00"
@.str.2 = [24 x i8] c"read less than expected\00"
@.str.3 = [24 x i8] c"child is sending %u...\0A\00"
@.str.4 = [24 x i8] c"child is exiting %u...\0A\00"
@EXIT_SUCCESS = global i32 0
@CLOCK_MONOTONIC = global i32 0
@.str.5 = [25 x i8] c"parent is writing %u...\0A\00"
@.str.6 = [25 x i8] c"parent is reading %u...\0A\00"
@.str.7 = [31 x i8] c"parent is waiting after %u...\0A\00"
@.str.8 = [33 x i8] c"parent is returning after %u...\0A\00"
define i64 @pipe_latency(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [2 x i32]
%6 = alloca [2 x i32]
%7 = alloca i32
%8 = alloca [524289 x i8]
%9 = alloca i32
%10 = alloca %struct.timespec
%11 = alloca %struct.timespec
store i32 %0, i32* %3
store i32 %1, i32* %4
%12 = getelementptr inbounds [524289 x i8], [524289 x i8]* %8, i64 0, i64 0
%13 = call i32 @memset(i8* %12, i32 0, i32 524289)
%14 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%15 = call i32 @pipe(i32* %14)
%16 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%17 = call i32 @pipe(i32* %16)
%18 = call i32 (...) @fork()
store i32 %18, i32* %7
%19 = load i32, i32* %7
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %25
21: ; preds = %2
%22 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%23 = load i32, i32* @EXIT_FAILURE
%24 = call i32 @exit(i32 %23)
unreachable
25: ; preds = %2
%26 = load i32, i32* %7
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %76
28: ; preds = %25
%29 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%30 = load i32, i32* %29
%31 = call i32 @close(i32 %30)
%32 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%33 = load i32, i32* %32
%34 = call i32 @close(i32 %33)
%35 = load i32, i32* %4
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %28
%38 = load i32, i32* %3
%39 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %38)
br label %40
40: ; preds = %37, %28
%41 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%42 = load i32, i32* %41
%43 = getelementptr inbounds [524289 x i8], [524289 x i8]* %8, i64 0, i64 0
%44 = load i32, i32* %3
%45 = call i32 @Readn(i32 %42, i8* %43, i32 %44)
store i32 %45, i32* %9
%46 = load i32, i32* %3
%47 = icmp ult i32 %45, %46
br i1 %47, label %48, label %50
48: ; preds = %40
%49 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
br label %50
50: ; preds = %48, %40
%51 = load i32, i32* %4
%52 = icmp ne i32 %51, 0
br i1 %52, label %53, label %56
53: ; preds = %50
%54 = load i32, i32* %3
%55 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %54)
br label %56
56: ; preds = %53, %50
%57 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%58 = load i32, i32* %57
%59 = getelementptr inbounds [524289 x i8], [524289 x i8]* %8, i64 0, i64 0
%60 = load i32, i32* %3
%61 = call i32 @Writen(i32 %58, i8* %59, i32 %60)
%62 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%63 = load i32, i32* %62
%64 = call i32 @close(i32 %63)
%65 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%66 = load i32, i32* %65
%67 = call i32 @close(i32 %66)
%68 = load i32, i32* %4
%69 = icmp ne i32 %68, 0
br i1 %69, label %70, label %73
70: ; preds = %56
%71 = load i32, i32* %3
%72 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i32 %71)
br label %73
73: ; preds = %70, %56
%74 = load i32, i32* @EXIT_SUCCESS
%75 = call i32 @_exit(i32 %74)
unreachable
76: ; preds = %25
%77 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%78 = load i32, i32* %77
%79 = call i32 @close(i32 %78)
%80 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%81 = load i32, i32* %80
%82 = call i32 @close(i32 %81)
%83 = load i32, i32* @CLOCK_MONOTONIC
%84 = call i32 @clock_gettime(i32 %83, %struct.timespec* %10)
%85 = load i32, i32* %4
%86 = icmp ne i32 %85, 0
br i1 %86, label %87, label %90
87: ; preds = %76
%88 = load i32, i32* %3
%89 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i32 %88)
br label %90
90: ; preds = %87, %76
%91 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%92 = load i32, i32* %91
%93 = getelementptr inbounds [524289 x i8], [524289 x i8]* %8, i64 0, i64 0
%94 = load i32, i32* %3
%95 = call i32 @Writen(i32 %92, i8* %93, i32 %94)
%96 = load i32, i32* %4
%97 = icmp ne i32 %96, 0
br i1 %97, label %98, label %101
98: ; preds = %90
%99 = load i32, i32* %3
%100 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i32 %99)
br label %101
101: ; preds = %98, %90
%102 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%103 = load i32, i32* %102
%104 = getelementptr inbounds [524289 x i8], [524289 x i8]* %8, i64 0, i64 0
%105 = load i32, i32* %3
%106 = call i32 @Readn(i32 %103, i8* %104, i32 %105)
store i32 %106, i32* %9
%107 = load i32, i32* %3
%108 = icmp ult i32 %106, %107
br i1 %108, label %109, label %111
109: ; preds = %101
%110 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
br label %111
111: ; preds = %109, %101
%112 = load i32, i32* @CLOCK_MONOTONIC
%113 = call i32 @clock_gettime(i32 %112, %struct.timespec* %11)
%114 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%115 = load i32, i32* %114
%116 = call i32 @close(i32 %115)
%117 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%118 = load i32, i32* %117
%119 = call i32 @close(i32 %118)
%120 = load i32, i32* %4
%121 = icmp ne i32 %120, 0
br i1 %121, label %122, label %125
122: ; preds = %111
%123 = load i32, i32* %3
%124 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0), i32 %123)
br label %125
125: ; preds = %122, %111
%126 = call i32 @wait(i32* null)
%127 = load i32, i32* %4
%128 = icmp ne i32 %127, 0
br i1 %128, label %129, label %132
129: ; preds = %125
%130 = load i32, i32* %3
%131 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0), i32 %130)
br label %132
132: ; preds = %129, %125
%133 = getelementptr inbounds %struct.timespec, %struct.timespec* %11, i32 0, i32 0
%134 = load i32, i32* %133
%135 = getelementptr inbounds %struct.timespec, %struct.timespec* %10, i32 0, i32 0
%136 = load i32, i32* %135
%137 = sub nsw i32 %134, %136
%138 = mul nsw i32 %137, 1000000000
%139 = getelementptr inbounds %struct.timespec, %struct.timespec* %11, i32 0, i32 1
%140 = load i32, i32* %139
%141 = add nsw i32 %138, %140
%142 = getelementptr inbounds %struct.timespec, %struct.timespec* %10, i32 0, i32 1
%143 = load i32, i32* %142
%144 = sub nsw i32 %141, %143
%145 = sdiv i32 %144, 2
%146 = sext i32 %145 to i64
ret i64 %146
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
@.str = [5 x i8] c"fork\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [24 x i8] c"child is reading %u...\0A\00"
@.str.2 = [24 x i8] c"read less than expected\00"
@.str.3 = [24 x i8] c"child is sending %u...\0A\00"
@.str.4 = [24 x i8] c"child is exiting %u...\0A\00"
@EXIT_SUCCESS = global i32 0
@CLOCK_MONOTONIC = global i32 0
@.str.5 = [25 x i8] c"parent is writing %u...\0A\00"
@.str.6 = [25 x i8] c"parent is reading %u...\0A\00"
@.str.7 = [31 x i8] c"parent is waiting after %u...\0A\00"
@.str.8 = [33 x i8] c"parent is returning after %u...\0A\00"
define i64 @pipe_latency(i32 %0, i32 %1) {
%3 = alloca [2 x i32]
%4 = alloca [2 x i32]
%5 = alloca [524289 x i8]
%6 = alloca %struct.timespec
%7 = alloca %struct.timespec
%8 = bitcast [2 x i32]* %3 to i8*
%9 = bitcast [2 x i32]* %4 to i8*
%10 = getelementptr inbounds [524289 x i8], [524289 x i8]* %5, i64 0, i64 0
%11 = bitcast %struct.timespec* %6 to i8*
%12 = bitcast %struct.timespec* %7 to i8*
%13 = call i32 @memset(i8* %10, i32 0, i32 524289)
%14 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%15 = call i32 @pipe(i32* %14)
%16 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%17 = call i32 @pipe(i32* %16)
%18 = call i32 (...) @fork()
switch i32 %18, label %60 [
i32 -1, label %19
i32 0, label %23
]
19: ; preds = %2
%20 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
23: ; preds = %2
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%25 = load i32, i32* %24
%26 = call i32 @close(i32 %25)
%27 = load i32, i32* %16
%28 = call i32 @close(i32 %27)
%29 = icmp eq i32 %1, 0
br i1 %29, label %32, label %30
30: ; preds = %23
%31 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %0)
br label %32
32: ; preds = %30, %23
%33 = load i32, i32* %14
%34 = call i32 @Readn(i32 %33, i8* %10, i32 %0)
%35 = icmp ult i32 %34, %0
br i1 %35, label %36, label %38
36: ; preds = %32
%37 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
br label %38
38: ; preds = %36, %32
br i1 %29, label %49, label %39
39: ; preds = %38
%40 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %0)
%41 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%42 = load i32, i32* %41
%43 = call i32 @Writen(i32 %42, i8* %10, i32 %0)
%44 = load i32, i32* %14
%45 = call i32 @close(i32 %44)
%46 = load i32, i32* %41
%47 = call i32 @close(i32 %46)
%48 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i32 %0)
br label %57
49: ; preds = %38
%50 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%51 = load i32, i32* %50
%52 = call i32 @Writen(i32 %51, i8* %10, i32 %0)
%53 = load i32, i32* %14
%54 = call i32 @close(i32 %53)
%55 = load i32, i32* %50
%56 = call i32 @close(i32 %55)
br label %57
57: ; preds = %49, %39
%58 = load i32, i32* @EXIT_SUCCESS
%59 = call i32 @_exit(i32 %58)
unreachable
60: ; preds = %2
%61 = load i32, i32* %14
%62 = call i32 @close(i32 %61)
%63 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%64 = load i32, i32* %63
%65 = call i32 @close(i32 %64)
%66 = load i32, i32* @CLOCK_MONOTONIC
%67 = call i32 @clock_gettime(i32 %66, %struct.timespec* %6)
%68 = icmp eq i32 %1, 0
br i1 %68, label %69, label %73
69: ; preds = %60
%70 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%71 = load i32, i32* %70
%72 = call i32 @Writen(i32 %71, i8* %10, i32 %0)
br label %79
73: ; preds = %60
%74 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i32 %0)
%75 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%76 = load i32, i32* %75
%77 = call i32 @Writen(i32 %76, i8* %10, i32 %0)
%78 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i32 %0)
br label %79
79: ; preds = %69, %73
%80 = phi i32* [ %70, %69 ], [ %75, %73 ]
%81 = load i32, i32* %16
%82 = call i32 @Readn(i32 %81, i8* %10, i32 %0)
%83 = icmp ult i32 %82, %0
br i1 %83, label %84, label %86
84: ; preds = %79
%85 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
br label %86
86: ; preds = %84, %79
%87 = load i32, i32* @CLOCK_MONOTONIC
%88 = call i32 @clock_gettime(i32 %87, %struct.timespec* %7)
%89 = load i32, i32* %80
%90 = call i32 @close(i32 %89)
%91 = load i32, i32* %16
%92 = call i32 @close(i32 %91)
br i1 %68, label %97, label %93
93: ; preds = %86
%94 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0), i32 %0)
%95 = call i32 @wait(i32* null)
%96 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0), i32 %0)
br label %99
97: ; preds = %86
%98 = call i32 @wait(i32* null)
br label %99
99: ; preds = %97, %93
%100 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i64 0, i32 0
%101 = load i32, i32* %100
%102 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i64 0, i32 0
%103 = load i32, i32* %102
%104 = sub nsw i32 %101, %103
%105 = mul nsw i32 %104, 1000000000
%106 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i64 0, i32 1
%107 = load i32, i32* %106
%108 = add nsw i32 %105, %107
%109 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i64 0, i32 1
%110 = load i32, i32* %109
%111 = sub i32 %108, %110
%112 = sdiv i32 %111, 2
%113 = sext i32 %112 to i64
ret i64 %113
}