#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_chdir(const char *path, int undersc) {
  if (undersc == 0) {
    static int (*prev)(const char *);
    if (!prev)
      prev = (int (*)(const char *))__av_get_real("chdir");
    return prev(path);
  } else {
    static int (*prev)(const char *);
    if (!prev)
      prev = (int (*)(const char *))__av_get_real("_chdir");
    return prev(path);
  }
}


x86 assembly (clang, -O0):
<real_chdir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    115f <real_chdir+0x4f>
cmpq   $0x0,0x2eff(%rip)
jne    114a <real_chdir+0x3a>
lea    0xec3(%rip),%rdi
call   1030 <__av_get_real@plt>
mov    %rax,0x2ee6(%rip)
mov    0x2edf(%rip),%rax
mov    -0x10(%rbp),%rdi
call   *%rax
mov    %eax,-0x4(%rbp)
jmp    1190 <real_chdir+0x80>
cmpq   $0x0,0x2ed1(%rip)
jne    1180 <real_chdir+0x70>
lea    0xe8c(%rip),%rdi
call   1030 <__av_get_real@plt>
mov    %rax,0x2eb8(%rip)
mov    0x2eb1(%rip),%rax
mov    -0x10(%rbp),%rdi
call   *%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<real_chdir>:
push   %rbx
mov    %rdi,%rbx
test   %esi,%esi
je     1139 <real_chdir+0x29>
mov    0x2f19(%rip),%rax
test   %rax,%rax
jne    1158 <real_chdir+0x48>
lea    0xed5(%rip),%rdi
call   1030 <__av_get_real@plt>
mov    %rax,0x2f01(%rip)
jmp    1158 <real_chdir+0x48>
mov    0x2ef0(%rip),%rax
test   %rax,%rax
jne    1158 <real_chdir+0x48>
lea    0xeb5(%rip),%rdi
call   1030 <__av_get_real@plt>
mov    %rax,0x2ed8(%rip)
mov    %rbx,%rdi
pop    %rbx
jmp    *%rax

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

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