// File: /workspace/github_c_makefile_star2_O1/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 $0x18, %rsp
movq %rcx, %r14
movq %rdx, %rbx
movq %rsi, %r15
movl %edi, %r12d
leaq -0x30(%rbp), %rsi
movl $0x2, (%rsi)
movl $0x4, %edx
xorl %ecx, %ecx
callq 0x20c0
movl $0x4, %edx
movl %r12d, %edi
movq %r14, -0x38(%rbp)
movq %r14, %rsi
xorl %ecx, %ecx
callq 0x20c0
leaq 0x2bb8(%rip), %rsi      # 0x5004
movq %r15, %rdi
callq 0x21e0
leaq -0x30(%rbp), %r14
testl %eax, %eax
je 0x2528
movl $0x1, (%r14)
movl $0x4, %edx
movl %r12d, %edi
movq %r14, %rsi
xorl %ecx, %ecx
callq 0x20c0
movq %r15, %rdi
callq 0x2080
leaq -0x2c(%rbp), %r13
movl %eax, (%r13)
movl $0x4, %edx
movl %r12d, %edi
movq %r13, %rsi
xorl %ecx, %ecx
callq 0x20c0
movslq (%r13), %rdx
movl %r12d, %edi
movq %r15, %rsi
xorl %ecx, %ecx
callq 0x20c0
movl $0x4, %edx
movl %r12d, %edi
movq %r14, %rsi
xorl %ecx, %ecx
callq 0x2070
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
cmpl $0x2, (%r14)
je 0x2594
xorl %r13d, %r13d
movl $0x4, %edx
movl %r12d, %edi
movq -0x38(%rbp), %rsi
xorl %ecx, %ecx
callq 0x2070
movq %rbx, %rdi
callq 0x2080
movl %eax, -0x2c(%rbp)
cmpl $0x1, %eax
je 0x2500
leal 0x1(%rax), %ecx
movl %ecx, -0x2c(%rbp)
cltq
movb $0x2f, (%rbx,%rax)
movslq -0x2c(%rbp), %r14
movq %r14, %rdi
addq %rbx, %rdi
movq %r15, %rsi
callq 0x2150
movq %r15, %rdi
callq 0x2080
addl %r14d, %eax
movl %eax, -0x2c(%rbp)
cltq
movb $0x0, (%rbx,%rax)
jmp 0x2594
movl $0x0, (%r14)
movl $0x4, %edx
movl %r12d, %edi
movq %r14, %rsi
xorl %ecx, %ecx
callq 0x20c0
movl $0x4, %edx
movl %r12d, %edi
movq %r14, %rsi
xorl %ecx, %ecx
callq 0x2070
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
cmpl $0x2, (%r14)
je 0x2594
movl $0x4, %edx
movl %r12d, %edi
movq -0x38(%rbp), %rsi
xorl %ecx, %ecx
callq 0x2070
movq %rbx, %rdi
callq 0x2080
decl %eax
movslq %eax, %rcx
cmpb $0x2f, (%rbx,%rcx)
jne 0x257a
cmpl $0x1, %eax
adcl $0x0, %eax
cltq
movb $0x0, (%rbx,%rax)
xorl %r13d, %r13d
movl %r13d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop