// File: /workspace/github_c_makefile_star2_O3/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
movq 0x8(%rdi), %rdi
testq %rdi, %rdi
je 0x3728
cmpq $0x0, 0x10(%rbx)
je 0x3749
leaq 0xb99f(%rip), %rsi      # 0xf0b0
leaq 0xb954(%rip), %rdx      # 0xf06c
movl $0x2, %edi
xorl %eax, %eax
callq 0xaf8c
xorl %edi, %edi
jmp 0x3768
leaq 0xb99f(%rip), %rdi      # 0xf0ce
callq 0xc9da
testq %rax, %rax
je 0x373e
movq (%rax), %rdi
jmp 0x3745
leaq 0xb98e(%rip), %rdi      # 0xf0d3
movq %rdi, 0x8(%rbx)
callq 0xc7b8
movq 0x8(%rbx), %rdi
testl %eax, %eax
je 0x377b
callq 0x3100
testl %eax, %eax
js 0x387d
movl $0x1, %edi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xbbec
cmpb $0x2e, (%rdi)
jne 0x3792
cmpb $0x0, 0x1(%rdi)
je 0x3756
cmpb $0x2e, 0x1(%rdi)
jne 0x3792
cmpb $0x0, 0x2(%rdi)
je 0x3756
leaq 0xb93c(%rip), %rdi      # 0xf0d5
callq 0xc9da
movq %rax, %r15
movq %rsp, %r13
testq %rax, %rax
jne 0x37c0
leaq 0xc677(%rip), %rax      # 0xfe27
movq %rax, (%rsp)
movq $0x0, 0x10(%rsp)
movq %r13, %r15
xorl %r14d, %r14d
xorl %ebp, %ebp
cmpq %r13, %r15
je 0x383e
movq (%r15), %r12
cmpb $0x0, (%r12)
je 0x383e
movq 0x8(%rbx), %rdi
callq 0x30f0
movq %rax, %r13
movq %r12, %rdi
callq 0x30f0
addq %rax, %r13
addq $0x2, %r13
cmpq %rbp, %r13
jbe 0x3805
movq %r13, %rdi
callq 0x9e80
movq %rax, %r14
movq (%r15), %r12
movq %r13, %rbp
movq %r14, %rdi
movq %r12, %rsi
callq 0x3070
movq (%r15), %rax
cmpb $0x2f, (%rax)
jne 0x381e
cmpb $0x0, 0x1(%rax)
je 0x382d
movq %r14, %rdi
callq 0x30f0
movw $0x2f, (%r14,%rax)
movq 0x8(%rbx), %rsi
movq %r14, %rdi
callq 0x3310
movq %rsp, %r13
jmp 0x3844
movq 0x8(%rbx), %r14
xorl %ebp, %ebp
movq %r14, %rdi
callq 0x3100
testl %eax, %eax
jns 0x389b
movq 0x10(%r15), %r15
testq %r15, %r15
jne 0x37c5
movq 0x8(%rbx), %rdx
leaq 0xb874(%rip), %rsi      # 0xf0dc
movl $0x2, %edi
xorl %eax, %eax
callq 0xaf8c
xorl %edi, %edi
callq 0xbbec
jmp 0x38dc
xorl %edi, %edi
callq 0xbbec
movq 0x8(%rbx), %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xc6dd
movl $0x1, %edi
callq 0xbbec
leaq 0x16328(%rip), %rax     # 0x19bd4
cmpl $0x0, (%rax)
je 0x38dc
movq (%r15), %rax
movzbl (%rax), %ecx
testl %ecx, %ecx
je 0x38dc
cmpl $0x2e, %ecx
jne 0x38c6
cmpb $0x0, 0x1(%rax)
je 0x38dc
leaq 0xc47b(%rip), %rsi      # 0xfd48
movl $0x1, %edi
movq %r14, %rdx
xorl %eax, %eax
callq 0xaf8c
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq