// File: /workspace/github_c_makefile_star2_O0/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
subq $0x11a0, %rsp           # imm = 0x11A0
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl $0x2, -0x18(%rbp)
movl -0x8(%rbp), %edi
leaq -0x18(%rbp), %rsi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0x20d0
movq -0x10(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x2150
movl -0x8(%rbp), %edi
leaq -0xa8(%rbp), %rsi
addq $0x18, %rsi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0x20d0
movl -0x8(%rbp), %edi
leaq -0x14(%rbp), %rsi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0x20d0
leaq -0x130(%rbp), %rdi
xorl %esi, %esi
movl $0x80, %edx
callq 0x20f0
leaq -0x130(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x2e30
leaq -0x130(%rbp), %rdi
callq 0x2090
movl %eax, -0x134(%rbp)
movl -0x8(%rbp), %edi
leaq -0x134(%rbp), %rsi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0x20d0
movl -0x8(%rbp), %eax
movl %eax, -0x1194(%rbp)
leaq -0x130(%rbp), %rax
movq %rax, -0x1190(%rbp)
leaq -0x130(%rbp), %rdi
callq 0x2090
movl -0x1194(%rbp), %edi
movq -0x1190(%rbp), %rsi
movq %rax, %rdx
xorl %ecx, %ecx
callq 0x20d0
movl -0x90(%rbp), %eax
andl $0xf000, %eax           # imm = 0xF000
cmpl $0x4000, %eax           # imm = 0x4000
jne 0x54e4
movl -0x8(%rbp), %edi
leaq -0x138(%rbp), %rsi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0x2080
movq -0x10(%rbp), %rdi
callq 0x2220
movq %rax, -0x140(%rbp)
leaq -0x1150(%rbp), %rdi
xorl %esi, %esi
movl $0x1000, %edx           # imm = 0x1000
callq 0x20f0
movq -0x140(%rbp), %rdi
callq 0x2240
movq %rax, -0x148(%rbp)
cmpq $0x0, %rax
je 0x54d8
movq -0x148(%rbp), %rdi
addq $0x13, %rdi
leaq 0xba6(%rip), %rsi       # 0x6005
callq 0x21e0
cmpl $0x0, %eax
je 0x5485
movq -0x148(%rbp), %rdi
addq $0x13, %rdi
leaq 0xb89(%rip), %rsi       # 0x6004
callq 0x21e0
cmpl $0x0, %eax
jne 0x5487
jmp 0x5430
leaq -0x1150(%rbp), %rdi
xorl %esi, %esi
movl $0x1000, %edx           # imm = 0x1000
callq 0x20f0
leaq -0x1150(%rbp), %rdi
movq -0x10(%rbp), %rdx
movq -0x148(%rbp), %rcx
addq $0x13, %rcx
leaq 0xbfa(%rip), %rsi       # 0x60b1
movb $0x0, %al
callq 0x2060
movl -0x8(%rbp), %edi
leaq -0x1150(%rbp), %rsi
movl -0x138(%rbp), %edx
callq 0x52f0
jmp 0x5430
movl $0x0, -0x4(%rbp)
jmp 0x561e
movl -0x8(%rbp), %edi
leaq -0xa8(%rbp), %rsi
addq $0x30, %rsi
movl $0x8, %edx
xorl %ecx, %ecx
callq 0x20d0
leaq -0x1180(%rbp), %rdi
xorl %esi, %esi
movl $0x21, %edx
callq 0x20f0
movq -0x10(%rbp), %rdi
leaq -0x1180(%rbp), %rsi
movq -0x78(%rbp), %rax
movl %eax, %edx
callq 0x2c30
movl -0x8(%rbp), %edi
leaq -0x1180(%rbp), %rsi
movl $0x20, %edx
xorl %ecx, %ecx
callq 0x20d0
movl -0x8(%rbp), %edi
leaq -0x18(%rbp), %rsi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0x2080
cmpl $0x4, -0x18(%rbp)
jne 0x5617
movq -0x10(%rbp), %rdi
movl $0x2, %esi
movb $0x0, %al
callq 0x2100
movl %eax, -0x1184(%rbp)
cmpl $-0x1, -0x1184(%rbp)
jne 0x55a5
movq -0x10(%rbp), %rdi
callq 0x2130
movl $0x0, -0x18(%rbp)
movl -0x8(%rbp), %edi
leaq -0x18(%rbp), %rsi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0x20d0
movl $0x0, -0x4(%rbp)
jmp 0x561e
movl $0x1, -0x18(%rbp)
movl -0x8(%rbp), %edi
leaq -0x18(%rbp), %rsi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0x20d0
movl -0x8(%rbp), %edi
movl -0x1184(%rbp), %esi
movq -0x78(%rbp), %rcx
xorl %eax, %eax
movl %eax, %edx
callq 0x2230
movl %eax, -0x1188(%rbp)
cmpl $-0x1, -0x1188(%rbp)
jne 0x55f9
leaq 0xc51(%rip), %rdi       # 0x623c
callq 0x2130
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x561e
movl -0x8(%rbp), %edi
leaq -0x18(%rbp), %rsi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0x2080
movl -0x1184(%rbp), %edi
callq 0x22c0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x11a0, %rsp           # imm = 0x11A0
popq %rbp
retq