#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 {
  int tv_sec;
  int tv_usec;
};

/* Variables and functions */
scalar_t__ EOF;
int atoi(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
char getopt(int, char **, char *);
scalar_t__ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
scalar_t__ pipe(int *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ read(int, char *, int);
int /*<<< orphan*/ usage();
scalar_t__ write(int, char *, int);
main(int argc, char **argv) {
  struct timeval starttime, endtime;
  char buf[1];
  int count = 1000;
  int debug = 0;
  int fd0[2];
  int fd1[2];
  int i;
  char word[256];
  extern int optind, opterr;
  extern char *optarg;
  while ((word[0] = getopt(argc, argv, "c:d?")) != (char)EOF) {
    switch (word[0]) {
    case 'd':
      debug++;
      break;
    case 'c':
      count = atoi(optarg);
      break;
    case '?':
      usage();
      return (0);
    default:
      usage();
      return (-1);
    }
  }
  if ((pipe(fd0) < 0) || (pipe(fd1) < 0)) {
    printf("Error: pipe\n");
    exit(0);
  }
  switch (fork()) {
  case -1:
    printf("Error: fork\n");
    exit(0);
  case 0:
    for (i = 0; i < count; i++) {
      if (read(fd1[0], buf, 1) < 0) {
        printf("Error: child read\n");
        exit(0);
      }
      if (write(fd0[1], buf, 1) < 0) {
        printf("Error: child write\n");
        exit(0);
      }
    }
    exit(0);
    break;
  default:
    break;
  }
  if (gettimeofday(&starttime, NULL)) {
    printf("Error: gettimeofday\n");
    exit(0);
  }
  count--;
  if (write(fd1[1], buf, 1) < 0) {
    perror("first parent write");
    exit(0);
  }
  for (i = 0; i < count; i++) {
    if (read(fd0[0], buf, 1) < 0) {
      printf("Error: parent read\n");
      exit(0);
    }
    if (write(fd1[1], buf, 1) < 0) {
      printf("Error: parent write\n");
      exit(0);
    }
  }
  if (gettimeofday(&endtime, NULL)) {
    printf("Error: gettimeofday\n");
    exit(0);
  }
  printf("%d ping pong tests took %d usecs.\n", count,
         (endtime.tv_sec - starttime.tv_sec) * 1000000 +
             (endtime.tv_usec - starttime.tv_usec));
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x3e8,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe1b(%rip),%rdx
call   10a0 <getopt@plt>
mov    %al,-0x140(%rbp)
movsbl %al,%eax
mov    0x2dee(%rip),%rcx
mov    (%rcx),%rcx
movsbl %cl,%ecx
cmp    %ecx,%eax
je     129b <main+0xeb>
movsbl -0x140(%rbp),%eax
mov    %eax,-0x144(%rbp)
sub    $0x3f,%eax
je     1270 <main+0xc0>
jmp    1223 <main+0x73>
mov    -0x144(%rbp),%eax
sub    $0x63,%eax
je     1259 <main+0xa9>
jmp    1237 <main+0x87>
mov    -0x144(%rbp),%eax
sub    $0x64,%eax
jne    1283 <main+0xd3>
jmp    124b <main+0x9b>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1296 <main+0xe6>
mov    0x2d78(%rip),%rax
mov    (%rax),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x28(%rbp)
jmp    1296 <main+0xe6>
mov    $0x0,%al
call   1080 <usage@plt>
movl   $0x0,-0x4(%rbp)
jmp    14e7 <main+0x337>
mov    $0x0,%al
call   1080 <usage@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14e7 <main+0x337>
jmp    11d7 <main+0x27>
lea    -0x34(%rbp),%rdi
call   1060 <pipe@plt>
cmp    $0x0,%rax
jl     12c1 <main+0x111>
lea    -0x3c(%rbp),%rdi
call   1060 <pipe@plt>
cmp    $0x0,%rax
jge    12d6 <main+0x126>
lea    0xd3d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
xor    %eax,%eax
call   10d0 <fork@plt>
mov    %eax,%ecx
mov    %ecx,-0x148(%rbp)
sub    $0xffffffff,%eax
je     1306 <main+0x156>
jmp    12f3 <main+0x143>
mov    -0x148(%rbp),%eax
test   %eax,%eax
je     131b <main+0x16b>
jmp    13a8 <main+0x1f8>
lea    0xd05(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
movl   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    13a1 <main+0x1f1>
mov    -0x3c(%rbp),%edi
lea    -0x21(%rbp),%rsi
mov    $0x1,%edx
call   1070 <read@plt>
cmp    $0x0,%rax
jge    135e <main+0x1ae>
lea    0xccf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
mov    -0x30(%rbp),%edi
lea    -0x21(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    138e <main+0x1de>
lea    0xcb2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
jmp    1393 <main+0x1e3>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    1322 <main+0x172>
xor    %edi,%edi
call   10c0 <exit@plt>
jmp    13ad <main+0x1fd>
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
cmp    $0x0,%rax
je     13d9 <main+0x229>
lea    0xc7b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
mov    -0x28(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x28(%rbp)
mov    -0x38(%rbp),%edi
lea    -0x21(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    1410 <main+0x260>
lea    0xc57(%rip),%rdi
call   1090 <perror@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
movl   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    1496 <main+0x2e6>
mov    -0x34(%rbp),%edi
lea    -0x21(%rbp),%rsi
mov    $0x1,%edx
call   1070 <read@plt>
cmp    $0x0,%rax
jge    1453 <main+0x2a3>
lea    0xc29(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
mov    -0x38(%rbp),%edi
lea    -0x21(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    1483 <main+0x2d3>
lea    0xc0d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
jmp    1488 <main+0x2d8>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    1417 <main+0x267>
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
cmp    $0x0,%rax
je     14c2 <main+0x312>
lea    0xb92(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
mov    -0x28(%rbp),%esi
mov    -0x20(%rbp),%eax
sub    -0x18(%rbp),%eax
imul   $0xf4240,%eax,%edx
mov    -0x1c(%rbp),%eax
sub    -0x14(%rbp),%eax
add    %eax,%edx
lea    0xbb7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rbp
mov    %edi,%ebx
lea    0xe26(%rip),%rdx
call   10b0 <getopt@plt>
movsbl %al,%eax
mov    0x2dff(%rip),%r12
movsbl (%r12),%ecx
mov    $0x3e8,%r14d
cmp    %eax,%ecx
jne    130a <main+0x14a>
lea    0x20(%rsp),%rdi
call   1070 <pipe@plt>
test   %rax,%rax
js     138d <main+0x1cd>
lea    0x8(%rsp),%rdi
call   1070 <pipe@plt>
test   %rax,%rax
js     138d <main+0x1cd>
xor    %eax,%eax
call   10e0 <fork@plt>
cmp    $0xffffffff,%eax
je     139f <main+0x1df>
test   %eax,%eax
je     13a8 <main+0x1e8>
lea    0x18(%rsp),%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
test   %rax,%rax
jne    1396 <main+0x1d6>
mov    0xc(%rsp),%edi
lea    0x7(%rsp),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
test   %rax,%rax
js     13eb <main+0x22b>
lea    -0x1(%r14),%r15d
cmp    $0x2,%r14d
jl     12b9 <main+0xf9>
lea    0x7(%rsp),%rbx
mov    %r15d,%ebp
nopl   (%rax)
mov    0x20(%rsp),%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1080 <read@plt>
test   %rax,%rax
js     1371 <main+0x1b1>
mov    0xc(%rsp),%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1040 <write@plt>
test   %rax,%rax
js     137a <main+0x1ba>
add    $0xffffffff,%ebp
jne    1280 <main+0xc0>
xor    %ebx,%ebx
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
test   %rax,%rax
jne    1396 <main+0x1d6>
mov    0x10(%rsp),%eax
mov    0x14(%rsp),%edx
sub    0x18(%rsp),%eax
imul   $0xf4240,%eax,%eax
sub    0x1c(%rsp),%edx
add    %eax,%edx
lea    0xd29(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x3e8,%r14d
mov    0x2cc1(%rip),%r13
lea    0xce2(%rip),%r15
jmp    1349 <main+0x189>
mov    0x0(%r13),%rdi
call   10c0 <atoi@plt>
mov    %eax,%r14d
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %r15,%rdx
call   10b0 <getopt@plt>
movsbl %al,%eax
movsbl (%r12),%ecx
cmp    %eax,%ecx
je     11fc <main+0x3c>
cmp    $0x63,%eax
je     1320 <main+0x160>
cmp    $0x64,%eax
je     132c <main+0x16c>
cmp    $0x3f,%eax
jne    1363 <main+0x1a3>
xor    %ebx,%ebx
xor    %eax,%eax
call   1090 <usage@plt>
jmp    12f9 <main+0x139>
xor    %eax,%eax
call   1090 <usage@plt>
mov    $0xffffffff,%ebx
jmp    12f9 <main+0x139>
lea    0xd08(%rip),%rdi
jmp    1381 <main+0x1c1>
lea    0xceb(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
lea    0xd13(%rip),%rdi
jmp    1381 <main+0x1c1>
lea    0xcf6(%rip),%rdi
jmp    1381 <main+0x1c1>
lea    0xcba(%rip),%rdi
jmp    1381 <main+0x1c1>
test   %r14d,%r14d
jle    13e4 <main+0x224>
lea    0x7(%rsp),%rbx
mov    0x8(%rsp),%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1080 <read@plt>
test   %rax,%rax
js     13fe <main+0x23e>
mov    0x24(%rsp),%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1040 <write@plt>
test   %rax,%rax
js     140a <main+0x24a>
add    $0xffffffff,%r14d
jne    13b2 <main+0x1f2>
xor    %edi,%edi
call   10d0 <exit@plt>
lea    0xc13(%rip),%rdi
call   10a0 <perror@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
lea    0xc49(%rip),%rdi
jmp    1381 <main+0x1c1>
lea    0xc2a(%rip),%rdi
jmp    1381 <main+0x1c1>

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@.str = [5 x i8] c"c:d?\00"
@EOF = global i64 0
@optarg = external global i8*
@.str.1 = [13 x i8] c"Error: pipe\0A\00"
@.str.2 = [13 x i8] c"Error: fork\0A\00"
@.str.3 = [19 x i8] c"Error: child read\0A\00"
@.str.4 = [20 x i8] c"Error: child write\0A\00"
@.str.5 = [21 x i8] c"Error: gettimeofday\0A\00"
@.str.6 = [19 x i8] c"first parent write\00"
@.str.7 = [20 x i8] c"Error: parent read\0A\00"
@.str.8 = [21 x i8] c"Error: parent write\0A\00"
@.str.9 = [35 x i8] c"%d ping pong tests took %d usecs.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.timeval
%7 = alloca %struct.timeval
%8 = alloca [1 x i8]
%9 = alloca i32
%10 = alloca i32
%11 = alloca [2 x i32]
%12 = alloca [2 x i32]
%13 = alloca i32
%14 = alloca [256 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1000, i32* %9
store i32 0, i32* %10
br label %15
15: ; preds = %39, %2
%16 = load i32, i32* %4
%17 = load i8**, i8*** %5
%18 = call signext i8 @getopt(i32 %16, i8** %17, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 0
store i8 %18, i8* %19
%20 = sext i8 %18 to i32
%21 = load i64, i64* @EOF
%22 = trunc i64 %21 to i8
%23 = sext i8 %22 to i32
%24 = icmp ne i32 %20, %23
br i1 %24, label %25, label %40
25: ; preds = %15
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 0
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
switch i32 %28, label %37 [
i32 100, label %29
i32 99, label %32
i32 63, label %35
]
29: ; preds = %25
%30 = load i32, i32* %10
%31 = add nsw i32 %30, 1
store i32 %31, i32* %10
br label %39
32: ; preds = %25
%33 = load i8*, i8** @optarg
%34 = call i32 @atoi(i8* %33)
store i32 %34, i32* %9
br label %39
35: ; preds = %25
%36 = call i32 (...) @usage()
store i32 0, i32* %3
br label %151
37: ; preds = %25
%38 = call i32 (...) @usage()
store i32 -1, i32* %3
br label %151
39: ; preds = %32, %29
br label %15
40: ; preds = %15
%41 = getelementptr inbounds [2 x i32], [2 x i32]* %11, i64 0, i64 0
%42 = call i64 @pipe(i32* %41)
%43 = icmp slt i64 %42, 0
br i1 %43, label %48, label %44
44: ; preds = %40
%45 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 0
%46 = call i64 @pipe(i32* %45)
%47 = icmp slt i64 %46, 0
br i1 %47, label %48, label %51
48: ; preds = %44, %40
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%50 = call i32 @exit(i32 0)
unreachable
51: ; preds = %44
%52 = call i32 (...) @fork()
switch i32 %52, label %85 [
i32 -1, label %53
i32 0, label %56
]
53: ; preds = %51
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%55 = call i32 @exit(i32 0)
unreachable
56: ; preds = %51
store i32 0, i32* %13
br label %57
57: ; preds = %80, %56
%58 = load i32, i32* %13
%59 = load i32, i32* %9
%60 = icmp slt i32 %58, %59
br i1 %60, label %61, label %83
61: ; preds = %57
%62 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 0
%63 = load i32, i32* %62
%64 = getelementptr inbounds [1 x i8], [1 x i8]* %8, i64 0, i64 0
%65 = call i64 @read(i32 %63, i8* %64, i32 1)
%66 = icmp slt i64 %65, 0
br i1 %66, label %67, label %70
67: ; preds = %61
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%69 = call i32 @exit(i32 0)
unreachable
70: ; preds = %61
%71 = getelementptr inbounds [2 x i32], [2 x i32]* %11, i64 0, i64 1
%72 = load i32, i32* %71
%73 = getelementptr inbounds [1 x i8], [1 x i8]* %8, i64 0, i64 0
%74 = call i64 @write(i32 %72, i8* %73, i32 1)
%75 = icmp slt i64 %74, 0
br i1 %75, label %76, label %79
76: ; preds = %70
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%78 = call i32 @exit(i32 0)
unreachable
79: ; preds = %70
br label %80
80: ; preds = %79
%81 = load i32, i32* %13
%82 = add nsw i32 %81, 1
store i32 %82, i32* %13
br label %57
83: ; preds = %57
%84 = call i32 @exit(i32 0)
unreachable
85: ; preds = %51
br label %86
86: ; preds = %85
%87 = call i64 @gettimeofday(%struct.timeval* %6, i32* null)
%88 = icmp ne i64 %87, 0
br i1 %88, label %89, label %92
89: ; preds = %86
%90 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
%91 = call i32 @exit(i32 0)
unreachable
92: ; preds = %86
%93 = load i32, i32* %9
%94 = add nsw i32 %93, -1
store i32 %94, i32* %9
%95 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 1
%96 = load i32, i32* %95
%97 = getelementptr inbounds [1 x i8], [1 x i8]* %8, i64 0, i64 0
%98 = call i64 @write(i32 %96, i8* %97, i32 1)
%99 = icmp slt i64 %98, 0
br i1 %99, label %100, label %103
100: ; preds = %92
%101 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0))
%102 = call i32 @exit(i32 0)
unreachable
103: ; preds = %92
store i32 0, i32* %13
br label %104
104: ; preds = %127, %103
%105 = load i32, i32* %13
%106 = load i32, i32* %9
%107 = icmp slt i32 %105, %106
br i1 %107, label %108, label %130
108: ; preds = %104
%109 = getelementptr inbounds [2 x i32], [2 x i32]* %11, i64 0, i64 0
%110 = load i32, i32* %109
%111 = getelementptr inbounds [1 x i8], [1 x i8]* %8, i64 0, i64 0
%112 = call i64 @read(i32 %110, i8* %111, i32 1)
%113 = icmp slt i64 %112, 0
br i1 %113, label %114, label %117
114: ; preds = %108
%115 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0))
%116 = call i32 @exit(i32 0)
unreachable
117: ; preds = %108
%118 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 1
%119 = load i32, i32* %118
%120 = getelementptr inbounds [1 x i8], [1 x i8]* %8, i64 0, i64 0
%121 = call i64 @write(i32 %119, i8* %120, i32 1)
%122 = icmp slt i64 %121, 0
br i1 %122, label %123, label %126
123: ; preds = %117
%124 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0))
%125 = call i32 @exit(i32 0)
unreachable
126: ; preds = %117
br label %127
127: ; preds = %126
%128 = load i32, i32* %13
%129 = add nsw i32 %128, 1
store i32 %129, i32* %13
br label %104
130: ; preds = %104
%131 = call i64 @gettimeofday(%struct.timeval* %7, i32* null)
%132 = icmp ne i64 %131, 0
br i1 %132, label %133, label %136
133: ; preds = %130
%134 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
%135 = call i32 @exit(i32 0)
unreachable
136: ; preds = %130
%137 = load i32, i32* %9
%138 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 0
%139 = load i32, i32* %138
%140 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
%141 = load i32, i32* %140
%142 = sub nsw i32 %139, %141
%143 = mul nsw i32 %142, 1000000
%144 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 1
%145 = load i32, i32* %144
%146 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 1
%147 = load i32, i32* %146
%148 = sub nsw i32 %145, %147
%149 = add nsw i32 %143, %148
%150 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.9, i64 0, i64 0), i32 %137, i32 %149)
br label %151
151: ; preds = %136, %37, %35
%152 = load i32, i32* %3
ret i32 %152
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@.str = [5 x i8] c"c:d?\00"
@EOF = global i64 0
@optarg = external global i8*
@.str.6 = [19 x i8] c"first parent write\00"
@.str.9 = [35 x i8] c"%d ping pong tests took %d usecs.\0A\00"
@str = [19 x i8] c"Error: child write\00"
@str.10 = [18 x i8] c"Error: child read\00"
@str.11 = [12 x i8] c"Error: fork\00"
@str.13 = [20 x i8] c"Error: parent write\00"
@str.14 = [19 x i8] c"Error: parent read\00"
@str.15 = [20 x i8] c"Error: gettimeofday\00"
@str.16 = [12 x i8] c"Error: pipe\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval
%5 = alloca [1 x i8]
%6 = alloca [2 x i32]
%7 = alloca [2 x i32]
%8 = bitcast %struct.timeval* %3 to i8*
%9 = bitcast %struct.timeval* %4 to i8*
%10 = getelementptr inbounds [1 x i8], [1 x i8]* %5, i64 0, i64 0
%11 = bitcast [2 x i32]* %6 to i8*
%12 = bitcast [2 x i32]* %7 to i8*
%13 = tail call signext i8 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%14 = sext i8 %13 to i32
%15 = load i64, i64* @EOF
%16 = trunc i64 %15 to i32
%17 = shl i32 %16, 24
%18 = ashr exact i32 %17, 24
%19 = icmp eq i32 %18, %14
br i1 %19, label %39, label %20
20: ; preds = %2, %30
%21 = phi i32 [ %33, %30 ], [ %14, %2 ]
%22 = phi i32 [ %31, %30 ], [ 1000, %2 ]
switch i32 %21, label %28 [
i32 100, label %30
i32 99, label %23
i32 63, label %26
]
23: ; preds = %20
%24 = load i8*, i8** @optarg
%25 = tail call i32 @atoi(i8* %24)
br label %30
26: ; preds = %20
%27 = tail call i32 (...) @usage()
br label %135
28: ; preds = %20
%29 = tail call i32 (...) @usage()
br label %135
30: ; preds = %20, %23
%31 = phi i32 [ %25, %23 ], [ %22, %20 ]
%32 = tail call signext i8 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%33 = sext i8 %32 to i32
%34 = load i64, i64* @EOF
%35 = trunc i64 %34 to i32
%36 = shl i32 %35, 24
%37 = ashr exact i32 %36, 24
%38 = icmp eq i32 %37, %33
br i1 %38, label %39, label %20
39: ; preds = %30, %2
%40 = phi i32 [ 1000, %2 ], [ %31, %30 ]
%41 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%42 = call i64 @pipe(i32* %41)
%43 = icmp slt i64 %42, 0
br i1 %43, label %48, label %44
44: ; preds = %39
%45 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%46 = call i64 @pipe(i32* %45)
%47 = icmp slt i64 %46, 0
br i1 %47, label %48, label %51
48: ; preds = %44, %39
%49 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.16, i64 0, i64 0))
%50 = call i32 @exit(i32 0)
unreachable
51: ; preds = %44
%52 = call i32 (...) @fork()
switch i32 %52, label %80 [
i32 -1, label %57
i32 0, label %53
]
53: ; preds = %51
%54 = icmp sgt i32 %40, 0
br i1 %54, label %55, label %78
55: ; preds = %53
%56 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
br label %62
57: ; preds = %51
%58 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.11, i64 0, i64 0))
%59 = call i32 @exit(i32 0)
unreachable
60: ; preds = %70
%61 = icmp eq i32 %74, %40
br i1 %61, label %78, label %62
62: ; preds = %55, %60
%63 = phi i32 [ 0, %55 ], [ %74, %60 ]
%64 = load i32, i32* %45
%65 = call i64 @read(i32 %64, i8* %10, i32 1)
%66 = icmp slt i64 %65, 0
br i1 %66, label %67, label %70
67: ; preds = %62
%68 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.10, i64 0, i64 0))
%69 = call i32 @exit(i32 0)
unreachable
70: ; preds = %62
%71 = load i32, i32* %56
%72 = call i64 @write(i32 %71, i8* %10, i32 1)
%73 = icmp slt i64 %72, 0
%74 = add nuw nsw i32 %63, 1
br i1 %73, label %75, label %60
75: ; preds = %70
%76 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%77 = call i32 @exit(i32 0)
unreachable
78: ; preds = %60, %53
%79 = call i32 @exit(i32 0)
unreachable
80: ; preds = %51
%81 = call i64 @gettimeofday(%struct.timeval* %3, i32* null)
%82 = icmp eq i64 %81, 0
br i1 %82, label %86, label %83
83: ; preds = %80
%84 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.15, i64 0, i64 0))
%85 = call i32 @exit(i32 0)
unreachable
86: ; preds = %80
%87 = add i32 %40, -1
%88 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%89 = load i32, i32* %88
%90 = call i64 @write(i32 %89, i8* %10, i32 1)
%91 = icmp slt i64 %90, 0
br i1 %91, label %94, label %92
92: ; preds = %86
%93 = icmp sgt i32 %40, 1
br i1 %93, label %99, label %115
94: ; preds = %86
%95 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0))
%96 = call i32 @exit(i32 0)
unreachable
97: ; preds = %107
%98 = icmp eq i32 %111, %87
br i1 %98, label %115, label %99
99: ; preds = %92, %97
%100 = phi i32 [ %111, %97 ], [ 0, %92 ]
%101 = load i32, i32* %41
%102 = call i64 @read(i32 %101, i8* %10, i32 1)
%103 = icmp slt i64 %102, 0
br i1 %103, label %104, label %107
104: ; preds = %99
%105 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.14, i64 0, i64 0))
%106 = call i32 @exit(i32 0)
unreachable
107: ; preds = %99
%108 = load i32, i32* %88
%109 = call i64 @write(i32 %108, i8* %10, i32 1)
%110 = icmp slt i64 %109, 0
%111 = add nuw nsw i32 %100, 1
br i1 %110, label %112, label %97
112: ; preds = %107
%113 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.13, i64 0, i64 0))
%114 = call i32 @exit(i32 0)
unreachable
115: ; preds = %97, %92
%116 = call i64 @gettimeofday(%struct.timeval* %4, i32* null)
%117 = icmp eq i64 %116, 0
br i1 %117, label %121, label %118
118: ; preds = %115
%119 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.15, i64 0, i64 0))
%120 = call i32 @exit(i32 0)
unreachable
121: ; preds = %115
%122 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%123 = load i32, i32* %122
%124 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%125 = load i32, i32* %124
%126 = sub nsw i32 %123, %125
%127 = mul nsw i32 %126, 1000000
%128 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%129 = load i32, i32* %128
%130 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%131 = load i32, i32* %130
%132 = sub i32 %129, %131
%133 = add nsw i32 %132, %127
%134 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.9, i64 0, i64 0), i32 %87, i32 %133)
br label %135
135: ; preds = %121, %28, %26
%136 = phi i32 [ -1, %28 ], [ 0, %26 ], [ 0, %121 ]
ret i32 %136
}