// File: /workspace/github_c_makefile_star2_O1/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 0x3530
xorps %xmm0, %xmm0
movaps %xmm0, -0x50(%rbp)
movaps %xmm0, -0x60(%rbp)
movaps %xmm0, -0x70(%rbp)
movaps %xmm0, -0x80(%rbp)
leaq -0x2c(%rbp), %rsi
movl $0x4, %edx
movl %ebx, %edi
xorl %ecx, %ecx
callq 0x20a0
cmpl $-0x1, %eax
je 0x341a
movl -0x2c(%rbp), %edx
leaq -0x60(%rbp), %rsi
movl %ebx, %edi
callq 0x481c
cmpl $-0x1, %eax
je 0x341a
leaq -0x60(%rbp), %r14
leaq -0x3c(%rbp), %r15
leaq -0x2c(%rbp), %r12
movq -0x38(%rbp), %rsi
movq %r14, %rdi
callq 0x4e70
cmpl $0x1, %eax
je 0x32c2
cmpl $-0x1, %eax
je 0x341a
xorps %xmm0, %xmm0
movaps %xmm0, -0x50(%rbp)
movaps %xmm0, -0x60(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x4, %edx
movl %ebx, %edi
movq %r15, %rsi
movl $0x4000, %ecx           # imm = 0x4000
callq 0x2100
cmpl $-0x1, %eax
je 0x341a
movl $0x4, %edx
movl %ebx, %edi
movq %r12, %rsi
xorl %ecx, %ecx
callq 0x20a0
cmpl $-0x1, %eax
je 0x341a
movl -0x2c(%rbp), %edx
movl %ebx, %edi
movq %r14, %rsi
callq 0x481c
cmpl $-0x1, %eax
jne 0x3248
jmp 0x341a
leaq -0x3c(%rbp), %rsi
movl $0x1, (%rsi)
movl $0x4, %edx
movl %ebx, %edi
movl $0x4000, %ecx           # imm = 0x4000
callq 0x2100
cmpl $-0x1, %eax
je 0x341a
leaq -0x2c(%rbp), %rsi
movl $0x4, %edx
movl %ebx, %edi
xorl %ecx, %ecx
callq 0x20a0
cmpl $-0x1, %eax
je 0x341a
movl -0x2c(%rbp), %edx
leaq -0x80(%rbp), %rsi
movl %ebx, %edi
callq 0x481c
cmpl $-0x1, %eax
je 0x341a
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 0x3878
leaq -0x1b0(%rbp), %r14
xorl %ebx, %ebx
movl $0x100, %edx            # imm = 0x100
movq %r14, %rdi
xorl %esi, %esi
callq 0x2130
leaq -0x88(%rbp), %r12
movq $0x0, (%r12)
leaq -0x40(%rbp), %rcx
movl $0x0, (%rcx)
leaq -0x80(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
movq %r12, %rdx
callq 0x2230
movq (%r12), %rdi
callq 0x37e0
leaq 0x1fc7(%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 0x3970
movq (%r12), %rdi
callq 0x2210
movq -0x38(%rbp), %rdx
movq %r14, %rdi
movq %r13, %rsi
callq 0x3900
movl %eax, %r15d
leaq 0x1fc7(%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 0x3970
movq -0x38(%rbp), %rdx
movq %r14, %rdi
movl %r15d, %esi
callq 0x3808
movq -0x38(%rbp), %rcx
movq %r14, %rdi
movl %r15d, %esi
movl %eax, %edx
callq 0x4e18
movq -0x38(%rbp), %rdi
callq 0x2250
jmp 0x3426
movl %ebx, %edi
callq 0x2370
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movl %ebx, %eax
addq $0x188, %rsp            # imm = 0x188
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop