#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 */
struct stat {
  int dummy;
};

/* Variables and functions */
int AT_SYMLINK_NOFOLLOW;
int /*<<< orphan*/ dir_mutex_lock(int);
int /*<<< orphan*/ dir_mutex_unlock();
int lstat(char const *, struct stat *);
int stat(char const *, struct stat *);
int fstatat(int dirfd, const char *pathname, struct stat *buf, int flags) {
  int rc;
  dir_mutex_lock(dirfd);
  if (flags & AT_SYMLINK_NOFOLLOW) {
    rc = lstat(pathname, buf);
  } else {
    rc = stat(pathname, buf);
  }
  dir_mutex_unlock();
  return rc;
}


x86 assembly (clang, -O0):
<fstatat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <dir_mutex_lock@plt>
mov    -0x1c(%rbp),%eax
mov    0x2e78(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1188 <fstatat+0x48>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <lstat@plt>
mov    %eax,-0x20(%rbp)
jmp    1198 <fstatat+0x58>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <stat@plt>
mov    %eax,-0x20(%rbp)
mov    $0x0,%al
call   1060 <dir_mutex_unlock@plt>
mov    -0x20(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fstatat>:
push   %rbp
push   %r14
push   %rbx
mov    %ecx,%ebp
mov    %rdx,%r14
mov    %rsi,%rbx
call   1030 <dir_mutex_lock@plt>
mov    0x2e88(%rip),%rax
test   %ebp,(%rax)
je     1169 <fstatat+0x29>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <lstat@plt>
jmp    1174 <fstatat+0x34>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <stat@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):
%struct.stat = type { i32 }
@AT_SYMLINK_NOFOLLOW = global i32 0
define i32 @fstatat(i32 %0, i8* %1, %struct.stat* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca %struct.stat*
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store %struct.stat* %2, %struct.stat** %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 i8*, i8** %6
%18 = load %struct.stat*, %struct.stat** %7
%19 = call i32 @lstat(i8* %17, %struct.stat* %18)
store i32 %19, i32* %9
br label %24
20: ; preds = %4
%21 = load i8*, i8** %6
%22 = load %struct.stat*, %struct.stat** %7
%23 = call i32 @stat(i8* %21, %struct.stat* %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):
%struct.stat = type { i32 }
@AT_SYMLINK_NOFOLLOW = global i32 0
define i32 @fstatat(i32 %0, i8* nocapture %1, %struct.stat* nocapture %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 %11, label %9
9: ; preds = %4
%10 = tail call i32 @lstat(i8* %1, %struct.stat* %2)
br label %13
11: ; preds = %4
%12 = tail call i32 @stat(i8* %1, %struct.stat* %2)
br label %13
13: ; preds = %11, %9
%14 = phi i32 [ %10, %9 ], [ %12, %11 ]
%15 = tail call i32 (...) @dir_mutex_unlock()
ret i32 %14
}