#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 */
scalar_t__ chdir(char const *);
scalar_t__ errno;
int /*<<< orphan*/ path_error(char *, char const *, int /*<<< orphan*/);
int /*<<< orphan*/ strerror(scalar_t__);
int set_working_dir(const char *new_dir) {
  if (new_dir == NULL) {
    return 1;
  } else if (chdir(new_dir)) {
    path_error("Setting the current working directory to `%s' failed: %s",
               new_dir, strerror(errno));
    errno = 0;
    return 1;
  } else {
    return 0;
  }
}


x86 assembly (clang, -O0):
<set_working_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1153 <set_working_dir+0x23>
movl   $0x1,-0x4(%rbp)
jmp    11b0 <set_working_dir+0x80>
mov    -0x10(%rbp),%rdi
call   1030 <chdir@plt>
cmp    $0x0,%rax
je     11a9 <set_working_dir+0x79>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e6b(%rip),%rax
mov    (%rax),%rdi
call   1050 <strerror@plt>
mov    -0x18(%rbp),%rsi
mov    %eax,%edx
lea    0xe76(%rip),%rdi
call   1040 <path_error@plt>
mov    0x2e4a(%rip),%rax
movq   $0x0,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    11b0 <set_working_dir+0x80>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_working_dir>:
push   %rbp
push   %r14
push   %rbx
mov    $0x1,%ebp
test   %rdi,%rdi
je     1176 <set_working_dir+0x46>
mov    %rdi,%rbx
call   1030 <chdir@plt>
test   %rax,%rax
je     1174 <set_working_dir+0x44>
mov    0x2e8e(%rip),%r14
mov    (%r14),%rdi
call   1050 <strerror@plt>
lea    0xe9f(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <path_error@plt>
movq   $0x0,(%r14)
jmp    1176 <set_working_dir+0x46>
xor    %ebp,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [57 x i8] c"Setting the current working directory to `%s' failed: %s\00"
@errno = global i64 0
define i32 @set_working_dir(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
store i8* %0, i8** %3
%4 = load i8*, i8** %3
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %7
6: ; preds = %1
store i32 1, i32* %2
br label %17
7: ; preds = %1
%8 = load i8*, i8** %3
%9 = call i64 @chdir(i8* %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %7
%12 = load i8*, i8** %3
%13 = load i64, i64* @errno
%14 = call i32 @strerror(i64 %13)
%15 = call i32 @path_error(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i8* %12, i32 %14)
store i64 0, i64* @errno
store i32 1, i32* %2
br label %17
16: ; preds = %7
store i32 0, i32* %2
br label %17
17: ; preds = %16, %11, %6
%18 = load i32, i32* %2
ret i32 %18
}

LLVM IR (-O2):
@.str = [57 x i8] c"Setting the current working directory to `%s' failed: %s\00"
@errno = global i64 0
define i32 @set_working_dir(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %10, label %3
3: ; preds = %1
%4 = tail call i64 @chdir(i8* %0)
%5 = icmp eq i64 %4, 0
br i1 %5, label %10, label %6
6: ; preds = %3
%7 = load i64, i64* @errno
%8 = tail call i32 @strerror(i64 %7)
%9 = tail call i32 @path_error(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %8)
store i64 0, i64* @errno
br label %10
10: ; preds = %3, %1, %6
%11 = phi i32 [ 1, %6 ], [ 1, %1 ], [ 0, %3 ]
ret i32 %11
}