#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 scalar_t__ pid_t;
typedef int /*<<< orphan*/ output;
typedef int /*<<< orphan*/ input;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
scalar_t__ fork();
int mkfifo(char *, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int strlen(char *);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  int ret_peter = 0;
  int ret_lucy = 0;
  ret_peter = mkfifo("./fifo_ptl", 0666);
  ret_lucy = mkfifo("./fifo_ltp", 0666);
  if ((ret_peter < 0) | (ret_lucy < 0)) {
    perror("mkfifo");
  }
  int fd_ptl = 0;
  int fd_ltp = 0;
  printf("hello,i am peter\n");
  fd_ptl = open("./fifo_ptl", O_WRONLY);
  fd_ltp = open("./fifo_ltp", O_RDONLY);
  if ((fd_ptl < 0) | (fd_ltp < 0)) {
    perror("open");
  }
  pid_t pid;
  pid = fork();
  if (pid < 0) {
    perror("fork");
  }
  if (pid == 0) {
    while (1) {
      char input[1024] = "";
      printf("peter:");
      fgets(input, sizeof(input), stdin);
      input[strlen(input) - 1] = '\0';
      write(fd_ptl, input, strlen(input));
    }
  } else {
    while (1) {
      char output[1024] = "";
      int ret_read = 0;
      bzero(output, sizeof(output));
      ret_read = read(fd_ltp, output, sizeof(output));
      printf("\rlucy:%s\n", output);
      printf("peter: ");
      fflush(stdout);
      if (ret_read == 0) {
        break;
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x850,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
lea    0xe12(%rip),%rdi
mov    $0x1b6,%esi
call   1090 <mkfifo@plt>
mov    %eax,-0x14(%rbp)
lea    0xe09(%rip),%rdi
mov    $0x1b6,%esi
call   1090 <mkfifo@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x14(%rbp)
setl   %al
and    $0x1,%al
movzbl %al,%eax
cmpl   $0x0,-0x18(%rbp)
setl   %cl
and    $0x1,%cl
movzbl %cl,%ecx
or     %ecx,%eax
cmp    $0x0,%eax
je     123f <main+0x7f>
lea    0xddc(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
lea    0xdc9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2d5e(%rip),%rax
mov    (%rax),%esi
lea    0xd95(%rip),%rdi
call   10b0 <open@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2d6e(%rip),%rax
mov    (%rax),%esi
lea    0xd88(%rip),%rdi
call   10b0 <open@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x1c(%rbp)
setl   %al
and    $0x1,%al
movzbl %al,%eax
cmpl   $0x0,-0x20(%rbp)
setl   %cl
and    $0x1,%cl
movzbl %cl,%ecx
or     %ecx,%eax
cmp    $0x0,%eax
je     12bb <main+0xfb>
lea    0xd79(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x0,%al
call   10e0 <fork@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jge    12dd <main+0x11d>
lea    0xd5c(%rip),%rdi
call   10c0 <perror@plt>
cmpq   $0x0,-0x28(%rbp)
jne    1383 <main+0x1c3>
jmp    12ed <main+0x12d>
lea    -0x430(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
lea    0xd32(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x430(%rbp),%rdi
mov    0x2cc4(%rip),%rax
mov    (%rax),%edx
mov    $0x400,%esi
call   1080 <fgets@plt>
lea    -0x430(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0x848(%rbp)
cltq
movb   $0x0,-0x430(%rbp,%rax,1)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x844(%rbp)
lea    -0x430(%rbp),%rax
mov    %rax,-0x840(%rbp)
lea    -0x430(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x844(%rbp),%edi
mov    -0x840(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
jmp    12ed <main+0x12d>
jmp    1388 <main+0x1c8>
lea    -0x830(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
movl   $0x0,-0x834(%rbp)
lea    -0x830(%rbp),%rdi
mov    $0x400,%esi
call   10d0 <bzero@plt>
mov    -0x20(%rbp),%edi
lea    -0x830(%rbp),%rsi
mov    $0x400,%edx
call   1070 <read@plt>
mov    %eax,-0x834(%rbp)
lea    -0x830(%rbp),%rsi
lea    0xc62(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xc5e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2bd6(%rip),%rax
mov    (%rax),%edi
call   10a0 <fflush@plt>
cmpl   $0x0,-0x834(%rbp)
jne    1413 <main+0x253>
jmp    1418 <main+0x258>
jmp    1388 <main+0x1c8>
jmp    141d <main+0x25d>
xor    %eax,%eax
add    $0x850,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
lea    0xe1c(%rip),%rdi
mov    $0x1b6,%esi
call   10a0 <mkfifo@plt>
mov    %eax,%ebx
lea    0xe14(%rip),%rdi
mov    $0x1b6,%esi
call   10a0 <mkfifo@plt>
or     %ebx,%eax
js     134e <main+0x17e>
lea    0xe30(%rip),%rdi
call   1030 <puts@plt>
mov    0x2da4(%rip),%rax
mov    (%rax),%esi
lea    0xddb(%rip),%rdi
call   10c0 <open@plt>
mov    %eax,%ebx
mov    0x2db5(%rip),%rax
mov    (%rax),%esi
lea    0xdcf(%rip),%rdi
call   10c0 <open@plt>
mov    %eax,%r14d
or     %ebx,%eax
js     135f <main+0x18f>
xor    %eax,%eax
call   10f0 <fork@plt>
test   %rax,%rax
js     1370 <main+0x1a0>
je     12e2 <main+0x112>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rsp,%rbx
mov    $0x400,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1070 <memset@plt>
mov    %rbx,%rdi
mov    $0x400,%esi
call   10e0 <bzero@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1080 <read@plt>
mov    %eax,%ebp
lea    0xd86(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xd7f(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2d09(%rip),%rax
mov    (%rax),%edi
call   10b0 <fflush@plt>
test   %ebp,%ebp
jne    1270 <main+0xa0>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rsp,%rbp
lea    0xd3b(%rip),%r14
mov    0x2ced(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0x400,%edx
mov    %rbp,%rdi
xor    %esi,%esi
call   1070 <memset@plt>
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    (%r15),%edx
mov    %rbp,%rdi
mov    $0x400,%esi
call   1090 <fgets@plt>
mov    %rbp,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbp,1)
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1040 <write@plt>
jmp    1300 <main+0x130>
lea    0xcc1(%rip),%rdi
call   10d0 <perror@plt>
jmp    1209 <main+0x39>
lea    0xcb7(%rip),%rdi
call   10d0 <perror@plt>
jmp    124c <main+0x7c>
lea    0xcab(%rip),%rdi
call   10d0 <perror@plt>
jmp    1270 <main+0xa0>

LLVM IR (-O0):
@.str = [11 x i8] c"./fifo_ptl\00"
@.str.1 = [11 x i8] c"./fifo_ltp\00"
@.str.2 = [7 x i8] c"mkfifo\00"
@.str.3 = [18 x i8] c"hello,i am peter\0A\00"
@O_WRONLY = global i32 0
@O_RDONLY = global i32 0
@.str.4 = [5 x i8] c"open\00"
@.str.5 = [5 x i8] c"fork\00"
@.str.6 = [7 x i8] c"peter:\00"
@stdin = global i32 0
@.str.7 = [10 x i8] c"\0Dlucy:%s\0A\00"
@.str.8 = [8 x i8] c"peter: \00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i64
%11 = alloca [1024 x i8]
%12 = alloca [1024 x i8]
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 0, i32* %7
%14 = call i32 @mkfifo(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 438)
store i32 %14, i32* %6
%15 = call i32 @mkfifo(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 438)
store i32 %15, i32* %7
%16 = load i32, i32* %6
%17 = icmp slt i32 %16, 0
%18 = zext i1 %17 to i32
%19 = load i32, i32* %7
%20 = icmp slt i32 %19, 0
%21 = zext i1 %20 to i32
%22 = or i32 %18, %21
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %2
%25 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %26
26: ; preds = %24, %2
store i32 0, i32* %8
store i32 0, i32* %9
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%28 = load i32, i32* @O_WRONLY
%29 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %28)
store i32 %29, i32* %8
%30 = load i32, i32* @O_RDONLY
%31 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %30)
store i32 %31, i32* %9
%32 = load i32, i32* %8
%33 = icmp slt i32 %32, 0
%34 = zext i1 %33 to i32
%35 = load i32, i32* %9
%36 = icmp slt i32 %35, 0
%37 = zext i1 %36 to i32
%38 = or i32 %34, %37
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %26
%41 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %42
42: ; preds = %40, %26
%43 = call i64 (...) @fork()
store i64 %43, i64* %10
%44 = load i64, i64* %10
%45 = icmp slt i64 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %42
%47 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
br label %48
48: ; preds = %46, %42
%49 = load i64, i64* %10
%50 = icmp eq i64 %49, 0
br i1 %50, label %51, label %68
51: ; preds = %48
br label %52
52: ; preds = %51, %52
%53 = bitcast [1024 x i8]* %11 to i8*
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%55 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%56 = load i32, i32* @stdin
%57 = call i32 @fgets(i8* %55, i32 1024, i32 %56)
%58 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%59 = call i32 @strlen(i8* %58)
%60 = sub nsw i32 %59, 1
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 %61
store i8 0, i8* %62
%63 = load i32, i32* %8
%64 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%65 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%66 = call i32 @strlen(i8* %65)
%67 = call i32 @write(i32 %63, i8* %64, i32 %66)
br label %52
68: ; preds = %48
br label %69
69: ; preds = %68, %84
%70 = bitcast [1024 x i8]* %12 to i8*
store i32 0, i32* %13
%71 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%72 = call i32 @bzero(i8* %71, i32 1024)
%73 = load i32, i32* %9
%74 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%75 = call i32 @read(i32 %73, i8* %74, i32 1024)
store i32 %75, i32* %13
%76 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i8* %76)
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0))
%79 = load i32, i32* @stdout
%80 = call i32 @fflush(i32 %79)
%81 = load i32, i32* %13
%82 = icmp eq i32 %81, 0
br i1 %82, label %83, label %84
83: ; preds = %69
br label %85
84: ; preds = %69
br label %69
85: ; preds = %83
br label %86
86: ; preds = %85
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"./fifo_ptl\00"
@.str.1 = [11 x i8] c"./fifo_ltp\00"
@.str.2 = [7 x i8] c"mkfifo\00"
@O_WRONLY = global i32 0
@O_RDONLY = global i32 0
@.str.4 = [5 x i8] c"open\00"
@.str.5 = [5 x i8] c"fork\00"
@.str.6 = [7 x i8] c"peter:\00"
@stdin = global i32 0
@.str.7 = [10 x i8] c"\0Dlucy:%s\0A\00"
@.str.8 = [8 x i8] c"peter: \00"
@stdout = global i32 0
@str = [17 x i8] c"hello,i am peter\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = tail call i32 @mkfifo(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 438)
%6 = tail call i32 @mkfifo(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 438)
%7 = or i32 %6, %5
%8 = icmp sgt i32 %7, -1
br i1 %8, label %11, label %9
9: ; preds = %2
%10 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %11
11: ; preds = %9, %2
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%13 = load i32, i32* @O_WRONLY
%14 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = load i32, i32* @O_RDONLY
%16 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = or i32 %16, %14
%18 = icmp sgt i32 %17, -1
br i1 %18, label %21, label %19
19: ; preds = %11
%20 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %21
21: ; preds = %19, %11
%22 = tail call i64 (...) @fork()
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
br label %28
26: ; preds = %21
%27 = icmp eq i64 %22, 0
br i1 %27, label %30, label %28
28: ; preds = %24, %26
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
br label %42
30: ; preds = %26
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
br label %32
32: ; preds = %30, %32
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%34 = load i32, i32* @stdin
%35 = call i32 @fgets(i8* %31, i32 1024, i32 %34)
%36 = call i32 @strlen(i8* %31)
%37 = add nsw i32 %36, -1
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %38
store i8 0, i8* %39
%40 = call i32 @strlen(i8* %31)
%41 = call i32 @write(i32 %14, i8* %31, i32 %40)
br label %32
42: ; preds = %28, %42
%43 = call i32 @bzero(i8* %29, i32 1024)
%44 = call i32 @read(i32 %16, i8* %29, i32 1024)
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i8* %29)
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0))
%47 = load i32, i32* @stdout
%48 = call i32 @fflush(i32 %47)
%49 = icmp eq i32 %44, 0
br i1 %49, label %50, label %42
50: ; preds = %42
ret i32 0
}