#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*/ O_RDONLY;
int /*<<< orphan*/ O_WRONLY;
int S_IFIFO;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int fork();
scalar_t__ mknod(char *, int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
size_t read(int, char *, int);
int /*<<< orphan*/ umask(int /*<<< orphan*/);
size_t write(int, char *, int);
int main() {
  int fd, result;
  size_t size;
  char resstring[14];
  char name[] = "aaa.fifo";
  (void)umask(0);
  if (mknod(name, S_IFIFO | 0666, 0) < 0) {
    printf("Can\'t create FIFO\n");
    exit(-1);
  }
  if ((result = fork()) < 0) {
    printf("Can\'t fork child\n");
    exit(-1);
  } else if (result > 0) {
    if ((fd = open(name, O_WRONLY)) < 0) {
      printf("Can\'t open FIFO for writting\n");
      exit(-1);
    }
    size = write(fd, "Hello, world!", 14);
    if (size != 14) {
      printf("Can\'t write all string to FIFO\n");
      exit(-1);
    }
    close(fd);
    printf("Parent exit\n");
  } else {
    if ((fd = open(name, O_RDONLY)) < 0) {
      printf("Can\'t open FIFO for reading\n");
      exit(-1);
    }
    size = read(fd, resstring, 14);
    if (size < 0) {
      printf("Can\'t read string\n");
      exit(-1);
    }
    printf("%s\n", resstring);
    close(fd);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe5a(%rip),%rax
mov    %rax,-0x2f(%rbp)
mov    0xe58(%rip),%al
mov    %al,-0x27(%rbp)
xor    %edi,%edi
call   1070 <umask@plt>
lea    -0x2f(%rbp),%rdi
mov    0x2e13(%rip),%rax
mov    (%rax),%esi
or     $0x1b6,%esi
xor    %edx,%edx
call   1080 <mknod@plt>
cmp    $0x0,%rax
jge    11f6 <main+0x66>
lea    0xe24(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    $0x0,%al
call   10b0 <fork@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    1221 <main+0x91>
lea    0xe0c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
cmpl   $0x0,-0xc(%rbp)
jle    12b7 <main+0x127>
lea    -0x2f(%rbp),%rdi
mov    0x2d92(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    1261 <main+0xd1>
lea    0xdde(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    -0x8(%rbp),%edi
lea    0xde1(%rip),%rsi
mov    $0xe,%edx
call   1030 <write@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0xe,-0x18(%rbp)
je     129c <main+0x10c>
lea    0xdcf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
lea    0xdcf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    133f <main+0x1af>
lea    -0x2f(%rbp),%rdi
mov    0x2d26(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    12ed <main+0x15d>
lea    0xdab(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    -0x8(%rbp),%edi
lea    -0x26(%rbp),%rsi
mov    $0xe,%edx
call   1060 <read@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jae    1325 <main+0x195>
lea    0xd90(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
lea    -0x26(%rbp),%rsi
lea    0xd87(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
jmp    1344 <main+0x1b4>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movabs $0x6f6669662e616161,%rax
69 66 6f
mov    %rax,(%rsp)
movb   $0x0,0x8(%rsp)
xor    %edi,%edi
call   1070 <umask@plt>
mov    0x2e20(%rip),%rax
mov    $0x1b6,%esi
or     (%rax),%esi
mov    %rsp,%rdi
xor    %edx,%edx
call   1080 <mknod@plt>
test   %rax,%rax
js     1270 <main+0xe0>
xor    %eax,%eax
call   10b0 <fork@plt>
test   %eax,%eax
js     1279 <main+0xe9>
je     122c <main+0x9c>
mov    0x2dde(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdi
call   1090 <open@plt>
test   %eax,%eax
js     1282 <main+0xf2>
mov    %eax,%ebx
lea    0xe04(%rip),%rsi
mov    %eax,%edi
mov    $0xe,%edx
call   1040 <write@plt>
cmp    $0xe,%rax
jne    128b <main+0xfb>
mov    %ebx,%edi
call   1050 <close@plt>
lea    0xe0e(%rip),%rdi
call   1030 <puts@plt>
jmp    1266 <main+0xd6>
mov    0x2db5(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdi
call   1090 <open@plt>
test   %eax,%eax
js     1294 <main+0x104>
mov    %eax,%ebx
lea    0xa(%rsp),%r14
mov    %eax,%edi
mov    %r14,%rsi
mov    $0xe,%edx
call   1060 <read@plt>
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe15(%rip),%rdi
jmp    129b <main+0x10b>
lea    0xdfb(%rip),%rdi
jmp    129b <main+0x10b>
lea    0xdd5(%rip),%rdi
jmp    129b <main+0x10b>
lea    0xdad(%rip),%rdi
jmp    129b <main+0x10b>
lea    0xd7c(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@__const.main.name = [9 x i8] c"aaa.fifo\00"
@S_IFIFO = global i32 0
@.str = [19 x i8] c"Can't create FIFO\0A\00"
@.str.1 = [18 x i8] c"Can't fork child\0A\00"
@O_WRONLY = global i32 0
@.str.2 = [30 x i8] c"Can't open FIFO for writting\0A\00"
@.str.3 = [14 x i8] c"Hello, world!\00"
@.str.4 = [32 x i8] c"Can't write all string to FIFO\0A\00"
@.str.5 = [13 x i8] c"Parent exit\0A\00"
@O_RDONLY = global i32 0
@.str.6 = [29 x i8] c"Can't open FIFO for reading\0A\00"
@.str.7 = [19 x i8] c"Can't read string\0A\00"
@.str.8 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i64
%5 = alloca [14 x i8]
%6 = alloca [9 x i8]
store i32 0, i32* %1
%7 = bitcast [9 x i8]* %6 to i8*
%8 = call i32 @umask(i32 0)
%9 = getelementptr inbounds [9 x i8], [9 x i8]* %6, i64 0, i64 0
%10 = load i32, i32* @S_IFIFO
%11 = or i32 %10, 438
%12 = call i64 @mknod(i8* %9, i32 %11, i32 0)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %0
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 -1)
unreachable
17: ; preds = %0
%18 = call i32 (...) @fork()
store i32 %18, i32* %3
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%22 = call i32 @exit(i32 -1)
unreachable
23: ; preds = %17
%24 = load i32, i32* %3
%25 = icmp sgt i32 %24, 0
br i1 %25, label %26, label %46
26: ; preds = %23
%27 = getelementptr inbounds [9 x i8], [9 x i8]* %6, i64 0, i64 0
%28 = load i32, i32* @O_WRONLY
%29 = call i32 @open(i8* %27, i32 %28)
store i32 %29, i32* %2
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %26
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%33 = call i32 @exit(i32 -1)
unreachable
34: ; preds = %26
%35 = load i32, i32* %2
%36 = call i64 @write(i32 %35, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 14)
store i64 %36, i64* %4
%37 = load i64, i64* %4
%38 = icmp ne i64 %37, 14
br i1 %38, label %39, label %42
39: ; preds = %34
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0))
%41 = call i32 @exit(i32 -1)
unreachable
42: ; preds = %34
%43 = load i32, i32* %2
%44 = call i32 @close(i32 %43)
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
br label %68
46: ; preds = %23
%47 = getelementptr inbounds [9 x i8], [9 x i8]* %6, i64 0, i64 0
%48 = load i32, i32* @O_RDONLY
%49 = call i32 @open(i8* %47, i32 %48)
store i32 %49, i32* %2
%50 = icmp slt i32 %49, 0
br i1 %50, label %51, label %54
51: ; preds = %46
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0))
%53 = call i32 @exit(i32 -1)
unreachable
54: ; preds = %46
%55 = load i32, i32* %2
%56 = getelementptr inbounds [14 x i8], [14 x i8]* %5, i64 0, i64 0
%57 = call i64 @read(i32 %55, i8* %56, i32 14)
store i64 %57, i64* %4
%58 = load i64, i64* %4
%59 = icmp ult i64 %58, 0
br i1 %59, label %60, label %63
60: ; preds = %54
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0))
%62 = call i32 @exit(i32 -1)
unreachable
63: ; preds = %54
%64 = getelementptr inbounds [14 x i8], [14 x i8]* %5, i64 0, i64 0
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i8* %64)
%66 = load i32, i32* %2
%67 = call i32 @close(i32 %66)
br label %68
68: ; preds = %63, %42
br label %69
69: ; preds = %68
ret i32 0
}

LLVM IR (-O2):
@__const.main.name = [9 x i8] c"aaa.fifo\00"
@S_IFIFO = global i32 0
@O_WRONLY = global i32 0
@.str.3 = [14 x i8] c"Hello, world!\00"
@O_RDONLY = global i32 0
@str = [28 x i8] c"Can't open FIFO for reading\00"
@str.9 = [12 x i8] c"Parent exit\00"
@str.10 = [31 x i8] c"Can't write all string to FIFO\00"
@str.11 = [29 x i8] c"Can't open FIFO for writting\00"
@str.12 = [17 x i8] c"Can't fork child\00"
@str.13 = [18 x i8] c"Can't create FIFO\00"
define i32 @main() {
%1 = alloca [14 x i8]
%2 = alloca [9 x i8]
%3 = getelementptr inbounds [14 x i8], [14 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 0
%5 = tail call i32 @umask(i32 0)
%6 = load i32, i32* @S_IFIFO
%7 = or i32 %6, 438
%8 = call i64 @mknod(i8* %4, i32 %7, i32 0)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.13, i64 0, i64 0))
%12 = call i32 @exit(i32 -1)
unreachable
13: ; preds = %0
%14 = call i32 (...) @fork()
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.12, i64 0, i64 0))
%18 = call i32 @exit(i32 -1)
unreachable
19: ; preds = %13
%20 = icmp eq i32 %14, 0
br i1 %20, label %37, label %21
21: ; preds = %19
%22 = load i32, i32* @O_WRONLY
%23 = call i32 @open(i8* %4, i32 %22)
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %21
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.11, i64 0, i64 0))
%27 = call i32 @exit(i32 -1)
unreachable
28: ; preds = %21
%29 = call i64 @write(i32 %23, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 14)
%30 = icmp eq i64 %29, 14
br i1 %30, label %34, label %31
31: ; preds = %28
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.10, i64 0, i64 0))
%33 = call i32 @exit(i32 -1)
unreachable
34: ; preds = %28
%35 = call i32 @close(i32 %23)
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.9, i64 0, i64 0))
br label %48
37: ; preds = %19
%38 = load i32, i32* @O_RDONLY
%39 = call i32 @open(i8* %4, i32 %38)
%40 = icmp slt i32 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %37
%42 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
%43 = call i32 @exit(i32 -1)
unreachable
44: ; preds = %37
%45 = call i64 @read(i32 %39, i8* %3, i32 14)
%46 = call i32 @puts(i8* %3)
%47 = call i32 @close(i32 %39)
br label %48
48: ; preds = %34, %44
ret i32 0
}