#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 ssize_t;

/* Variables and functions */
int AT_FDCWD;
int /*<<< orphan*/ EBADF;
int /*<<< orphan*/ EINVAL;
int /*<<< orphan*/ ENOSYS;
int /*<<< orphan*/ __set_errno(int /*<<< orphan*/);
ssize_t readlinkat(int fd, const char *path, char *buf, size_t len) {
  if (path == NULL) {
    __set_errno(EINVAL);
    return -1;
  }
  if (fd != AT_FDCWD && fd < 0 && *path != '/') {
    __set_errno(EBADF);
    return -1;
  }
  __set_errno(ENOSYS);
  return -1;
}


x86 assembly (clang, -O0):
<readlinkat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    114c <readlinkat+0x3c>
mov    0x2e9f(%rip),%rax
mov    (%rax),%edi
call   1030 <__set_errno@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a7 <readlinkat+0x97>
mov    -0x8(%rbp),%eax
mov    0x2e6a(%rip),%rcx
cmp    (%rcx),%eax
je     1192 <readlinkat+0x82>
cmpl   $0x0,-0x8(%rbp)
jge    1192 <readlinkat+0x82>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     1192 <readlinkat+0x82>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
call   1030 <__set_errno@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a7 <readlinkat+0x97>
mov    0x2e4f(%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):
<readlinkat>:
push   %rax
test   %rsi,%rsi
je     1133 <readlinkat+0x23>
test   %edi,%edi
jns    112a <readlinkat+0x1a>
mov    0x2e9f(%rip),%rax
cmp    %edi,(%rax)
je     112a <readlinkat+0x1a>
cmpb   $0x2f,(%rsi)
jne    113c <readlinkat+0x2c>
mov    0x2eb7(%rip),%rax
jmp    1143 <readlinkat+0x33>
mov    0x2e9e(%rip),%rax
jmp    1143 <readlinkat+0x33>
mov    0x2e8d(%rip),%rax
mov    (%rax),%edi
call   1030 <__set_errno@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret

LLVM IR (-O0):
@EINVAL = global i32 0
@AT_FDCWD = global i32 0
@EBADF = global i32 0
@ENOSYS = global i32 0
define i32 @readlinkat(i32 %0, i8* %1, i8* %2, i64 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
store i32 %0, i32* %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i64 %3, i64* %9
%10 = load i8*, i8** %7
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %15
12: ; preds = %4
%13 = load i32, i32* @EINVAL
%14 = call i32 @__set_errno(i32 %13)
store i32 -1, i32* %5
br label %33
15: ; preds = %4
%16 = load i32, i32* %6
%17 = load i32, i32* @AT_FDCWD
%18 = icmp ne i32 %16, %17
br i1 %18, label %19, label %30
19: ; preds = %15
%20 = load i32, i32* %6
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %30
22: ; preds = %19
%23 = load i8*, i8** %7
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %25, 47
br i1 %26, label %27, label %30
27: ; preds = %22
%28 = load i32, i32* @EBADF
%29 = call i32 @__set_errno(i32 %28)
store i32 -1, i32* %5
br label %33
30: ; preds = %22, %19, %15
%31 = load i32, i32* @ENOSYS
%32 = call i32 @__set_errno(i32 %31)
store i32 -1, i32* %5
br label %33
33: ; preds = %30, %27, %12
%34 = load i32, i32* %5
ret i32 %34
}

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