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

/* Variables and functions */
int AT_FDCWD;
int AT_SYMLINK_NOFOLLOW;
int /*<<< orphan*/ EBADF;
int /*<<< orphan*/ EINVAL;
int /*<<< orphan*/ ENOSYS;
int /*<<< orphan*/ __set_errno(int /*<<< orphan*/);
int fchmodat(int fd, const char *file, mode_t mode, int flag) {
  if (file == NULL || (flag & ~AT_SYMLINK_NOFOLLOW) != 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):
<fchmodat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     114a <fchmodat+0x3a>
mov    -0x18(%rbp),%eax
mov    0x2e8e(%rip),%rcx
mov    (%rcx),%ecx
xor    $0xffffffff,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     1164 <fchmodat+0x54>
mov    0x2e87(%rip),%rax
mov    (%rax),%edi
call   1030 <__set_errno@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11af <fchmodat+0x9f>
cmpl   $0x0,-0x8(%rbp)
jge    119a <fchmodat+0x8a>
mov    -0x8(%rbp),%eax
mov    0x2e40(%rip),%rcx
cmp    (%rcx),%eax
je     119a <fchmodat+0x8a>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
call   1030 <__set_errno@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11af <fchmodat+0x9f>
mov    0x2e47(%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):
<fchmodat>:
push   %rax
mov    0x2ec0(%rip),%rax
test   %rsi,%rsi
je     114e <fchmodat+0x3e>
mov    0x2ea4(%rip),%rdx
mov    (%rdx),%edx
not    %edx
test   %ecx,%edx
jne    114e <fchmodat+0x3e>
mov    0x2e85(%rip),%rdx
mov    0x2eae(%rip),%rcx
mov    %rcx,%rax
cmp    %edi,(%rdx)
je     1148 <fchmodat+0x38>
mov    0x2e88(%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_SYMLINK_NOFOLLOW = global i32 0
@EINVAL = global i32 0
@AT_FDCWD = global i32 0
@EBADF = global i32 0
@ENOSYS = global i32 0
define i32 @fchmodat(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 i8*, i8** %7
%11 = icmp eq i8* %10, null
br i1 %11, label %18, label %12
12: ; preds = %4
%13 = load i32, i32* %9
%14 = load i32, i32* @AT_SYMLINK_NOFOLLOW
%15 = xor i32 %14, -1
%16 = and i32 %13, %15
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %12, %4
%19 = load i32, i32* @EINVAL
%20 = call i32 @__set_errno(i32 %19)
store i32 -1, i32* %5
br label %34
21: ; preds = %12
%22 = load i32, i32* %6
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %31
24: ; preds = %21
%25 = load i32, i32* %6
%26 = load i32, i32* @AT_FDCWD
%27 = icmp ne i32 %25, %26
br i1 %27, label %28, label %31
28: ; preds = %24
%29 = load i32, i32* @EBADF
%30 = call i32 @__set_errno(i32 %29)
store i32 -1, i32* %5
br label %34
31: ; preds = %24, %21
%32 = load i32, i32* @ENOSYS
%33 = call i32 @__set_errno(i32 %32)
store i32 -1, i32* %5
br label %34
34: ; preds = %31, %28, %18
%35 = load i32, i32* %5
ret i32 %35
}

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