#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 chdir(char *);
char *getenv(char *);
int /*<<< orphan*/ printf(char *, char *);
int changeDirectory(char *args[]) {
  if (args[1] == NULL) {
    chdir(getenv("HOME"));
    return 1;
  } else {
    if (chdir(args[1]) == -1) {
      printf(" %s: no such directory\n", args[1]);
      return -1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<changeDirectory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
jne    116b <changeDirectory+0x3b>
lea    0xeae(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rdi
call   1040 <chdir@plt>
movl   $0x1,-0x4(%rbp)
jmp    11ad <changeDirectory+0x7d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <chdir@plt>
cmp    $0xffffffff,%eax
jne    11a1 <changeDirectory+0x71>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe75(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ad <changeDirectory+0x7d>
jmp    11a6 <changeDirectory+0x76>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<changeDirectory>:
push   %rbx
mov    %rdi,%rbx
mov    0x8(%rdi),%rdi
test   %rdi,%rdi
je     114d <changeDirectory+0x1d>
call   1040 <chdir@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
je     1168 <changeDirectory+0x38>
pop    %rbx
ret
lea    0xeac(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rdi
call   1040 <chdir@plt>
mov    $0x1,%eax
pop    %rbx
ret
mov    0x8(%rbx),%rsi
lea    0xe92(%rip),%rdi
call   1050 <printf@plt>
mov    $0xffffffff,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [5 x i8] c"HOME\00"
@.str.1 = [24 x i8] c" %s: no such directory\0A\00"
define i32 @changeDirectory(i8** %0) {
%2 = alloca i32
%3 = alloca i8**
store i8** %0, i8*** %3
%4 = load i8**, i8*** %3
%5 = getelementptr inbounds i8*, i8** %4, i64 1
%6 = load i8*, i8** %5
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @chdir(i8* %9)
store i32 1, i32* %2
br label %24
11: ; preds = %1
%12 = load i8**, i8*** %3
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i32 @chdir(i8* %14)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %22
17: ; preds = %11
%18 = load i8**, i8*** %3
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %20)
store i32 -1, i32* %2
br label %24
22: ; preds = %11
br label %23
23: ; preds = %22
store i32 0, i32* %2
br label %24
24: ; preds = %23, %17, %8
%25 = load i32, i32* %2
ret i32 %25
}

LLVM IR (-O2):
@.str = [5 x i8] c"HOME\00"
@.str.1 = [24 x i8] c" %s: no such directory\0A\00"
define i32 @changeDirectory(i8** nocapture %0) {
%2 = getelementptr inbounds i8*, i8** %0, i64 1
%3 = load i8*, i8** %2
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %8
5: ; preds = %1
%6 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @chdir(i8* %6)
br label %14
8: ; preds = %1
%9 = tail call i32 @chdir(i8* %3)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = load i8*, i8** %2
%13 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %12)
br label %14
14: ; preds = %8, %11, %5
%15 = phi i32 [ 1, %5 ], [ -1, %11 ], [ 0, %8 ]
ret i32 %15
}