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

/* Variables and functions */
scalar_t__ __av_get_real(char *);
int real_readlink(const char *path, char *buf, size_t bufsiz, int undersc) {
  if (undersc == 0) {
    static int (*prev)(const char *, char *, size_t);
    if (!prev)
      prev = (int (*)(const char *, char *, size_t))__av_get_real("readlink");
    return prev(path, buf, bufsiz);
  } else {
    static int (*prev)(const char *, char *, size_t);
    if (!prev)
      prev = (int (*)(const char *, char *, size_t))__av_get_real("_readlink");
    return prev(path, buf, bufsiz);
  }
}


x86 assembly (clang, -O0):
<real_readlink>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    116f <real_readlink+0x5f>
cmpq   $0x0,0x2ef7(%rip)
jne    1152 <real_readlink+0x42>
lea    0xebb(%rip),%rdi
call   1030 <__av_get_real@plt>
mov    %rax,0x2ede(%rip)
mov    0x2ed7(%rip),%rax
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   *%rax
mov    %eax,-0x4(%rbp)
jmp    11a8 <real_readlink+0x98>
cmpq   $0x0,0x2ec1(%rip)
jne    1190 <real_readlink+0x80>
lea    0xe7c(%rip),%rdi
call   1030 <__av_get_real@plt>
mov    %rax,0x2ea8(%rip)
mov    0x2ea1(%rip),%rax
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   *%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<real_readlink>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
test   %ecx,%ecx
je     1143 <real_readlink+0x33>
mov    0x2f0f(%rip),%rax
test   %rax,%rax
jne    1162 <real_readlink+0x52>
lea    0xecb(%rip),%rdi
call   1030 <__av_get_real@plt>
mov    %rax,0x2ef7(%rip)
jmp    1162 <real_readlink+0x52>
mov    0x2ee6(%rip),%rax
test   %rax,%rax
jne    1162 <real_readlink+0x52>
lea    0xeab(%rip),%rdi
call   1030 <__av_get_real@plt>
mov    %rax,0x2ece(%rip)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
pop    %rbx
pop    %r14
pop    %r15
jmp    *%rax

LLVM IR (-O0):
@real_readlink.prev = internal global i32 (i8*, i8*, i64)* null
@.str = [9 x i8] c"readlink\00"
@real_readlink.prev.1 = internal global i32 (i8*, i8*, i64)* null
@.str.2 = [10 x i8] c"_readlink\00"
define i32 @real_readlink(i8* %0, i8* %1, i64 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i64 %2, i64* %8
store i32 %3, i32* %9
%10 = load i32, i32* %9
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %24
12: ; preds = %4
%13 = load i32 (i8*, i8*, i64)*, i32 (i8*, i8*, i64)** @real_readlink.prev
%14 = icmp ne i32 (i8*, i8*, i64)* %13, null
br i1 %14, label %18, label %15
15: ; preds = %12
%16 = call i64 @__av_get_real(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%17 = inttoptr i64 %16 to i32 (i8*, i8*, i64)*
store i32 (i8*, i8*, i64)* %17, i32 (i8*, i8*, i64)** @real_readlink.prev
br label %18
18: ; preds = %15, %12
%19 = load i32 (i8*, i8*, i64)*, i32 (i8*, i8*, i64)** @real_readlink.prev
%20 = load i8*, i8** %6
%21 = load i8*, i8** %7
%22 = load i64, i64* %8
%23 = call i32 %19(i8* %20, i8* %21, i64 %22)
store i32 %23, i32* %5
br label %36
24: ; preds = %4
%25 = load i32 (i8*, i8*, i64)*, i32 (i8*, i8*, i64)** @real_readlink.prev.1
%26 = icmp ne i32 (i8*, i8*, i64)* %25, null
br i1 %26, label %30, label %27
27: ; preds = %24
%28 = call i64 @__av_get_real(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%29 = inttoptr i64 %28 to i32 (i8*, i8*, i64)*
store i32 (i8*, i8*, i64)* %29, i32 (i8*, i8*, i64)** @real_readlink.prev.1
br label %30
30: ; preds = %27, %24
%31 = load i32 (i8*, i8*, i64)*, i32 (i8*, i8*, i64)** @real_readlink.prev.1
%32 = load i8*, i8** %6
%33 = load i8*, i8** %7
%34 = load i64, i64* %8
%35 = call i32 %31(i8* %32, i8* %33, i64 %34)
store i32 %35, i32* %5
br label %36
36: ; preds = %30, %18
%37 = load i32, i32* %5
ret i32 %37
}

LLVM IR (-O2):
@real_readlink.prev = internal unnamed_addr global i32 (i8*, i8*, i64)* null
@.str = [9 x i8] c"readlink\00"
@real_readlink.prev.1 = internal unnamed_addr global i32 (i8*, i8*, i64)* null
@.str.2 = [10 x i8] c"_readlink\00"
define i32 @real_readlink(i8* %0, i8* %1, i64 %2, i32 %3) {
%5 = icmp eq i32 %3, 0
br i1 %5, label %6, label %12
6: ; preds = %4
%7 = load i32 (i8*, i8*, i64)*, i32 (i8*, i8*, i64)** @real_readlink.prev
%8 = icmp eq i32 (i8*, i8*, i64)* %7, null
br i1 %8, label %9, label %18
9: ; preds = %6
%10 = tail call i64 @__av_get_real(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%11 = inttoptr i64 %10 to i32 (i8*, i8*, i64)*
store i32 (i8*, i8*, i64)* %11, i32 (i8*, i8*, i64)** @real_readlink.prev
br label %18
12: ; preds = %4
%13 = load i32 (i8*, i8*, i64)*, i32 (i8*, i8*, i64)** @real_readlink.prev.1
%14 = icmp eq i32 (i8*, i8*, i64)* %13, null
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = tail call i64 @__av_get_real(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%17 = inttoptr i64 %16 to i32 (i8*, i8*, i64)*
store i32 (i8*, i8*, i64)* %17, i32 (i8*, i8*, i64)** @real_readlink.prev.1
br label %18
18: ; preds = %12, %15, %6, %9
%19 = phi i32 (i8*, i8*, i64)* [ %11, %9 ], [ %7, %6 ], [ %17, %15 ], [ %13, %12 ]
%20 = tail call i32 %19(i8* %0, i8* %1, i64 %2)
ret i32 %20
}