#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 */
struct stat {
  int /*<<< orphan*/ st_mode;
};
typedef void FILE;

/* Variables and functions */
int /*<<< orphan*/ FS_Remove(char const *);
int /*<<< orphan*/ F_SETFL;
int /*<<< orphan*/ O_NONBLOCK;
scalar_t__ S_ISFIFO(int /*<<< orphan*/);
int /*<<< orphan*/ fcntl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int fileno(void *);
void *fopen(char const *, char *);
int mkfifo(char const *, int);
int /*<<< orphan*/ stat(char const *, struct stat *);
FILE *Sys_Mkfifo(const char *ospath) {
  FILE *fifo;
  int result;
  int fn;
  struct stat buf;
  if (!stat(ospath, &buf) && S_ISFIFO(buf.st_mode))
    FS_Remove(ospath);
  result = mkfifo(ospath, 0600);
  if (result != 0)
    return ((void *)0);
  fifo = fopen(ospath, "w+");
  if (fifo) {
    fn = fileno(fifo);
    fcntl(fn, F_SETFL, O_NONBLOCK);
  }
  return fifo;
}


x86 assembly (clang, -O0):
<Sys_Mkfifo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1070 <stat@plt>
cmp    $0x0,%eax
jne    11ad <Sys_Mkfifo+0x3d>
mov    -0x28(%rbp),%edi
call   1040 <S_ISFIFO@plt>
cmp    $0x0,%rax
je     11ad <Sys_Mkfifo+0x3d>
mov    -0x10(%rbp),%rdi
call   1050 <FS_Remove@plt>
mov    -0x10(%rbp),%rdi
mov    $0x180,%esi
call   1060 <mkfifo@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     11d5 <Sys_Mkfifo+0x65>
movq   $0x0,-0x8(%rbp)
jmp    1222 <Sys_Mkfifo+0xb2>
mov    -0x10(%rbp),%rdi
lea    0xe20(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     121a <Sys_Mkfifo+0xaa>
mov    -0x18(%rbp),%rdi
call   1080 <fileno@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%edi
mov    0x2dce(%rip),%rax
mov    (%rax),%esi
mov    0x2dd5(%rip),%rax
mov    (%rax),%edx
call   1030 <fcntl@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Sys_Mkfifo>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
call   1070 <stat@plt>
test   %eax,%eax
jne    119c <Sys_Mkfifo+0x2c>
mov    0x8(%rsp),%edi
call   1040 <S_ISFIFO@plt>
test   %rax,%rax
je     119c <Sys_Mkfifo+0x2c>
mov    %rbx,%rdi
call   1050 <FS_Remove@plt>
mov    %rbx,%rdi
mov    $0x180,%esi
call   1060 <mkfifo@plt>
test   %eax,%eax
je     11b1 <Sys_Mkfifo+0x41>
xor    %ebx,%ebx
jmp    11e9 <Sys_Mkfifo+0x79>
lea    0xe48(%rip),%rsi
mov    %rbx,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     11ad <Sys_Mkfifo+0x3d>
mov    %rax,%rbx
mov    %rax,%rdi
call   1080 <fileno@plt>
mov    0x2e01(%rip),%rcx
mov    (%rcx),%esi
mov    0x2e08(%rip),%rcx
mov    (%rcx),%edx
mov    %eax,%edi
call   1030 <fcntl@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [3 x i8] c"w+\00"
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
define i8* @Sys_Mkfifo(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.stat
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = call i32 @stat(i8* %8, %struct.stat* %7)
%10 = icmp ne i32 %9, 0
br i1 %10, label %19, label %11
11: ; preds = %1
%12 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%13 = load i32, i32* %12
%14 = call i64 @S_ISFIFO(i32 %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = load i8*, i8** %3
%18 = call i32 @FS_Remove(i8* %17)
br label %19
19: ; preds = %16, %11, %1
%20 = load i8*, i8** %3
%21 = call i32 @mkfifo(i8* %20, i32 384)
store i32 %21, i32* %5
%22 = load i32, i32* %5
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %19
store i8* null, i8** %2
br label %39
25: ; preds = %19
%26 = load i8*, i8** %3
%27 = call i8* @fopen(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* %27, i8** %4
%28 = load i8*, i8** %4
%29 = icmp ne i8* %28, null
br i1 %29, label %30, label %37
30: ; preds = %25
%31 = load i8*, i8** %4
%32 = call i32 @fileno(i8* %31)
store i32 %32, i32* %6
%33 = load i32, i32* %6
%34 = load i32, i32* @F_SETFL
%35 = load i32, i32* @O_NONBLOCK
%36 = call i32 @fcntl(i32 %33, i32 %34, i32 %35)
br label %37
37: ; preds = %30, %25
%38 = load i8*, i8** %4
store i8* %38, i8** %2
br label %39
39: ; preds = %37, %24
%40 = load i8*, i8** %2
ret i8* %40
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [3 x i8] c"w+\00"
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
define noalias i8* @Sys_Mkfifo(i8* %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = call i32 @stat(i8* %0, %struct.stat* %2)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %13
6: ; preds = %1
%7 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%8 = load i32, i32* %7
%9 = tail call i64 @S_ISFIFO(i32 %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %6
%12 = tail call i32 @FS_Remove(i8* %0)
br label %13
13: ; preds = %11, %6, %1
%14 = tail call i32 @mkfifo(i8* %0, i32 384)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %24
16: ; preds = %13
%17 = tail call i8* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%18 = icmp eq i8* %17, null
br i1 %18, label %24, label %19
19: ; preds = %16
%20 = tail call i32 @fileno(i8* %17)
%21 = load i32, i32* @F_SETFL
%22 = load i32, i32* @O_NONBLOCK
%23 = tail call i32 @fcntl(i32 %20, i32 %21, i32 %22)
br label %24
24: ; preds = %16, %19, %13
%25 = phi i8* [ null, %13 ], [ %17, %19 ], [ null, %16 ]
ret i8* %25
}