#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 EEXIST;
int O_NONBLOCK;
int O_RDWR;
int errno;
scalar_t__ mkfifo(char const *, int);
int open(char const *, int, int /*<<< orphan*/);
int /*<<< orphan*/ zclose(int);
int zfifo_listen(const char *path) {
  int fd;
  int errno2;
  fd = -1;
  if ((mkfifo(path, 0666) < 0) && (errno != EEXIST)) {
    goto err;
  }
  if ((fd = open(path, O_RDWR | O_NONBLOCK, 0)) < 0) {
    goto err;
  }
  return (fd);
err:
  errno2 = errno;
  if (fd != -1) {
    zclose(fd);
  }
  errno = errno2;
  return -1;
}


x86 assembly (clang, -O0):
<zfifo_listen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x1b6,%esi
call   1040 <mkfifo@plt>
cmp    $0x0,%rax
jge    1178 <zfifo_listen+0x48>
mov    0x2e66(%rip),%rax
mov    (%rax),%eax
mov    0x2e65(%rip),%rcx
cmp    (%rcx),%eax
je     1178 <zfifo_listen+0x48>
jmp    11b1 <zfifo_listen+0x81>
mov    -0x10(%rbp),%rdi
mov    0x2e65(%rip),%rax
mov    (%rax),%esi
mov    0x2e54(%rip),%rax
or     (%rax),%esi
xor    %edx,%edx
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    11a6 <zfifo_listen+0x76>
jmp    11b1 <zfifo_listen+0x81>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11e2 <zfifo_listen+0xb2>
mov    0x2e10(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
je     11cf <zfifo_listen+0x9f>
mov    -0x14(%rbp),%edi
call   1030 <zclose@plt>
mov    -0x18(%rbp),%ecx
mov    0x2def(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<zfifo_listen>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    $0x1b6,%esi
call   1040 <mkfifo@plt>
test   %rax,%rax
jns    1159 <zfifo_listen+0x29>
mov    0x2e7c(%rip),%rax
mov    (%rax),%ebp
mov    0x2e7b(%rip),%rax
cmp    (%rax),%ebp
jne    118e <zfifo_listen+0x5e>
mov    0x2e88(%rip),%rax
mov    0x2e79(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %rbx,%rdi
xor    %edx,%edx
call   1050 <open@plt>
test   %eax,%eax
jns    119c <zfifo_listen+0x6c>
mov    0x2e48(%rip),%rcx
mov    (%rcx),%ebp
cmp    $0xffffffff,%eax
je     118e <zfifo_listen+0x5e>
mov    %eax,%edi
call   1030 <zclose@plt>
mov    0x2e33(%rip),%rax
mov    %ebp,(%rax)
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i32 0
@EEXIST = global i32 0
@O_RDWR = global i32 0
@O_NONBLOCK = global i32 0
define i32 @zfifo_listen(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
store i32 -1, i32* %4
%6 = load i8*, i8** %3
%7 = call i64 @mkfifo(i8* %6, i32 438)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %14
9: ; preds = %1
%10 = load i32, i32* @errno
%11 = load i32, i32* @EEXIST
%12 = icmp ne i32 %10, %11
br i1 %12, label %13, label %14
13: ; preds = %9
br label %24
14: ; preds = %9, %1
%15 = load i8*, i8** %3
%16 = load i32, i32* @O_RDWR
%17 = load i32, i32* @O_NONBLOCK
%18 = or i32 %16, %17
%19 = call i32 @open(i8* %15, i32 %18, i32 0)
store i32 %19, i32* %4
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %14
br label %24
22: ; preds = %14
%23 = load i32, i32* %4
store i32 %23, i32* %2
br label %33
24: ; preds = %21, %13
%25 = load i32, i32* @errno
store i32 %25, i32* %5
%26 = load i32, i32* %4
%27 = icmp ne i32 %26, -1
br i1 %27, label %28, label %31
28: ; preds = %24
%29 = load i32, i32* %4
%30 = call i32 @zclose(i32 %29)
br label %31
31: ; preds = %28, %24
%32 = load i32, i32* %5
store i32 %32, i32* @errno
store i32 -1, i32* %2
br label %33
33: ; preds = %31, %22
%34 = load i32, i32* %2
ret i32 %34
}

LLVM IR (-O2):
@errno = global i32 0
@EEXIST = global i32 0
@O_RDWR = global i32 0
@O_NONBLOCK = global i32 0
define i32 @zfifo_listen(i8* %0) {
%2 = tail call i64 @mkfifo(i8* %0, i32 438)
%3 = icmp slt i64 %2, 0
br i1 %3, label %4, label %8
4: ; preds = %1
%5 = load i32, i32* @errno
%6 = load i32, i32* @EEXIST
%7 = icmp eq i32 %5, %6
br i1 %7, label %8, label %19
8: ; preds = %4, %1
%9 = load i32, i32* @O_RDWR
%10 = load i32, i32* @O_NONBLOCK
%11 = or i32 %10, %9
%12 = tail call i32 @open(i8* %0, i32 %11, i32 0)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %21
14: ; preds = %8
%15 = load i32, i32* @errno
%16 = icmp eq i32 %12, -1
br i1 %16, label %19, label %17
17: ; preds = %14
%18 = tail call i32 @zclose(i32 %12)
br label %19
19: ; preds = %4, %17, %14
%20 = phi i32 [ %15, %17 ], [ %15, %14 ], [ %5, %4 ]
store i32 %20, i32* @errno
br label %21
21: ; preds = %8, %19
%22 = phi i32 [ -1, %19 ], [ %12, %8 ]
ret i32 %22
}