#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 */
struct forth_instance {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ chdir(char *);
int /*<<< orphan*/ iswhitespace(char);
scalar_t__ st_pop(struct forth_instance *);
int /*<<< orphan*/ st_push(struct forth_instance *, int);
void chdir_func(struct forth_instance *fi) {
  char back, *name;
  int i = 0;
  name = (char *)st_pop(fi);
  while (name[i] && !iswhitespace(name[i]))
    i++;
  back = name[i];
  name[i] = '\0';
  st_push(fi, (int)!chdir(name));
  name[i] = back;
}


x86 assembly (clang, -O0):
<chdir_func>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <st_pop@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x1d(%rbp)
je     1196 <chdir_func+0x56>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <iswhitespace@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    11a6 <chdir_func+0x66>
jmp    11b4 <chdir_func+0x74>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1160 <chdir_func+0x20>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x9(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <chdir@plt>
mov    -0x28(%rbp),%rdi
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%esi
call   1060 <st_push@plt>
mov    -0x9(%rbp),%dl
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chdir_func>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1050 <st_pop@plt>
mov    %rax,%r15
mov    (%rax),%al
test   %al,%al
je     1182 <chdir_func+0x42>
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
movsbl %al,%edi
call   1030 <iswhitespace@plt>
test   %eax,%eax
jne    117a <chdir_func+0x3a>
movzbl 0x1(%r15,%rbx,1),%eax
add    $0x1,%rbx
test   %al,%al
jne    1160 <chdir_func+0x20>
mov    %ebx,%eax
mov    (%r15,%rax,1),%bpl
jmp    1186 <chdir_func+0x46>
xor    %ebp,%ebp
xor    %ebx,%ebx
mov    %ebx,%ebx
movb   $0x0,(%r15,%rbx,1)
mov    %r15,%rdi
call   1040 <chdir@plt>
xor    %esi,%esi
test   %eax,%eax
sete   %sil
mov    %r14,%rdi
call   1060 <st_push@plt>
mov    %bpl,(%r15,%rbx,1)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.forth_instance = type { i32 }
define void @chdir_func(%struct.forth_instance* %0) {
%2 = alloca %struct.forth_instance*
%3 = alloca i8
%4 = alloca i8*
%5 = alloca i32
store %struct.forth_instance* %0, %struct.forth_instance** %2
store i32 0, i32* %5
%6 = load %struct.forth_instance*, %struct.forth_instance** %2
%7 = call i64 @st_pop(%struct.forth_instance* %6)
%8 = inttoptr i64 %7 to i8*
store i8* %8, i8** %4
br label %9
9: ; preds = %28, %1
%10 = load i8*, i8** %4
%11 = load i32, i32* %5
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %10, i64 %12
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %26
17: ; preds = %9
%18 = load i8*, i8** %4
%19 = load i32, i32* %5
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = load i8, i8* %21
%23 = call i32 @iswhitespace(i8 signext %22)
%24 = icmp ne i32 %23, 0
%25 = xor i1 %24, true
br label %26
26: ; preds = %17, %9
%27 = phi i1 [ false, %9 ], [ %25, %17 ]
br i1 %27, label %28, label %31
28: ; preds = %26
%29 = load i32, i32* %5
%30 = add nsw i32 %29, 1
store i32 %30, i32* %5
br label %9
31: ; preds = %26
%32 = load i8*, i8** %4
%33 = load i32, i32* %5
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
%36 = load i8, i8* %35
store i8 %36, i8* %3
%37 = load i8*, i8** %4
%38 = load i32, i32* %5
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %37, i64 %39
store i8 0, i8* %40
%41 = load %struct.forth_instance*, %struct.forth_instance** %2
%42 = load i8*, i8** %4
%43 = call i32 @chdir(i8* %42)
%44 = icmp ne i32 %43, 0
%45 = xor i1 %44, true
%46 = zext i1 %45 to i32
%47 = call i32 @st_push(%struct.forth_instance* %41, i32 %46)
%48 = load i8, i8* %3
%49 = load i8*, i8** %4
%50 = load i32, i32* %5
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %49, i64 %51
store i8 %48, i8* %52
ret void
}

LLVM IR (-O2):
%struct.forth_instance = type { i32 }
define void @chdir_func(%struct.forth_instance* %0) {
%2 = tail call i64 @st_pop(%struct.forth_instance* %0)
%3 = inttoptr i64 %2 to i8*
%4 = load i8, i8* %3
%5 = icmp eq i8 %4, 0
br i1 %5, label %25, label %6
6: ; preds = %1, %12
%7 = phi i64 [ %13, %12 ], [ 0, %1 ]
%8 = phi i8 [ %16, %12 ], [ %4, %1 ]
%9 = phi i32 [ %14, %12 ], [ 0, %1 ]
%10 = tail call i32 @iswhitespace(i8 signext %8)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %18
12: ; preds = %6
%13 = add nuw i64 %7, 1
%14 = add nuw nsw i32 %9, 1
%15 = getelementptr inbounds i8, i8* %3, i64 %13
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 0
br i1 %17, label %20, label %6
18: ; preds = %6
%19 = trunc i64 %7 to i32
br label %20
20: ; preds = %12, %18
%21 = phi i32 [ %19, %18 ], [ %14, %12 ]
%22 = zext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %3, i64 %22
%24 = load i8, i8* %23
br label %25
25: ; preds = %1, %20
%26 = phi i8 [ %24, %20 ], [ 0, %1 ]
%27 = phi i32 [ %21, %20 ], [ 0, %1 ]
%28 = zext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %3, i64 %28
store i8 0, i8* %29
%30 = tail call i32 @chdir(i8* %3)
%31 = icmp eq i32 %30, 0
%32 = zext i1 %31 to i32
%33 = tail call i32 @st_push(%struct.forth_instance* %0, i32 %32)
store i8 %26, i8* %29
ret void
}