// File: /workspace/github_c_makefile_star2_O0/VeeeectorPan[P]MyNetdisk/SourceFile/client_put.c
// Function: client_put
int client_put(int client_fd)
{
    MYSQL* connect;
    connect_mysql(&connect);
    int user_id;
    int ret = recv(client_fd,&user_id,sizeof(int),0);
    DISCON_CHECK(ret,0,client_fd);
    int file_id;
    recv(client_fd,&file_id,sizeof(int),0);
    DISCON_CHECK(ret,0,client_fd);
    int len;
    ret = recv(client_fd,&len,sizeof(int),0);
    DISCON_CHECK(ret,0,client_fd);
    char file_name[128] = {0};
    ret = recv_client_all(client_fd,file_name,len);
    DISCON_CHECK(ret,-1,client_fd);
    char mysql_oper[256] = {0};
    sprintf(mysql_oper,"select * from File where parent_id='%d' and file_name='%s' and user_id='%d'"
            ,file_id,file_name,user_id);
    MYSQL_RES* res = query(mysql_oper,connect);
    MYSQL_ROW row = mysql_fetch_row(res);
    int ctl_num;
    if(row == NULL)
    {
        ctl_num = PUT_SUCCESS;
    }
    else
    {
        ctl_num = PUT_FAIL;
    }
    mysql_free_result(res);
    ret = send(client_fd,&ctl_num,sizeof(int),MSG_NOSIGNAL);
    DISCON_CHECK(ret,-1,client_fd);
    // upload 
    while(1)
    {
        ret = recv(client_fd,&ctl_num,sizeof(int),0);
        DISCON_CHECK(ret,0,client_fd);
        if(ctl_num == NO_MORE_FILE)
            break;
        int parent_id;
        mode_t mode;
        ret = recv(client_fd,&mode,sizeof(mode_t),0);
        DISCON_CHECK(ret,0,client_fd);
        ret = recv(client_fd,&parent_id,sizeof(int),0);
        DISCON_CHECK(ret,0,client_fd);
        ret = recv(client_fd,&len,sizeof(int),0);
        DISCON_CHECK(ret,0,client_fd);
        ret= recv_client_all(client_fd,file_name,len);
        DISCON_CHECK(ret,-1,client_fd);
        file_name[len] = '\0';
        if((mode & S_IFMT) == S_IFDIR)
        {
            sprintf(mysql_oper,"insert into File(user_id,parent_id,file_name,file_type) values(%d,%d,'%s','d');"
                    ,user_id,parent_id,file_name);
            insert_to_mysql(mysql_oper,connect);
            sprintf(mysql_oper,"select file_id from File where file_name='%s' and user_id=%d and parent_id=%d;"
                    ,file_name,user_id,parent_id);
            res = query(mysql_oper,connect);
            row = mysql_fetch_row(res);
            int new_dir_id = atoi(row[0]);
            mysql_free_result(res);
            ret = send(client_fd,&new_dir_id,sizeof(int),0);
            DISCON_CHECK(ret,0,client_fd);
            continue;
        }
        off_t file_size;
        ret = recv(client_fd,&file_size,sizeof(off_t),0);
        DISCON_CHECK(ret,0,client_fd);
        char md5[33] = {0};
        ret = recv_client_all(client_fd,md5,32);
        DISCON_CHECK(ret,-1,client_fd);
        sprintf(mysql_oper,"select * from File where md5='%s';",md5);
        res = query(mysql_oper,connect);
        row = mysql_fetch_row(res);
        if(row == NULL)
        {
            ctl_num = PUT_NOT_EXIST;
        }
        else
        {
            ctl_num = PUT_EXIST;
        }
        mysql_free_result(res);
        sprintf(mysql_oper,"insert into File(parent_id,file_name,user_id,md5,file_size,file_type) values(%d,'%s',%d,'%s',%ld,'f');"
                ,parent_id,file_name,user_id,md5,file_size);
        insert_to_mysql(mysql_oper,connect);
        ret = send(client_fd,&ctl_num,sizeof(int),MSG_NOSIGNAL);
        DISCON_CHECK(ret,-1,client_fd);
        printf("ctl_num = %d\n",ctl_num);
        if(ctl_num == PUT_EXIST)
        {
            printf("hi");
            continue;
        }
        ret = recv(client_fd,&ctl_num,sizeof(int),0);
        DISCON_CHECK(ret,0,client_fd);
        if(ctl_num != PUT_SUCCESS)
        {
            sprintf(mysql_oper,"delete from File where parent_id=%d and file_name='%s';"
                    ,parent_id,file_name);
            insert_to_mysql(mysql_oper,connect);
            continue;
        }
        char file_path[4096] = {0};
        sprintf(file_path,"%s/%s",FILE_STORE_PATH,md5);
        int file_fd = open(file_path,O_RDWR|O_CREAT|O_EXCL,mode);
        DISCON_CHECK(file_fd,-1,client_fd);
        ret = recv_user_file(client_fd,file_fd,file_size);
        DISCON_CHECK(ret,-1,client_fd);
        close(file_fd);
        ret = send(client_fd,&ctl_num,sizeof(int),MSG_NOSIGNAL);
        DISCON_CHECK(ret,-1,client_fd);
    }
    close(client_fd);
    mysql_close(connect);
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1200, %rsp           # imm = 0x1200
movl %edi, -0x8(%rbp)
leaq -0x10(%rbp), %rdi
callq 0x3c20
movl -0x8(%rbp), %edi
leaq -0x14(%rbp), %rsi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0x20b0
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
jne 0x3097
movl -0x8(%rbp), %edi
callq 0x2380
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3706
movl -0x8(%rbp), %edi
leaq -0x1c(%rbp), %rsi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0x20b0
cmpl $0x0, -0x18(%rbp)
jne 0x30c4
movl -0x8(%rbp), %edi
callq 0x2380
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3706
movl -0x8(%rbp), %edi
leaq -0x20(%rbp), %rsi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0x20b0
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
jne 0x30f4
movl -0x8(%rbp), %edi
callq 0x2380
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3706
leaq -0xa0(%rbp), %rdi
xorl %esi, %esi
movl $0x80, %edx
callq 0x2140
movl -0x8(%rbp), %edi
leaq -0xa0(%rbp), %rsi
movl -0x20(%rbp), %edx
callq 0x5cb0
movl %eax, -0x18(%rbp)
cmpl $-0x1, -0x18(%rbp)
jne 0x3136
movl -0x8(%rbp), %edi
callq 0x2380
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3706
leaq -0x1a0(%rbp), %rdi
xorl %esi, %esi
movl $0x100, %edx            # imm = 0x100
callq 0x2140
leaq -0x1a0(%rbp), %rdi
movl -0x1c(%rbp), %edx
leaq -0xa0(%rbp), %rcx
movl -0x14(%rbp), %r8d
leaq 0x4017(%rip), %rsi      # 0x717c
movb $0x0, %al
callq 0x2070
leaq -0x1a0(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x59e0
movq %rax, -0x1a8(%rbp)
movq -0x1a8(%rbp), %rdi
callq 0x2200
movq %rax, -0x1b0(%rbp)
cmpq $0x0, -0x1b0(%rbp)
jne 0x31ac
movl $0x1, -0x1b4(%rbp)
jmp 0x31b6
movl $0x0, -0x1b4(%rbp)
movq -0x1a8(%rbp), %rdi
callq 0x21f0
movl -0x8(%rbp), %edi
leaq -0x1b4(%rbp), %rsi
movl $0x4, %edx
movl $0x4000, %ecx           # imm = 0x4000
callq 0x2110
movl %eax, -0x18(%rbp)
cmpl $-0x1, -0x18(%rbp)
jne 0x31f8
movl -0x8(%rbp), %edi
callq 0x2380
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3706
jmp 0x31fa
movl -0x8(%rbp), %edi
leaq -0x1b4(%rbp), %rsi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0x20b0
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
jne 0x322d
movl -0x8(%rbp), %edi
callq 0x2380
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3706
cmpl $0x3, -0x1b4(%rbp)
jne 0x323b
jmp 0x36ee
movl -0x8(%rbp), %edi
leaq -0x1bc(%rbp), %rsi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0x20b0
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
jne 0x326e
movl -0x8(%rbp), %edi
callq 0x2380
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3706
movl -0x8(%rbp), %edi
leaq -0x1b8(%rbp), %rsi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0x20b0
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
jne 0x32a1
movl -0x8(%rbp), %edi
callq 0x2380
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3706
movl -0x8(%rbp), %edi
leaq -0x20(%rbp), %rsi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0x20b0
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
jne 0x32d1
movl -0x8(%rbp), %edi
callq 0x2380
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3706
movl -0x8(%rbp), %edi
leaq -0xa0(%rbp), %rsi
movl -0x20(%rbp), %edx
callq 0x5cb0
movl %eax, -0x18(%rbp)
cmpl $-0x1, -0x18(%rbp)
jne 0x3300
movl -0x8(%rbp), %edi
callq 0x2380
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3706
movslq -0x20(%rbp), %rax
movb $0x0, -0xa0(%rbp,%rax)
movl -0x1bc(%rbp), %eax
andl $0xf000, %eax           # imm = 0xF000
cmpl $0x4000, %eax           # imm = 0x4000
jne 0x3400
leaq -0x1a0(%rbp), %rdi
movl -0x14(%rbp), %edx
movl -0x1b8(%rbp), %ecx
leaq -0xa0(%rbp), %r8
leaq 0x3e88(%rip), %rsi      # 0x71c8
movb $0x0, %al
callq 0x2070
leaq -0x1a0(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x4250
leaq -0x1a0(%rbp), %rdi
leaq -0xa0(%rbp), %rdx
movl -0x14(%rbp), %ecx
movl -0x1b8(%rbp), %r8d
leaq 0x3ea2(%rip), %rsi      # 0x7218
movb $0x0, %al
callq 0x2070
leaq -0x1a0(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x59e0
movq %rax, -0x1a8(%rbp)
movq -0x1a8(%rbp), %rdi
callq 0x2200
movq %rax, -0x1b0(%rbp)
movq -0x1b0(%rbp), %rax
movq (%rax), %rdi
callq 0x2310
movl %eax, -0x1c0(%rbp)
movq -0x1a8(%rbp), %rdi
callq 0x21f0
movl -0x8(%rbp), %edi
leaq -0x1c0(%rbp), %rsi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0x2110
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
jne 0x33fb
movl -0x8(%rbp), %edi
callq 0x2380
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3706
jmp 0x31fa
movl -0x8(%rbp), %edi
leaq -0x1c8(%rbp), %rsi
movl $0x8, %edx
xorl %ecx, %ecx
callq 0x20b0
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
jne 0x3433
movl -0x8(%rbp), %edi
callq 0x2380
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3706
leaq -0x1f0(%rbp), %rdi
xorl %esi, %esi
movl $0x21, %edx
callq 0x2140
movl -0x8(%rbp), %edi
leaq -0x1f0(%rbp), %rsi
movl $0x20, %edx
callq 0x5cb0
movl %eax, -0x18(%rbp)
cmpl $-0x1, -0x18(%rbp)
jne 0x3477
movl -0x8(%rbp), %edi
callq 0x2380
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3706
leaq -0x1a0(%rbp), %rdi
leaq -0x1f0(%rbp), %rdx
leaq 0x3ddb(%rip), %rsi      # 0x7267
movb $0x0, %al
callq 0x2070
leaq -0x1a0(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x59e0
movq %rax, -0x1a8(%rbp)
movq -0x1a8(%rbp), %rdi
callq 0x2200
movq %rax, -0x1b0(%rbp)
cmpq $0x0, -0x1b0(%rbp)
jne 0x34d3
movl $0x4, -0x1b4(%rbp)
jmp 0x34dd
movl $0x5, -0x1b4(%rbp)
movq -0x1a8(%rbp), %rdi
callq 0x21f0
leaq -0x1a0(%rbp), %rdi
movl -0x1b8(%rbp), %edx
leaq -0xa0(%rbp), %rcx
movl -0x14(%rbp), %r8d
leaq -0x1f0(%rbp), %r9
movq -0x1c8(%rbp), %rax
leaq 0x3d74(%rip), %rsi      # 0x728a
movq %rax, (%rsp)
movb $0x0, %al
callq 0x2070
leaq -0x1a0(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x4250
movl -0x8(%rbp), %edi
leaq -0x1b4(%rbp), %rsi
movl $0x4, %edx
movl $0x4000, %ecx           # imm = 0x4000
callq 0x2110
movl %eax, -0x18(%rbp)
cmpl $-0x1, -0x18(%rbp)
jne 0x3567
movl -0x8(%rbp), %edi
callq 0x2380
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3706
movl -0x1b4(%rbp), %esi
leaq 0x3d7d(%rip), %rdi      # 0x72f1
movb $0x0, %al
callq 0x2040
cmpl $0x5, -0x1b4(%rbp)
jne 0x3597
leaq 0x3d74(%rip), %rdi      # 0x72ff
movb $0x0, %al
callq 0x2040
jmp 0x31fa
movl -0x8(%rbp), %edi
leaq -0x1b4(%rbp), %rsi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0x20b0
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
jne 0x35ca
movl -0x8(%rbp), %edi
callq 0x2380
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3706
cmpl $0x1, -0x1b4(%rbp)
je 0x360a
leaq -0x1a0(%rbp), %rdi
movl -0x1b8(%rbp), %edx
leaq -0xa0(%rbp), %rcx
leaq 0x3d14(%rip), %rsi      # 0x7302
movb $0x0, %al
callq 0x2070
leaq -0x1a0(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x4250
jmp 0x31fa
leaq -0x11f0(%rbp), %rdi
xorl %esi, %esi
movl $0x1000, %edx           # imm = 0x1000
callq 0x2140
leaq -0x11f0(%rbp), %rdi
leaq -0x1f0(%rbp), %rcx
leaq 0x3d08(%rip), %rsi      # 0x733a
leaq 0x3d07(%rip), %rdx      # 0x7340
movb $0x0, %al
callq 0x2070
leaq -0x11f0(%rbp), %rdi
movl -0x1bc(%rbp), %edx
movl $0xc2, %esi
movb $0x0, %al
callq 0x2160
movl %eax, -0x11f4(%rbp)
cmpl $-0x1, -0x11f4(%rbp)
jne 0x367c
movl -0x8(%rbp), %edi
callq 0x2380
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3706
movl -0x8(%rbp), %edi
movl -0x11f4(%rbp), %esi
movq -0x1c8(%rbp), %rdx
callq 0x5da0
movl %eax, -0x18(%rbp)
cmpl $-0x1, -0x18(%rbp)
jne 0x36ab
movl -0x8(%rbp), %edi
callq 0x2380
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3706
movl -0x11f4(%rbp), %edi
callq 0x2380
movl -0x8(%rbp), %edi
leaq -0x1b4(%rbp), %rsi
movl $0x4, %edx
movl $0x4000, %ecx           # imm = 0x4000
callq 0x2110
movl %eax, -0x18(%rbp)
cmpl $-0x1, -0x18(%rbp)
jne 0x36e9
movl -0x8(%rbp), %edi
callq 0x2380
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3706
jmp 0x31fa
movl -0x8(%rbp), %edi
callq 0x2380
movq -0x10(%rbp), %rdi
callq 0x2260
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x1200, %rsp           # imm = 0x1200
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax)