#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*/ F_OK;
int O_WRONLY;
scalar_t__ access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int mkfifo(char *, int);
int open(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strlen(char *);
int umask(int);
int /*<<< orphan*/ write(int, char *, scalar_t__);
int main(int argc, char *argv[]) {
  int fifo_fd = -1;
  int fd = -1;
  int flag = O_WRONLY;
  int default_umask = umask(0);
  printf("default umask = %o\n", default_umask);
  umask(default_umask);
  if (access("/tmp/test_fifo", F_OK) < 0) {
    fifo_fd = mkfifo("/tmp/test_fifo", 0777);
    if (fifo_fd < 0) {
      perror("mkfifo error\n");
      exit(0);
    }
  }
  fd = open("/tmp/test_fifo", flag);
  if (fd < 0) {
    perror("fifo open error\n");
    exit(0);
  }
  printf("write data to fifo = %s\n", "fifo write/read test!");
  write(fd, "fifo write/read test!", strlen("fifo write/read test!") + 1);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
movl   $0xffffffff,-0x18(%rbp)
mov    0x2e0d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
xor    %edi,%edi
call   1080 <umask@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%esi
lea    0xe1c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%edi
call   1080 <umask@plt>
mov    0x2dd6(%rip),%rax
mov    (%rax),%esi
lea    0xe11(%rip),%rdi
call   10a0 <access@plt>
cmp    $0x0,%rax
jge    1248 <main+0xa8>
lea    0xdfb(%rip),%rdi
mov    $0x1ff,%esi
call   1070 <mkfifo@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1243 <main+0xa3>
lea    0xdec(%rip),%rdi
call   10b0 <perror@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
jmp    1248 <main+0xa8>
mov    -0x1c(%rbp),%esi
lea    0xdc2(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1277 <main+0xd7>
lea    0xdc6(%rip),%rdi
call   10b0 <perror@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
lea    0xdc4(%rip),%rdi
lea    0xdd6(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x24(%rbp)
lea    0xdc2(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x24(%rbp),%edi
mov    %rax,%rdx
add    $0x1,%rdx
lea    0xdac(%rip),%rsi
call   1030 <write@plt>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    0x2e3e(%rip),%rax
mov    (%rax),%ebx
xor    %edi,%edi
call   1070 <umask@plt>
mov    %eax,%ebp
lea    0xe54(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%edi
call   1070 <umask@plt>
mov    0x2e0d(%rip),%rax
mov    (%rax),%esi
lea    0xe48(%rip),%rdi
call   1090 <access@plt>
test   %rax,%rax
jns    11eb <main+0x5b>
lea    0xe37(%rip),%rdi
mov    $0x1ff,%esi
call   1060 <mkfifo@plt>
test   %eax,%eax
js     123f <main+0xaf>
lea    0xe22(%rip),%rdi
mov    %ebx,%esi
call   1080 <open@plt>
test   %eax,%eax
js     1236 <main+0xa6>
mov    %eax,%ebx
lea    0xe3c(%rip),%rdi
lea    0xe4e(%rip),%rbp
mov    %rbp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x16,%edx
mov    %ebx,%edi
mov    %rbp,%rsi
call   1030 <write@plt>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xdf4(%rip),%rdi
jmp    1246 <main+0xb6>
lea    0xddd(%rip),%rdi
call   10a0 <perror@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@O_WRONLY = global i32 0
@.str = [20 x i8] c"default umask = %o\0A\00"
@.str.1 = [15 x i8] c"/tmp/test_fifo\00"
@F_OK = global i32 0
@.str.2 = [14 x i8] c"mkfifo error\0A\00"
@.str.3 = [17 x i8] c"fifo open error\0A\00"
@.str.4 = [25 x i8] c"write data to fifo = %s\0A\00"
@.str.5 = [22 x i8] c"fifo write/read test!\00"
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
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -1, i32* %6
store i32 -1, i32* %7
%10 = load i32, i32* @O_WRONLY
store i32 %10, i32* %8
%11 = call i32 @umask(i32 0)
store i32 %11, i32* %9
%12 = load i32, i32* %9
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = load i32, i32* %9
%15 = call i32 @umask(i32 %14)
%16 = load i32, i32* @F_OK
%17 = call i64 @access(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %27
19: ; preds = %2
%20 = call i32 @mkfifo(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 511)
store i32 %20, i32* %6
%21 = load i32, i32* %6
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %19
%24 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%25 = call i32 @exit(i32 0)
unreachable
26: ; preds = %19
br label %27
27: ; preds = %26, %2
%28 = load i32, i32* %8
%29 = call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %28)
store i32 %29, i32* %7
%30 = load i32, i32* %7
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %27
%33 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%34 = call i32 @exit(i32 0)
unreachable
35: ; preds = %27
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
%37 = load i32, i32* %7
%38 = call i64 @strlen(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
%39 = add nsw i64 %38, 1
%40 = call i32 @write(i32 %37, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i64 %39)
%41 = load i32, i32* %7
%42 = call i32 @close(i32 %41)
ret i32 0
}

LLVM IR (-O2):
@O_WRONLY = global i32 0
@.str = [20 x i8] c"default umask = %o\0A\00"
@.str.1 = [15 x i8] c"/tmp/test_fifo\00"
@F_OK = global i32 0
@.str.2 = [14 x i8] c"mkfifo error\0A\00"
@.str.3 = [17 x i8] c"fifo open error\0A\00"
@.str.4 = [25 x i8] c"write data to fifo = %s\0A\00"
@.str.5 = [22 x i8] c"fifo write/read test!\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @O_WRONLY
%4 = tail call i32 @umask(i32 0)
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = tail call i32 @umask(i32 %4)
%7 = load i32, i32* @F_OK
%8 = tail call i64 @access(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %16
10: ; preds = %2
%11 = tail call i32 @mkfifo(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 511)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%15 = tail call i32 @exit(i32 0)
unreachable
16: ; preds = %10, %2
%17 = tail call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %3)
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = tail call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%21 = tail call i32 @exit(i32 0)
unreachable
22: ; preds = %16
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
%24 = tail call i32 @write(i32 %17, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i64 22)
%25 = tail call i32 @close(i32 %17)
ret i32 0
}