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

/* Variables and functions */
int /*<<< orphan*/ F_OK;
char O_WRONLY;
int S_IFIFO;
int access(char *, int /*<<< orphan*/);
scalar_t__ atoi(char *);
char *calloc(int, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
scalar_t__ fork();
scalar_t__ mknod(char *, int, int /*<<< orphan*/);
int open(char *, char);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ read(int, ...);
int /*<<< orphan*/ sleep(double);
int /*<<< orphan*/ stdin;
int strlen(char *);
int /*<<< orphan*/ write(int, ...);
int main(int argc, char **argv) {
  char *input;
  char *filename_1 = "/tmp/fifo_to.fifo";
  char *filename_2 = "/tmp/fifo_in.fifo";
  int ssize = 1;
  if (access(filename_1, F_OK) == -1 &&
      mknod(filename_1, S_IFIFO | 0666, 0) < 0) {
    exit(-1);
  }
  if (access(filename_2, F_OK) == -1 &&
      mknod(filename_2, S_IFIFO | 0666, 0) < 0) {
    exit(-1);
  }
  pid_t pid = fork();
  if (pid == 0) {
    input = calloc(256, sizeof(char *));
    int fd_1;
    fd_1 = open(atoi(argv[1]) == 0 ? filename_1 : filename_2, O_WRONLY);
    while (1) {
      fgets(input, 256 - 1, stdin);
      if (strlen(input) < 1)
        sleep(0.1);
      else {
        ssize = strlen(input);
        write(fd_1, &ssize, sizeof(ssize));
        write(fd_1, input, (strlen(input) + 1) * sizeof(char));
      }
    }
  } else {
    int fd_2;
    fd_2 = open(atoi(argv[1]) == 0 ? filename_2 : filename_1, 'r');
    input = calloc(256, sizeof(char *));
    while (1) {
      read(fd_2, &ssize, sizeof(ssize));
      read(fd_2, input, (ssize + 1) * sizeof(char));
      printf("re_1:%s", input);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe1b(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xe22(%rip),%rax
mov    %rax,-0x28(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2db2(%rip),%rax
mov    (%rax),%esi
call   10b0 <access@plt>
cmp    $0xffffffff,%eax
jne    124c <main+0x7c>
mov    -0x20(%rbp),%rdi
mov    0x2daf(%rip),%rax
mov    (%rax),%esi
or     $0x1b6,%esi
xor    %edx,%edx
call   1090 <mknod@plt>
cmp    $0x0,%rax
jge    124c <main+0x7c>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
mov    -0x28(%rbp),%rdi
mov    0x2d69(%rip),%rax
mov    (%rax),%esi
call   10b0 <access@plt>
cmp    $0xffffffff,%eax
jne    1295 <main+0xc5>
mov    -0x28(%rbp),%rdi
mov    0x2d66(%rip),%rax
mov    (%rax),%esi
or     $0x1b6,%esi
xor    %edx,%edx
call   1090 <mknod@plt>
cmp    $0x0,%rax
jge    1295 <main+0xc5>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
mov    $0x0,%al
call   10f0 <fork@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    138e <main+0x1be>
mov    $0x100,%edi
mov    $0x8,%esi
call   1080 <calloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10c0 <atoi@plt>
cmp    $0x0,%rax
jne    12e2 <main+0x112>
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
jmp    12ea <main+0x11a>
mov    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
mov    0x2cd3(%rip),%rax
movsbl (%rax),%esi
call   10a0 <open@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2cdd(%rip),%rax
mov    (%rax),%edx
mov    $0xff,%esi
call   1070 <fgets@plt>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x1,%eax
jge    133b <main+0x16b>
movsd  0xccf(%rip),%xmm0
call   10e0 <sleep@plt>
jmp    1389 <main+0x1b9>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x3c(%rbp),%edi
lea    -0x2c(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1030 <write@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x54(%rbp),%edi
mov    -0x50(%rbp),%rsi
add    $0x1,%eax
movslq %eax,%rdx
shl    $0x0,%rdx
mov    $0x0,%al
call   1030 <write@plt>
jmp    1300 <main+0x130>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10c0 <atoi@plt>
cmp    $0x0,%rax
jne    13b2 <main+0x1e2>
mov    -0x28(%rbp),%rax
mov    %rax,-0x60(%rbp)
jmp    13ba <main+0x1ea>
mov    -0x20(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rdi
mov    $0x72,%esi
call   10a0 <open@plt>
mov    %eax,-0x40(%rbp)
mov    $0x100,%edi
mov    $0x8,%esi
call   1080 <calloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x40(%rbp),%edi
lea    -0x2c(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1060 <read@plt>
mov    -0x40(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x6c(%rbp)
movslq %eax,%rdx
shl    $0x0,%rdx
mov    %rdx,-0x68(%rbp)
mov    $0x0,%al
call   1060 <read@plt>
mov    -0x18(%rbp),%rsi
lea    0xc0e(%rip),%rdi
call   1050 <printf@plt>
jmp    13de <main+0x20e>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
movl   $0x1,0xc(%rsp)
mov    0x2dd2(%rip),%rbx
mov    (%rbx),%esi
lea    0xe11(%rip),%r15
mov    %r15,%rdi
call   10b0 <access@plt>
cmp    $0xffffffff,%eax
jne    1229 <main+0x59>
mov    0x2dcd(%rip),%rax
mov    $0x1b6,%esi
or     (%rax),%esi
lea    0xdef(%rip),%rdi
xor    %edx,%edx
call   1090 <mknod@plt>
test   %rax,%rax
js     1392 <main+0x1c2>
mov    (%rbx),%esi
lea    0xde8(%rip),%r12
mov    %r12,%rdi
call   10b0 <access@plt>
cmp    $0xffffffff,%eax
jne    1264 <main+0x94>
mov    0x2d92(%rip),%rax
mov    $0x1b6,%esi
or     (%rax),%esi
lea    0xdc6(%rip),%rdi
xor    %edx,%edx
call   1090 <mknod@plt>
test   %rax,%rax
js     1392 <main+0x1c2>
xor    %eax,%eax
call   10f0 <fork@plt>
test   %rax,%rax
je     12e3 <main+0x113>
mov    0x8(%r14),%rdi
call   10c0 <atoi@plt>
test   %rax,%rax
cmove  %r12,%r15
mov    %r15,%rdi
mov    $0x72,%esi
call   10a0 <open@plt>
mov    %eax,%ebx
mov    $0x100,%edi
mov    $0x8,%esi
call   1080 <calloc@plt>
mov    %rax,%rbp
lea    0xc(%rsp),%r14
lea    0xd7f(%rip),%r15
nopl   (%rax)
mov    $0x4,%edx
mov    %ebx,%edi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <read@plt>
movslq 0xc(%rsp),%rdx
add    $0x1,%rdx
mov    %ebx,%edi
mov    %rbp,%rsi
xor    %eax,%eax
call   1060 <read@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
call   1050 <printf@plt>
jmp    12b0 <main+0xe0>
mov    $0x100,%edi
mov    $0x8,%esi
call   1080 <calloc@plt>
mov    %rax,%rbx
mov    0x8(%r14),%rdi
call   10c0 <atoi@plt>
test   %rax,%rax
cmove  %r15,%r12
mov    0x2cbc(%rip),%rax
movsbl (%rax),%esi
mov    %r12,%rdi
call   10a0 <open@plt>
mov    %eax,%ebp
mov    0x2cc8(%rip),%r15
lea    0xc(%rsp),%r14
jmp    1367 <main+0x197>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,0xc(%rsp)
mov    $0x4,%edx
mov    %ebp,%edi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <write@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
movslq %eax,%rdx
mov    %ebp,%edi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <write@plt>
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0xff,%esi
call   1070 <fgets@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jg     1330 <main+0x160>
movsd  0xc75(%rip),%xmm0
call   10e0 <sleep@plt>
jmp    1367 <main+0x197>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"/tmp/fifo_to.fifo\00"
@.str.1 = [18 x i8] c"/tmp/fifo_in.fifo\00"
@F_OK = global i32 0
@S_IFIFO = global i32 0
@O_WRONLY = global i8 0
@stdin = global i32 0
@.str.2 = [8 x i8] c"re_1:%s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i64
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8** %7
store i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8** %8
store i32 1, i32* %9
%13 = load i8*, i8** %7
%14 = load i32, i32* @F_OK
%15 = call i32 @access(i8* %13, i32 %14)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %25
17: ; preds = %2
%18 = load i8*, i8** %7
%19 = load i32, i32* @S_IFIFO
%20 = or i32 %19, 438
%21 = call i64 @mknod(i8* %18, i32 %20, i32 0)
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %17
%24 = call i32 @exit(i32 -1)
unreachable
25: ; preds = %17, %2
%26 = load i8*, i8** %8
%27 = load i32, i32* @F_OK
%28 = call i32 @access(i8* %26, i32 %27)
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %38
30: ; preds = %25
%31 = load i8*, i8** %8
%32 = load i32, i32* @S_IFIFO
%33 = or i32 %32, 438
%34 = call i64 @mknod(i8* %31, i32 %33, i32 0)
%35 = icmp slt i64 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %30
%37 = call i32 @exit(i32 -1)
unreachable
38: ; preds = %30, %25
%39 = call i64 (...) @fork()
store i64 %39, i64* %10
%40 = load i64, i64* %10
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %80
42: ; preds = %38
%43 = call i8* @calloc(i32 256, i32 8)
store i8* %43, i8** %6
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 1
%46 = load i8*, i8** %45
%47 = call i64 @atoi(i8* %46)
%48 = icmp eq i64 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %42
%50 = load i8*, i8** %7
br label %53
51: ; preds = %42
%52 = load i8*, i8** %8
br label %53
53: ; preds = %51, %49
%54 = phi i8* [ %50, %49 ], [ %52, %51 ]
%55 = load i8, i8* @O_WRONLY
%56 = call i32 @open(i8* %54, i8 signext %55)
store i32 %56, i32* %11
br label %57
57: ; preds = %53, %79
%58 = load i8*, i8** %6
%59 = load i32, i32* @stdin
%60 = call i32 @fgets(i8* %58, i32 255, i32 %59)
%61 = load i8*, i8** %6
%62 = call i32 @strlen(i8* %61)
%63 = icmp slt i32 %62, 1
br i1 %63, label %64, label %66
64: ; preds = %57
%65 = call i32 @sleep(double 1.000000e-01)
br label %79
66: ; preds = %57
%67 = load i8*, i8** %6
%68 = call i32 @strlen(i8* %67)
store i32 %68, i32* %9
%69 = load i32, i32* %11
%70 = call i32 (i32, ...) @write(i32 %69, i32* %9, i64 4)
%71 = load i32, i32* %11
%72 = load i8*, i8** %6
%73 = load i8*, i8** %6
%74 = call i32 @strlen(i8* %73)
%75 = add nsw i32 %74, 1
%76 = sext i32 %75 to i64
%77 = mul i64 %76, 1
%78 = call i32 (i32, ...) @write(i32 %71, i8* %72, i64 %77)
br label %79
79: ; preds = %66, %64
br label %57
80: ; preds = %38
%81 = load i8**, i8*** %5
%82 = getelementptr inbounds i8*, i8** %81, i64 1
%83 = load i8*, i8** %82
%84 = call i64 @atoi(i8* %83)
%85 = icmp eq i64 %84, 0
br i1 %85, label %86, label %88
86: ; preds = %80
%87 = load i8*, i8** %8
br label %90
88: ; preds = %80
%89 = load i8*, i8** %7
br label %90
90: ; preds = %88, %86
%91 = phi i8* [ %87, %86 ], [ %89, %88 ]
%92 = call i32 @open(i8* %91, i8 signext 114)
store i32 %92, i32* %12
%93 = call i8* @calloc(i32 256, i32 8)
store i8* %93, i8** %6
br label %94
94: ; preds = %90, %94
%95 = load i32, i32* %12
%96 = call i32 (i32, ...) @read(i32 %95, i32* %9, i64 4)
%97 = load i32, i32* %12
%98 = load i8*, i8** %6
%99 = load i32, i32* %9
%100 = add nsw i32 %99, 1
%101 = sext i32 %100 to i64
%102 = mul i64 %101, 1
%103 = call i32 (i32, ...) @read(i32 %97, i8* %98, i64 %102)
%104 = load i8*, i8** %6
%105 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %104)
br label %94
}

LLVM IR (-O2):
@.str = [18 x i8] c"/tmp/fifo_to.fifo\00"
@.str.1 = [18 x i8] c"/tmp/fifo_in.fifo\00"
@F_OK = global i32 0
@S_IFIFO = global i32 0
@O_WRONLY = global i8 0
@stdin = global i32 0
@.str.2 = [8 x i8] c"re_1:%s\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 1, i32* %3
%5 = load i32, i32* @F_OK
%6 = tail call i32 @access(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %15
8: ; preds = %2
%9 = load i32, i32* @S_IFIFO
%10 = or i32 %9, 438
%11 = tail call i64 @mknod(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %10, i32 0)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = tail call i32 @exit(i32 -1)
unreachable
15: ; preds = %8, %2
%16 = load i32, i32* @F_OK
%17 = tail call i32 @access(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %26
19: ; preds = %15
%20 = load i32, i32* @S_IFIFO
%21 = or i32 %20, 438
%22 = tail call i64 @mknod(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %21, i32 0)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %19
%25 = tail call i32 @exit(i32 -1)
unreachable
26: ; preds = %19, %15
%27 = tail call i64 (...) @fork()
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %53
29: ; preds = %26
%30 = tail call dereferenceable_or_null(2048) i8* @calloc(i32 256, i32 8)
%31 = getelementptr inbounds i8*, i8** %1, i64 1
%32 = load i8*, i8** %31
%33 = tail call i64 @atoi(i8* %32)
%34 = icmp eq i64 %33, 0
%35 = select i1 %34, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0)
%36 = load i8, i8* @O_WRONLY
%37 = tail call i32 @open(i8* %35, i8 signext %36)
br label %38
38: ; preds = %52, %29
%39 = load i32, i32* @stdin
%40 = call i32 @fgets(i8* %30, i32 255, i32 %39)
%41 = call i32 @strlen(i8* %30)
%42 = icmp slt i32 %41, 1
br i1 %42, label %43, label %45
43: ; preds = %38
%44 = call i32 @sleep(double 1.000000e-01)
br label %52
45: ; preds = %38
%46 = call i32 @strlen(i8* %30)
store i32 %46, i32* %3
%47 = call i32 (i32, ...) @write(i32 %37, i32* %3, i64 4)
%48 = call i32 @strlen(i8* %30)
%49 = add nsw i32 %48, 1
%50 = sext i32 %49 to i64
%51 = call i32 (i32, ...) @write(i32 %37, i8* %30, i64 %50)
br label %52
52: ; preds = %45, %43
br label %38
53: ; preds = %26
%54 = getelementptr inbounds i8*, i8** %1, i64 1
%55 = load i8*, i8** %54
%56 = tail call i64 @atoi(i8* %55)
%57 = icmp eq i64 %56, 0
%58 = select i1 %57, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0)
%59 = tail call i32 @open(i8* %58, i8 signext 114)
%60 = tail call dereferenceable_or_null(2048) i8* @calloc(i32 256, i32 8)
br label %61
61: ; preds = %61, %53
%62 = call i32 (i32, ...) @read(i32 %59, i32* %3, i64 4)
%63 = load i32, i32* %3
%64 = add nsw i32 %63, 1
%65 = sext i32 %64 to i64
%66 = call i32 (i32, ...) @read(i32 %59, i8* %60, i64 %65)
%67 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %60)
br label %61
}