int main(void) {
  int fd[2];
  char buf[1];
  pipe(fd);
  pipe(fd);
  if (fork()) {
    puts("a");
    puts("a ping");
    do {
      typeof(write(fd[0], "a", 1)) __r = write(fd[0], "a", 1);
      if (__r < 0) {
        printf(" bad value for \"%s\" :  %lld\n", "write(fd[0], \"a\", 1)",
               (long long)__r);
      }
    } while (0);
    do {
      typeof(read(fd[1], buf, 1)) __r = read(fd[1], buf, 1);
      if (__r < 0) {
        printf(" bad value for \"%s\" :  %lld\n", "read(fd[1], buf, 1)",
               (long long)__r);
      }
    } while (0);
    printf("a pong (%d), done\n", buf[0]);
  } else {
    puts("b");
    do {
      typeof(read(fd[1], buf, 1)) __r = read(fd[1], buf, 1);
      if (__r < 0) {
        printf(" bad value for \"%s\" :  %lld\n", "read(fd[1], buf, 1)",
               (long long)__r);
      }
    } while (0);
    printf("b pong (%d), ping\n", buf[0]);
    do {
      typeof(write(fd[0], "b", 1)) __r = write(fd[0], "b", 1);
      if (__r < 0) {
        printf(" bad value for \"%s\" :  %lld\n", "write(fd[0], \"b\", 1)",
               (long long)__r);
      }
    } while (0);
    puts("b done");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0xc(%rbp),%rdi
mov    $0x0,%al
call   1060 <pipe@plt>
lea    -0xc(%rbp),%rdi
mov    $0x0,%al
call   1060 <pipe@plt>
mov    $0x0,%al
call   1080 <fork@plt>
cmp    $0x0,%eax
je     124c <main+0xec>
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1030 <puts@plt>
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1030 <puts@plt>
mov    -0xc(%rbp),%edi
lea    0xe45(%rip),%rsi
mov    $0x1,%edx
mov    $0x0,%al
call   1040 <write@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11ed <main+0x8d>
movslq -0x14(%rbp),%rdx
lea    0xe2a(%rip),%rdi
lea    0xe40(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11f2 <main+0x92>
jmp    11f7 <main+0x97>
mov    -0x8(%rbp),%edi
lea    -0xd(%rbp),%rsi
mov    $0x1,%edx
mov    $0x0,%al
call   1070 <read@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1230 <main+0xd0>
movslq -0x18(%rbp),%rdx
lea    0xde7(%rip),%rdi
lea    0xe12(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1235 <main+0xd5>
movsbl -0xd(%rbp),%esi
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12f9 <main+0x199>
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1030 <puts@plt>
mov    -0x8(%rbp),%edi
lea    -0xd(%rbp),%rsi
mov    $0x1,%edx
mov    $0x0,%al
call   1070 <read@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1293 <main+0x133>
movslq -0x1c(%rbp),%rdx
lea    0xd84(%rip),%rdi
lea    0xdaf(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1298 <main+0x138>
movsbl -0xd(%rbp),%esi
lea    0xdc1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xc(%rbp),%edi
lea    0xdae(%rip),%rsi
mov    $0x1,%edx
mov    $0x0,%al
call   1040 <write@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    12e6 <main+0x186>
movslq -0x20(%rbp),%rdx
lea    0xd31(%rip),%rdi
lea    0xd98(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12eb <main+0x18b>
lea    0xd9a(%rip),%rdi
mov    $0x0,%al
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <pipe@plt>
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <pipe@plt>
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     1224 <main+0xc4>
lea    0xe6c(%rip),%rbx
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <puts@plt>
lea    0xe5d(%rip),%rdi
xor    %eax,%eax
call   1030 <puts@plt>
mov    0x8(%rsp),%edi
mov    %rbx,%rsi
mov    $0x1,%edx
xor    %eax,%eax
call   1040 <write@plt>
test   %eax,%eax
jns    11db <main+0x7b>
movslq %eax,%rdx
lea    0xe3c(%rip),%rdi
lea    0xe52(%rip),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rsp),%edi
lea    0x7(%rsp),%rsi
mov    $0x1,%edx
xor    %eax,%eax
call   1070 <read@plt>
test   %eax,%eax
jns    120c <main+0xac>
movslq %eax,%rdx
lea    0xe0b(%rip),%rdi
lea    0xe36(%rip),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
movsbl 0x7(%rsp),%esi
lea    0xe37(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    12b7 <main+0x157>
lea    0xe37(%rip),%rdi
xor    %eax,%eax
call   1030 <puts@plt>
mov    0xc(%rsp),%edi
lea    0x7(%rsp),%rsi
mov    $0x1,%edx
xor    %eax,%eax
call   1070 <read@plt>
test   %eax,%eax
jns    1263 <main+0x103>
movslq %eax,%rdx
lea    0xdb4(%rip),%rdi
lea    0xddf(%rip),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
movsbl 0x7(%rsp),%esi
lea    0xdf5(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rsp),%edi
lea    0xde1(%rip),%rsi
mov    $0x1,%edx
xor    %eax,%eax
call   1040 <write@plt>
test   %eax,%eax
jns    12a9 <main+0x149>
movslq %eax,%rdx
lea    0xd6e(%rip),%rdi
lea    0xdd5(%rip),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xddc(%rip),%rdi
xor    %eax,%eax
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [2 x i8] c"a\00"
@.str.1 = [7 x i8] c"a ping\00"
@.str.2 = [29 x i8] c" bad value for \22%s\22 : %lld\0A\00"
@.str.3 = [21 x i8] c"write(fd[0], \22a\22, 1)\00"
@.str.4 = [20 x i8] c"read(fd[1], buf, 1)\00"
@.str.5 = [19 x i8] c"a pong (%d), done\0A\00"
@.str.6 = [2 x i8] c"b\00"
@.str.7 = [19 x i8] c"b pong (%d), ping\0A\00"
@.str.8 = [21 x i8] c"write(fd[0], \22b\22, 1)\00"
@.str.9 = [7 x i8] c"b done\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i32]
%3 = alloca [1 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%9 = call i32 (i32*, ...) bitcast (i32 (...)* @pipe to i32 (i32*, ...)*)(i32* %8)
%10 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%11 = call i32 (i32*, ...) bitcast (i32 (...)* @pipe to i32 (i32*, ...)*)(i32* %10)
%12 = call i32 (...) @fork()
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %46
14: ; preds = %0
%15 = call i32 (i8*, ...) bitcast (i32 (...)* @puts to i32 (i8*, ...)*)(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%16 = call i32 (i8*, ...) bitcast (i32 (...)* @puts to i32 (i8*, ...)*)(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %14
%18 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%19 = load i32, i32* %18
%20 = call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @write to i32 (i32, i8*, i32, ...)*)(i32 %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
store i32 %20, i32* %4
%21 = load i32, i32* %4
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %17
%24 = load i32, i32* %4
%25 = sext i32 %24 to i64
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i64 %25)
br label %27
27: ; preds = %23, %17
br label %28
28: ; preds = %27
br label %29
29: ; preds = %28
%30 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%31 = load i32, i32* %30
%32 = getelementptr inbounds [1 x i8], [1 x i8]* %3, i64 0, i64 0
%33 = call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @read to i32 (i32, i8*, i32, ...)*)(i32 %31, i8* %32, i32 1)
store i32 %33, i32* %5
%34 = load i32, i32* %5
%35 = icmp slt i32 %34, 0
br i1 %35, label %36, label %40
36: ; preds = %29
%37 = load i32, i32* %5
%38 = sext i32 %37 to i64
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i64 %38)
br label %40
40: ; preds = %36, %29
br label %41
41: ; preds = %40
%42 = getelementptr inbounds [1 x i8], [1 x i8]* %3, i64 0, i64 0
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i32 %44)
br label %78
46: ; preds = %0
%47 = call i32 (i8*, ...) bitcast (i32 (...)* @puts to i32 (i8*, ...)*)(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %48
48: ; preds = %46
%49 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%50 = load i32, i32* %49
%51 = getelementptr inbounds [1 x i8], [1 x i8]* %3, i64 0, i64 0
%52 = call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @read to i32 (i32, i8*, i32, ...)*)(i32 %50, i8* %51, i32 1)
store i32 %52, i32* %6
%53 = load i32, i32* %6
%54 = icmp slt i32 %53, 0
br i1 %54, label %55, label %59
55: ; preds = %48
%56 = load i32, i32* %6
%57 = sext i32 %56 to i64
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i64 %57)
br label %59
59: ; preds = %55, %48
br label %60
60: ; preds = %59
%61 = getelementptr inbounds [1 x i8], [1 x i8]* %3, i64 0, i64 0
%62 = load i8, i8* %61
%63 = sext i8 %62 to i32
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), i32 %63)
br label %65
65: ; preds = %60
%66 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%67 = load i32, i32* %66
%68 = call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @write to i32 (i32, i8*, i32, ...)*)(i32 %67, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i32 1)
store i32 %68, i32* %7
%69 = load i32, i32* %7
%70 = icmp slt i32 %69, 0
br i1 %70, label %71, label %75
71: ; preds = %65
%72 = load i32, i32* %7
%73 = sext i32 %72 to i64
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0), i64 %73)
br label %75
75: ; preds = %71, %65
br label %76
76: ; preds = %75
%77 = call i32 (i8*, ...) bitcast (i32 (...)* @puts to i32 (i8*, ...)*)(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0))
br label %78
78: ; preds = %76, %41
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"a\00"
@.str.1 = [7 x i8] c"a ping\00"
@.str.2 = [29 x i8] c" bad value for \22%s\22 : %lld\0A\00"
@.str.3 = [21 x i8] c"write(fd[0], \22a\22, 1)\00"
@.str.4 = [20 x i8] c"read(fd[1], buf, 1)\00"
@.str.5 = [19 x i8] c"a pong (%d), done\0A\00"
@.str.6 = [2 x i8] c"b\00"
@.str.7 = [19 x i8] c"b pong (%d), ping\0A\00"
@.str.8 = [21 x i8] c"write(fd[0], \22b\22, 1)\00"
@.str.9 = [7 x i8] c"b done\00"
define i32 @main() {
%1 = alloca [2 x i32]
%2 = alloca [1 x i8]
%3 = bitcast [2 x i32]* %1 to i8*
%4 = getelementptr inbounds [1 x i8], [1 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%6 = call i32 (i32*, ...) bitcast (i32 (...)* @pipe to i32 (i32*, ...)*)(i32* %5)
%7 = call i32 (i32*, ...) bitcast (i32 (...)* @pipe to i32 (i32*, ...)*)(i32* %5)
%8 = call i32 (...) @fork()
%9 = icmp eq i32 %8, 0
br i1 %9, label %31, label %10
10: ; preds = %0
%11 = call i32 (i8*, ...) bitcast (i32 (...)* @puts to i32 (i8*, ...)*)(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%12 = call i32 (i8*, ...) bitcast (i32 (...)* @puts to i32 (i8*, ...)*)(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%13 = load i32, i32* %5
%14 = call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @write to i32 (i32, i8*, i32, ...)*)(i32 %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %10
%17 = sext i32 %14 to i64
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i64 %17)
br label %19
19: ; preds = %16, %10
%20 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%21 = load i32, i32* %20
%22 = call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @read to i32 (i32, i8*, i32, ...)*)(i32 %21, i8* %4, i32 1)
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %19
%25 = sext i32 %22 to i64
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i64 %25)
br label %27
27: ; preds = %24, %19
%28 = load i8, i8* %4
%29 = sext i8 %28 to i32
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i32 %29)
br label %52
31: ; preds = %0
%32 = call i32 (i8*, ...) bitcast (i32 (...)* @puts to i32 (i8*, ...)*)(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%33 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%34 = load i32, i32* %33
%35 = call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @read to i32 (i32, i8*, i32, ...)*)(i32 %34, i8* %4, i32 1)
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %31
%38 = sext i32 %35 to i64
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i64 %38)
br label %40
40: ; preds = %37, %31
%41 = load i8, i8* %4
%42 = sext i8 %41 to i32
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), i32 %42)
%44 = load i32, i32* %5
%45 = call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @write to i32 (i32, i8*, i32, ...)*)(i32 %44, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i32 1)
%46 = icmp slt i32 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %40
%48 = sext i32 %45 to i64
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0), i64 %48)
br label %50
50: ; preds = %47, %40
%51 = call i32 (i8*, ...) bitcast (i32 (...)* @puts to i32 (i8*, ...)*)(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0))
br label %52
52: ; preds = %50, %27
ret i32 0
}