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

/* Variables and functions */
int __syscall(int, int, char const *, char *, size_t);
int /*<<< orphan*/ __syscall_ret(int);
ssize_t readlinkat(int fd, const char *restrict path, char *restrict buf,
                   size_t bufsize) {
  char dummy[1];
  if (!bufsize) {
    buf = dummy;
    bufsize = 1;
  }
  int r = __syscall(298, fd, path, buf, bufsize);
  if (buf == dummy && r > 0)
    r = 0;
  return __syscall_ret(r);
}


x86 assembly (clang, -O0):
<readlinkat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1152 <readlinkat+0x32>
lea    -0x21(%rbp),%rax
mov    %rax,-0x18(%rbp)
movq   $0x1,-0x20(%rbp)
mov    -0x4(%rbp),%esi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
mov    $0x12a,%edi
call   1030 <__syscall@plt>
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
lea    -0x21(%rbp),%rcx
cmp    %rcx,%rax
jne    1190 <readlinkat+0x70>
cmpl   $0x0,-0x28(%rbp)
jle    1190 <readlinkat+0x70>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%edi
call   1040 <__syscall_ret@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readlinkat>:
push   %r14
push   %rbx
push   %rax
test   %rcx,%rcx
mov    $0x1,%r8d
cmovne %rcx,%r8
mov    %rdx,%rbx
mov    %rsi,%rdx
mov    %edi,%esi
lea    0x7(%rsp),%r14
cmove  %r14,%rbx
mov    $0x12a,%edi
mov    %rbx,%rcx
call   1030 <__syscall@plt>
xor    %edi,%edi
test   %eax,%eax
cmovle %eax,%edi
cmp    %r14,%rbx
cmovne %eax,%edi
call   1040 <__syscall_ret@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @readlinkat(i32 %0, i8* noalias %1, i8* noalias %2, i64 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca [1 x i8]
%10 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i64 %3, i64* %8
%11 = load i64, i64* %8
%12 = icmp ne i64 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %4
%14 = getelementptr inbounds [1 x i8], [1 x i8]* %9, i64 0, i64 0
store i8* %14, i8** %7
store i64 1, i64* %8
br label %15
15: ; preds = %13, %4
%16 = load i32, i32* %5
%17 = load i8*, i8** %6
%18 = load i8*, i8** %7
%19 = load i64, i64* %8
%20 = call i32 @__syscall(i32 298, i32 %16, i8* %17, i8* %18, i64 %19)
store i32 %20, i32* %10
%21 = load i8*, i8** %7
%22 = getelementptr inbounds [1 x i8], [1 x i8]* %9, i64 0, i64 0
%23 = icmp eq i8* %21, %22
br i1 %23, label %24, label %28
24: ; preds = %15
%25 = load i32, i32* %10
%26 = icmp sgt i32 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %24
store i32 0, i32* %10
br label %28
28: ; preds = %27, %24, %15
%29 = load i32, i32* %10
%30 = call i32 @__syscall_ret(i32 %29)
ret i32 %30
}

LLVM IR (-O2):
define i32 @readlinkat(i32 %0, i8* noalias %1, i8* noalias %2, i64 %3) {
%5 = alloca [1 x i8]
%6 = getelementptr inbounds [1 x i8], [1 x i8]* %5, i64 0, i64 0
%7 = icmp eq i64 %3, 0
%8 = select i1 %7, i64 1, i64 %3
%9 = select i1 %7, i8* %6, i8* %2
%10 = call i32 @__syscall(i32 298, i32 %0, i8* %1, i8* %9, i64 %8)
%11 = icmp eq i8* %9, %6
%12 = icmp sgt i32 %10, 0
%13 = select i1 %11, i1 %12, i1 false
%14 = select i1 %13, i32 0, i32 %10
%15 = call i32 @__syscall_ret(i32 %14)
ret i32 %15
}