#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_SYMLINK_NOFOLLOW;
int /*<<< orphan*/ ENOSYS;
int chmod(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ dir_mutex_lock(int);
int /*<<< orphan*/ dir_mutex_unlock();
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int fchmodat(int dirfd, const char *pathname, mode_t mode, int flags) {
  int rc;
  dir_mutex_lock(dirfd);
  if (flags & AT_SYMLINK_NOFOLLOW) {
    fprintf(stderr, "tup error: fchmodat(AT_SYMLINK_NOFOLLOW) not supported in "
                    "compat library.\n");
    rc = -1;
    errno = ENOSYS;
  } else {
    rc = chmod(pathname, mode);
  }
  dir_mutex_unlock();
  return rc;
}


x86 assembly (clang, -O0):
<fchmodat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <dir_mutex_lock@plt>
mov    -0x18(%rbp),%eax
mov    0x2e61(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     11a5 <fchmodat+0x65>
mov    0x2e5f(%rip),%rax
mov    (%rax),%edi
lea    0xe7e(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x1c(%rbp)
mov    0x2e53(%rip),%rax
mov    (%rax),%ecx
mov    0x2e32(%rip),%rax
mov    %ecx,(%rax)
jmp    11b4 <fchmodat+0x74>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1050 <chmod@plt>
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   1060 <dir_mutex_unlock@plt>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fchmodat>:
push   %rbp
push   %r14
push   %rbx
mov    %ecx,%ebp
mov    %edx,%r14d
mov    %rsi,%rbx
call   1030 <dir_mutex_lock@plt>
mov    0x2e70(%rip),%rax
test   %ebp,(%rax)
je     118a <fchmodat+0x4a>
mov    0x2e75(%rip),%rax
mov    (%rax),%edi
lea    0xe94(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e70(%rip),%rax
mov    (%rax),%eax
mov    0x2e4f(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%ebx
jmp    1197 <fchmodat+0x57>
mov    %rbx,%rdi
mov    %r14d,%esi
call   1050 <chmod@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1060 <dir_mutex_unlock@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@AT_SYMLINK_NOFOLLOW = global i32 0
@stderr = global i32 0
@.str = [75 x i8] c"tup error: fchmodat(AT_SYMLINK_NOFOLLOW) not supported in compat library.\0A\00"
@ENOSYS = global i32 0
@errno = global i32 0
define i32 @fchmodat(i32 %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%10 = load i32, i32* %5
%11 = call i32 @dir_mutex_lock(i32 %10)
%12 = load i32, i32* %8
%13 = load i32, i32* @AT_SYMLINK_NOFOLLOW
%14 = and i32 %12, %13
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %4
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %9
%19 = load i32, i32* @ENOSYS
store i32 %19, i32* @errno
br label %24
20: ; preds = %4
%21 = load i8*, i8** %6
%22 = load i32, i32* %7
%23 = call i32 @chmod(i8* %21, i32 %22)
store i32 %23, i32* %9
br label %24
24: ; preds = %20, %16
%25 = call i32 (...) @dir_mutex_unlock()
%26 = load i32, i32* %9
ret i32 %26
}

LLVM IR (-O2):
@AT_SYMLINK_NOFOLLOW = global i32 0
@stderr = global i32 0
@.str = [75 x i8] c"tup error: fchmodat(AT_SYMLINK_NOFOLLOW) not supported in compat library.\0A\00"
@ENOSYS = global i32 0
@errno = global i32 0
define i32 @fchmodat(i32 %0, i8* nocapture %1, i32 %2, i32 %3) {
%5 = tail call i32 @dir_mutex_lock(i32 %0)
%6 = load i32, i32* @AT_SYMLINK_NOFOLLOW
%7 = and i32 %6, %3
%8 = icmp eq i32 %7, 0
br i1 %8, label %13, label %9
9: ; preds = %4
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* @ENOSYS
store i32 %12, i32* @errno
br label %15
13: ; preds = %4
%14 = tail call i32 @chmod(i8* %1, i32 %2)
br label %15
15: ; preds = %13, %9
%16 = phi i32 [ -1, %9 ], [ %14, %13 ]
%17 = tail call i32 (...) @dir_mutex_unlock()
ret i32 %16
}