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

/* Variables and functions */
int /*<<< orphan*/ dirname(char *);
int /*<<< orphan*/ getcwd(char *, int);
int readlink(char *, char *, int);
const char *Sys_Pwd(void) {
  static char pwd[256];
  if (pwd[0])
    return pwd;
  if (readlink("/proc/self/exe", pwd, sizeof(pwd) - 1) != -1) {
    pwd[sizeof(pwd) - 1] = '\0';
    dirname(pwd);
    return pwd;
  }
  if (!getcwd(pwd, sizeof(pwd))) {
    pwd[0] = '\0';
  }
  return pwd;
}


x86 assembly (clang, -O0):
<Sys_Pwd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
cmpb   $0x0,0x2f11(%rip)
je     1155 <Sys_Pwd+0x25>
lea    0x2f04(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11c5 <Sys_Pwd+0x95>
lea    0xea4(%rip),%rdi
lea    0x2eed(%rip),%rsi
mov    $0xff,%edx
call   1030 <readlink@plt>
cmp    $0xffffffff,%eax
je     1199 <Sys_Pwd+0x69>
movb   $0x0,0x2fd2(%rip)
lea    0x2ecc(%rip),%rdi
call   1040 <dirname@plt>
lea    0x2ec0(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11c5 <Sys_Pwd+0x95>
lea    0x2eb0(%rip),%rdi
mov    $0x100,%esi
call   1050 <getcwd@plt>
cmp    $0x0,%eax
jne    11ba <Sys_Pwd+0x8a>
movb   $0x0,0x2e96(%rip)
lea    0x2e8f(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Sys_Pwd>:
push   %rax
cmpb   $0x0,0x2f18(%rip)
jne    1188 <Sys_Pwd+0x58>
lea    0xebf(%rip),%rdi
lea    0x2f08(%rip),%rsi
mov    $0xff,%edx
call   1030 <readlink@plt>
cmp    $0xffffffff,%eax
je     116c <Sys_Pwd+0x3c>
movb   $0x0,0x2ff1(%rip)
lea    0x2eeb(%rip),%rdi
call   1040 <dirname@plt>
jmp    1188 <Sys_Pwd+0x58>
lea    0x2edd(%rip),%rdi
mov    $0x100,%esi
call   1050 <getcwd@plt>
test   %eax,%eax
jne    1188 <Sys_Pwd+0x58>
movb   $0x0,0x2ec8(%rip)
lea    0x2ec1(%rip),%rax
pop    %rcx
ret

LLVM IR (-O0):
@Sys_Pwd.pwd = internal global [256 x i8] zeroinitializer
@.str = [15 x i8] c"/proc/self/exe\00"
define i8* @Sys_Pwd() {
%1 = alloca i8*
%2 = load i8, i8* getelementptr inbounds ([256 x i8], [256 x i8]* @Sys_Pwd.pwd, i64 0, i64 0)
%3 = icmp ne i8 %2, 0
br i1 %3, label %4, label %5
4: ; preds = %0
store i8* getelementptr inbounds ([256 x i8], [256 x i8]* @Sys_Pwd.pwd, i64 0, i64 0), i8** %1
br label %15
5: ; preds = %0
%6 = call i32 @readlink(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([256 x i8], [256 x i8]* @Sys_Pwd.pwd, i64 0, i64 0), i32 255)
%7 = icmp ne i32 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %5
store i8 0, i8* getelementptr inbounds ([256 x i8], [256 x i8]* @Sys_Pwd.pwd, i64 0, i64 255)
%9 = call i32 @dirname(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @Sys_Pwd.pwd, i64 0, i64 0))
store i8* getelementptr inbounds ([256 x i8], [256 x i8]* @Sys_Pwd.pwd, i64 0, i64 0), i8** %1
br label %15
10: ; preds = %5
%11 = call i32 @getcwd(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @Sys_Pwd.pwd, i64 0, i64 0), i32 256)
%12 = icmp ne i32 %11, 0
br i1 %12, label %14, label %13
13: ; preds = %10
store i8 0, i8* getelementptr inbounds ([256 x i8], [256 x i8]* @Sys_Pwd.pwd, i64 0, i64 0)
br label %14
14: ; preds = %13, %10
store i8* getelementptr inbounds ([256 x i8], [256 x i8]* @Sys_Pwd.pwd, i64 0, i64 0), i8** %1
br label %15
15: ; preds = %14, %8, %4
%16 = load i8*, i8** %1
ret i8* %16
}

LLVM IR (-O2):
@Sys_Pwd.pwd = internal global [256 x i8] zeroinitializer
@.str = [15 x i8] c"/proc/self/exe\00"
define i8* @Sys_Pwd() {
%1 = load i8, i8* getelementptr inbounds ([256 x i8], [256 x i8]* @Sys_Pwd.pwd, i64 0, i64 0)
%2 = icmp eq i8 %1, 0
br i1 %2, label %3, label %12
3: ; preds = %0
%4 = tail call i32 @readlink(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([256 x i8], [256 x i8]* @Sys_Pwd.pwd, i64 0, i64 0), i32 255)
%5 = icmp eq i32 %4, -1
br i1 %5, label %8, label %6
6: ; preds = %3
store i8 0, i8* getelementptr inbounds ([256 x i8], [256 x i8]* @Sys_Pwd.pwd, i64 0, i64 255)
%7 = tail call i32 @dirname(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @Sys_Pwd.pwd, i64 0, i64 0))
br label %12
8: ; preds = %3
%9 = tail call i32 @getcwd(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @Sys_Pwd.pwd, i64 0, i64 0), i32 256)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %8
store i8 0, i8* getelementptr inbounds ([256 x i8], [256 x i8]* @Sys_Pwd.pwd, i64 0, i64 0)
br label %12
12: ; preds = %8, %11, %0, %6
ret i8* getelementptr inbounds ([256 x i8], [256 x i8]* @Sys_Pwd.pwd, i64 0, i64 0)
}