// File: /workspace/github_c_makefile_star2_O1/rakitzis[P]rc/builtins.c
// Function: b_cd
static void b_cd(char **av) {
    List *s, nil;
    char *path = NULL;
    size_t t, pathlen = 0;
    if (*++av == NULL) {
	s = varlookup("home");
	*av = (s == NULL) ? "/" : s->w;
    } else if (av[1] != NULL) {
	arg_count("cd");
	return;
    }
    if (isabsolute(*av) || streq(*av, ".") || streq(*av, "..")) { /* absolute pathname? */
	if (chdir(*av) < 0) {
	    set(FALSE);
	    uerror(*av);
	} else
	    set(TRUE);
    } else {
	s = varlookup("cdpath");
	if (s == NULL) {
	    s = &nil;
	    nil.w = "";
	    nil.n = NULL;
	}
	do {
	    if (s != &nil && *s->w != '\0') {
		t = strlen(*av) + strlen(s->w) + 2;
		if (t > pathlen)
		    path = nalloc(pathlen = t);
		strcpy(path, s->w);
		if (!streq(s->w, "/")) /* "//" is special to POSIX */
		    strcat(path, "/");
		strcat(path, *av);
	    } else {
		pathlen = 0;
		path = *av;
	    }
	    if (chdir(path) >= 0) {
		set(TRUE);
		if (interactive && *s->w != '\0' && !streq(s->w, "."))
		    fprint(1, "%s\n", path);
		return;
	    }
	    s = s->n;
	} while (s != NULL);
	fprint(2, "couldn't cd to %s\n", *av);
	set(FALSE);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
cmpq $0x0, 0x8(%rdi)
je 0x3731
cmpq $0x0, 0x10(%rbx)
je 0x3752
leaq 0xb997(%rip), %rsi      # 0xf0b1
leaq 0xb94e(%rip), %rdx      # 0xf06f
movl $0x2, %edi
xorl %eax, %eax
callq 0xb06f
xorl %edi, %edi
jmp 0x3775
leaq 0xb997(%rip), %rdi      # 0xf0cf
callq 0xcaf4
testq %rax, %rax
je 0x3747
movq (%rax), %rax
jmp 0x374e
leaq 0xb986(%rip), %rax      # 0xf0d4
movq %rax, 0x8(%rbx)
movq 0x8(%rbx), %rdi
callq 0xc8c8
testl %eax, %eax
je 0x3788
movq 0x8(%rbx), %rdi
callq 0x3100
testl %eax, %eax
js 0x38b6
movl $0x1, %edi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xbcdc
movq 0x8(%rbx), %r14
movb (%r14), %bpl
cmpb $0x2e, %bpl
jne 0x37c1
leaq 0xb93b(%rip), %rsi      # 0xf0d7
movq %r14, %rdi
callq 0x31f0
testl %eax, %eax
je 0x375f
cmpb $0x2e, %bpl
jne 0x37c1
leaq 0xb921(%rip), %rsi      # 0xf0d6
movq %r14, %rdi
callq 0x31f0
testl %eax, %eax
je 0x375f
leaq 0xb911(%rip), %rdi      # 0xf0d9
callq 0xcaf4
movq %rax, %r15
movq %rsp, %rbp
testq %rax, %rax
jne 0x37ef
leaq 0xc5f8(%rip), %rax      # 0xfdd7
movq %rax, (%rsp)
movq $0x0, 0x10(%rsp)
movq %rbp, %r15
xorl %r14d, %r14d
xorl %r12d, %r12d
cmpq %rbp, %r15
je 0x3876
movq (%r15), %r13
cmpb $0x0, (%r13)
je 0x3876
movq 0x8(%rbx), %rdi
callq 0x30f0
movq %rax, %rbp
movq %r13, %rdi
callq 0x30f0
leaq (%rax,%rbp), %r13
addq $0x2, %r13
cmpq %r12, %r13
jbe 0x3833
movq %r13, %rdi
callq 0x9f28
movq %rax, %r14
movq %r13, %r12
movq (%r15), %rsi
movq %r14, %rdi
callq 0x3070
movq (%r15), %rdi
cmpb $0x2f, (%rdi)
jne 0x3856
leaq 0xb887(%rip), %rsi      # 0xf0d4
callq 0x31f0
testl %eax, %eax
je 0x3865
movq %r14, %rdi
callq 0x30f0
movw $0x2f, (%r14,%rax)
movq 0x8(%rbx), %rsi
movq %r14, %rdi
callq 0x3310
movq %rsp, %rbp
jmp 0x387d
movq 0x8(%rbx), %r14
xorl %r12d, %r12d
movq %r14, %rdi
callq 0x3100
testl %eax, %eax
jns 0x38d4
movq 0x10(%r15), %r15
testq %r15, %r15
jne 0x37f5
movq 0x8(%rbx), %rdx
leaq 0xb83f(%rip), %rsi      # 0xf0e0
movl $0x2, %edi
xorl %eax, %eax
callq 0xb06f
xorl %edi, %edi
callq 0xbcdc
jmp 0x391f
xorl %edi, %edi
callq 0xbcdc
movq 0x8(%rbx), %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xc7ed
movl $0x1, %edi
callq 0xbcdc
leaq 0x162ef(%rip), %rax     # 0x19bd4
cmpl $0x0, (%rax)
je 0x391f
movq (%r15), %rdi
movzbl (%rdi), %eax
testl %eax, %eax
je 0x391f
cmpl $0x2e, %eax
jne 0x3909
leaq 0xb7d7(%rip), %rsi      # 0xf0d7
callq 0x31f0
testl %eax, %eax
je 0x391f
leaq 0xc3e8(%rip), %rsi      # 0xfcf8
movl $0x1, %edi
movq %r14, %rdx
xorl %eax, %eax
callq 0xb06f
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq