#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 *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
char *getenv(char *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
void cd(char *dir) {
  if (dir && strcmp(dir, "~")) {
    if (chdir(dir)) {
      fprintf(stderr, "-qshell: cd: %s: No such directory\n", dir);
    }
  } else {
    chdir(getenv("HOME"));
  }
}


x86 assembly (clang, -O0):
<cd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11a2 <cd+0x62>
mov    -0x8(%rbp),%rdi
lea    0xe9e(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     11a2 <cd+0x62>
mov    -0x8(%rbp),%rdi
call   1040 <chdir@plt>
cmp    $0x0,%rax
je     119d <cd+0x5d>
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe6a(%rip),%rsi
call   1060 <fprintf@plt>
jmp    11b6 <cd+0x76>
lea    0xe7d(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rdi
call   1040 <chdir@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cd>:
push   %rbx
test   %rdi,%rdi
je     1180 <cd+0x40>
mov    %rdi,%rbx
lea    0xeb0(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1180 <cd+0x40>
mov    %rbx,%rdi
call   1040 <chdir@plt>
test   %rax,%rax
je     1195 <cd+0x55>
mov    0x2e72(%rip),%rax
mov    (%rax),%edi
lea    0xe8b(%rip),%rsi
mov    %rbx,%rdx
pop    %rbx
jmp    1060 <fprintf@plt>
lea    0xe9f(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rdi
pop    %rbx
jmp    1040 <chdir@plt>
pop    %rbx
ret

LLVM IR (-O0):
@.str = [2 x i8] c"~\00"
@stderr = global i32 0
@.str.1 = [36 x i8] c"-qshell: cd: %s: No such directory\0A\00"
@.str.2 = [5 x i8] c"HOME\00"
define void @cd(i8* %0) {
%2 = alloca i8*
store i8* %0, i8** %2
%3 = load i8*, i8** %2
%4 = icmp ne i8* %3, null
br i1 %4, label %5, label %18
5: ; preds = %1
%6 = load i8*, i8** %2
%7 = call i64 @strcmp(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %18
9: ; preds = %5
%10 = load i8*, i8** %2
%11 = call i64 @chdir(i8* %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %9
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %2
%16 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8* %15)
br label %17
17: ; preds = %13, %9
br label %21
18: ; preds = %5, %1
%19 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%20 = call i64 @chdir(i8* %19)
br label %21
21: ; preds = %18, %17
ret void
}

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