// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x8(%rbp), %rax
movq %rax, %rcx
addq $0x8, %rcx
movq %rcx, -0x8(%rbp)
cmpq $0x0, 0x8(%rax)
jne 0x389e
leaq 0x118ba(%rip), %rdi     # 0x15123
callq 0x12110
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x3886
leaq 0x118a8(%rip), %rax     # 0x15128
movq %rax, -0x48(%rbp)
jmp 0x3891
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, (%rax)
jmp 0x38bc
movq -0x8(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x38ba
leaq 0x11813(%rip), %rdi     # 0x150c3
callq 0x4840
jmp 0x3b1d
jmp 0x38bc
movq -0x8(%rbp), %rax
movq (%rax), %rdi
callq 0x11d90
cmpl $0x0, %eax
jne 0x3927
movq -0x8(%rbp), %rax
movq (%rax), %rax
movsbl (%rax), %eax
movsbl 0x1184d(%rip), %ecx     # 0x1512b
cmpl %ecx, %eax
jne 0x38fa
movq -0x8(%rbp), %rax
movq (%rax), %rdi
leaq 0x1183b(%rip), %rsi     # 0x1512b
callq 0x31e0
cmpl $0x0, %eax
je 0x3927
movq -0x8(%rbp), %rax
movq (%rax), %rax
movsbl (%rax), %eax
movsbl 0x1181f(%rip), %ecx     # 0x1512a
cmpl %ecx, %eax
jne 0x395c
movq -0x8(%rbp), %rax
movq (%rax), %rdi
leaq 0x1180d(%rip), %rsi     # 0x1512a
callq 0x31e0
cmpl $0x0, %eax
jne 0x395c
movq -0x8(%rbp), %rax
movq (%rax), %rdi
callq 0x3100
cmpl $0x0, %eax
jge 0x394d
xorl %edi, %edi
callq 0x107a0
movq -0x8(%rbp), %rax
movq (%rax), %rdi
callq 0x11c10
jmp 0x3957
movl $0x1, %edi
callq 0x107a0
jmp 0x3b1d
leaq 0x117ca(%rip), %rdi     # 0x1512d
callq 0x12110
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x398e
leaq -0x28(%rbp), %rax
movq %rax, -0x10(%rbp)
leaq 0x126f5(%rip), %rax     # 0x16077
movq %rax, -0x28(%rbp)
movq $0x0, -0x18(%rbp)
jmp 0x3990
leaq -0x28(%rbp), %rax
cmpq %rax, -0x10(%rbp)
je 0x3a59
movq -0x10(%rbp), %rax
movq (%rax), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x3a59
movq -0x8(%rbp), %rax
movq (%rax), %rdi
callq 0x30f0
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x30f0
movq %rax, %rcx
movq -0x50(%rbp), %rax
addq %rcx, %rax
addq $0x2, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
jbe 0x39fa
movq -0x38(%rbp), %rdi
movq %rdi, -0x40(%rbp)
callq 0xd4c0
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
callq 0x3070
movq -0x10(%rbp), %rax
movq (%rax), %rax
movsbl (%rax), %eax
movsbl 0x1170d(%rip), %ecx     # 0x15128
cmpl %ecx, %eax
jne 0x3a37
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq 0x116fb(%rip), %rsi     # 0x15128
callq 0x31e0
cmpl $0x0, %eax
je 0x3a47
movq -0x30(%rbp), %rdi
leaq 0x116e6(%rip), %rsi     # 0x15128
callq 0x3300
movq -0x30(%rbp), %rdi
movq -0x8(%rbp), %rax
movq (%rax), %rsi
callq 0x3300
jmp 0x3a6c
movq $0x0, -0x40(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
callq 0x3100
cmpl $0x0, %eax
jl 0x3ae5
movl $0x1, %edi
callq 0x107a0
leaq 0x1c1d9(%rip), %rax     # 0x1fc64
cmpl $0x0, (%rax)
je 0x3ae3
movq -0x10(%rbp), %rax
movq (%rax), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x3ae3
movq -0x10(%rbp), %rax
movq (%rax), %rax
movsbl (%rax), %eax
movsbl 0x1167b(%rip), %ecx     # 0x1512b
cmpl %ecx, %eax
jne 0x3acc
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq 0x11669(%rip), %rsi     # 0x1512b
callq 0x31e0
cmpl $0x0, %eax
je 0x3ae3
movq -0x30(%rbp), %rdx
movl $0x1, %edi
leaq 0x1242c(%rip), %rsi     # 0x15f08
movb $0x0, %al
callq 0xf3a0
jmp 0x3b1d
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x3990
movq -0x8(%rbp), %rax
movq (%rax), %rdx
movl $0x2, %edi
leaq 0x11625(%rip), %rsi     # 0x15134
movb $0x0, %al
callq 0xf3a0
xorl %edi, %edi
callq 0x107a0
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)