// File: /workspace/github_c_makefile_star2_O1/VeeeectorPan[P]MyNetdisk/clientSrc/upload.c
// Function: upload
int upload(int sock_fd,char* path,int parent_id)
{
    int ctl_num = MORE_FILE;
    send(sock_fd,&ctl_num,sizeof(int),0);
    struct stat st;
    stat(path,&st);
    send(sock_fd,&st.st_mode,sizeof(mode_t),0);
    send(sock_fd,&parent_id,sizeof(int),0);
    char dir_name[128] = {0};
    get_file_name(dir_name,path);
    int len = strlen(dir_name);
    send(sock_fd,&len,sizeof(int),0);
    send(sock_fd,dir_name,strlen(dir_name),0);
    if((st.st_mode & S_IFMT) == S_IFDIR)
    {
        int file_id;
        recv(sock_fd,&file_id,sizeof(int),0);
        DIR* pdir = opendir(path);
        struct dirent* file;
        char buf[4096] = {0};
        while((file = readdir(pdir)) != NULL)
        {
            if(strcmp(file->d_name,".") == 0 || strcmp(file->d_name,"..") == 0)
            {
                continue;
            }
            memset(buf,0,4096);
            sprintf(buf,"%s/%s",path,file->d_name);
            upload(sock_fd,buf,file_id);
        }
        return 0;
    }
    send(sock_fd,&st.st_size,sizeof(off_t),0);
    char md5[33] = {0};
    compute_file_md5(path,md5,st.st_size);
    send(sock_fd,md5,32,0);
    recv(sock_fd,&ctl_num,sizeof(int),0);
    if(ctl_num == PUT_NOT_EXIST)
    {
        int file_fd = open(path,O_RDWR);
        if(file_fd == -1)
        {
            perror(path);
            ctl_num = PUT_FAIL;
            send(sock_fd,&ctl_num,sizeof(int),0);
            return 0;
        }
        else
        {
            ctl_num = PUT_SUCCESS;
            send(sock_fd,&ctl_num,sizeof(int),0);
        }
        int ret = sendfile(sock_fd,file_fd,NULL,st.st_size);
        ERROR_CHECK(ret,-1,"sendfile");
        recv(sock_fd,&ctl_num,sizeof(int),0);
        close(file_fd);
    }
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1128, %rsp           # imm = 0x1128
movq %rsi, %r12
movl %edi, %ebx
leaq -0x40(%rbp), %r14
movl %edx, (%r14)
leaq -0x2c(%rbp), %rsi
movl $0x2, (%rsi)
movl $0x4, %edx
xorl %ecx, %ecx
callq 0x20c0
leaq -0xd0(%rbp), %rsi
movq %r12, %rdi
callq 0x2140
leaq -0xb8(%rbp), %r15
movl $0x4, %edx
movl %ebx, %edi
movq %r15, %rsi
xorl %ecx, %ecx
callq 0x20c0
movl $0x4, %edx
movl %ebx, %edi
movq %r14, %rsi
xorl %ecx, %ecx
callq 0x20c0
xorps %xmm0, %xmm0
leaq -0x150(%rbp), %r14
movaps %xmm0, 0x70(%r14)
movaps %xmm0, 0x60(%r14)
movaps %xmm0, 0x50(%r14)
movaps %xmm0, 0x40(%r14)
movaps %xmm0, 0x30(%r14)
movaps %xmm0, 0x20(%r14)
movaps %xmm0, 0x10(%r14)
movaps %xmm0, (%r14)
movq %r14, %rdi
movq %r12, %rsi
callq 0x2c44
movq %r14, %rdi
callq 0x2080
leaq -0x3c(%rbp), %rsi
movl %eax, (%rsi)
movl $0x4, %edx
movl %ebx, %edi
xorl %ecx, %ecx
callq 0x20c0
movq %r14, %rdi
callq 0x2080
movl %ebx, %edi
movq %r14, %rsi
movq %rax, %rdx
xorl %ecx, %ecx
callq 0x20c0
movl $0xf000, %eax           # imm = 0xF000
andl (%r15), %eax
cmpl $0x4000, %eax           # imm = 0x4000
jne 0x47b9
leaq -0x30(%rbp), %rsi
movl $0x4, %edx
movl %ebx, %edi
xorl %ecx, %ecx
callq 0x2070
movq %r12, -0x38(%rbp)
movq %r12, %rdi
callq 0x2210
movq %rax, %r12
leaq -0x1150(%rbp), %rdi
movl $0x1000, %edx           # imm = 0x1000
xorl %esi, %esi
callq 0x20e0
movq %r12, %rdi
callq 0x2230
testq %rax, %rax
je 0x4893
movq %rax, %r15
leaq 0x8c2(%rip), %r13       # 0x5005
leaq -0x1150(%rbp), %r14
addq $0x13, %r15
movq %r15, %rdi
movq %r13, %rsi
callq 0x21e0
testl %eax, %eax
je 0x47a4
movq %r15, %rdi
leaq 0x89d(%rip), %rsi       # 0x5004
callq 0x21e0
testl %eax, %eax
je 0x47a4
movl $0x1000, %edx           # imm = 0x1000
movq %r14, %rdi
xorl %esi, %esi
callq 0x20e0
movq %r14, %rdi
leaq 0x924(%rip), %rsi       # 0x50ad
movq -0x38(%rbp), %rdx
movq %r15, %rcx
xorl %eax, %eax
callq 0x2050
movl -0x30(%rbp), %edx
movl %ebx, %edi
movq %r14, %rsi
callq 0x4604
movq %r12, %rdi
callq 0x2230
movq %rax, %r15
testq %rax, %rax
jne 0x474a
jmp 0x4893
leaq -0xa0(%rbp), %r14
movl $0x8, %edx
movl %ebx, %edi
movq %r14, %rsi
xorl %ecx, %ecx
callq 0x20c0
leaq -0x1150(%rbp), %r15
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%r15)
movaps %xmm0, (%r15)
movb $0x0, 0x20(%r15)
movl (%r14), %edx
movq %r12, %rdi
movq %r15, %rsi
callq 0x2ac0
movl $0x20, %edx
movl %ebx, %edi
movq %r15, %rsi
xorl %ecx, %ecx
callq 0x20c0
leaq -0x2c(%rbp), %r14
movl $0x4, %edx
movl %ebx, %edi
movq %r14, %rsi
xorl %ecx, %ecx
callq 0x2070
cmpl $0x4, (%r14)
jne 0x4893
xorl %r15d, %r15d
movq %r12, %rdi
movl $0x2, %esi
xorl %eax, %eax
callq 0x20f0
cmpl $-0x1, %eax
je 0x48ab
movl %eax, %r14d
leaq -0x2c(%rbp), %rsi
movl $0x1, (%rsi)
movl $0x4, %edx
movl %ebx, %edi
xorl %ecx, %ecx
callq 0x20c0
movq -0xa0(%rbp), %rcx
movl %ebx, %edi
movl %r14d, %esi
xorl %edx, %edx
callq 0x2220
cmpl $-0x1, %eax
je 0x48cd
leaq -0x2c(%rbp), %rsi
movl $0x4, %edx
movl %ebx, %edi
xorl %ecx, %ecx
callq 0x2070
movl %r14d, %edi
callq 0x22c0
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
movb $0x1, %al
testb %al, %al
je 0x4896
xorl %r15d, %r15d
movl %r15d, %eax
addq $0x1128, %rsp           # imm = 0x1128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r12, %rdi
callq 0x2120
leaq -0x2c(%rbp), %rsi
movl $0x0, (%rsi)
movl $0x4, %edx
movl %ebx, %edi
xorl %ecx, %ecx
callq 0x20c0
jmp 0x48df
leaq 0x978(%rip), %rdi       # 0x524c
callq 0x2120
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
xorl %eax, %eax
jmp 0x488f