// File: /workspace/github_c_makefile_star2_O2/VeeeectorPan[P]MyNetdisk/SourceFile/client_register.c
// Function: client_register
int client_register(int client_fd)
{
    MYSQL* connect;
    int ret = connect_mysql(&connect);
    char user_name[32] = {0};
    char user_passwd[32] = {0};
    int length;

    // user_name check
    ret = recv(client_fd,&length,sizeof(int),0);
    DISCON_CHECK(ret,-1,client_fd);
    ret = recv_client_all(client_fd,user_name,length);
    DISCON_CHECK(ret,-1,client_fd);

    int flag;
    while((ret = user_name_avaiable(user_name,connect)) != 1)
    {
        DISCON_CHECK(ret,-1,client_fd);
        memset(user_name,0,sizeof(user_name));
        flag = USER_NAME_NO_AVAIABLE;
        ret = send(client_fd,&flag,sizeof(int),MSG_NOSIGNAL);
        DISCON_CHECK(ret,-1,client_fd);
        ret = recv(client_fd,&length,sizeof(int),0);
        DISCON_CHECK(ret,-1,client_fd);
        ret = recv_client_all(client_fd,user_name,length);
        DISCON_CHECK(ret,-1,client_fd);
    }
    flag = USER_NAME_AVAIABLE;
    ret = send(client_fd,&flag,sizeof(int),MSG_NOSIGNAL);
    DISCON_CHECK(ret,-1,client_fd);


    // user_passwd no check
    ret = recv(client_fd,&length,sizeof(int),0);
    DISCON_CHECK(ret,-1,client_fd);
    ret = recv_client_all(client_fd,user_passwd,length);
    DISCON_CHECK(ret,-1,client_fd);

    char salt[32] = {0};
    strcpy(salt,"$6$");
    get_salt(salt + 3);

    char mysql_oper[256] = {0};

    void* crybuf = NULL;
    int cry_size = 0;
    crypt_ra(user_passwd,salt,&crybuf,&cry_size);
    sprintf(mysql_oper,"insert into User(user_name,salt,cryptpasswd) values('%s','%s','%s');"
            ,user_name,salt + 3,get_crypt_passwd((const char*)crybuf));
    insert_to_mysql(mysql_oper,connect);
    free(crybuf);
    int user_id = get_user_id(mysql_oper,user_name,connect);

    sprintf(mysql_oper,"insert into File(parent_id,file_name,user_id,file_type) values(0,'%d_dir',%d,'d')"
            ,user_id,user_id);
    insert_to_mysql(mysql_oper,connect);

    int file_id = get_file_id(mysql_oper,user_id,connect);
    update_user_table(mysql_oper,user_id,file_id,connect);

    mysql_close(connect);
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x188, %rsp            # imm = 0x188
movl %edi, %ebx
leaq -0x38(%rbp), %rdi
callq 0x3434
xorps %xmm0, %xmm0
movaps %xmm0, -0x50(%rbp)
movaps %xmm0, -0x60(%rbp)
movaps %xmm0, -0x70(%rbp)
movaps %xmm0, -0x80(%rbp)
leaq -0x2c(%rbp), %rsi
pushq $0x4
popq %rdx
movl %ebx, %edi
xorl %ecx, %ecx
callq 0x20a0
cmpl $-0x1, %eax
je 0x331f
movl -0x2c(%rbp), %edx
leaq -0x60(%rbp), %rsi
movl %ebx, %edi
callq 0x45cc
cmpl $-0x1, %eax
je 0x331f
leaq -0x60(%rbp), %r14
leaq -0x3c(%rbp), %r15
pushq $0x4
popq %r12
leaq -0x2c(%rbp), %r13
movq -0x38(%rbp), %rsi
movq %r14, %rdi
callq 0x4c0c
cmpl $0x1, %eax
je 0x31d1
cmpl $-0x1, %eax
je 0x331f
xorps %xmm0, %xmm0
movaps %xmm0, -0x50(%rbp)
movaps %xmm0, -0x60(%rbp)
andl $0x0, -0x3c(%rbp)
movl %ebx, %edi
movq %r15, %rsi
movq %r12, %rdx
movl $0x4000, %ecx           # imm = 0x4000
callq 0x2100
cmpl $-0x1, %eax
je 0x331f
movl %ebx, %edi
movq %r13, %rsi
movq %r12, %rdx
xorl %ecx, %ecx
callq 0x20a0
cmpl $-0x1, %eax
je 0x331f
movl -0x2c(%rbp), %edx
movl %ebx, %edi
movq %r14, %rsi
callq 0x45cc
cmpl $-0x1, %eax
jne 0x315e
jmp 0x331f
leaq -0x3c(%rbp), %rsi
movl $0x1, (%rsi)
pushq $0x4
popq %rdx
movl %ebx, %edi
movl $0x4000, %ecx           # imm = 0x4000
callq 0x2100
cmpl $-0x1, %eax
je 0x331f
leaq -0x2c(%rbp), %rsi
pushq $0x4
popq %rdx
movl %ebx, %edi
xorl %ecx, %ecx
callq 0x20a0
cmpl $-0x1, %eax
je 0x331f
movl -0x2c(%rbp), %edx
leaq -0x80(%rbp), %rsi
movl %ebx, %edi
callq 0x45cc
cmpl $-0x1, %eax
je 0x331f
xorps %xmm0, %xmm0
leaq -0xad(%rbp), %r15
movaps %xmm0, -0x3(%r15)
movaps %xmm0, 0xd(%r15)
movl $0x243624, -0x3(%r15)   # imm = 0x243624
movq %r15, %rdi
callq 0x3764
leaq -0x1b0(%rbp), %r14
xorl %ebx, %ebx
movl $0x100, %edx            # imm = 0x100
movq %r14, %rdi
xorl %esi, %esi
callq 0x2130
leaq -0x88(%rbp), %r12
andq $0x0, (%r12)
leaq -0x40(%rbp), %rcx
andl $0x0, (%rcx)
leaq -0x80(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
movq %r12, %rdx
callq 0x2240
movq (%r12), %rdi
callq 0x36d0
leaq 0x20c2(%rip), %rsi      # 0x5357
leaq -0x60(%rbp), %r13
movq %r14, %rdi
movq %r13, %rdx
movq %r15, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0x2060
movq -0x38(%rbp), %rsi
movq %r14, %rdi
callq 0x384c
movq (%r12), %rdi
callq 0x2220
movq -0x38(%rbp), %rdx
movq %r14, %rdi
movq %r13, %rsi
callq 0x37dc
movl %eax, %r15d
leaq 0x20c2(%rip), %rsi      # 0x539c
movq %r14, %rdi
movl %eax, %edx
movl %eax, %ecx
xorl %eax, %eax
callq 0x2060
movq -0x38(%rbp), %rsi
movq %r14, %rdi
callq 0x384c
movq -0x38(%rbp), %rdx
movq %r14, %rdi
movl %r15d, %esi
callq 0x36f8
movq -0x38(%rbp), %rcx
movq %r14, %rdi
movl %r15d, %esi
movl %eax, %edx
callq 0x4bb8
movq -0x38(%rbp), %rdi
callq 0x2260
jmp 0x3329
movl %ebx, %edi
callq 0x2380
pushq $-0x1
popq %rbx
movl %ebx, %eax
addq $0x188, %rsp            # imm = 0x188
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)