#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 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 mkfifo2!";
  sleep(6);
  if ((fd[0] = open("TEST1", O_RDONLY)) == -1) {
    printf("open error!\n");
    return -1;
  }
  memset(buf, 0, sizeof(buf));
  read(fd[0], buf, sizeof(buf));
  printf("mkfifo2 fd[0]: %s\n", buf);
  close(fd[0]);
  sleep(3);
  printf("mkfifo2 fd[1]: %s\n", msg);
  if ((fd[1] = open("TEST2", O_WRONLY)) == -1) {
    printf("open error!\n");
    close(fd[0]);
    return -2;
  }
  write(fd[1], msg, strlen(msg));
  close(fd[1]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe67(%rip),%rax
mov    %rax,-0x118(%rbp)
mov    $0x6,%edi
call   10a0 <sleep@plt>
mov    0x2e37(%rip),%rax
mov    (%rax),%esi
lea    0xe54(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0xc(%rbp)
cmp    $0xffffffff,%eax
jne    11e5 <main+0x65>
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12d1 <main+0x151>
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    0xe07(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xc(%rbp),%edi
call   1070 <close@plt>
mov    $0x3,%edi
call   10a0 <sleep@plt>
mov    -0x118(%rbp),%rsi
lea    0xdf3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2d81(%rip),%rax
mov    (%rax),%esi
lea    0xdef(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    128b <main+0x10b>
lea    0xda4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xc(%rbp),%edi
call   1070 <close@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    12d1 <main+0x151>
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>
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
mov    $0x6,%edi
call   10b0 <sleep@plt>
mov    0x2e3c(%rip),%rax
mov    (%rax),%esi
lea    0xe59(%rip),%rdi
call   10a0 <open@plt>
cmp    $0xffffffff,%eax
je     1260 <main+0xd0>
mov    %eax,%ebp
mov    %rsp,%rbx
xor    %r14d,%r14d
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1070 <memset@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x100,%edx
call   1090 <read@plt>
lea    0xe24(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebp,%edi
call   1080 <close@plt>
mov    $0x3,%edi
call   10b0 <sleep@plt>
lea    0xe15(%rip),%rdi
lea    0xde7(%rip),%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2da9(%rip),%rax
mov    (%rax),%esi
lea    0xe0a(%rip),%rdi
call   10a0 <open@plt>
cmp    $0xffffffff,%eax
je     1274 <main+0xe4>
mov    %eax,%ebx
lea    0xdbd(%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>
jmp    128d <main+0xfd>
lea    0xdd9(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%r14d
jmp    128d <main+0xfd>
lea    0xdc5(%rip),%rdi
call   1030 <puts@plt>
mov    %ebp,%edi
call   1080 <close@plt>
mov    $0xfffffffe,%r14d
mov    %r14d,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [14 x i8] c"I am mkfifo2!\00"
@.str.1 = [6 x i8] c"TEST1\00"
@O_RDONLY = global i32 0
@.str.3 = [19 x i8] c"mkfifo2 fd[0]: %s\0A\00"
@.str.4 = [19 x i8] c"mkfifo2 fd[1]: %s\0A\00"
@.str.5 = [6 x i8] c"TEST2\00"
@O_WRONLY = global i32 0
@str.6 = [12 x i8] c"open 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 @sleep(i32 6)
%4 = load i32, i32* @O_RDONLY
%5 = tail call i32 @open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.6, i64 0, i64 0))
br label %26
9: ; preds = %0
%10 = call i32 @memset(i8* %2, i32 0, i32 256)
%11 = call i32 @read(i32 %5, i8* %2, i32 256)
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %2)
%13 = call i32 @close(i32 %5)
%14 = call i32 @sleep(i32 3)
%15 = 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))
%16 = load i32, i32* @O_WRONLY
%17 = call i32 @open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 %16)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %22
19: ; preds = %9
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.6, i64 0, i64 0))
%21 = call i32 @close(i32 %5)
br label %26
22: ; preds = %9
%23 = call i32 @strlen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%24 = call i32 @write(i32 %17, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %23)
%25 = call i32 @close(i32 %17)
br label %26
26: ; preds = %22, %19, %7
%27 = phi i32 [ -1, %7 ], [ -2, %19 ], [ 0, %22 ]
ret i32 %27
}