#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 */

/* Variables and functions */
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char);
int /*<<< orphan*/ pipe(int *);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ setbuf(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stdout;
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ wait(int *);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char **argv) {
  int fd[2];
  char c;
  setbuf(stdout, 0);
  pipe(fd);
  if (fork() != 0) {
    while (1) {
      if (strcmp(argv[1], "F") == 0 || strcmp(argv[1], "FC") == 0) {
        c = 'F';
        fprintf(stdout, "Father Write %c\n", c);
        write(fd[1], &c, 1);
      }
      sleep(2);
      if (strcmp(argv[1], "C") == 0 || strcmp(argv[1], "FC") == 0) {
        read(fd[0], &c, 1);
        fprintf(stdout, "Father Read %c\n", c);
      }
      sleep(2);
    }
    wait((int *)0);
  } else {
    while (1) {
      if (strcmp(argv[1], "F") == 0 || strcmp(argv[1], "FC") == 0) {
        read(fd[0], &c, 1);
        fprintf(stdout, "Child Read %c\n", c);
      }
      sleep(2);
      if (strcmp(argv[1], "C") == 0 || strcmp(argv[1], "FC") == 0) {
        c = 'C';
        fprintf(stdout, "Child Write %c\n", c);
        write(fd[1], &c, 1);
      }
      sleep(2);
    }
    exit(0);
  }
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1040 <setbuf@plt>
lea    -0x18(%rbp),%rdi
call   1050 <pipe@plt>
mov    $0x0,%al
call   10a0 <fork@plt>
cmp    $0x0,%rax
je     12ae <main+0x12e>
jmp    11c5 <main+0x45>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe2c(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     1201 <main+0x81>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe10(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    122f <main+0xaf>
movb   $0x46,-0x19(%rbp)
mov    0x2dd4(%rip),%rax
mov    (%rax),%edi
lea    0xdf0(%rip),%rsi
movsbl -0x19(%rbp),%edx
call   1080 <fprintf@plt>
mov    -0x14(%rbp),%edi
lea    -0x19(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    $0x2,%edi
call   1090 <sleep@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdbb(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     1275 <main+0xf5>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd9c(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    129f <main+0x11f>
mov    -0x18(%rbp),%edi
lea    -0x19(%rbp),%rsi
mov    $0x1,%edx
call   1060 <read@plt>
mov    0x2d53(%rip),%rax
mov    (%rax),%edi
lea    0xd80(%rip),%rsi
movsbl -0x19(%rbp),%edx
call   1080 <fprintf@plt>
mov    $0x2,%edi
call   1090 <sleep@plt>
jmp    11c5 <main+0x45>
jmp    12b3 <main+0x133>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd3e(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     12ef <main+0x16f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd22(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1319 <main+0x199>
mov    -0x18(%rbp),%edi
lea    -0x19(%rbp),%rsi
mov    $0x1,%edx
call   1060 <read@plt>
mov    0x2cd9(%rip),%rax
mov    (%rax),%edi
lea    0xd16(%rip),%rsi
movsbl -0x19(%rbp),%edx
call   1080 <fprintf@plt>
mov    $0x2,%edi
call   1090 <sleep@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xcd1(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     135f <main+0x1df>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xcb2(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    138d <main+0x20d>
movb   $0x43,-0x19(%rbp)
mov    0x2c76(%rip),%rax
mov    (%rax),%edi
lea    0xcc2(%rip),%rsi
movsbl -0x19(%rbp),%edx
call   1080 <fprintf@plt>
mov    -0x14(%rbp),%edi
lea    -0x19(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    $0x2,%edi
call   1090 <sleep@plt>
jmp    12b3 <main+0x133>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    0x2e48(%rip),%r13
mov    0x0(%r13),%edi
xor    %esi,%esi
call   1040 <setbuf@plt>
lea    0x10(%rsp),%rdi
call   1050 <pipe@plt>
xor    %eax,%eax
call   10a0 <fork@plt>
lea    0xe45(%rip),%r14
test   %rax,%rax
je     1296 <main+0x116>
lea    0xf(%rsp),%r12
lea    0xe33(%rip),%rbp
lea    0xe2b(%rip),%r15
jmp    1210 <main+0x90>
nopl   0x0(%rax)
mov    0x10(%rsp),%edi
mov    %r12,%rsi
mov    $0x1,%edx
call   1060 <read@plt>
mov    0x0(%r13),%edi
movsbl 0xf(%rsp),%edx
lea    0xe15(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x2,%edi
call   1090 <sleep@plt>
mov    0x8(%rbx),%rdi
mov    %r14,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1232 <main+0xb2>
mov    0x8(%rbx),%rdi
mov    %r15,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    125d <main+0xdd>
movb   $0x46,0xf(%rsp)
mov    0x0(%r13),%edi
lea    0xdc3(%rip),%rsi
mov    $0x46,%edx
call   1080 <fprintf@plt>
mov    0x14(%rsp),%edi
mov    %r12,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    $0x2,%edi
call   1090 <sleep@plt>
mov    0x8(%rbx),%rdi
mov    %rbp,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     11e0 <main+0x60>
mov    0x8(%rbx),%rdi
mov    %r15,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    1206 <main+0x86>
jmp    11e0 <main+0x60>
lea    0xf(%rsp),%r15
lea    0xd61(%rip),%rbp
lea    0xd59(%rip),%r12
jmp    12e5 <main+0x165>
nopl   0x0(%rax,%rax,1)
movb   $0x43,0xf(%rsp)
mov    0x0(%r13),%edi
lea    0xd75(%rip),%rsi
mov    $0x43,%edx
call   1080 <fprintf@plt>
mov    0x14(%rsp),%edi
mov    %r15,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    $0x2,%edi
call   1090 <sleep@plt>
mov    0x8(%rbx),%rdi
mov    %r14,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1307 <main+0x187>
mov    0x8(%rbx),%rdi
mov    %r12,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    132d <main+0x1ad>
mov    0x10(%rsp),%edi
mov    %r15,%rsi
mov    $0x1,%edx
call   1060 <read@plt>
mov    0x0(%r13),%edi
movsbl 0xf(%rsp),%edx
lea    0xcfe(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x2,%edi
call   1090 <sleep@plt>
mov    0x8(%rbx),%rdi
mov    %rbp,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     12b0 <main+0x130>
mov    0x8(%rbx),%rdi
mov    %r12,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    12db <main+0x15b>
jmp    12b0 <main+0x130>

LLVM IR (-O0):
@stdout = global i32 0
@.str = [2 x i8] c"F\00"
@.str.1 = [3 x i8] c"FC\00"
@.str.2 = [17 x i8] c"Father Write %c\0A\00"
@.str.3 = [2 x i8] c"C\00"
@.str.4 = [16 x i8] c"Father Read %c\0A\00"
@.str.5 = [15 x i8] c"Child Read %c\0A\00"
@.str.6 = [16 x i8] c"Child Write %c\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [2 x i32]
%7 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* @stdout
%9 = call i32 @setbuf(i32 %8, i32 0)
%10 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%11 = call i32 @pipe(i32* %10)
%12 = call i64 (...) @fork()
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %56
14: ; preds = %2
br label %15
15: ; preds = %14, %54
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %27, label %21
21: ; preds = %15
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i64 @strcmp(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %34
27: ; preds = %21, %15
store i8 70, i8* %7
%28 = load i32, i32* @stdout
%29 = load i8, i8* %7
%30 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8 signext %29)
%31 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%32 = load i32, i32* %31
%33 = call i32 @write(i32 %32, i8* %7, i32 1)
br label %34
34: ; preds = %27, %21
%35 = call i32 @sleep(i32 2)
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 1
%38 = load i8*, i8** %37
%39 = call i64 @strcmp(i8* %38, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%40 = icmp eq i64 %39, 0
br i1 %40, label %47, label %41
41: ; preds = %34
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 1
%44 = load i8*, i8** %43
%45 = call i64 @strcmp(i8* %44, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%46 = icmp eq i64 %45, 0
br i1 %46, label %47, label %54
47: ; preds = %41, %34
%48 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%49 = load i32, i32* %48
%50 = call i32 @read(i32 %49, i8* %7, i32 1)
%51 = load i32, i32* @stdout
%52 = load i8, i8* %7
%53 = call i32 @fprintf(i32 %51, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8 signext %52)
br label %54
54: ; preds = %47, %41
%55 = call i32 @sleep(i32 2)
br label %15
56: ; preds = %2
br label %57
57: ; preds = %56, %96
%58 = load i8**, i8*** %5
%59 = getelementptr inbounds i8*, i8** %58, i64 1
%60 = load i8*, i8** %59
%61 = call i64 @strcmp(i8* %60, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%62 = icmp eq i64 %61, 0
br i1 %62, label %69, label %63
63: ; preds = %57
%64 = load i8**, i8*** %5
%65 = getelementptr inbounds i8*, i8** %64, i64 1
%66 = load i8*, i8** %65
%67 = call i64 @strcmp(i8* %66, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%68 = icmp eq i64 %67, 0
br i1 %68, label %69, label %76
69: ; preds = %63, %57
%70 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%71 = load i32, i32* %70
%72 = call i32 @read(i32 %71, i8* %7, i32 1)
%73 = load i32, i32* @stdout
%74 = load i8, i8* %7
%75 = call i32 @fprintf(i32 %73, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i8 signext %74)
br label %76
76: ; preds = %69, %63
%77 = call i32 @sleep(i32 2)
%78 = load i8**, i8*** %5
%79 = getelementptr inbounds i8*, i8** %78, i64 1
%80 = load i8*, i8** %79
%81 = call i64 @strcmp(i8* %80, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%82 = icmp eq i64 %81, 0
br i1 %82, label %89, label %83
83: ; preds = %76
%84 = load i8**, i8*** %5
%85 = getelementptr inbounds i8*, i8** %84, i64 1
%86 = load i8*, i8** %85
%87 = call i64 @strcmp(i8* %86, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%88 = icmp eq i64 %87, 0
br i1 %88, label %89, label %96
89: ; preds = %83, %76
store i8 67, i8* %7
%90 = load i32, i32* @stdout
%91 = load i8, i8* %7
%92 = call i32 @fprintf(i32 %90, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i8 signext %91)
%93 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%94 = load i32, i32* %93
%95 = call i32 @write(i32 %94, i8* %7, i32 1)
br label %96
96: ; preds = %89, %83
%97 = call i32 @sleep(i32 2)
br label %57
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [2 x i8] c"F\00"
@.str.1 = [3 x i8] c"FC\00"
@.str.2 = [17 x i8] c"Father Write %c\0A\00"
@.str.3 = [2 x i8] c"C\00"
@.str.4 = [16 x i8] c"Father Read %c\0A\00"
@.str.5 = [15 x i8] c"Child Read %c\0A\00"
@.str.6 = [16 x i8] c"Child Write %c\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [2 x i32]
%4 = alloca i8
%5 = bitcast [2 x i32]* %3 to i8*
%6 = load i32, i32* @stdout
%7 = tail call i32 @setbuf(i32 %6, i32 0)
%8 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%9 = call i32 @pipe(i32* %8)
%10 = call i64 (...) @fork()
%11 = icmp eq i64 %10, 0
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
br i1 %11, label %44, label %14
14: ; preds = %2, %42
%15 = load i8*, i8** %12
%16 = call i64 @strcmp(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %22, label %18
18: ; preds = %14
%19 = load i8*, i8** %12
%20 = call i64 @strcmp(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %27
22: ; preds = %18, %14
store i8 70, i8* %4
%23 = load i32, i32* @stdout
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8 signext 70)
%25 = load i32, i32* %13
%26 = call i32 @write(i32 %25, i8* %4, i32 1)
br label %27
27: ; preds = %22, %18
%28 = call i32 @sleep(i32 2)
%29 = load i8*, i8** %12
%30 = call i64 @strcmp(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%31 = icmp eq i64 %30, 0
br i1 %31, label %36, label %32
32: ; preds = %27
%33 = load i8*, i8** %12
%34 = call i64 @strcmp(i8* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %42
36: ; preds = %32, %27
%37 = load i32, i32* %8
%38 = call i32 @read(i32 %37, i8* %4, i32 1)
%39 = load i32, i32* @stdout
%40 = load i8, i8* %4
%41 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8 signext %40)
br label %42
42: ; preds = %36, %32
%43 = call i32 @sleep(i32 2)
br label %14
44: ; preds = %2, %72
%45 = load i8*, i8** %12
%46 = call i64 @strcmp(i8* %45, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%47 = icmp eq i64 %46, 0
br i1 %47, label %52, label %48
48: ; preds = %44
%49 = load i8*, i8** %12
%50 = call i64 @strcmp(i8* %49, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %58
52: ; preds = %48, %44
%53 = load i32, i32* %8
%54 = call i32 @read(i32 %53, i8* %4, i32 1)
%55 = load i32, i32* @stdout
%56 = load i8, i8* %4
%57 = call i32 @fprintf(i32 %55, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i8 signext %56)
br label %58
58: ; preds = %52, %48
%59 = call i32 @sleep(i32 2)
%60 = load i8*, i8** %12
%61 = call i64 @strcmp(i8* %60, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%62 = icmp eq i64 %61, 0
br i1 %62, label %67, label %63
63: ; preds = %58
%64 = load i8*, i8** %12
%65 = call i64 @strcmp(i8* %64, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%66 = icmp eq i64 %65, 0
br i1 %66, label %67, label %72
67: ; preds = %63, %58
store i8 67, i8* %4
%68 = load i32, i32* @stdout
%69 = call i32 @fprintf(i32 %68, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i8 signext 67)
%70 = load i32, i32* %13
%71 = call i32 @write(i32 %70, i8* %4, i32 1)
br label %72
72: ; preds = %67, %63
%73 = call i32 @sleep(i32 2)
br label %44
}