// File: /workspace/github_c_makefile_star2_O2/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 0x36f6
cmpq $0x0, 0x10(%rbx)
je 0x3717
leaq 0xa989(%rip), %rdi      # 0xe06c
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4234
leaq 0xa9d1(%rip), %rdi      # 0xe0ce
callq 0xc16d
testq %rax, %rax
je 0x370c
movq (%rax), %rdi
jmp 0x3713
leaq 0xa9c0(%rip), %rdi      # 0xe0d3
movq %rdi, 0x8(%rbx)
callq 0xbf5d
movq 0x8(%rbx), %rdi
testl %eax, %eax
je 0x3747
callq 0x3100
testl %eax, %eax
js 0x3844
pushq $0x1
popq %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xb43a
cmpb $0x2e, (%rdi)
jne 0x375e
cmpb $0x0, 0x1(%rdi)
je 0x3724
cmpb $0x2e, 0x1(%rdi)
jne 0x375e
cmpb $0x0, 0x2(%rdi)
je 0x3724
leaq 0xa970(%rip), %rdi      # 0xe0d5
callq 0xc16d
movq %rax, %r15
movq %rsp, %r13
testq %rax, %rax
jne 0x3789
leaq 0xb6ab(%rip), %rax      # 0xee27
movq %rax, (%rsp)
andq $0x0, 0x10(%rsp)
movq %r13, %r15
xorl %r14d, %r14d
xorl %ebp, %ebp
cmpq %r13, %r15
je 0x3807
movq (%r15), %r12
cmpb $0x0, (%r12)
je 0x3807
movq 0x8(%rbx), %rdi
callq 0x30f0
movq %rax, %r13
movq %r12, %rdi
callq 0x30f0
addq %rax, %r13
addq $0x2, %r13
cmpq %rbp, %r13
jbe 0x37ce
movq %r13, %rdi
callq 0x9928
movq %rax, %r14
movq (%r15), %r12
movq %r13, %rbp
movq %r14, %rdi
movq %r12, %rsi
callq 0x3070
movq (%r15), %rax
cmpb $0x2f, (%rax)
jne 0x37e7
cmpb $0x0, 0x1(%rax)
je 0x37f6
movq %r14, %rdi
callq 0x30f0
movw $0x2f, (%r14,%rax)
movq 0x8(%rbx), %rsi
movq %r14, %rdi
callq 0x3310
movq %rsp, %r13
jmp 0x380d
movq 0x8(%rbx), %r14
xorl %ebp, %ebp
movq %r14, %rdi
callq 0x3100
testl %eax, %eax
jns 0x3862
movq 0x10(%r15), %r15
testq %r15, %r15
jne 0x378e
movq 0x8(%rbx), %rdx
leaq 0xa8ab(%rip), %rsi      # 0xe0dc
pushq $0x2
popq %rdi
xorl %eax, %eax
callq 0xa8f6
xorl %edi, %edi
callq 0xb43a
jmp 0x389f
xorl %edi, %edi
callq 0xb43a
movq 0x8(%rbx), %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xbe9d
pushq $0x1
popq %rdi
callq 0xb43a
leaq 0x16363(%rip), %rax     # 0x19bd4
cmpl $0x0, (%rax)
je 0x389f
movq (%r15), %rax
movzbl (%rax), %ecx
testl %ecx, %ecx
je 0x389f
cmpl $0x2e, %ecx
jne 0x388b
cmpb $0x0, 0x1(%rax)
je 0x389f
leaq 0xb4b6(%rip), %rsi      # 0xed48
pushq $0x1
popq %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0xa8f6
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq