#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 *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int /*<<< orphan*/ *getenv(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, int /*<<< orphan*/ *);
char *strerror(int /*<<< orphan*/);
void cdCommand(char *command) {
  if (command == NULL) {
    char homeDir[125];
    if (getenv("HOME") != NULL) {
      strcpy(homeDir, getenv("HOME"));
      if (chdir(homeDir) == -1)
        fprintf(stderr, "minish: cd: %s: %s\n", homeDir, strerror(errno));
    }
  } else if (command[0] == '~') {
    char homeDir[125];
    char buffer[512];
    if (getenv("HOME") != NULL) {
      strcpy(homeDir, getenv("HOME"));
      command = command + 1;
      sprintf(buffer, "%s%s", homeDir, command);
      if (chdir(buffer) == -1)
        fprintf(stderr, "minish: cd: %s: %s\n", buffer, strerror(errno));
    }
  } else {
    if (chdir(command) == -1)
      fprintf(stderr, "minish: cd: %s: %s\n", command, strerror(errno));
  }
}


x86 assembly (clang, -O0):
<cdCommand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x350,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    121f <cdCommand+0xbf>
lea    0xe7f(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%rax
je     121a <cdCommand+0xba>
lea    -0x90(%rbp),%rax
mov    %rax,-0x318(%rbp)
lea    0xe5b(%rip),%rdi
call   1030 <getenv@plt>
mov    -0x318(%rbp),%rdi
mov    %rax,%rsi
call   1040 <strcpy@plt>
lea    -0x90(%rbp),%rdi
call   1050 <chdir@plt>
cmp    $0xffffffff,%eax
jne    1215 <cdCommand+0xb5>
mov    0x2e0b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x324(%rbp)
lea    -0x90(%rbp),%rax
mov    %rax,-0x320(%rbp)
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x324(%rbp),%edi
mov    -0x320(%rbp),%rdx
mov    %rax,%rcx
lea    0xdf5(%rip),%rsi
call   1060 <fprintf@plt>
jmp    121a <cdCommand+0xba>
jmp    135e <cdCommand+0x1fe>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x7e,%eax
jne    12fe <cdCommand+0x19e>
lea    0xdca(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%rax
je     12f9 <cdCommand+0x199>
lea    -0x110(%rbp),%rax
mov    %rax,-0x330(%rbp)
lea    0xda6(%rip),%rdi
call   1030 <getenv@plt>
mov    -0x330(%rbp),%rdi
mov    %rax,%rsi
call   1040 <strcpy@plt>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
lea    -0x310(%rbp),%rdi
lea    -0x110(%rbp),%rdx
mov    -0x8(%rbp),%rcx
lea    0xd86(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x310(%rbp),%rdi
call   1050 <chdir@plt>
cmp    $0xffffffff,%eax
jne    12f4 <cdCommand+0x194>
mov    0x2d2c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x33c(%rbp)
lea    -0x310(%rbp),%rax
mov    %rax,-0x338(%rbp)
mov    0x2d07(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x33c(%rbp),%edi
mov    -0x338(%rbp),%rdx
mov    %rax,%rcx
lea    0xd16(%rip),%rsi
call   1060 <fprintf@plt>
jmp    12f9 <cdCommand+0x199>
jmp    1359 <cdCommand+0x1f9>
mov    -0x8(%rbp),%rdi
call   1050 <chdir@plt>
cmp    $0xffffffff,%eax
jne    1354 <cdCommand+0x1f4>
mov    0x2cc9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x348(%rbp)
mov    0x2ca7(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x34c(%rbp),%edi
mov    -0x348(%rbp),%rdx
mov    %rax,%rcx
lea    0xcb6(%rip),%rsi
call   1060 <fprintf@plt>
jmp    1359 <cdCommand+0x1f9>
jmp    135e <cdCommand+0x1fe>
add    $0x350,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cdCommand>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x288,%rsp
test   %rdi,%rdi
je     11c7 <cdCommand+0x67>
mov    %rdi,%rbx
cmpb   $0x7e,(%rdi)
jne    122a <cdCommand+0xca>
lea    0xe7b(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1237 <cdCommand+0xd7>
mov    %rsp,%r14
mov    %r14,%rdi
mov    %rax,%rsi
call   1040 <strcpy@plt>
add    $0x1,%rbx
lea    0xe6d(%rip),%rsi
lea    0x80(%rsp),%r15
mov    %r15,%rdi
mov    %r14,%rdx
mov    %rbx,%rcx
call   1070 <sprintf@plt>
mov    %r15,%rdi
jmp    11ee <cdCommand+0x8e>
lea    0xe32(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1237 <cdCommand+0xd7>
lea    0x80(%rsp),%rbx
mov    %rbx,%rdi
mov    %rax,%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
call   1050 <chdir@plt>
cmp    $0xffffffff,%eax
jne    1237 <cdCommand+0xd7>
mov    0x2de1(%rip),%rax
mov    (%rax),%ebx
mov    0x2dd0(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xdef(%rip),%rsi
lea    0x80(%rsp),%rdx
mov    %ebx,%edi
mov    %rax,%rcx
call   1060 <fprintf@plt>
jmp    1237 <cdCommand+0xd7>
mov    %rbx,%rdi
call   1050 <chdir@plt>
cmp    $0xffffffff,%eax
je     1245 <cdCommand+0xe5>
add    $0x288,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d94(%rip),%rax
mov    (%rax),%ebp
mov    0x2d83(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xda2(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
add    $0x288,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <fprintf@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"HOME\00"
@stderr = global i32 0
@.str.1 = [20 x i8] c"minish: cd: %s: %s\0A\00"
@errno = global i32 0
@.str.2 = [5 x i8] c"%s%s\00"
define void @cdCommand(i8* %0) {
%2 = alloca i8*
%3 = alloca [125 x i8]
%4 = alloca [125 x i8]
%5 = alloca [512 x i8]
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %26
8: ; preds = %1
%9 = call i32* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%10 = icmp ne i32* %9, null
br i1 %10, label %11, label %25
11: ; preds = %8
%12 = getelementptr inbounds [125 x i8], [125 x i8]* %3, i64 0, i64 0
%13 = call i32* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @strcpy(i8* %12, i32* %13)
%15 = getelementptr inbounds [125 x i8], [125 x i8]* %3, i64 0, i64 0
%16 = call i32 @chdir(i8* %15)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %24
18: ; preds = %11
%19 = load i32, i32* @stderr
%20 = getelementptr inbounds [125 x i8], [125 x i8]* %3, i64 0, i64 0
%21 = load i32, i32* @errno
%22 = call i8* @strerror(i32 %21)
%23 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %20, i8* %22)
br label %24
24: ; preds = %18, %11
br label %25
25: ; preds = %24, %8
br label %68
26: ; preds = %1
%27 = load i8*, i8** %2
%28 = getelementptr inbounds i8, i8* %27, i64 0
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 126
br i1 %31, label %32, label %56
32: ; preds = %26
%33 = call i32* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%34 = icmp ne i32* %33, null
br i1 %34, label %35, label %55
35: ; preds = %32
%36 = getelementptr inbounds [125 x i8], [125 x i8]* %4, i64 0, i64 0
%37 = call i32* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%38 = call i32 @strcpy(i8* %36, i32* %37)
%39 = load i8*, i8** %2
%40 = getelementptr inbounds i8, i8* %39, i64 1
store i8* %40, i8** %2
%41 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%42 = getelementptr inbounds [125 x i8], [125 x i8]* %4, i64 0, i64 0
%43 = load i8*, i8** %2
%44 = call i32 @sprintf(i8* %41, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %42, i8* %43)
%45 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%46 = call i32 @chdir(i8* %45)
%47 = icmp eq i32 %46, -1
br i1 %47, label %48, label %54
48: ; preds = %35
%49 = load i32, i32* @stderr
%50 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%51 = load i32, i32* @errno
%52 = call i8* @strerror(i32 %51)
%53 = call i32 @fprintf(i32 %49, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %50, i8* %52)
br label %54
54: ; preds = %48, %35
br label %55
55: ; preds = %54, %32
br label %67
56: ; preds = %26
%57 = load i8*, i8** %2
%58 = call i32 @chdir(i8* %57)
%59 = icmp eq i32 %58, -1
br i1 %59, label %60, label %66
60: ; preds = %56
%61 = load i32, i32* @stderr
%62 = load i8*, i8** %2
%63 = load i32, i32* @errno
%64 = call i8* @strerror(i32 %63)
%65 = call i32 @fprintf(i32 %61, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %62, i8* %64)
br label %66
66: ; preds = %60, %56
br label %67
67: ; preds = %66, %55
br label %68
68: ; preds = %67, %25
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"HOME\00"
@stderr = global i32 0
@.str.1 = [20 x i8] c"minish: cd: %s: %s\0A\00"
@errno = global i32 0
@.str.2 = [5 x i8] c"%s%s\00"
define void @cdCommand(i8* %0) {
%2 = alloca [125 x i8]
%3 = alloca [125 x i8]
%4 = alloca [512 x i8]
%5 = icmp eq i8* %0, null
br i1 %5, label %6, label %20
6: ; preds = %1
%7 = getelementptr inbounds [125 x i8], [125 x i8]* %2, i64 0, i64 0
%8 = tail call i32* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %19, label %10
10: ; preds = %6
%11 = call i32 @strcpy(i8* %7, i32* %8)
%12 = call i32 @chdir(i8* %7)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %19
14: ; preds = %10
%15 = load i32, i32* @stderr
%16 = load i32, i32* @errno
%17 = call i8* @strerror(i32 %16)
%18 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %7, i8* %17)
br label %19
19: ; preds = %10, %14, %6
br label %48
20: ; preds = %1
%21 = load i8, i8* %0
%22 = icmp eq i8 %21, 126
br i1 %22, label %23, label %40
23: ; preds = %20
%24 = getelementptr inbounds [125 x i8], [125 x i8]* %3, i64 0, i64 0
%25 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%26 = tail call i32* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%27 = icmp eq i32* %26, null
br i1 %27, label %39, label %28
28: ; preds = %23
%29 = call i32 @strcpy(i8* %24, i32* %26)
%30 = getelementptr inbounds i8, i8* %0, i64 1
%31 = call i32 @sprintf(i8* %25, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %24, i8* %30)
%32 = call i32 @chdir(i8* %25)
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %39
34: ; preds = %28
%35 = load i32, i32* @stderr
%36 = load i32, i32* @errno
%37 = call i8* @strerror(i32 %36)
%38 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %25, i8* %37)
br label %39
39: ; preds = %28, %34, %23
br label %48
40: ; preds = %20
%41 = tail call i32 @chdir(i8* %0)
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %48
43: ; preds = %40
%44 = load i32, i32* @stderr
%45 = load i32, i32* @errno
%46 = tail call i8* @strerror(i32 %45)
%47 = tail call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %46)
br label %48
48: ; preds = %39, %43, %40, %19
ret void
}