// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rcx, %rbx
movq %rdx, -0x38(%rbp)
movq %rsi, %r14
movl %edi, %r12d
leaq -0x2c(%rbp), %rsi
movl $0x2, (%rsi)
pushq $0x4
popq %r15
movq %r15, %rdx
xorl %ecx, %ecx
callq 0x20c0
movl %r12d, %edi
movq %rbx, %rsi
movq %r15, %rdx
xorl %ecx, %ecx
callq 0x20c0
cmpb $0x2e, (%r14)
jne 0x244a
cmpb $0x2e, 0x1(%r14)
jne 0x244a
cmpb $0x0, 0x2(%r14)
je 0x251c
movq %rbx, -0x40(%rbp)
leaq -0x2c(%rbp), %r13
movl $0x1, (%r13)
movl %r12d, %edi
movq %r13, %rsi
movq %r15, %rdx
xorl %ecx, %ecx
callq 0x20c0
movq %r14, %rdi
callq 0x2080
leaq -0x44(%rbp), %rbx
movl %eax, (%rbx)
movl %r12d, %edi
movq %rbx, %rsi
movq %r15, %rdx
xorl %ecx, %ecx
callq 0x20c0
movslq (%rbx), %rdx
movl %r12d, %edi
movq %r14, %rsi
xorl %ecx, %ecx
callq 0x20c0
movl %r12d, %edi
movq %r13, %rsi
movq %r15, %rdx
xorl %ecx, %ecx
callq 0x2070
cmpl $0x2, (%r13)
jne 0x24b5
pushq $-0x1
popq %r13
jmp 0x250a
pushq $0x4
popq %rdx
xorl %r13d, %r13d
movl %r12d, %edi
movq -0x40(%rbp), %rsi
xorl %ecx, %ecx
callq 0x2070
movq -0x38(%rbp), %r15
movq %r15, %rdi
callq 0x2080
cmpl $0x1, %eax
jne 0x24df
pushq $0x1
popq %rcx
jmp 0x24e9
leal 0x1(%rax), %ecx
cltq
movb $0x2f, (%r15,%rax)
movslq %ecx, %rbx
leaq (%r15,%rbx), %rdi
movq %r14, %rsi
callq 0x2160
movq %r14, %rdi
callq 0x2080
addl %eax, %ebx
movslq %ebx, %rax
movb $0x0, (%r15,%rax)
movl %r13d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq -0x2c(%rbp), %r14
andl $0x0, (%r14)
movl %r12d, %edi
movq %r14, %rsi
movq %r15, %rdx
xorl %ecx, %ecx
callq 0x20c0
movl %r12d, %edi
movq %r14, %rsi
movq %r15, %rdx
xorl %ecx, %ecx
callq 0x2070
cmpl $0x2, (%r14)
je 0x24af
pushq $0x4
popq %rdx
movl %r12d, %edi
movq %rbx, %rsi
xorl %ecx, %ecx
callq 0x2070
movq -0x38(%rbp), %rbx
movq %rbx, %rdi
callq 0x2080
decl %eax
movslq %eax, %rcx
cmpb $0x2f, (%rbx,%rcx)
jne 0x256a
cmpl $0x1, %eax
adcl $0x0, %eax
cltq
movb $0x0, (%rbx,%rax)
xorl %r13d, %r13d
jmp 0x250a
nop