#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 AT_FDCWD;
int AT_REMOVEDIR;
int /*<<< orphan*/ EBADF;
int /*<<< orphan*/ EINVAL;
int /*<<< orphan*/ ENOSYS;
int /*<<< orphan*/ __set_errno(int /*<<< orphan*/);
int unlinkat(int fd, const char *name, int flag) {
  if (name == NULL || (flag & AT_REMOVEDIR) != 0) {
    __set_errno(EINVAL);
    return -1;
  }
  if (fd < 0 && fd != AT_FDCWD) {
    __set_errno(EBADF);
    return -1;
  }
  __set_errno(ENOSYS);
  return -1;
}


x86 assembly (clang, -O0):
<unlinkat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1142 <unlinkat+0x32>
mov    -0x14(%rbp),%eax
mov    0x2ea1(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     115c <unlinkat+0x4c>
mov    0x2e87(%rip),%rax
mov    (%rax),%edi
call   1030 <__set_errno@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a7 <unlinkat+0x97>
cmpl   $0x0,-0x8(%rbp)
jge    1192 <unlinkat+0x82>
mov    -0x8(%rbp),%eax
mov    0x2e48(%rip),%rcx
cmp    (%rcx),%eax
je     1192 <unlinkat+0x82>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
call   1030 <__set_errno@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a7 <unlinkat+0x97>
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
call   1030 <__set_errno@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unlinkat>:
push   %rax
mov    0x2eb8(%rip),%rax
test   %rsi,%rsi
je     114a <unlinkat+0x3a>
mov    0x2eb4(%rip),%rcx
test   %edx,(%rcx)
jne    114a <unlinkat+0x3a>
mov    0x2e89(%rip),%rdx
mov    0x2eb2(%rip),%rcx
mov    %rcx,%rax
cmp    %edi,(%rdx)
je     1144 <unlinkat+0x34>
mov    0x2e84(%rip),%rax
test   %edi,%edi
cmovns %rcx,%rax
mov    (%rax),%edi
call   1030 <__set_errno@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret

LLVM IR (-O0):
@AT_REMOVEDIR = global i32 0
@EINVAL = global i32 0
@AT_FDCWD = global i32 0
@EBADF = global i32 0
@ENOSYS = global i32 0
define i32 @unlinkat(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%8 = load i8*, i8** %6
%9 = icmp eq i8* %8, null
br i1 %9, label %15, label %10
10: ; preds = %3
%11 = load i32, i32* %7
%12 = load i32, i32* @AT_REMOVEDIR
%13 = and i32 %11, %12
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %10, %3
%16 = load i32, i32* @EINVAL
%17 = call i32 @__set_errno(i32 %16)
store i32 -1, i32* %4
br label %31
18: ; preds = %10
%19 = load i32, i32* %5
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %28
21: ; preds = %18
%22 = load i32, i32* %5
%23 = load i32, i32* @AT_FDCWD
%24 = icmp ne i32 %22, %23
br i1 %24, label %25, label %28
25: ; preds = %21
%26 = load i32, i32* @EBADF
%27 = call i32 @__set_errno(i32 %26)
store i32 -1, i32* %4
br label %31
28: ; preds = %21, %18
%29 = load i32, i32* @ENOSYS
%30 = call i32 @__set_errno(i32 %29)
store i32 -1, i32* %4
br label %31
31: ; preds = %28, %25, %15
%32 = load i32, i32* %4
ret i32 %32
}

LLVM IR (-O2):
@AT_REMOVEDIR = global i32 0
@EINVAL = global i32 0
@AT_FDCWD = global i32 0
@EBADF = global i32 0
@ENOSYS = global i32 0
define i32 @unlinkat(i32 %0, i8* readnone %1, i32 %2) {
%4 = icmp eq i8* %1, null
br i1 %4, label %15, label %5
5: ; preds = %3
%6 = load i32, i32* @AT_REMOVEDIR
%7 = and i32 %6, %2
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %15
9: ; preds = %5
%10 = icmp sgt i32 %0, -1
%11 = load i32, i32* @AT_FDCWD
%12 = icmp eq i32 %11, %0
%13 = select i1 %10, i1 true, i1 %12
%14 = select i1 %13, i32* @ENOSYS, i32* @EBADF
br label %15
15: ; preds = %9, %3, %5
%16 = phi i32* [ @EINVAL, %5 ], [ @EINVAL, %3 ], [ %14, %9 ]
%17 = load i32, i32* %16
%18 = tail call i32 @__set_errno(i32 %17)
ret i32 -1
}