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

/* Variables and functions */
int /*<<< orphan*/ *getcwd(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ setenv(char *, char *, int);
int update_pwd() {
  char path_buf[8192] = {0};
  if (getcwd(path_buf, sizeof(path_buf)) == NULL) {
    perror("ish: update_cwd()");
    return -1;
  }
  setenv("PWD", path_buf, 1);
  return 0;
}


x86 assembly (clang, -O0):
<update_pwd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2010,%rsp
lea    -0x2010(%rbp),%rdi
xor    %esi,%esi
mov    $0x2000,%edx
call   1040 <memset@plt>
lea    -0x2010(%rbp),%rdi
mov    $0x2000,%esi
call   1050 <getcwd@plt>
cmp    $0x0,%rax
jne    1191 <update_pwd+0x51>
lea    0xe80(%rip),%rdi
call   1060 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b0 <update_pwd+0x70>
lea    -0x2010(%rbp),%rsi
lea    0xe73(%rip),%rdi
mov    $0x1,%edx
call   1030 <setenv@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2010,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<update_pwd>:
push   %rbp
push   %rbx
sub    $0x2008,%rsp
mov    %rsp,%rbx
xor    %ebp,%ebp
mov    $0x2000,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
mov    %rbx,%rdi
mov    $0x2000,%esi
call   1050 <getcwd@plt>
test   %rax,%rax
je     118f <update_pwd+0x4f>
lea    0xe9c(%rip),%rdi
mov    %rsp,%rsi
mov    $0x1,%edx
call   1030 <setenv@plt>
mov    %ebp,%eax
add    $0x2008,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe6a(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%ebp
jmp    1183 <update_pwd+0x43>

LLVM IR (-O0):
@.str = [18 x i8] c"ish: update_cwd()\00"
@.str.1 = [4 x i8] c"PWD\00"
define i32 @update_pwd() {
%1 = alloca i32
%2 = alloca [8192 x i8]
%3 = bitcast [8192 x i8]* %2 to i8*
%4 = getelementptr inbounds [8192 x i8], [8192 x i8]* %2, i64 0, i64 0
%5 = call i32* @getcwd(i8* %4, i32 8192)
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %1
br label %12
9: ; preds = %0
%10 = getelementptr inbounds [8192 x i8], [8192 x i8]* %2, i64 0, i64 0
%11 = call i32 @setenv(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %10, i32 1)
store i32 0, i32* %1
br label %12
12: ; preds = %9, %7
%13 = load i32, i32* %1
ret i32 %13
}

LLVM IR (-O2):
@.str = [18 x i8] c"ish: update_cwd()\00"
@.str.1 = [4 x i8] c"PWD\00"
define i32 @update_pwd() {
%1 = alloca [8192 x i8]
%2 = getelementptr inbounds [8192 x i8], [8192 x i8]* %1, i64 0, i64 0
%3 = call i32* @getcwd(i8* %2, i32 8192)
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %9
7: ; preds = %0
%8 = call i32 @setenv(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %2, i32 1)
br label %9
9: ; preds = %7, %5
%10 = phi i32 [ -1, %5 ], [ 0, %7 ]
ret i32 %10
}