#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*/ int8_t;
typedef int int32_t;

/* Variables and functions */
int chdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ *getenv(char *);
int /*<<< orphan*/ perror(char *);
scalar_t__ strcmp(int /*<<< orphan*/ *, char *);
int32_t hush_cd(int8_t **args) {
  if (args == NULL)
    return -1;
  int8_t *dir;
  if (NULL == args[1] || 0 == strcmp(args[1], "\x7E"))
    dir = getenv("HOME");
  else
    dir = args[1];
  int32_t status = chdir(dir);
  if (status == -1)
    perror("cd");
  return status;
}


x86 assembly (clang, -O0):
<hush_cd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1163 <hush_cd+0x23>
movl   $0xffffffff,-0x4(%rbp)
jmp    11de <hush_cd+0x9e>
mov    -0x10(%rbp),%rcx
xor    %eax,%eax
cmp    0x8(%rcx),%rax
je     1195 <hush_cd+0x55>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe7e(%rip),%rsi
call   1050 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    11aa <hush_cd+0x6a>
lea    0xe66(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
jmp    11b6 <hush_cd+0x76>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <chdir@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11d8 <hush_cd+0x98>
lea    0xe34(%rip),%rdi
call   1060 <perror@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hush_cd>:
push   %rbx
mov    $0xffffffff,%eax
test   %rdi,%rdi
je     1187 <hush_cd+0x47>
mov    %rdi,%rbx
mov    0x8(%rdi),%rdi
test   %rdi,%rdi
je     116e <hush_cd+0x2e>
lea    0xea2(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     116e <hush_cd+0x2e>
mov    0x8(%rbx),%rdi
jmp    117d <hush_cd+0x3d>
lea    0xe8d(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rdi
call   1040 <chdir@plt>
cmp    $0xffffffff,%eax
je     1189 <hush_cd+0x49>
pop    %rbx
ret
lea    0xe77(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [2 x i8] c"~\00"
@.str.1 = [5 x i8] c"HOME\00"
@.str.2 = [3 x i8] c"cd\00"
define i32 @hush_cd(i32** %0) {
%2 = alloca i32
%3 = alloca i32**
%4 = alloca i32*
%5 = alloca i32
store i32** %0, i32*** %3
%6 = load i32**, i32*** %3
%7 = icmp eq i32** %6, null
br i1 %7, label %8, label %9
8: ; preds = %1
store i32 -1, i32* %2
br label %35
9: ; preds = %1
%10 = load i32**, i32*** %3
%11 = getelementptr inbounds i32*, i32** %10, i64 1
%12 = load i32*, i32** %11
%13 = icmp eq i32* null, %12
br i1 %13, label %20, label %14
14: ; preds = %9
%15 = load i32**, i32*** %3
%16 = getelementptr inbounds i32*, i32** %15, i64 1
%17 = load i32*, i32** %16
%18 = call i64 @strcmp(i32* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%19 = icmp eq i64 0, %18
br i1 %19, label %20, label %22
20: ; preds = %14, %9
%21 = call i32* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i32* %21, i32** %4
br label %26
22: ; preds = %14
%23 = load i32**, i32*** %3
%24 = getelementptr inbounds i32*, i32** %23, i64 1
%25 = load i32*, i32** %24
store i32* %25, i32** %4
br label %26
26: ; preds = %22, %20
%27 = load i32*, i32** %4
%28 = call i32 @chdir(i32* %27)
store i32 %28, i32* %5
%29 = load i32, i32* %5
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %33
31: ; preds = %26
%32 = call i32 @perror(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %33
33: ; preds = %31, %26
%34 = load i32, i32* %5
store i32 %34, i32* %2
br label %35
35: ; preds = %33, %8
%36 = load i32, i32* %2
ret i32 %36
}

LLVM IR (-O2):
@.str = [2 x i8] c"~\00"
@.str.1 = [5 x i8] c"HOME\00"
@.str.2 = [3 x i8] c"cd\00"
define i32 @hush_cd(i32** %0) {
%2 = icmp eq i32** %0, null
br i1 %2, label %20, label %3
3: ; preds = %1
%4 = getelementptr inbounds i32*, i32** %0, i64 1
%5 = load i32*, i32** %4
%6 = icmp eq i32* %5, null
br i1 %6, label %10, label %7
7: ; preds = %3
%8 = tail call i64 @strcmp(i32* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %7, %3
%11 = tail call i32* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %14
12: ; preds = %7
%13 = load i32*, i32** %4
br label %14
14: ; preds = %12, %10
%15 = phi i32* [ %11, %10 ], [ %13, %12 ]
%16 = tail call i32 @chdir(i32* %15)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = tail call i32 @perror(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %20
20: ; preds = %14, %18, %1
%21 = phi i32 [ -1, %1 ], [ -1, %18 ], [ %16, %14 ]
ret i32 %21
}