#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 st_mode;
};

/* Variables and functions */
int /*<<< orphan*/ AT_SYMLINK_NOFOLLOW;
int S_IFLNK;
int S_IFMT;
int /*<<< orphan*/ check(int /*<<< orphan*/, char *);
int /*<<< orphan*/ fstatat(int, char const *, struct stat *,
                           int /*<<< orphan*/);
int is_link(int dir_fd, const char *path) {
  struct stat sb;
  check(fstatat(dir_fd, path, &sb, AT_SYMLINK_NOFOLLOW), "fstatat");
  return (sb.st_mode & S_IFMT) == S_IFLNK;
}


x86 assembly (clang, -O0):
<is_link>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    0x2e93(%rip),%rax
mov    (%rax),%ecx
lea    -0x18(%rbp),%rdx
call   1040 <fstatat@plt>
mov    %eax,%edi
lea    0xeaf(%rip),%rsi
call   1030 <check@plt>
mov    -0x18(%rbp),%eax
mov    0x2e78(%rip),%rcx
and    (%rcx),%eax
mov    0x2e7f(%rip),%rcx
cmp    (%rcx),%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_link>:
push   %rax
mov    0x2ea8(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rdx
call   1040 <fstatat@plt>
lea    0xec7(%rip),%rsi
mov    %eax,%edi
call   1030 <check@plt>
mov    0x2e91(%rip),%rax
mov    (%rax),%ecx
and    (%rsp),%ecx
mov    0x2e95(%rip),%rdx
xor    %eax,%eax
cmp    (%rdx),%ecx
sete   %al
pop    %rcx
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@AT_SYMLINK_NOFOLLOW = global i32 0
@.str = [8 x i8] c"fstatat\00"
@S_IFMT = global i32 0
@S_IFLNK = global i32 0
define i32 @is_link(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca %struct.stat
store i32 %0, i32* %3
store i8* %1, i8** %4
%6 = load i32, i32* %3
%7 = load i8*, i8** %4
%8 = load i32, i32* @AT_SYMLINK_NOFOLLOW
%9 = call i32 @fstatat(i32 %6, i8* %7, %struct.stat* %5, i32 %8)
%10 = call i32 @check(i32 %9, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%11 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%12 = load i32, i32* %11
%13 = load i32, i32* @S_IFMT
%14 = and i32 %12, %13
%15 = load i32, i32* @S_IFLNK
%16 = icmp eq i32 %14, %15
%17 = zext i1 %16 to i32
ret i32 %17
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@AT_SYMLINK_NOFOLLOW = global i32 0
@.str = [8 x i8] c"fstatat\00"
@S_IFMT = global i32 0
@S_IFLNK = global i32 0
define i32 @is_link(i32 %0, i8* %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = load i32, i32* @AT_SYMLINK_NOFOLLOW
%6 = call i32 @fstatat(i32 %0, i8* %1, %struct.stat* %3, i32 %5)
%7 = call i32 @check(i32 %6, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%8 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%9 = load i32, i32* %8
%10 = load i32, i32* @S_IFMT
%11 = and i32 %10, %9
%12 = load i32, i32* @S_IFLNK
%13 = icmp eq i32 %11, %12
%14 = zext i1 %13 to i32
ret i32 %14
}