#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 /*<<< orphan*/ chdir(char *);
char *getenv(char *);
void cd(char **args) {
  char *destination;
  if (args[1] == NULL)
    chdir(getenv("HOME"));
  else if (args[1][0] == '~') {
    chdir(getenv("HOME"));
    if (args[1][1] == '/')
      chdir(&args[1][2]);
  } else
    chdir(args[1]);
}


x86 assembly (clang, -O0):
<cd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
cmpq   $0x0,0x8(%rax)
jne    1154 <cd+0x34>
lea    0xebe(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rdi
call   1040 <chdir@plt>
jmp    11b9 <cd+0x99>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
cmp    $0x7e,%eax
jne    11a7 <cd+0x87>
lea    0xe91(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rdi
call   1040 <chdir@plt>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
movsbl 0x1(%rax),%eax
cmp    $0x2f,%eax
jne    11a2 <cd+0x82>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rdi
add    $0x2,%rdi
call   1040 <chdir@plt>
jmp    11b4 <cd+0x94>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <chdir@plt>
jmp    11b9 <cd+0x99>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cd>:
push   %rbx
mov    %rdi,%rbx
mov    0x8(%rdi),%rdi
test   %rdi,%rdi
je     115a <cd+0x3a>
cmpb   $0x7e,(%rdi)
jne    1154 <cd+0x34>
lea    0xec7(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rdi
call   1040 <chdir@plt>
mov    0x8(%rbx),%rdi
cmpb   $0x2f,0x1(%rdi)
jne    116f <cd+0x4f>
add    $0x2,%rdi
pop    %rbx
jmp    1040 <chdir@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 = [5 x i8] c"HOME\00"
define void @cd(i8** %0) {
%2 = alloca i8**
%3 = alloca i8*
store i8** %0, i8*** %2
%4 = load i8**, i8*** %2
%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)
br label %42
11: ; preds = %1
%12 = load i8**, i8*** %2
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = getelementptr inbounds i8, i8* %14, i64 0
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 126
br i1 %18, label %19, label %36
19: ; preds = %11
%20 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%21 = call i32 @chdir(i8* %20)
%22 = load i8**, i8*** %2
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = getelementptr inbounds i8, i8* %24, i64 1
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 47
br i1 %28, label %29, label %35
29: ; preds = %19
%30 = load i8**, i8*** %2
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = getelementptr inbounds i8, i8* %32, i64 2
%34 = call i32 @chdir(i8* %33)
br label %35
35: ; preds = %29, %19
br label %41
36: ; preds = %11
%37 = load i8**, i8*** %2
%38 = getelementptr inbounds i8*, i8** %37, i64 1
%39 = load i8*, i8** %38
%40 = call i32 @chdir(i8* %39)
br label %41
41: ; preds = %36, %35
br label %42
42: ; preds = %41, %8
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"HOME\00"
define void @cd(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 %23
8: ; preds = %1
%9 = load i8, i8* %3
%10 = icmp eq i8 %9, 126
br i1 %10, label %11, label %21
11: ; preds = %8
%12 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @chdir(i8* %12)
%14 = load i8*, i8** %2
%15 = getelementptr inbounds i8, i8* %14, i64 1
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 47
br i1 %17, label %18, label %23
18: ; preds = %11
%19 = getelementptr inbounds i8, i8* %14, i64 2
%20 = tail call i32 @chdir(i8* %19)
br label %23
21: ; preds = %8
%22 = tail call i32 @chdir(i8* %3)
br label %23
23: ; preds = %21, %18, %11, %5
ret void
}