#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 mode_t;
typedef int /*<<< orphan*/ dev_t;

/* Variables and functions */
int /*<<< orphan*/ EINVAL;
int S_IFMT;
scalar_t__ S_ISFIFO(int);
int _MKNOD_VER;
int __mkfifo(char const *, int);
int /*<<< orphan*/ __set_errno(int /*<<< orphan*/);
int __syscall_mknod(char const *, int, int /*<<< orphan*/);
int __xmknod(int vers, const char *path, mode_t mode, dev_t *dev) {
  if (vers != _MKNOD_VER) {
    __set_errno(EINVAL);
    return -1;
  }
  if (S_ISFIFO(mode))
    return __mkfifo(path, mode & ~S_IFMT);
  return __syscall_mknod(path, mode, *dev);
}


x86 assembly (clang, -O0):
<__xmknod>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%eax
mov    0x2e88(%rip),%rcx
cmp    (%rcx),%eax
je     1182 <__xmknod+0x42>
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
call   1030 <__set_errno@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11cb <__xmknod+0x8b>
mov    -0x14(%rbp),%edi
call   1040 <S_ISFIFO@plt>
cmp    $0x0,%rax
je     11b6 <__xmknod+0x76>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    0x2e36(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    %eax,%esi
call   1050 <__mkfifo@plt>
mov    %eax,-0x4(%rbp)
jmp    11cb <__xmknod+0x8b>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rax
mov    (%rax),%edx
call   1060 <__syscall_mknod@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__xmknod>:
push   %r15
push   %r14
push   %rbx
mov    0x2e9c(%rip),%rax
cmp    %edi,(%rax)
jne    117e <__xmknod+0x3e>
mov    %rcx,%r15
mov    %edx,%ebx
mov    %rsi,%r14
mov    %edx,%edi
call   1040 <S_ISFIFO@plt>
test   %rax,%rax
je     1197 <__xmknod+0x57>
mov    0x2e6d(%rip),%rax
mov    (%rax),%esi
not    %esi
and    %ebx,%esi
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1050 <__mkfifo@plt>
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
call   1030 <__set_errno@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    (%r15),%edx
mov    %r14,%rdi
mov    %ebx,%esi
pop    %rbx
pop    %r14
pop    %r15
jmp    1060 <__syscall_mknod@plt>

LLVM IR (-O0):
@_MKNOD_VER = global i32 0
@EINVAL = global i32 0
@S_IFMT = global i32 0
define i32 @__xmknod(i32 %0, i8* %1, i32 %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32*
store i32 %0, i32* %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32* %3, i32** %9
%10 = load i32, i32* %6
%11 = load i32, i32* @_MKNOD_VER
%12 = icmp ne i32 %10, %11
br i1 %12, label %13, label %16
13: ; preds = %4
%14 = load i32, i32* @EINVAL
%15 = call i32 @__set_errno(i32 %14)
store i32 -1, i32* %5
br label %33
16: ; preds = %4
%17 = load i32, i32* %8
%18 = call i64 @S_ISFIFO(i32 %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %27
20: ; preds = %16
%21 = load i8*, i8** %7
%22 = load i32, i32* %8
%23 = load i32, i32* @S_IFMT
%24 = xor i32 %23, -1
%25 = and i32 %22, %24
%26 = call i32 @__mkfifo(i8* %21, i32 %25)
store i32 %26, i32* %5
br label %33
27: ; preds = %16
%28 = load i8*, i8** %7
%29 = load i32, i32* %8
%30 = load i32*, i32** %9
%31 = load i32, i32* %30
%32 = call i32 @__syscall_mknod(i8* %28, i32 %29, i32 %31)
store i32 %32, i32* %5
br label %33
33: ; preds = %27, %20, %13
%34 = load i32, i32* %5
ret i32 %34
}

LLVM IR (-O2):
@_MKNOD_VER = global i32 0
@EINVAL = global i32 0
@S_IFMT = global i32 0
define i32 @__xmknod(i32 %0, i8* %1, i32 %2, i32* nocapture %3) {
%5 = load i32, i32* @_MKNOD_VER
%6 = icmp eq i32 %5, %0
br i1 %6, label %10, label %7
7: ; preds = %4
%8 = load i32, i32* @EINVAL
%9 = tail call i32 @__set_errno(i32 %8)
br label %21
10: ; preds = %4
%11 = tail call i64 @S_ISFIFO(i32 %2)
%12 = icmp eq i64 %11, 0
br i1 %12, label %18, label %13
13: ; preds = %10
%14 = load i32, i32* @S_IFMT
%15 = xor i32 %14, -1
%16 = and i32 %15, %2
%17 = tail call i32 @__mkfifo(i8* %1, i32 %16)
br label %21
18: ; preds = %10
%19 = load i32, i32* %3
%20 = tail call i32 @__syscall_mknod(i8* %1, i32 %2, i32 %19)
br label %21
21: ; preds = %18, %13, %7
%22 = phi i32 [ -1, %7 ], [ %17, %13 ], [ %20, %18 ]
ret i32 %22
}