#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 lucy\n");
  fd_ptl = open("./fifo_ptl", O_RDONLY);
  fd_ltp = open("./fifo_ltp", O_WRONLY);
  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("lucy:");
      fgets(input, sizeof(input), stdin);
      input[strlen(input) - 1] = '\0';
      write(fd_ltp, input, strlen(input));
    }
  } else {
    while (1) {
      char output[1024] = "";
      int ret_read = 0;
      bzero(output, sizeof(output));
      ret_read = read(fd_ptl, output, sizeof(output));
      printf("\rpeter:%s\n", output);
      printf("lucy: ");
      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    0x2d86(%rip),%rax
mov    (%rax),%esi
lea    0xd95(%rip),%rdi
call   10b0 <open@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2d46(%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    0xd78(%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    0xd5b(%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    0xd31(%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    -0x20(%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    -0x1c(%rbp),%edi
lea    -0x830(%rbp),%rsi
mov    $0x400,%edx
call   1070 <read@plt>
mov    %eax,-0x834(%rbp)
lea    -0x830(%rbp),%rsi
lea    0xc60(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xc5d(%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     133e <main+0x16e>
lea    0xe2f(%rip),%rdi
call   1030 <puts@plt>
mov    0x2dcc(%rip),%rax
mov    (%rax),%esi
lea    0xddb(%rip),%rdi
call   10c0 <open@plt>
mov    %eax,%r14d
mov    0x2d8c(%rip),%rax
mov    (%rax),%esi
lea    0xdce(%rip),%rdi
call   10c0 <open@plt>
mov    %eax,%ebp
or     %r14d,%eax
js     134f <main+0x17f>
xor    %eax,%eax
call   10f0 <fork@plt>
test   %rax,%rax
js     1360 <main+0x190>
je     12d2 <main+0x102>
nop
mov    %rsp,%rbp
mov    $0x400,%edx
mov    %rbp,%rdi
xor    %esi,%esi
call   1070 <memset@plt>
mov    %rbp,%rdi
mov    $0x400,%esi
call   10e0 <bzero@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0x400,%edx
call   1080 <read@plt>
mov    %eax,%ebx
lea    0xd95(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xd8f(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2d19(%rip),%rax
mov    (%rax),%edi
call   10b0 <fflush@plt>
test   %ebx,%ebx
jne    1260 <main+0x90>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rsp,%rbx
lea    0xd4b(%rip),%r14
mov    0x2cfd(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0x400,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1070 <memset@plt>
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0x400,%esi
call   1090 <fgets@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
jmp    12f0 <main+0x120>
lea    0xcd1(%rip),%rdi
call   10d0 <perror@plt>
jmp    1209 <main+0x39>
lea    0xcc7(%rip),%rdi
call   10d0 <perror@plt>
jmp    124d <main+0x7d>
lea    0xcbb(%rip),%rdi
call   10d0 <perror@plt>
jmp    1260 <main+0x90>

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 = [17 x i8] c"hello,i am lucy\0A\00"
@O_RDONLY = global i32 0
@O_WRONLY = global i32 0
@.str.4 = [5 x i8] c"open\00"
@.str.5 = [5 x i8] c"fork\00"
@.str.6 = [6 x i8] c"lucy:\00"
@stdin = global i32 0
@.str.7 = [11 x i8] c"\0Dpeter:%s\0A\00"
@.str.8 = [7 x i8] c"lucy: \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 ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%28 = load i32, i32* @O_RDONLY
%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_WRONLY
%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 ([6 x i8], [6 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* %9
%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* %8
%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 ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), i8* %76)
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 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_RDONLY = global i32 0
@O_WRONLY = global i32 0
@.str.4 = [5 x i8] c"open\00"
@.str.5 = [5 x i8] c"fork\00"
@.str.6 = [6 x i8] c"lucy:\00"
@stdin = global i32 0
@.str.7 = [11 x i8] c"\0Dpeter:%s\0A\00"
@.str.8 = [7 x i8] c"lucy: \00"
@stdout = global i32 0
@str = [16 x i8] c"hello,i am lucy\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 ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%13 = load i32, i32* @O_RDONLY
%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_WRONLY
%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 ([6 x i8], [6 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 %16, i8* %31, i32 %40)
br label %32
42: ; preds = %28, %42
%43 = call i32 @bzero(i8* %29, i32 1024)
%44 = call i32 @read(i32 %14, i8* %29, i32 1024)
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), i8* %29)
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 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
}