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

/* Variables and functions */
scalar_t__ EAGAIN;
scalar_t__ ENXIO;
scalar_t__ EWOULDBLOCK;
int O_CREAT;
int O_NONBLOCK;
int O_RDONLY;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ S_IRWXU;
scalar_t__ close(int);
scalar_t__ errno;
scalar_t__ fork();
scalar_t__ mkfifo(char *, int /*<<< orphan*/);
int open(char *, int, ...);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char **, int);
int /*<<< orphan*/ sched_yield();
int /*<<< orphan*/ snprintf(char *, int, char *);
scalar_t__ strlen(char *);
scalar_t__ unlink(char *);
scalar_t__ wait(int /*<<< orphan*/ *);
scalar_t__ write(int, char **, scalar_t__);
int main(int argc, char **argv) {
  int fd;
  char buffer[1024];
  if (mkfifo("tmp/fifo", S_IRWXU) < 0) {
    perror("mkfifo error");
    return 1;
  }
  pid_t pid = fork();
  if (pid < 0) {
    perror("fork error");
    return 1;
  } else if (pid == 0) {
    fd = open("tmp/fifo", O_NONBLOCK | O_RDONLY);
    if (fd < 0) {
      perror("[child] open error");
      return 1;
    }
    ssize_t bytes = 0;
    while (bytes <= 0) {
      errno = 0;
      bytes = read(fd, &buffer, sizeof(buffer));
      if (bytes < 0 && errno != EAGAIN && errno != EWOULDBLOCK) {
        perror("[child] read error");
        return 1;
      }
      sched_yield();
    }
    buffer[sizeof(buffer) - 1] = '\0';
    if (bytes < sizeof(buffer))
      buffer[bytes] = '\0';
    if (close(fd) < 0) {
      perror("[child] close error");
      return 1;
    }
    printf("read on FIFO: %s\n", buffer);
  } else {
    fd = -1;
    while (fd < 0) {
      errno = 0;
      fd = open("tmp/fifo", O_NONBLOCK | O_WRONLY);
      if (fd < 0 && errno != ENXIO) {
        perror("[parent] open error");
        return 1;
      }
      sched_yield();
    }
    snprintf(buffer, sizeof(buffer), "Hello from write end of FIFO!");
    if (write(fd, &buffer, strlen(buffer) + 1) < 0) {
      perror("[parent] write error");
      return 1;
    }
    if (close(fd) < 0) {
      perror("[parent] close error");
      return 1;
    }
    pid = wait(NULL);
    if (pid < 0) {
      perror("[parent] wait error");
      return 1;
    }
    if (unlink("tmp/fifo") < 0) {
      perror("[parent] unlink error");
      return 1;
    }
    fd = open("tmp/fifo", O_CREAT | O_TRUNC, 0600);
    if (fd < 0) {
      perror("[parent] open error");
      return 1;
    }
    if (close(fd) < 0) {
      perror("[parent] close error");
      return 1;
    }
    if (unlink("tmp/fifo") < 0) {
      perror("[parent] unlink error");
      return 1;
    }
    printf("[parent] TEST OK\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2de8(%rip),%rax
mov    (%rax),%esi
lea    0xe07(%rip),%rdi
call   10b0 <mkfifo@plt>
cmp    $0x0,%rax
jge    1220 <main+0x50>
lea    0xdfa(%rip),%rdi
call   10d0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    15ff <main+0x42f>
mov    $0x0,%al
call   10f0 <fork@plt>
mov    %rax,-0x428(%rbp)
cmpq   $0x0,-0x428(%rbp)
jge    1254 <main+0x84>
lea    0xdd3(%rip),%rdi
call   10d0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    15ff <main+0x42f>
cmpq   $0x0,-0x428(%rbp)
jne    13b5 <main+0x1e5>
mov    0x2d67(%rip),%rax
mov    (%rax),%esi
mov    0x2d56(%rip),%rax
or     (%rax),%esi
lea    0xd85(%rip),%rdi
mov    $0x0,%al
call   10c0 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    12a7 <main+0xd7>
lea    0xd8b(%rip),%rdi
call   10d0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    15ff <main+0x42f>
movl   $0x0,-0x42c(%rbp)
cmpl   $0x0,-0x42c(%rbp)
jg     134b <main+0x17b>
mov    0x2cf3(%rip),%rax
movq   $0x0,(%rax)
mov    -0x14(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   10a0 <read@plt>
mov    %eax,-0x42c(%rbp)
cmpl   $0x0,-0x42c(%rbp)
jge    133f <main+0x16f>
mov    0x2cbe(%rip),%rax
mov    (%rax),%rax
mov    0x2c8c(%rip),%rcx
cmp    (%rcx),%rax
je     133f <main+0x16f>
mov    0x2ca4(%rip),%rax
mov    (%rax),%rax
mov    0x2c92(%rip),%rcx
cmp    (%rcx),%rax
je     133f <main+0x16f>
lea    0xd06(%rip),%rdi
call   10d0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    15ff <main+0x42f>
mov    $0x0,%al
call   1090 <sched_yield@plt>
jmp    12b1 <main+0xe1>
movb   $0x0,-0x21(%rbp)
movslq -0x42c(%rbp),%rax
cmp    $0x400,%rax
jae    1371 <main+0x1a1>
movslq -0x42c(%rbp),%rax
movb   $0x0,-0x420(%rbp,%rax,1)
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
cmp    $0x0,%rax
jge    139b <main+0x1cb>
lea    0xcbd(%rip),%rdi
call   10d0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    15ff <main+0x42f>
lea    -0x420(%rbp),%rsi
lea    0xcb2(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    15f3 <main+0x423>
movl   $0xffffffff,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    143f <main+0x26f>
mov    0x2beb(%rip),%rax
movq   $0x0,(%rax)
mov    0x2bf5(%rip),%rax
mov    (%rax),%esi
mov    0x2bb4(%rip),%rax
or     (%rax),%esi
lea    0xc13(%rip),%rdi
mov    $0x0,%al
call   10c0 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1433 <main+0x263>
mov    0x2bb0(%rip),%rax
mov    (%rax),%rax
mov    0x2b96(%rip),%rcx
cmp    (%rcx),%rax
je     1433 <main+0x263>
lea    0xc4b(%rip),%rdi
call   10d0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    15ff <main+0x42f>
mov    $0x0,%al
call   1090 <sched_yield@plt>
jmp    13bc <main+0x1ec>
lea    -0x420(%rbp),%rdi
mov    $0x400,%esi
lea    0xc2f(%rip),%rdx
call   1070 <snprintf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x43c(%rbp)
lea    -0x420(%rbp),%rax
mov    %rax,-0x438(%rbp)
lea    -0x420(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x43c(%rbp),%edi
mov    -0x438(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1040 <write@plt>
cmp    $0x0,%rax
jge    14b5 <main+0x2e5>
lea    0xbfb(%rip),%rdi
call   10d0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    15ff <main+0x42f>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
cmp    $0x0,%rax
jge    14df <main+0x30f>
lea    0xbe6(%rip),%rdi
call   10d0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    15ff <main+0x42f>
xor    %eax,%eax
mov    %eax,%edi
call   10e0 <wait@plt>
mov    %rax,-0x428(%rbp)
cmpq   $0x0,-0x428(%rbp)
jge    1515 <main+0x345>
lea    0xbc5(%rip),%rdi
call   10d0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    15ff <main+0x42f>
lea    0xae4(%rip),%rdi
call   1030 <unlink@plt>
cmp    $0x0,%rax
jge    1543 <main+0x373>
lea    0xbab(%rip),%rdi
call   10d0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    15ff <main+0x42f>
mov    0x2aae(%rip),%rax
mov    (%rax),%esi
mov    0x2a9d(%rip),%rax
or     (%rax),%esi
lea    0xaa4(%rip),%rdi
mov    $0x180,%edx
mov    $0x0,%al
call   10c0 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    158d <main+0x3bd>
lea    0xaf1(%rip),%rdi
call   10d0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    15ff <main+0x42f>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
cmp    $0x0,%rax
jge    15b7 <main+0x3e7>
lea    0xb0e(%rip),%rdi
call   10d0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    15ff <main+0x42f>
lea    0xa42(%rip),%rdi
call   1030 <unlink@plt>
cmp    $0x0,%rax
jge    15e5 <main+0x415>
lea    0xb09(%rip),%rdi
call   10d0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    15ff <main+0x42f>
lea    0xb07(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    15f8 <main+0x428>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    0x2de0(%rip),%rax
mov    (%rax),%esi
lea    0xdff(%rip),%rdi
call   10c0 <mkfifo@plt>
test   %rax,%rax
js     1439 <main+0x259>
xor    %eax,%eax
call   1100 <fork@plt>
test   %rax,%rax
js     1442 <main+0x262>
je     137b <main+0x19b>
mov    0x2d8c(%rip),%rbp
movq   $0x0,0x0(%rbp)
mov    0x2d95(%rip),%r15
mov    0x2d56(%rip),%r12
mov    (%r12),%esi
or     (%r15),%esi
lea    0xdb0(%rip),%rdi
xor    %eax,%eax
call   10d0 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    12a4 <main+0xc4>
mov    0x2d44(%rip),%r13
lea    0xd95(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    0x0(%rbp),%rax
cmp    0x0(%r13),%rax
jne    145d <main+0x27d>
xor    %eax,%eax
call   10a0 <sched_yield@plt>
movq   $0x0,0x0(%rbp)
mov    (%r12),%esi
or     (%r15),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   10d0 <open@plt>
test   %eax,%eax
js     1270 <main+0x90>
mov    %eax,%ebx
xor    %eax,%eax
call   10a0 <sched_yield@plt>
lea    0xdcf(%rip),%rdx
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0x400,%esi
call   1080 <snprintf@plt>
mov    %rbp,%rdi
call   1060 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %ebx,%edi
mov    %rbp,%rsi
call   1050 <write@plt>
test   %rax,%rax
js     1466 <main+0x286>
mov    %ebx,%edi
call   1090 <close@plt>
test   %rax,%rax
js     144b <main+0x26b>
xor    %edi,%edi
call   10f0 <wait@plt>
test   %rax,%rax
js     146f <main+0x28f>
lea    0xcf8(%rip),%rdi
call   1030 <unlink@plt>
test   %rax,%rax
js     1454 <main+0x274>
mov    0x2cdb(%rip),%rax
mov    0x2ccc(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xcd1(%rip),%rdi
mov    $0x180,%edx
xor    %eax,%eax
call   10d0 <open@plt>
test   %eax,%eax
js     145d <main+0x27d>
mov    %eax,%edi
call   1090 <close@plt>
test   %rax,%rax
js     144b <main+0x26b>
lea    0xca6(%rip),%rdi
call   1030 <unlink@plt>
test   %rax,%rax
js     1454 <main+0x274>
lea    0xd84(%rip),%rdi
call   1040 <puts@plt>
xor    %ebx,%ebx
jmp    1492 <main+0x2b2>
mov    0x2c4e(%rip),%rax
mov    0x2c3f(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xc6c(%rip),%rdi
xor    %eax,%eax
call   10d0 <open@plt>
test   %eax,%eax
js     1478 <main+0x298>
mov    %eax,%ebx
mov    0x2c0c(%rip),%r15
mov    %rsp,%r14
mov    0x2bda(%rip),%r12
mov    0x2bf3(%rip),%r13
jmp    13cb <main+0x1eb>
nop
xor    %eax,%eax
call   10a0 <sched_yield@plt>
test   %ebp,%ebp
jg     1402 <main+0x222>
movq   $0x0,(%r15)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x400,%edx
call   10b0 <read@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    13c0 <main+0x1e0>
mov    (%r15),%rax
cmp    (%r12),%rax
je     13c0 <main+0x1e0>
cmp    0x0(%r13),%rax
je     13c0 <main+0x1e0>
lea    0xc37(%rip),%rdi
jmp    1488 <main+0x2a8>
movb   $0x0,0x3ff(%rsp)
cmp    $0x3ff,%ebp
ja     1418 <main+0x238>
mov    %ebp,%eax
movb   $0x0,(%rsp,%rax,1)
mov    %ebx,%edi
call   1090 <close@plt>
test   %rax,%rax
js     1481 <main+0x2a1>
lea    0xc30(%rip),%rdi
xor    %ebx,%ebx
mov    %rsp,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    1492 <main+0x2b2>
lea    0xbc9(%rip),%rdi
jmp    1488 <main+0x2a8>
lea    0xbcd(%rip),%rdi
jmp    1488 <main+0x2a8>
lea    0xc62(%rip),%rdi
jmp    1488 <main+0x2a8>
lea    0xc82(%rip),%rdi
jmp    1488 <main+0x2a8>
lea    0xc09(%rip),%rdi
jmp    1488 <main+0x2a8>
lea    0xc32(%rip),%rdi
jmp    1488 <main+0x2a8>
lea    0xc53(%rip),%rdi
jmp    1488 <main+0x2a8>
lea    0xba2(%rip),%rdi
jmp    1488 <main+0x2a8>
lea    0xbbf(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"tmp/fifo\00"
@S_IRWXU = global i32 0
@.str.1 = [13 x i8] c"mkfifo error\00"
@.str.2 = [11 x i8] c"fork error\00"
@O_NONBLOCK = global i32 0
@O_RDONLY = global i32 0
@.str.3 = [19 x i8] c"[child] open error\00"
@errno = global i64 0
@EAGAIN = global i64 0
@EWOULDBLOCK = global i64 0
@.str.4 = [19 x i8] c"[child] read error\00"
@.str.5 = [20 x i8] c"[child] close error\00"
@.str.6 = [18 x i8] c"read on FIFO: %s\0A\00"
@O_WRONLY = global i32 0
@ENXIO = global i64 0
@.str.7 = [20 x i8] c"[parent] open error\00"
@.str.8 = [30 x i8] c"Hello from write end of FIFO!\00"
@.str.9 = [21 x i8] c"[parent] write error\00"
@.str.10 = [21 x i8] c"[parent] close error\00"
@.str.11 = [20 x i8] c"[parent] wait error\00"
@.str.12 = [22 x i8] c"[parent] unlink error\00"
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.13 = [18 x i8] c"[parent] TEST OK\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [1024 x i8]
%8 = alloca i64
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* @S_IRWXU
%11 = call i64 @mkfifo(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %145
15: ; preds = %2
%16 = call i64 (...) @fork()
store i64 %16, i64* %8
%17 = load i64, i64* %8
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %145
21: ; preds = %15
%22 = load i64, i64* %8
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %73
24: ; preds = %21
%25 = load i32, i32* @O_NONBLOCK
%26 = load i32, i32* @O_RDONLY
%27 = or i32 %25, %26
%28 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %27)
store i32 %28, i32* %6
%29 = load i32, i32* %6
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %24
%32 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %145
33: ; preds = %24
store i32 0, i32* %9
br label %34
34: ; preds = %53, %33
%35 = load i32, i32* %9
%36 = icmp sle i32 %35, 0
br i1 %36, label %37, label %55
37: ; preds = %34
store i64 0, i64* @errno
%38 = load i32, i32* %6
%39 = bitcast [1024 x i8]* %7 to i8**
%40 = call i32 @read(i32 %38, i8** %39, i32 1024)
store i32 %40, i32* %9
%41 = load i32, i32* %9
%42 = icmp slt i32 %41, 0
br i1 %42, label %43, label %53
43: ; preds = %37
%44 = load i64, i64* @errno
%45 = load i64, i64* @EAGAIN
%46 = icmp ne i64 %44, %45
br i1 %46, label %47, label %53
47: ; preds = %43
%48 = load i64, i64* @errno
%49 = load i64, i64* @EWOULDBLOCK
%50 = icmp ne i64 %48, %49
br i1 %50, label %51, label %53
51: ; preds = %47
%52 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %3
br label %145
53: ; preds = %47, %43, %37
%54 = call i32 (...) @sched_yield()
br label %34
55: ; preds = %34
%56 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 1023
store i8 0, i8* %56
%57 = load i32, i32* %9
%58 = sext i32 %57 to i64
%59 = icmp ult i64 %58, 1024
br i1 %59, label %60, label %64
60: ; preds = %55
%61 = load i32, i32* %9
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 %62
store i8 0, i8* %63
br label %64
64: ; preds = %60, %55
%65 = load i32, i32* %6
%66 = call i64 @close(i32 %65)
%67 = icmp slt i64 %66, 0
br i1 %67, label %68, label %70
68: ; preds = %64
%69 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %3
br label %145
70: ; preds = %64
%71 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i8* %71)
br label %143
73: ; preds = %21
store i32 -1, i32* %6
br label %74
74: ; preds = %90, %73
%75 = load i32, i32* %6
%76 = icmp slt i32 %75, 0
br i1 %76, label %77, label %92
77: ; preds = %74
store i64 0, i64* @errno
%78 = load i32, i32* @O_NONBLOCK
%79 = load i32, i32* @O_WRONLY
%80 = or i32 %78, %79
%81 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %80)
store i32 %81, i32* %6
%82 = load i32, i32* %6
%83 = icmp slt i32 %82, 0
br i1 %83, label %84, label %90
84: ; preds = %77
%85 = load i64, i64* @errno
%86 = load i64, i64* @ENXIO
%87 = icmp ne i64 %85, %86
br i1 %87, label %88, label %90
88: ; preds = %84
%89 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0))
store i32 1, i32* %3
br label %145
90: ; preds = %84, %77
%91 = call i32 (...) @sched_yield()
br label %74
92: ; preds = %74
%93 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%94 = call i32 @snprintf(i8* %93, i32 1024, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.8, i64 0, i64 0))
%95 = load i32, i32* %6
%96 = bitcast [1024 x i8]* %7 to i8**
%97 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%98 = call i64 @strlen(i8* %97)
%99 = add nsw i64 %98, 1
%100 = call i64 @write(i32 %95, i8** %96, i64 %99)
%101 = icmp slt i64 %100, 0
br i1 %101, label %102, label %104
102: ; preds = %92
%103 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.9, i64 0, i64 0))
store i32 1, i32* %3
br label %145
104: ; preds = %92
%105 = load i32, i32* %6
%106 = call i64 @close(i32 %105)
%107 = icmp slt i64 %106, 0
br i1 %107, label %108, label %110
108: ; preds = %104
%109 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.10, i64 0, i64 0))
store i32 1, i32* %3
br label %145
110: ; preds = %104
%111 = call i64 @wait(i32* null)
store i64 %111, i64* %8
%112 = load i64, i64* %8
%113 = icmp slt i64 %112, 0
br i1 %113, label %114, label %116
114: ; preds = %110
%115 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.11, i64 0, i64 0))
store i32 1, i32* %3
br label %145
116: ; preds = %110
%117 = call i64 @unlink(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%118 = icmp slt i64 %117, 0
br i1 %118, label %119, label %121
119: ; preds = %116
%120 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.12, i64 0, i64 0))
store i32 1, i32* %3
br label %145
121: ; preds = %116
%122 = load i32, i32* @O_CREAT
%123 = load i32, i32* @O_TRUNC
%124 = or i32 %122, %123
%125 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %124, i32 384)
store i32 %125, i32* %6
%126 = load i32, i32* %6
%127 = icmp slt i32 %126, 0
br i1 %127, label %128, label %130
128: ; preds = %121
%129 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0))
store i32 1, i32* %3
br label %145
130: ; preds = %121
%131 = load i32, i32* %6
%132 = call i64 @close(i32 %131)
%133 = icmp slt i64 %132, 0
br i1 %133, label %134, label %136
134: ; preds = %130
%135 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.10, i64 0, i64 0))
store i32 1, i32* %3
br label %145
136: ; preds = %130
%137 = call i64 @unlink(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%138 = icmp slt i64 %137, 0
br i1 %138, label %139, label %141
139: ; preds = %136
%140 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.12, i64 0, i64 0))
store i32 1, i32* %3
br label %145
141: ; preds = %136
%142 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.13, i64 0, i64 0))
br label %143
143: ; preds = %141, %70
br label %144
144: ; preds = %143
store i32 0, i32* %3
br label %145
145: ; preds = %144, %139, %134, %128, %119, %114, %108, %102, %88, %68, %51, %31, %19, %13
%146 = load i32, i32* %3
ret i32 %146
}

LLVM IR (-O2):
@.str = [9 x i8] c"tmp/fifo\00"
@S_IRWXU = global i32 0
@.str.1 = [13 x i8] c"mkfifo error\00"
@.str.2 = [11 x i8] c"fork error\00"
@O_NONBLOCK = global i32 0
@O_RDONLY = global i32 0
@.str.3 = [19 x i8] c"[child] open error\00"
@errno = global i64 0
@EAGAIN = global i64 0
@EWOULDBLOCK = global i64 0
@.str.4 = [19 x i8] c"[child] read error\00"
@.str.5 = [20 x i8] c"[child] close error\00"
@.str.6 = [18 x i8] c"read on FIFO: %s\0A\00"
@O_WRONLY = global i32 0
@ENXIO = global i64 0
@.str.7 = [20 x i8] c"[parent] open error\00"
@.str.8 = [30 x i8] c"Hello from write end of FIFO!\00"
@.str.9 = [21 x i8] c"[parent] write error\00"
@.str.10 = [21 x i8] c"[parent] close error\00"
@.str.11 = [20 x i8] c"[parent] wait error\00"
@.str.12 = [22 x i8] c"[parent] unlink error\00"
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@str = [17 x i8] c"[parent] TEST OK\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @S_IRWXU
%6 = tail call i64 @mkfifo(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %120
10: ; preds = %2
%11 = tail call i64 (...) @fork()
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %120
15: ; preds = %10
%16 = icmp eq i64 %11, 0
br i1 %16, label %23, label %17
17: ; preds = %15
store i64 0, i64* @errno
%18 = load i32, i32* @O_NONBLOCK
%19 = load i32, i32* @O_WRONLY
%20 = or i32 %19, %18
%21 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %20)
%22 = icmp slt i32 %21, 0
br i1 %22, label %61, label %74
23: ; preds = %15
%24 = load i32, i32* @O_NONBLOCK
%25 = load i32, i32* @O_RDONLY
%26 = or i32 %25, %24
%27 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %26)
%28 = icmp slt i32 %27, 0
br i1 %28, label %31, label %29
29: ; preds = %23
%30 = bitcast [1024 x i8]* %3 to i8**
br label %33
31: ; preds = %23
%32 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
br label %120
33: ; preds = %29, %45
store i64 0, i64* @errno
%34 = call i32 @read(i32 %27, i8** %30, i32 1024)
%35 = icmp slt i32 %34, 0
br i1 %35, label %36, label %45
36: ; preds = %33
%37 = load i64, i64* @errno
%38 = load i64, i64* @EAGAIN
%39 = icmp eq i64 %37, %38
%40 = load i64, i64* @EWOULDBLOCK
%41 = icmp eq i64 %37, %40
%42 = select i1 %39, i1 true, i1 %41
br i1 %42, label %45, label %43
43: ; preds = %36
%44 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
br label %120
45: ; preds = %36, %33
%46 = tail call i32 (...) @sched_yield()
%47 = icmp slt i32 %34, 1
br i1 %47, label %33, label %48
48: ; preds = %45
%49 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 1023
store i8 0, i8* %49
%50 = icmp ult i32 %34, 1024
br i1 %50, label %51, label %54
51: ; preds = %48
%52 = zext i32 %34 to i64
%53 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %52
store i8 0, i8* %53
br label %54
54: ; preds = %51, %48
%55 = tail call i64 @close(i32 %27)
%56 = icmp slt i64 %55, 0
br i1 %56, label %57, label %59
57: ; preds = %54
%58 = tail call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
br label %120
59: ; preds = %54
%60 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i8* %4)
br label %120
61: ; preds = %17, %67
%62 = load i64, i64* @errno
%63 = load i64, i64* @ENXIO
%64 = icmp eq i64 %62, %63
br i1 %64, label %67, label %65
65: ; preds = %61
%66 = tail call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0))
br label %120
67: ; preds = %61
%68 = tail call i32 (...) @sched_yield()
store i64 0, i64* @errno
%69 = load i32, i32* @O_NONBLOCK
%70 = load i32, i32* @O_WRONLY
%71 = or i32 %70, %69
%72 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %71)
%73 = icmp slt i32 %72, 0
br i1 %73, label %61, label %74
74: ; preds = %67, %17
%75 = phi i32 [ %21, %17 ], [ %72, %67 ]
%76 = tail call i32 (...) @sched_yield()
%77 = call i32 @snprintf(i8* %4, i32 1024, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.8, i64 0, i64 0))
%78 = bitcast [1024 x i8]* %3 to i8**
%79 = call i64 @strlen(i8* %4)
%80 = add nsw i64 %79, 1
%81 = call i64 @write(i32 %75, i8** %78, i64 %80)
%82 = icmp slt i64 %81, 0
br i1 %82, label %83, label %85
83: ; preds = %74
%84 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.9, i64 0, i64 0))
br label %120
85: ; preds = %74
%86 = call i64 @close(i32 %75)
%87 = icmp slt i64 %86, 0
br i1 %87, label %88, label %90
88: ; preds = %85
%89 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.10, i64 0, i64 0))
br label %120
90: ; preds = %85
%91 = call i64 @wait(i32* null)
%92 = icmp slt i64 %91, 0
br i1 %92, label %93, label %95
93: ; preds = %90
%94 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.11, i64 0, i64 0))
br label %120
95: ; preds = %90
%96 = call i64 @unlink(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%97 = icmp slt i64 %96, 0
br i1 %97, label %98, label %100
98: ; preds = %95
%99 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.12, i64 0, i64 0))
br label %120
100: ; preds = %95
%101 = load i32, i32* @O_CREAT
%102 = load i32, i32* @O_TRUNC
%103 = or i32 %102, %101
%104 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %103, i32 384)
%105 = icmp slt i32 %104, 0
br i1 %105, label %106, label %108
106: ; preds = %100
%107 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0))
br label %120
108: ; preds = %100
%109 = call i64 @close(i32 %104)
%110 = icmp slt i64 %109, 0
br i1 %110, label %111, label %113
111: ; preds = %108
%112 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.10, i64 0, i64 0))
br label %120
113: ; preds = %108
%114 = call i64 @unlink(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%115 = icmp slt i64 %114, 0
br i1 %115, label %116, label %118
116: ; preds = %113
%117 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.12, i64 0, i64 0))
br label %120
118: ; preds = %113
%119 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
br label %120
120: ; preds = %43, %57, %118, %59, %13, %31, %65, %83, %88, %93, %98, %106, %111, %116, %8
%121 = phi i32 [ 1, %8 ], [ 1, %13 ], [ 1, %31 ], [ 1, %65 ], [ 1, %83 ], [ 1, %88 ], [ 1, %93 ], [ 1, %98 ], [ 1, %106 ], [ 1, %111 ], [ 1, %116 ], [ 0, %59 ], [ 0, %118 ], [ 1, %57 ], [ 1, %43 ]
ret i32 %121
}