// File: /workspace/github_c_makefile_star2_O0/ffoissey[P]minishell_42/srcs/ft_cd.c
// Function: ft_process_cd
int		ft_process_cd(t_list_ex *lst, char *s)
{
	char	*new;
	char	*tmp;
	char	*tmp2;

	new = NULL;
	tmp = ft_lst_returnvalue(lst, "PWD");
	if (!s || !s[0])
		return (0);
	else if (s[0] == '/')
		return (ft_process_cd(lst, s + 1));
	else if (!ft_strncmp(s, "..", 2))
	{
		tmp2 = ft_strrchr(tmp + 1, '/');
		new = tmp2 ? ft_strsub(tmp, 0, tmp2 - tmp) : ft_strdup("/");
		ft_lst_changevalue(&lst, "PWD", new);
		ft_strdel(&new);
		return (ft_process_cd(lst, s + 2));
	}
	else if (!ft_strncmp(s, ".", 1) && (*(s + 1) == '/' || !*(s + 1)))
		return (ft_process_cd(lst, s + 1));
	tmp = ft_strcmp(tmp, "/") ? ft_strjoin(tmp, "/") : ft_strdup(tmp);
	tmp2 = ft_strchr(s, '/');
	new = tmp2 ? ft_strsub(s, 0, tmp2 - s) : ft_strdup(s);
	tmp = ft_strjoinfree_n(&tmp, &new, BOTH);
	return (ft_cd_access(lst, tmp, s));
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq -0x10(%rbp), %rdi
leaq 0x9b51(%rip), %rsi      # 0xc044
callq 0x2b90
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x250c
movq -0x18(%rbp), %rax
cmpb $0x0, (%rax)
jne 0x2518
movl $0x0, -0x4(%rbp)
jmp 0x26e6
movq -0x18(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2f, %eax
jne 0x253d
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0x1, %rsi
callq 0x24d0
movl %eax, -0x4(%rbp)
jmp 0x26e6
movq -0x18(%rbp), %rdi
leaq 0x9c28(%rip), %rsi      # 0xc170
movl $0x2, %edx
callq 0x36c0
cmpl $0x0, %eax
jne 0x25e2
movq -0x28(%rbp), %rdi
addq $0x1, %rdi
movl $0x2f, %esi
callq 0x3860
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x2594
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rdx
movq -0x28(%rbp), %rax
subq %rax, %rdx
xorl %esi, %esi
callq 0x3c00
movq %rax, -0x38(%rbp)
jmp 0x25a4
leaq 0x9bd8(%rip), %rdi      # 0xc173
callq 0x3990
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdx
leaq -0x10(%rbp), %rdi
leaq 0x9a89(%rip), %rsi      # 0xc044
callq 0x2a90
leaq -0x20(%rbp), %rdi
callq 0x3d50
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0x2, %rsi
callq 0x24d0
movl %eax, -0x4(%rbp)
jmp 0x26e6
movq -0x18(%rbp), %rdi
leaq 0x9b84(%rip), %rsi      # 0xc171
movl $0x1, %edx
callq 0x36c0
cmpl $0x0, %eax
jne 0x262c
movq -0x18(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x2f, %eax
je 0x2613
movq -0x18(%rbp), %rax
cmpb $0x0, 0x1(%rax)
jne 0x262c
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0x1, %rsi
callq 0x24d0
movl %eax, -0x4(%rbp)
jmp 0x26e6
jmp 0x262e
jmp 0x2630
jmp 0x2632
movq -0x28(%rbp), %rdi
leaq 0x9b36(%rip), %rsi      # 0xc173
callq 0x3640
cmpl $0x0, %eax
je 0x265d
movq -0x28(%rbp), %rdi
leaq 0x9b21(%rip), %rsi      # 0xc173
callq 0x3a40
movq %rax, -0x40(%rbp)
jmp 0x266a
movq -0x28(%rbp), %rdi
callq 0x3990
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rdi
movl $0x2f, %esi
callq 0x37d0
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x26a7
movq -0x18(%rbp), %rdi
movq -0x30(%rbp), %rdx
movq -0x18(%rbp), %rax
subq %rax, %rdx
xorl %esi, %esi
callq 0x3c00
movq %rax, -0x48(%rbp)
jmp 0x26b4
movq -0x18(%rbp), %rdi
callq 0x3990
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x20(%rbp)
leaq -0x28(%rbp), %rdi
leaq -0x20(%rbp), %rsi
movl $0x3, %edx
callq 0x3b40
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x23e0
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nop