// File: /workspace/github_c_makefile_star2_O0/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
subq $0x1c0, %rsp            # imm = 0x1C0
movl %edi, -0x8(%rbp)
leaq -0x10(%rbp), %rdi
callq 0x3c20
movl %eax, -0x14(%rbp)
leaq -0x40(%rbp), %rdi
xorl %esi, %esi
movl $0x20, %edx
callq 0x2140
leaq -0x60(%rbp), %rdi
xorl %esi, %esi
movl $0x20, %edx
callq 0x2140
movl -0x8(%rbp), %edi
leaq -0x64(%rbp), %rsi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0x20b0
movl %eax, -0x14(%rbp)
cmpl $-0x1, -0x14(%rbp)
jne 0x379a
movl -0x8(%rbp), %edi
callq 0x2380
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3ac4
movl -0x8(%rbp), %edi
leaq -0x40(%rbp), %rsi
movl -0x64(%rbp), %edx
callq 0x5cb0
movl %eax, -0x14(%rbp)
cmpl $-0x1, -0x14(%rbp)
jne 0x37c6
movl -0x8(%rbp), %edi
callq 0x2380
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3ac4
jmp 0x37c8
leaq -0x40(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x65c0
movl %eax, -0x14(%rbp)
cmpl $0x1, %eax
je 0x38a6
cmpl $-0x1, -0x14(%rbp)
jne 0x37fb
movl -0x8(%rbp), %edi
callq 0x2380
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3ac4
leaq -0x40(%rbp), %rdi
xorl %esi, %esi
movl $0x20, %edx
callq 0x2140
movl $0x0, -0x68(%rbp)
movl -0x8(%rbp), %edi
leaq -0x68(%rbp), %rsi
movl $0x4, %edx
movl $0x4000, %ecx           # imm = 0x4000
callq 0x2110
movl %eax, -0x14(%rbp)
cmpl $-0x1, -0x14(%rbp)
jne 0x3845
movl -0x8(%rbp), %edi
callq 0x2380
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3ac4
movl -0x8(%rbp), %edi
leaq -0x64(%rbp), %rsi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0x20b0
movl %eax, -0x14(%rbp)
cmpl $-0x1, -0x14(%rbp)
jne 0x3875
movl -0x8(%rbp), %edi
callq 0x2380
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3ac4
movl -0x8(%rbp), %edi
leaq -0x40(%rbp), %rsi
movl -0x64(%rbp), %edx
callq 0x5cb0
movl %eax, -0x14(%rbp)
cmpl $-0x1, -0x14(%rbp)
jne 0x38a1
movl -0x8(%rbp), %edi
callq 0x2380
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3ac4
jmp 0x37c8
movl $0x1, -0x68(%rbp)
movl -0x8(%rbp), %edi
leaq -0x68(%rbp), %rsi
movl $0x4, %edx
movl $0x4000, %ecx           # imm = 0x4000
callq 0x2110
movl %eax, -0x14(%rbp)
cmpl $-0x1, -0x14(%rbp)
jne 0x38e0
movl -0x8(%rbp), %edi
callq 0x2380
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3ac4
movl -0x8(%rbp), %edi
leaq -0x64(%rbp), %rsi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0x20b0
movl %eax, -0x14(%rbp)
cmpl $-0x1, -0x14(%rbp)
jne 0x3910
movl -0x8(%rbp), %edi
callq 0x2380
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3ac4
movl -0x8(%rbp), %edi
leaq -0x60(%rbp), %rsi
movl -0x64(%rbp), %edx
callq 0x5cb0
movl %eax, -0x14(%rbp)
cmpl $-0x1, -0x14(%rbp)
jne 0x393c
movl -0x8(%rbp), %edi
callq 0x2380
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3ac4
leaq -0x90(%rbp), %rdi
xorl %esi, %esi
movl $0x20, %edx
callq 0x2140
leaq -0x90(%rbp), %rdi
leaq 0x39fa(%rip), %rsi      # 0x7357
callq 0x21c0
leaq -0x90(%rbp), %rdi
addq $0x3, %rdi
callq 0x40c0
leaq -0x190(%rbp), %rdi
xorl %esi, %esi
movl $0x100, %edx            # imm = 0x100
callq 0x2140
movq $0x0, -0x198(%rbp)
movl $0x0, -0x19c(%rbp)
leaq -0x60(%rbp), %rdi
leaq -0x90(%rbp), %rsi
leaq -0x198(%rbp), %rdx
leaq -0x19c(%rbp), %rcx
callq 0x2240
leaq -0x190(%rbp), %rax
movq %rax, -0x1c0(%rbp)
leaq -0x40(%rbp), %rax
movq %rax, -0x1b8(%rbp)
leaq -0x90(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x1b0(%rbp)
movq -0x198(%rbp), %rdi
callq 0x3fc0
movq -0x1c0(%rbp), %rdi
movq -0x1b8(%rbp), %rdx
movq -0x1b0(%rbp), %rcx
movq %rax, %r8
leaq 0x394d(%rip), %rsi      # 0x735b
movb $0x0, %al
callq 0x2070
leaq -0x190(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x4250
movq -0x198(%rbp), %rdi
callq 0x2220
leaq -0x190(%rbp), %rdi
leaq -0x40(%rbp), %rsi
movq -0x10(%rbp), %rdx
callq 0x41a0
movl %eax, -0x1a0(%rbp)
leaq -0x190(%rbp), %rdi
movl -0x1a0(%rbp), %edx
movl -0x1a0(%rbp), %ecx
leaq 0x393b(%rip), %rsi      # 0x73a0
movb $0x0, %al
callq 0x2070
leaq -0x190(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x4250
leaq -0x190(%rbp), %rdi
movl -0x1a0(%rbp), %esi
movq -0x10(%rbp), %rdx
callq 0x4010
movl %eax, -0x1a4(%rbp)
leaq -0x190(%rbp), %rdi
movl -0x1a0(%rbp), %esi
movl -0x1a4(%rbp), %edx
movq -0x10(%rbp), %rcx
callq 0x6540
movq -0x10(%rbp), %rdi
callq 0x2260
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x1c0, %rsp            # imm = 0x1C0
popq %rbp
retq