#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 *);
char *getenv(char *);
int /*<<< orphan*/ printf(char *);
int cmd_cd(int argc, char *argv[]) {
  if (argc == 1)
    chdir(getenv("HOME"));
  else if (argc == 2) {
    if (chdir(argv[1]))
      printf("No directory\n");
  } else
    printf("USAGE: cd [dir]\n");
  return 1;
}


x86 assembly (clang, -O0):
<cmd_cd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x4(%rbp)
jne    1162 <cmd_cd+0x32>
lea    0xeb0(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rdi
call   1040 <chdir@plt>
jmp    11a5 <cmd_cd+0x75>
cmpl   $0x2,-0x4(%rbp)
jne    1194 <cmd_cd+0x64>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <chdir@plt>
cmp    $0x0,%rax
je     118f <cmd_cd+0x5f>
lea    0xe7b(%rip),%rdi
call   1050 <printf@plt>
jmp    11a0 <cmd_cd+0x70>
lea    0xe78(%rip),%rdi
call   1050 <printf@plt>
jmp    11a5 <cmd_cd+0x75>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmd_cd>:
push   %rax
cmp    $0x2,%edi
je     1151 <cmd_cd+0x21>
cmp    $0x1,%edi
jne    1168 <cmd_cd+0x38>
lea    0xebe(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rdi
call   1050 <chdir@plt>
jmp    1174 <cmd_cd+0x44>
mov    0x8(%rsi),%rdi
call   1050 <chdir@plt>
test   %rax,%rax
je     1174 <cmd_cd+0x44>
lea    0xeaf(%rip),%rdi
jmp    116f <cmd_cd+0x3f>
lea    0xe96(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%eax
pop    %rcx
ret

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

LLVM IR (-O2):
@.str = [5 x i8] c"HOME\00"
@str = [16 x i8] c"USAGE: cd [dir]\00"
@str.3 = [13 x i8] c"No directory\00"
define i32 @cmd_cd(i32 %0, i8** nocapture %1) {
switch i32 %0, label %13 [
i32 1, label %3
i32 2, label %6
]
3: ; preds = %2
%4 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%5 = tail call i64 @chdir(i8* %4)
br label %15
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i64 @chdir(i8* %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %6
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.3, i64 0, i64 0))
br label %15
13: ; preds = %2
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
br label %15
15: ; preds = %13, %11, %6, %3
ret i32 1
}