#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 */
int _cd_chdir(int *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
char *getenv(char *);
int /*<<< orphan*/ stderr;
int _cd_previous(void) {
  char *oldpwd;
  int prefs = 0;
  int ret;
  if ((oldpwd = getenv("OLDPWD")) == NULL) {
    fputs("sh: cd: $OLDPWD is not set\n", stderr);
    return 125;
  }
  if ((ret = _cd_chdir(&prefs, oldpwd)) == 0)
    fprintf(stderr, "%s%s", oldpwd, "\n");
  return ret;
}


x86 assembly (clang, -O0):
<_cd_previous>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x14(%rbp)
lea    0xeaa(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    118a <_cd_previous+0x4a>
mov    0x2e70(%rip),%rax
mov    (%rax),%esi
lea    0xe8e(%rip),%rdi
call   1040 <fputs@plt>
movl   $0x7d,-0x4(%rbp)
jmp    11c9 <_cd_previous+0x89>
mov    -0x10(%rbp),%rsi
lea    -0x14(%rbp),%rdi
call   1050 <_cd_chdir@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jne    11c3 <_cd_previous+0x83>
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe6c(%rip),%rsi
lea    0xe63(%rip),%rcx
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_cd_previous>:
push   %rbx
sub    $0x10,%rsp
movl   $0x0,0xc(%rsp)
lea    0xeac(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1195 <_cd_previous+0x55>
mov    %rax,%rbx
lea    0xc(%rsp),%rdi
mov    %rax,%rsi
call   1050 <_cd_chdir@plt>
test   %eax,%eax
jne    11af <_cd_previous+0x6f>
mov    0x2e67(%rip),%rax
mov    (%rax),%edi
lea    0xea1(%rip),%rsi
lea    0xe98(%rip),%rcx
mov    %rbx,%rdx
call   1060 <fprintf@plt>
xor    %eax,%eax
jmp    11af <_cd_previous+0x6f>
mov    0x2e44(%rip),%rax
mov    (%rax),%esi
lea    0xe62(%rip),%rdi
call   1040 <fputs@plt>
mov    $0x7d,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [7 x i8] c"OLDPWD\00"
@.str.1 = [28 x i8] c"sh: cd: $OLDPWD is not set\0A\00"
@stderr = global i32 0
@.str.2 = [5 x i8] c"%s%s\00"
@.str.3 = [2 x i8] c"\0A\00"
define i32 @_cd_previous() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %3
%5 = call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i8* %5, i8** %2
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = load i32, i32* @stderr
%9 = call i32 @fputs(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %8)
store i32 125, i32* %1
br label %20
10: ; preds = %0
%11 = load i8*, i8** %2
%12 = call i32 @_cd_chdir(i32* %3, i8* %11)
store i32 %12, i32* %4
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %10
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %2
%17 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %18
18: ; preds = %14, %10
%19 = load i32, i32* %4
store i32 %19, i32* %1
br label %20
20: ; preds = %18, %7
%21 = load i32, i32* %1
ret i32 %21
}

LLVM IR (-O2):
@.str = [7 x i8] c"OLDPWD\00"
@.str.1 = [28 x i8] c"sh: cd: $OLDPWD is not set\0A\00"
@stderr = global i32 0
@.str.2 = [5 x i8] c"%s%s\00"
@.str.3 = [2 x i8] c"\0A\00"
define i32 @_cd_previous() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%3 = tail call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = load i32, i32* @stderr
%7 = tail call i32 @fputs(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %6)
br label %14
8: ; preds = %0
%9 = call i32 @_cd_chdir(i32* %1, i8* %3)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %14
14: ; preds = %8, %11, %5
%15 = phi i32 [ 125, %5 ], [ 0, %11 ], [ %9, %8 ]
ret i32 %15
}