#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*/ fexpand(char *, char *);
int fget(char *);
int fgettype(int);
int /*<<< orphan*/ fsetwd(char *);
int /*<<< orphan*/ iwrites(char *);
void cd(char *dir) {
  char dir2[512];
  int f;
  fexpand(dir2, dir);
  f = fget(dir2);
  if (!f) {
    iwrites("Error: directory does not exist\n");
    return;
  }
  if (fgettype(f) != 3) {
    iwrites("Error: file is not a directory\n");
    return;
  }
  fsetwd(dir2);
}


x86 assembly (clang, -O0):
<cd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x210(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <fexpand@plt>
lea    -0x210(%rbp),%rdi
call   1040 <fget@plt>
mov    %eax,-0x214(%rbp)
cmpl   $0x0,-0x214(%rbp)
jne    119f <cd+0x4f>
lea    0xe6b(%rip),%rdi
call   1070 <iwrites@plt>
jmp    11d0 <cd+0x80>
mov    -0x214(%rbp),%edi
call   1050 <fgettype@plt>
cmp    $0x3,%eax
je     11c4 <cd+0x74>
lea    0xe67(%rip),%rdi
call   1070 <iwrites@plt>
jmp    11d0 <cd+0x80>
lea    -0x210(%rbp),%rdi
call   1060 <fsetwd@plt>
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cd>:
push   %rbx
sub    $0x200,%rsp
mov    %rdi,%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1030 <fexpand@plt>
mov    %rbx,%rdi
call   1040 <fget@plt>
test   %eax,%eax
je     1188 <cd+0x38>
mov    %eax,%edi
call   1050 <fgettype@plt>
cmp    $0x3,%eax
jne    1191 <cd+0x41>
mov    %rsp,%rdi
call   1060 <fsetwd@plt>
jmp    119d <cd+0x4d>
lea    0xe71(%rip),%rdi
jmp    1198 <cd+0x48>
lea    0xe89(%rip),%rdi
call   1070 <iwrites@plt>
add    $0x200,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [33 x i8] c"Error: directory does not exist\0A\00"
@.str.1 = [32 x i8] c"Error: file is not a directory\0A\00"
define void @cd(i8* %0) {
%2 = alloca i8*
%3 = alloca [512 x i8]
%4 = alloca i32
store i8* %0, i8** %2
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%6 = load i8*, i8** %2
%7 = call i32 @fexpand(i8* %5, i8* %6)
%8 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%9 = call i32 @fget(i8* %8)
store i32 %9, i32* %4
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %1
%13 = call i32 @iwrites(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
br label %23
14: ; preds = %1
%15 = load i32, i32* %4
%16 = call i32 @fgettype(i32 %15)
%17 = icmp ne i32 %16, 3
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = call i32 @iwrites(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
br label %23
20: ; preds = %14
%21 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%22 = call i32 @fsetwd(i8* %21)
br label %23
23: ; preds = %20, %18, %12
ret void
}

LLVM IR (-O2):
@.str = [33 x i8] c"Error: directory does not exist\0A\00"
@.str.1 = [32 x i8] c"Error: file is not a directory\0A\00"
define void @cd(i8* %0) {
%2 = alloca [512 x i8]
%3 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%4 = call i32 @fexpand(i8* %3, i8* %0)
%5 = call i32 @fget(i8* %3)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = call i32 @iwrites(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
br label %16
9: ; preds = %1
%10 = call i32 @fgettype(i32 %5)
%11 = icmp eq i32 %10, 3
br i1 %11, label %14, label %12
12: ; preds = %9
%13 = call i32 @iwrites(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
br label %16
14: ; preds = %9
%15 = call i32 @fsetwd(i8* %3)
br label %16
16: ; preds = %14, %12, %7
ret void
}