#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*/ *);
int /*<<< orphan*/ *popen(char *, char *);
scalar_t__ *rindex(char *, char);
int /*<<< orphan*/ stderr;
char *pwd() {
  register FILE *pp;
  static char curpath[128];
  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
call   1070 <popen@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
je     11bb <pwd+0x5b>
mov    -0x8(%rbp),%rdx
lea    0x2ecc(%rip),%rdi
mov    $0x80,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11bb <pwd+0x5b>
mov    -0x8(%rbp),%rdi
call   1040 <pclose@plt>
cmp    $0x0,%rax
je     11da <pwd+0x7a>
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
lea    0xe3b(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1030 <done@plt>
lea    0x2e7f(%rip),%rdi
mov    $0xa,%esi
call   1080 <rindex@plt>
movq   $0x0,(%rax)
lea    0x2e67(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pwd>:
push   %rbx
lea    0xe98(%rip),%rdi
lea    0xe95(%rip),%rsi
call   1070 <popen@plt>
test   %rax,%rax
je     11a2 <pwd+0x42>
mov    %rax,%rbx
lea    0x2edd(%rip),%rdi
mov    $0x80,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11a2 <pwd+0x42>
mov    %rbx,%rdi
call   1040 <pclose@plt>
test   %rax,%rax
je     11c1 <pwd+0x61>
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
lea    0xe54(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1030 <done@plt>
lea    0x2e98(%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 = call i32* @popen(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* %2, i32** %1
%3 = icmp eq i32* %2, null
br i1 %3, label %12, label %4
4: ; preds = %0
%5 = load i32*, i32** %1
%6 = call i32* @fgets(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @pwd.curpath, i64 0, i64 0), i32 128, i32* %5)
%7 = icmp eq i32* %6, null
br i1 %7, label %12, label %8
8: ; preds = %4
%9 = load i32*, i32** %1
%10 = call i64 @pclose(i32* %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %8, %4, %0
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%15 = call i32 @done(i32 1)
br label %16
16: ; preds = %12, %8
%17 = 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* %17
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* @popen(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)
}