// File: /workspace/github_c_makefile_star2_O0/VeeeectorPan[P]MyNetdisk/clientSrc/cd.c
// Function: cd
int cd(int sock_fd,char* file_name,char* path,int *file_id)
{
    int ctl_num = CTL_CD;
    send(sock_fd,&ctl_num,sizeof(int),0);
    send(sock_fd,file_id,sizeof(int),0);
    if(strcmp(file_name,"..") == 0)
    {
        ctl_num = CD_BACK;
        send(sock_fd,&ctl_num,sizeof(int),0);
        recv(sock_fd,&ctl_num,sizeof(int),0);
        if(ctl_num == CD_FAIL)
            return -1;
        recv(sock_fd,file_id,sizeof(int),0);
        int i;
        for(i = strlen(path) - 1; path[i] != '/'; --i);
        if(i == 0)
        {
            ++i;
        }
        path[i] = '\0';
        return 0;
    }
    ctl_num = CD_JMP;
    send(sock_fd,&ctl_num,sizeof(int),0);
    int len = strlen(file_name);
    send(sock_fd,&len,sizeof(int),0);
    send(sock_fd,file_name,len,0);
    recv(sock_fd,&ctl_num,sizeof(int),0);
    if(ctl_num == CD_FAIL)
    {
        return -1;
    }
    recv(sock_fd,file_id,sizeof(int),0);
    len = strlen(path);
    if(len != 1)
    {
        path[len++] = '/';
    }
    sprintf(path + len,"%s",file_name);
    len += strlen(file_name);
    path[len] = '\0';
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl $0x2, -0x24(%rbp)
movl -0x8(%rbp), %edi
leaq -0x24(%rbp), %rsi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0x20d0
movl -0x8(%rbp), %edi
movq -0x20(%rbp), %rsi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0x20d0
movq -0x10(%rbp), %rdi
leaq 0x3be5(%rip), %rsi      # 0x6004
callq 0x21e0
cmpl $0x0, %eax
jne 0x24d4
movl $0x0, -0x24(%rbp)
movl -0x8(%rbp), %edi
leaq -0x24(%rbp), %rsi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0x20d0
movl -0x8(%rbp), %edi
leaq -0x24(%rbp), %rsi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0x2080
cmpl $0x2, -0x24(%rbp)
jne 0x246c
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x25c5
movl -0x8(%rbp), %edi
movq -0x20(%rbp), %rsi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0x2080
movq -0x18(%rbp), %rdi
callq 0x2090
subq $0x1, %rax
movl %eax, -0x28(%rbp)
movq -0x18(%rbp), %rax
movslq -0x28(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2f, %eax
je 0x24ad
jmp 0x24a2
movl -0x28(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x248f
cmpl $0x0, -0x28(%rbp)
jne 0x24bc
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
movq -0x18(%rbp), %rax
movslq -0x28(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movl $0x0, -0x4(%rbp)
jmp 0x25c5
movl $0x1, -0x24(%rbp)
movl -0x8(%rbp), %edi
leaq -0x24(%rbp), %rsi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0x20d0
movq -0x10(%rbp), %rdi
callq 0x2090
movl %eax, -0x2c(%rbp)
movl -0x8(%rbp), %edi
leaq -0x2c(%rbp), %rsi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0x20d0
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
movslq -0x2c(%rbp), %rdx
xorl %ecx, %ecx
callq 0x20d0
movl -0x8(%rbp), %edi
leaq -0x24(%rbp), %rsi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0x2080
cmpl $0x2, -0x24(%rbp)
jne 0x2544
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x25c5
movl -0x8(%rbp), %edi
movq -0x20(%rbp), %rsi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0x2080
movq -0x18(%rbp), %rdi
callq 0x2090
movl %eax, -0x2c(%rbp)
cmpl $0x1, -0x2c(%rbp)
je 0x257f
movq -0x18(%rbp), %rax
movl -0x2c(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x2c(%rbp)
movslq %ecx, %rcx
movb $0x2f, (%rax,%rcx)
movq -0x18(%rbp), %rdi
movslq -0x2c(%rbp), %rax
addq %rax, %rdi
movq -0x10(%rbp), %rdx
leaq 0x3b1f(%rip), %rsi      # 0x60b4
movb $0x0, %al
callq 0x2060
movq -0x10(%rbp), %rdi
callq 0x2090
movq %rax, %rcx
movslq -0x2c(%rbp), %rax
addq %rcx, %rax
movl %eax, -0x2c(%rbp)
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nop