#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*/ buf;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int mkfifo(char *, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int main(void) {
  int fd[2];
  char buf[256];
  char *msg = "I am mkfifo1!";
  if (mkfifo("TEST1", 0666) == -1) {
    printf("mkfifo error!\n");
    return -1;
  }
  if (mkfifo("TEST2", 0666) == -1) {
    printf("mkfifo error!\n");
    return -2;
  }
  sleep(3);
  printf("mkfifo1 fd[1]: %s\n", msg);
  if ((fd[1] = open("TEST1", O_WRONLY)) == -1) {
    printf("open error!\n");
    return -3;
  }
  write(fd[1], msg, strlen(msg));
  close(fd[1]);
  sleep(9);
  if ((fd[0] = open("TEST2", O_RDONLY)) == -1) {
    printf("open error!\n");
    return -4;
  }
  memset(buf, 0, sizeof(buf));
  read(fd[0], buf, sizeof(buf));
  printf("mkfifo1 fd[0]: %s\n", buf);
  close(fd[0]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe57(%rip),%rax
mov    %rax,-0x118(%rbp)
lea    0xe57(%rip),%rdi
mov    $0x1b6,%esi
call   1090 <mkfifo@plt>
cmp    $0xffffffff,%eax
jne    11e4 <main+0x54>
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1341 <main+0x1b1>
lea    0xe38(%rip),%rdi
mov    $0x1b6,%esi
call   1090 <mkfifo@plt>
cmp    $0xffffffff,%eax
jne    1218 <main+0x88>
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1341 <main+0x1b1>
mov    $0x3,%edi
call   10b0 <sleep@plt>
mov    -0x118(%rbp),%rsi
lea    0xdf9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2d92(%rip),%rax
mov    (%rax),%esi
lea    0xdc7(%rip),%rdi
call   10a0 <open@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    1272 <main+0xe2>
lea    0xddd(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xfffffffd,-0x4(%rbp)
jmp    1341 <main+0x1b1>
mov    -0x8(%rbp),%eax
mov    %eax,-0x124(%rbp)
mov    -0x118(%rbp),%rax
mov    %rax,-0x120(%rbp)
mov    -0x118(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x124(%rbp),%edi
mov    -0x120(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%edi
call   1070 <close@plt>
mov    $0x9,%edi
call   10b0 <sleep@plt>
mov    0x2d26(%rip),%rax
mov    (%rax),%esi
lea    0xd58(%rip),%rdi
call   10a0 <open@plt>
mov    %eax,-0xc(%rbp)
cmp    $0xffffffff,%eax
jne    12f6 <main+0x166>
lea    0xd59(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xfffffffc,-0x4(%rbp)
jmp    1341 <main+0x1b1>
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
mov    -0xc(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    $0x100,%edx
call   1080 <read@plt>
lea    -0x110(%rbp),%rsi
lea    0xd1e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xc(%rbp),%edi
call   1070 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x100,%rsp
lea    0xe5c(%rip),%rdi
mov    $0x1b6,%esi
call   10a0 <mkfifo@plt>
cmp    $0xffffffff,%eax
je     12a3 <main+0x103>
lea    0xe48(%rip),%rdi
mov    $0x1b6,%esi
call   10a0 <mkfifo@plt>
cmp    $0xffffffff,%eax
je     12b6 <main+0x116>
mov    $0x3,%edi
call   10c0 <sleep@plt>
lea    0xe2a(%rip),%rdi
lea    0xe09(%rip),%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2dcb(%rip),%rax
mov    (%rax),%esi
lea    0xe00(%rip),%rdi
call   10b0 <open@plt>
cmp    $0xffffffff,%eax
je     12c9 <main+0x129>
mov    %eax,%ebx
lea    0xddb(%rip),%rbp
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %ebx,%edi
call   1080 <close@plt>
mov    $0x9,%edi
call   10c0 <sleep@plt>
mov    0x2d97(%rip),%rax
mov    (%rax),%esi
lea    0xdba(%rip),%rdi
call   10b0 <open@plt>
cmp    $0xffffffff,%eax
je     12dc <main+0x13c>
mov    %eax,%ebp
mov    %rsp,%r14
xor    %ebx,%ebx
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1070 <memset@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x100,%edx
call   1090 <read@plt>
lea    0xd9d(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebp,%edi
call   1080 <close@plt>
jmp    12ed <main+0x14d>
lea    0xda2(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebx
jmp    12ed <main+0x14d>
lea    0xd8f(%rip),%rdi
call   1030 <puts@plt>
mov    $0xfffffffe,%ebx
jmp    12ed <main+0x14d>
lea    0xd70(%rip),%rdi
call   1030 <puts@plt>
mov    $0xfffffffd,%ebx
jmp    12ed <main+0x14d>
lea    0xd5d(%rip),%rdi
call   1030 <puts@plt>
mov    $0xfffffffc,%ebx
mov    %ebx,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"I am mkfifo1!\00"
@.str.1 = [6 x i8] c"TEST1\00"
@.str.2 = [15 x i8] c"mkfifo error!\0A\00"
@.str.3 = [6 x i8] c"TEST2\00"
@.str.4 = [19 x i8] c"mkfifo1 fd[1]: %s\0A\00"
@O_WRONLY = global i32 0
@.str.5 = [13 x i8] c"open error!\0A\00"
@O_RDONLY = global i32 0
@.str.6 = [19 x i8] c"mkfifo1 fd[0]: %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i32]
%3 = alloca [256 x i8]
%4 = alloca i8*
store i32 0, i32* %1
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8** %4
%5 = call i32 @mkfifo(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 438)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %53
9: ; preds = %0
%10 = call i32 @mkfifo(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 438)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
store i32 -2, i32* %1
br label %53
14: ; preds = %9
%15 = call i32 @sleep(i32 3)
%16 = load i8*, i8** %4
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %16)
%18 = load i32, i32* @O_WRONLY
%19 = call i32 @open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%20 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
store i32 %19, i32* %20
%21 = icmp eq i32 %19, -1
br i1 %21, label %22, label %24
22: ; preds = %14
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
store i32 -3, i32* %1
br label %53
24: ; preds = %14
%25 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%26 = load i32, i32* %25
%27 = load i8*, i8** %4
%28 = load i8*, i8** %4
%29 = call i32 @strlen(i8* %28)
%30 = call i32 @write(i32 %26, i8* %27, i32 %29)
%31 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%32 = load i32, i32* %31
%33 = call i32 @close(i32 %32)
%34 = call i32 @sleep(i32 9)
%35 = load i32, i32* @O_RDONLY
%36 = call i32 @open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %35)
%37 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
store i32 %36, i32* %37
%38 = icmp eq i32 %36, -1
br i1 %38, label %39, label %41
39: ; preds = %24
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
store i32 -4, i32* %1
br label %53
41: ; preds = %24
%42 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%43 = call i32 @memset(i8* %42, i32 0, i32 256)
%44 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%45 = load i32, i32* %44
%46 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%47 = call i32 @read(i32 %45, i8* %46, i32 256)
%48 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i8* %48)
%50 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%51 = load i32, i32* %50
%52 = call i32 @close(i32 %51)
store i32 0, i32* %1
br label %53
53: ; preds = %41, %39, %22, %12, %7
%54 = load i32, i32* %1
ret i32 %54
}

LLVM IR (-O2):
@.str = [14 x i8] c"I am mkfifo1!\00"
@.str.1 = [6 x i8] c"TEST1\00"
@.str.3 = [6 x i8] c"TEST2\00"
@.str.4 = [19 x i8] c"mkfifo1 fd[1]: %s\0A\00"
@O_WRONLY = global i32 0
@O_RDONLY = global i32 0
@.str.6 = [19 x i8] c"mkfifo1 fd[0]: %s\0A\00"
@str.7 = [12 x i8] c"open error!\00"
@str.9 = [14 x i8] c"mkfifo error!\00"
define i32 @main() {
%1 = alloca [256 x i8]
%2 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @mkfifo(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 438)
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.9, i64 0, i64 0))
br label %35
7: ; preds = %0
%8 = tail call i32 @mkfifo(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 438)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.9, i64 0, i64 0))
br label %35
12: ; preds = %7
%13 = tail call i32 @sleep(i32 3)
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @O_WRONLY
%16 = tail call i32 @open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %20
18: ; preds = %12
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.7, i64 0, i64 0))
br label %35
20: ; preds = %12
%21 = tail call i32 @strlen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%22 = tail call i32 @write(i32 %16, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %21)
%23 = tail call i32 @close(i32 %16)
%24 = tail call i32 @sleep(i32 9)
%25 = load i32, i32* @O_RDONLY
%26 = tail call i32 @open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %25)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %30
28: ; preds = %20
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.7, i64 0, i64 0))
br label %35
30: ; preds = %20
%31 = call i32 @memset(i8* %2, i32 0, i32 256)
%32 = call i32 @read(i32 %26, i8* %2, i32 256)
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i8* %2)
%34 = call i32 @close(i32 %26)
br label %35
35: ; preds = %30, %28, %18, %10, %5
%36 = phi i32 [ -1, %5 ], [ -2, %10 ], [ -3, %18 ], [ -4, %28 ], [ 0, %30 ]
ret i32 %36
}