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

/* Variables and functions */
int /*<<< orphan*/ done(int);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ pclose(int /*<<< orphan*/ *);
scalar_t__ *rindex(char *, char);
int /*<<< orphan*/ stderr;
char *pwd() {
  register FILE *pp;
  static char curpath[128];
  register int i;
  FILE *popen();
  if ((pp = popen("pwd", "r")) == NULL ||
      fgets(curpath, sizeof curpath, pp) == NULL || pclose(pp) != 0) {
    fprintf(stderr, "Can't find current directory!\n");
    done(1);
  }
  *rindex(curpath, '\n') = 0;
  return curpath;
}


x86 assembly (clang, -O0):
<pwd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xe91(%rip),%rdi
lea    0xe8e(%rip),%rsi
mov    $0x0,%al
call   1070 <popen@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
je     11bd <pwd+0x5d>
mov    -0x8(%rbp),%rdx
lea    0x2eca(%rip),%rdi
mov    $0x80,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11bd <pwd+0x5d>
mov    -0x8(%rbp),%rdi
call   1040 <pclose@plt>
cmp    $0x0,%rax
je     11dc <pwd+0x7c>
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
lea    0xe39(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1030 <done@plt>
lea    0x2e7d(%rip),%rdi
mov    $0xa,%esi
call   1080 <rindex@plt>
movq   $0x0,(%rax)
lea    0x2e65(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pwd>:
push   %rbx
lea    0xe98(%rip),%rdi
lea    0xe95(%rip),%rsi
xor    %eax,%eax
call   1070 <popen@plt>
test   %rax,%rax
je     11a4 <pwd+0x44>
mov    %rax,%rbx
lea    0x2edb(%rip),%rdi
mov    $0x80,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11a4 <pwd+0x44>
mov    %rbx,%rdi
call   1040 <pclose@plt>
test   %rax,%rax
je     11c3 <pwd+0x63>
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
lea    0xe52(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1030 <done@plt>
lea    0x2e96(%rip),%rbx
mov    %rbx,%rdi
mov    $0xa,%esi
call   1080 <rindex@plt>
movq   $0x0,(%rax)
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@pwd.curpath = internal global [128 x i8] zeroinitializer
@.str = [4 x i8] c"pwd\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [31 x i8] c"Can't find current directory!\0A\00"
define i8* @pwd() {
%1 = alloca i32*
%2 = alloca i32
%3 = call i32* (i8*, i8*, ...) bitcast (i32* (...)* @popen to i32* (i8*, i8*, ...)*)(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %3, i32** %1
%4 = icmp eq i32* %3, null
br i1 %4, label %13, label %5
5: ; preds = %0
%6 = load i32*, i32** %1
%7 = call i32* @fgets(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @pwd.curpath, i64 0, i64 0), i32 128, i32* %6)
%8 = icmp eq i32* %7, null
br i1 %8, label %13, label %9
9: ; preds = %5
%10 = load i32*, i32** %1
%11 = call i64 @pclose(i32* %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %9, %5, %0
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%16 = call i32 @done(i32 1)
br label %17
17: ; preds = %13, %9
%18 = call i64* @rindex(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @pwd.curpath, i64 0, i64 0), i8 signext 10)
store i64 0, i64* %18
ret i8* getelementptr inbounds ([128 x i8], [128 x i8]* @pwd.curpath, i64 0, i64 0)
}

LLVM IR (-O2):
@pwd.curpath = internal global [128 x i8] zeroinitializer
@.str = [4 x i8] c"pwd\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [31 x i8] c"Can't find current directory!\0A\00"
define i8* @pwd() {
%1 = tail call i32* (i8*, i8*, ...) bitcast (i32* (...)* @popen to i32* (i8*, i8*, ...)*)(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %9, label %3
3: ; preds = %0
%4 = tail call i32* @fgets(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @pwd.curpath, i64 0, i64 0), i32 128, i32* %1)
%5 = icmp eq i32* %4, null
br i1 %5, label %9, label %6
6: ; preds = %3
%7 = tail call i64 @pclose(i32* %1)
%8 = icmp eq i64 %7, 0
br i1 %8, label %13, label %9
9: ; preds = %6, %3, %0
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%12 = tail call i32 @done(i32 1)
br label %13
13: ; preds = %9, %6
%14 = tail call i64* @rindex(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @pwd.curpath, i64 0, i64 0), i8 signext 10)
store i64 0, i64* %14
ret i8* getelementptr inbounds ([128 x i8], [128 x i8]* @pwd.curpath, i64 0, i64 0)
}