#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*/ uid_t;
typedef int /*<<< orphan*/ gid_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 fchownat(int fd, const char *file, uid_t owner, gid_t group, 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):
<fchownat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     114e <fchownat+0x3e>
mov    -0x1c(%rbp),%eax
mov    0x2e8a(%rip),%rcx
mov    (%rcx),%ecx
xor    $0xffffffff,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     1168 <fchownat+0x58>
mov    0x2e83(%rip),%rax
mov    (%rax),%edi
call   1030 <__set_errno@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b3 <fchownat+0xa3>
cmpl   $0x0,-0x8(%rbp)
jge    119e <fchownat+0x8e>
mov    -0x8(%rbp),%eax
mov    0x2e3c(%rip),%rcx
cmp    (%rcx),%eax
je     119e <fchownat+0x8e>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
call   1030 <__set_errno@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b3 <fchownat+0xa3>
mov    0x2e43(%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):
<fchownat>:
push   %rax
mov    0x2ec0(%rip),%rax
test   %rsi,%rsi
je     114f <fchownat+0x3f>
mov    0x2ea4(%rip),%rcx
mov    (%rcx),%ecx
not    %ecx
test   %r8d,%ecx
jne    114f <fchownat+0x3f>
mov    0x2e84(%rip),%rdx
mov    0x2ead(%rip),%rcx
mov    %rcx,%rax
cmp    %edi,(%rdx)
je     1149 <fchownat+0x39>
mov    0x2e87(%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 @fchownat(i32 %0, i8* %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %7
store i8* %1, i8** %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i32 %4, i32* %11
%12 = load i8*, i8** %8
%13 = icmp eq i8* %12, null
br i1 %13, label %20, label %14
14: ; preds = %5
%15 = load i32, i32* %11
%16 = load i32, i32* @AT_SYMLINK_NOFOLLOW
%17 = xor i32 %16, -1
%18 = and i32 %15, %17
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %14, %5
%21 = load i32, i32* @EINVAL
%22 = call i32 @__set_errno(i32 %21)
store i32 -1, i32* %6
br label %36
23: ; preds = %14
%24 = load i32, i32* %7
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %33
26: ; preds = %23
%27 = load i32, i32* %7
%28 = load i32, i32* @AT_FDCWD
%29 = icmp ne i32 %27, %28
br i1 %29, label %30, label %33
30: ; preds = %26
%31 = load i32, i32* @EBADF
%32 = call i32 @__set_errno(i32 %31)
store i32 -1, i32* %6
br label %36
33: ; preds = %26, %23
%34 = load i32, i32* @ENOSYS
%35 = call i32 @__set_errno(i32 %34)
store i32 -1, i32* %6
br label %36
36: ; preds = %33, %30, %20
%37 = load i32, i32* %6
ret i32 %37
}

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