// File: /workspace/github_c_makefile_star2_O3/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, %r15
movl %edi, %r14d
leaq -0x38(%rbp), %rbx
movl %edx, (%rbx)
leaq -0x2c(%rbp), %rsi
movl $0x2, (%rsi)
xorl %r13d, %r13d
movl $0x4, %edx
xorl %ecx, %ecx
callq 0x20c0
leaq -0xc8(%rbp), %rsi
movq %r15, %rdi
callq 0x2150
leaq -0xb0(%rbp), %r12
movl $0x4, %edx
movl %r14d, %edi
movq %r12, %rsi
xorl %ecx, %ecx
callq 0x20c0
movl $0x4, %edx
movl %r14d, %edi
movq %rbx, %rsi
xorl %ecx, %ecx
callq 0x20c0
xorps %xmm0, %xmm0
leaq -0x150(%rbp), %rbx
movaps %xmm0, 0x70(%rbx)
movaps %xmm0, 0x60(%rbx)
movaps %xmm0, 0x50(%rbx)
movaps %xmm0, 0x40(%rbx)
movaps %xmm0, 0x30(%rbx)
movaps %xmm0, 0x20(%rbx)
movaps %xmm0, 0x10(%rbx)
movaps %xmm0, (%rbx)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2c10
movq %rbx, %rdi
callq 0x2080
leaq -0x34(%rbp), %rsi
movl %eax, (%rsi)
movl $0x4, %edx
movl %r14d, %edi
xorl %ecx, %ecx
callq 0x20c0
movq %rbx, %rdi
callq 0x2080
movl %r14d, %edi
movq %rbx, %rsi
movq %rax, %rdx
xorl %ecx, %ecx
callq 0x20c0
movl $0xf000, %eax           # imm = 0xF000
andl (%r12), %eax
cmpl $0x4000, %eax           # imm = 0x4000
jne 0x47db
leaq -0x30(%rbp), %rsi
movl $0x4, %edx
movl %r14d, %edi
xorl %ecx, %ecx
callq 0x2070
movq %r15, %rbx
movq %r15, %rdi
callq 0x2220
movq %rax, %r12
leaq -0x1150(%rbp), %rdi
movl $0x1000, %edx           # imm = 0x1000
xorl %esi, %esi
callq 0x20e0
movq %r12, %rdi
callq 0x2240
testq %rax, %rax
je 0x47d3
movq %rax, %r15
leaq -0x1150(%rbp), %r13
cmpb $0x2e, 0x13(%r15)
jne 0x478b
cmpb $0x0, 0x14(%r15)
je 0x47c3
cmpb $0x2e, 0x14(%r15)
jne 0x478b
cmpb $0x0, 0x15(%r15)
je 0x47c3
addq $0x13, %r15
movl $0x1000, %edx           # imm = 0x1000
movq %r13, %rdi
xorl %esi, %esi
callq 0x20e0
movq %r13, %rdi
leaq 0x905(%rip), %rsi       # 0x50ad
movq %rbx, %rdx
movq %r15, %rcx
xorl %eax, %eax
callq 0x2050
movl -0x30(%rbp), %edx
movl %r14d, %edi
movq %r13, %rsi
callq 0x4634
movq %r12, %rdi
callq 0x2240
movq %rax, %r15
testq %rax, %rax
jne 0x476f
xorl %r13d, %r13d
jmp 0x48b0
leaq -0x98(%rbp), %rbx
movl $0x8, %edx
movl %r14d, %edi
movq %rbx, %rsi
xorl %ecx, %ecx
callq 0x20c0
movq %r15, %r12
leaq -0x1150(%rbp), %r15
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%r15)
movaps %xmm0, (%r15)
movb $0x0, 0x20(%r15)
movl (%rbx), %edx
movq %r12, %rdi
movq %r15, %rsi
callq 0x2a8c
movl $0x20, %edx
movl %r14d, %edi
movq %r15, %rsi
xorl %ecx, %ecx
callq 0x20c0
leaq -0x2c(%rbp), %rbx
movl $0x4, %edx
movl %r14d, %edi
movq %rbx, %rsi
xorl %ecx, %ecx
callq 0x2070
cmpl $0x4, (%rbx)
jne 0x48b0
xorl %r13d, %r13d
movq %r12, %rdi
movl $0x2, %esi
xorl %eax, %eax
callq 0x2100
cmpl $-0x1, %eax
je 0x48c5
movl %eax, %ebx
leaq -0x2c(%rbp), %rsi
movl $0x1, (%rsi)
xorl %r13d, %r13d
movl $0x4, %edx
movl %r14d, %edi
xorl %ecx, %ecx
callq 0x20c0
movq -0x98(%rbp), %rcx
movl %r14d, %edi
movl %ebx, %esi
xorl %edx, %edx
callq 0x2230
cmpl $-0x1, %eax
je 0x48e8
leaq -0x2c(%rbp), %rsi
movl $0x4, %edx
movl %r14d, %edi
xorl %ecx, %ecx
callq 0x2070
movl %ebx, %edi
callq 0x22d0
movl %r13d, %eax
addq $0x1128, %rsp           # imm = 0x1128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r12, %rdi
callq 0x2130
leaq -0x2c(%rbp), %rsi
movl $0x0, (%rsi)
movl $0x4, %edx
movl %r14d, %edi
xorl %ecx, %ecx
callq 0x20c0
jmp 0x48b0
leaq 0x95d(%rip), %rdi       # 0x524c
callq 0x2130
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
jmp 0x48b0