#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 *);
char *real_getcwd(char *buf, size_t size, int undersc) {
  if (undersc == 0) {
    static char *(*prev)(char *, size_t);
    if (!prev)
      prev = (char *(*)(char *, size_t))__av_get_real("getcwd");
    return prev(buf, size);
  } else {
    static char *(*prev)(char *, size_t);
    if (!prev)
      prev = (char *(*)(char *, size_t))__av_get_real("_getcwd");
    return prev(buf, size);
  }
}


x86 assembly (clang, -O0):
<real_getcwd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    1168 <real_getcwd+0x58>
cmpq   $0x0,0x2efb(%rip)
jne    114e <real_getcwd+0x3e>
lea    0xebf(%rip),%rdi
call   1030 <__av_get_real@plt>
mov    %rax,0x2ee2(%rip)
mov    0x2edb(%rip),%rax
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   *%rax
mov    %rax,-0x8(%rbp)
jmp    119e <real_getcwd+0x8e>
cmpq   $0x0,0x2ec8(%rip)
jne    1189 <real_getcwd+0x79>
lea    0xe83(%rip),%rdi
call   1030 <__av_get_real@plt>
mov    %rax,0x2eaf(%rip)
mov    0x2ea8(%rip),%rax
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   *%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<real_getcwd>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
test   %edx,%edx
je     113f <real_getcwd+0x2f>
mov    0x2f13(%rip),%rax
test   %rax,%rax
jne    115e <real_getcwd+0x4e>
lea    0xecf(%rip),%rdi
call   1030 <__av_get_real@plt>
mov    %rax,0x2efb(%rip)
jmp    115e <real_getcwd+0x4e>
mov    0x2eea(%rip),%rax
test   %rax,%rax
jne    115e <real_getcwd+0x4e>
lea    0xeaf(%rip),%rdi
call   1030 <__av_get_real@plt>
mov    %rax,0x2ed2(%rip)
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    *%rax

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

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