#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*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ F_OK;
int O_NONBLOCK;
int O_RDONLY;
int O_WRONLY;
int access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int getpid();
int mkfifo(char *, int);
int open(char *, int);
int /*<<< orphan*/ printf(char *, int, ...);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
scalar_t__ strncmp(char *, char *, int);
int main(int argc, char *argv[]) {
  int res;
  int open_mode = 0;
  int i;
  if (argc < 2) {
    fprintf(stderr,
            "Usage: %s <some combination of               O_RDONLY O_WRONLY "
            "O_NONBLOCK>\n",
            *argv);
    exit(EXIT_FAILURE);
  }
  for (i = 1; i < argc; i++) {
    if (strncmp(*++argv, "O_RDONLY", 8) == 0)
      open_mode |= O_RDONLY;
    if (strncmp(*argv, "O_WRONLY", 8) == 0)
      open_mode |= O_WRONLY;
    if (strncmp(*argv, "O_NONBLOCK", 10) == 0)
      open_mode |= O_NONBLOCK;
  }
  if (access("/tmp/my_fifo", F_OK) == -1) {
    res = mkfifo("/tmp/my_fifo", 0777);
    if (res != 0) {
      fprintf(stderr, "Could not create fifo %s\n", "/tmp/my_fifo");
      exit(EXIT_FAILURE);
    }
  }
  printf("Process %d opening FIFO\n", getpid());
  res = open("/tmp/my_fifo", open_mode);
  printf("Process %d result %d\n", getpid(), res);
  sleep(5);
  if (res != -1)
    (void)close(res);
  printf("Process %d finished\n", getpid());
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11f1 <main+0x51>
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe22(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2dde(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12b6 <main+0x116>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x8(%rax),%rdi
lea    0xe2e(%rip),%rsi
mov    $0x8,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1241 <main+0xa1>
mov    0x2da7(%rip),%rax
mov    (%rax),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xe06(%rip),%rsi
mov    $0x8,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1272 <main+0xd2>
mov    0x2d46(%rip),%rax
mov    (%rax),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xdde(%rip),%rsi
mov    $0xa,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    12a3 <main+0x103>
mov    0x2d4d(%rip),%rax
mov    (%rax),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    12a8 <main+0x108>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11f8 <main+0x58>
mov    0x2ceb(%rip),%rax
mov    (%rax),%esi
lea    0xda3(%rip),%rdi
call   10a0 <access@plt>
cmp    $0xffffffff,%eax
jne    1321 <main+0x181>
lea    0xd8e(%rip),%rdi
mov    $0x1ff,%esi
call   1080 <mkfifo@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     131c <main+0x17c>
mov    0x2cd7(%rip),%rax
mov    (%rax),%edi
lea    0xd74(%rip),%rsi
lea    0xd60(%rip),%rdx
call   1070 <fprintf@plt>
mov    0x2cb3(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
jmp    1321 <main+0x181>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%esi
lea    0xd5f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%esi
lea    0xd27(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%esi
mov    -0x14(%rbp),%edx
lea    0xd4c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x5,%edi
call   10c0 <sleep@plt>
cmpl   $0xffffffff,-0x14(%rbp)
je     1380 <main+0x1e0>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%esi
lea    0xd2f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2c22(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
cmp    $0x2,%edi
jge    11cb <main+0x2b>
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xe3a(%rip),%rsi
jmp    133c <main+0x19c>
mov    %edi,%ebp
xor    %ebx,%ebx
mov    $0x1,%r15d
jmp    11f3 <main+0x53>
nopw   0x0(%rax,%rax,1)
or     %ecx,%r12d
or     %r12d,%ebx
add    $0x1,%r15
cmp    %r15d,%ebp
je     127b <main+0xdb>
mov    (%r14,%r15,8),%rdi
lea    0xe4e(%rip),%rsi
mov    $0x8,%edx
call   1030 <strncmp@plt>
mov    $0x0,%r13d
test   %rax,%rax
jne    121d <main+0x7d>
mov    0x2dc6(%rip),%rax
mov    (%rax),%r13d
mov    (%r14,%r15,8),%rdi
lea    0xe2d(%rip),%rsi
mov    $0x8,%edx
call   1030 <strncmp@plt>
mov    $0x0,%r12d
test   %rax,%rax
jne    1247 <main+0xa7>
mov    0x2d6c(%rip),%rax
mov    (%rax),%r12d
or     %r13d,%ebx
mov    (%r14,%r15,8),%rdi
lea    0xe09(%rip),%rsi
mov    $0xa,%edx
call   1030 <strncmp@plt>
mov    $0x0,%ecx
test   %rax,%rax
jne    11e0 <main+0x40>
mov    0x2d74(%rip),%rax
mov    (%rax),%ecx
jmp    11e0 <main+0x40>
mov    0x2d26(%rip),%rax
mov    (%rax),%esi
lea    0xdde(%rip),%rdi
call   10a0 <access@plt>
cmp    $0xffffffff,%eax
jne    12aa <main+0x10a>
lea    0xdcd(%rip),%rdi
mov    $0x1ff,%esi
call   1080 <mkfifo@plt>
test   %eax,%eax
jne    1325 <main+0x185>
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xdd8(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xda1(%rip),%rdi
mov    %ebx,%esi
call   1090 <open@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xdca(%rip),%rdi
mov    %eax,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x5,%edi
call   10c0 <sleep@plt>
cmp    $0xffffffff,%ebx
je     1300 <main+0x160>
mov    %ebx,%edi
call   1060 <close@plt>
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xdb1(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2ca2(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    0x2ca4(%rip),%rax
mov    (%rax),%edi
lea    0xd41(%rip),%rsi
lea    0xd2d(%rip),%rdx
call   1070 <fprintf@plt>
mov    0x2c80(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [76 x i8] c"Usage: %s <some combination of O_RDONLY O_WRONLY O_NONBLOCK>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [9 x i8] c"O_RDONLY\00"
@O_RDONLY = global i32 0
@.str.2 = [9 x i8] c"O_WRONLY\00"
@O_WRONLY = global i32 0
@.str.3 = [11 x i8] c"O_NONBLOCK\00"
@O_NONBLOCK = global i32 0
@.str.4 = [13 x i8] c"/tmp/my_fifo\00"
@F_OK = global i32 0
@.str.5 = [26 x i8] c"Could not create fifo %s\0A\00"
@.str.6 = [25 x i8] c"Process %d opening FIFO\0A\00"
@.str.7 = [22 x i8] c"Process %d result %d\0A\00"
@.str.8 = [21 x i8] c"Process %d finished\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %18
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8**, i8*** %5
%14 = load i8*, i8** %13
%15 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = load i32, i32* @EXIT_FAILURE
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %2
store i32 1, i32* %8
br label %19
19: ; preds = %52, %18
%20 = load i32, i32* %8
%21 = load i32, i32* %4
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %55
23: ; preds = %19
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i32 1
store i8** %25, i8*** %5
%26 = load i8*, i8** %25
%27 = call i64 @strncmp(i8* %26, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 8)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %33
29: ; preds = %23
%30 = load i32, i32* @O_RDONLY
%31 = load i32, i32* %7
%32 = or i32 %31, %30
store i32 %32, i32* %7
br label %33
33: ; preds = %29, %23
%34 = load i8**, i8*** %5
%35 = load i8*, i8** %34
%36 = call i64 @strncmp(i8* %35, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 8)
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %42
38: ; preds = %33
%39 = load i32, i32* @O_WRONLY
%40 = load i32, i32* %7
%41 = or i32 %40, %39
store i32 %41, i32* %7
br label %42
42: ; preds = %38, %33
%43 = load i8**, i8*** %5
%44 = load i8*, i8** %43
%45 = call i64 @strncmp(i8* %44, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 10)
%46 = icmp eq i64 %45, 0
br i1 %46, label %47, label %51
47: ; preds = %42
%48 = load i32, i32* @O_NONBLOCK
%49 = load i32, i32* %7
%50 = or i32 %49, %48
store i32 %50, i32* %7
br label %51
51: ; preds = %47, %42
br label %52
52: ; preds = %51
%53 = load i32, i32* %8
%54 = add nsw i32 %53, 1
store i32 %54, i32* %8
br label %19
55: ; preds = %19
%56 = load i32, i32* @F_OK
%57 = call i32 @access(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i32 %56)
%58 = icmp eq i32 %57, -1
br i1 %58, label %59, label %69
59: ; preds = %55
%60 = call i32 @mkfifo(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i32 511)
store i32 %60, i32* %6
%61 = load i32, i32* %6
%62 = icmp ne i32 %61, 0
br i1 %62, label %63, label %68
63: ; preds = %59
%64 = load i32, i32* @stderr
%65 = call i32 @fprintf(i32 %64, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%66 = load i32, i32* @EXIT_FAILURE
%67 = call i32 @exit(i32 %66)
unreachable
68: ; preds = %59
br label %69
69: ; preds = %68, %55
%70 = call i32 (...) @getpid()
%71 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i32 %70)
%72 = load i32, i32* %7
%73 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i32 %72)
store i32 %73, i32* %6
%74 = call i32 (...) @getpid()
%75 = load i32, i32* %6
%76 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), i32 %74, i32 %75)
%77 = call i32 @sleep(i32 5)
%78 = load i32, i32* %6
%79 = icmp ne i32 %78, -1
br i1 %79, label %80, label %83
80: ; preds = %69
%81 = load i32, i32* %6
%82 = call i32 @close(i32 %81)
br label %83
83: ; preds = %80, %69
%84 = call i32 (...) @getpid()
%85 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0), i32 %84)
%86 = load i32, i32* @EXIT_SUCCESS
%87 = call i32 @exit(i32 %86)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [76 x i8] c"Usage: %s <some combination of O_RDONLY O_WRONLY O_NONBLOCK>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [9 x i8] c"O_RDONLY\00"
@O_RDONLY = global i32 0
@.str.2 = [9 x i8] c"O_WRONLY\00"
@O_WRONLY = global i32 0
@.str.3 = [11 x i8] c"O_NONBLOCK\00"
@O_NONBLOCK = global i32 0
@.str.4 = [13 x i8] c"/tmp/my_fifo\00"
@F_OK = global i32 0
@.str.5 = [26 x i8] c"Could not create fifo %s\0A\00"
@.str.6 = [25 x i8] c"Process %d opening FIFO\0A\00"
@.str.7 = [22 x i8] c"Process %d result %d\0A\00"
@.str.8 = [21 x i8] c"Process %d finished\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %10
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %2, %10
%11 = phi i32 [ %33, %10 ], [ 1, %2 ]
%12 = phi i32 [ %32, %10 ], [ 0, %2 ]
%13 = phi i8** [ %14, %10 ], [ %1, %2 ]
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = tail call i64 @strncmp(i8* %15, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 8)
%17 = icmp eq i64 %16, 0
%18 = load i32, i32* @O_RDONLY
%19 = select i1 %17, i32 %18, i32 0
%20 = or i32 %19, %12
%21 = load i8*, i8** %14
%22 = tail call i64 @strncmp(i8* %21, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 8)
%23 = icmp eq i64 %22, 0
%24 = load i32, i32* @O_WRONLY
%25 = select i1 %23, i32 %24, i32 0
%26 = or i32 %20, %25
%27 = load i8*, i8** %14
%28 = tail call i64 @strncmp(i8* %27, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 10)
%29 = icmp eq i64 %28, 0
%30 = load i32, i32* @O_NONBLOCK
%31 = select i1 %29, i32 %30, i32 0
%32 = or i32 %26, %31
%33 = add nuw nsw i32 %11, 1
%34 = icmp eq i32 %33, %0
br i1 %34, label %35, label %10
35: ; preds = %10
%36 = load i32, i32* @F_OK
%37 = tail call i32 @access(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i32 %36)
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %47
39: ; preds = %35
%40 = tail call i32 @mkfifo(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i32 511)
%41 = icmp eq i32 %40, 0
br i1 %41, label %47, label %42
42: ; preds = %39
%43 = load i32, i32* @stderr
%44 = tail call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%45 = load i32, i32* @EXIT_FAILURE
%46 = tail call i32 @exit(i32 %45)
unreachable
47: ; preds = %39, %35
%48 = tail call i32 (...) @getpid()
%49 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i32 %48)
%50 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i32 %32)
%51 = tail call i32 (...) @getpid()
%52 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), i32 %51, i32 %50)
%53 = tail call i32 @sleep(i32 5)
%54 = icmp eq i32 %50, -1
br i1 %54, label %57, label %55
55: ; preds = %47
%56 = tail call i32 @close(i32 %50)
br label %57
57: ; preds = %55, %47
%58 = tail call i32 (...) @getpid()
%59 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0), i32 %58)
%60 = load i32, i32* @EXIT_SUCCESS
%61 = tail call i32 @exit(i32 %60)
unreachable
}