// File: /workspace/github_c_makefile_star2_O1/xiaowenhuyuehu[P]remote_access/src/core/session_mgr.c
// Function: alloc_new_session
char *alloc_new_session(int *socketfd)
{
    char *session_id = NULL; 
    int ret = 0;
    SESSION_ITEM  *item = NULL; 

    if(g_session_count >= DEFAULT_SESSION_COUNT){
        log_error("session is full ");
        return NULL;    
    }

    if(g_ht == NULL){
        log_error("session system is not ready, please retry ");
        return NULL;
    }

    item = malloc(sizeof(SESSION_ITEM));
    if(item == NULL){
        log_error("no memory to alloc space to store session item "); 
        return NULL;
    }
    item->sockfd = socketfd; 
    item->last_modify_time = 0;

    session_id = rand_string_alloc(DEFAULT_SESSION_LEN);
    if(session_id == NULL){
        log_error("failed to alloc new session for socketfd: %d ", *socketfd);
        free(item);
        return NULL;
    }

    ret = ht_add_lockless(g_ht, session_id, DEFAULT_SESSION_LEN, item, sizeof(SESSION_ITEM));
    if(ret != 0){
        log_error("failed to add mapping for socketfd: %d ", *socketfd);
        free(session_id);
        free(item);
        return NULL; 
    }
    log_debug("session id: %s, socketfd: %d\n", session_id, *socketfd);
    ++g_session_count;
    free(item);
    return session_id;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x10, %rsp
cmpl $0x20, 0x6961(%rip)     # 0xe7b0
jl 0x7e77
leaq 0x17d8(%rip), %rsi      # 0x9630
leaq 0x238e(%rip), %rdx      # 0xa1ed
leaq 0x23c0(%rip), %r8       # 0xa226
xorl %ebx, %ebx
movl $0x3, %edi
movl $0x57, %ecx
jmp 0x7f65
cmpq $0x0, 0x6929(%rip)      # 0xe7a8
je 0x7f21
movq %rdi, %r15
movl $0x10, %edi
callq 0x2150
testq %rax, %rax
je 0x7f44
movq %rax, %r14
movq %r15, (%rax)
movq $0x0, 0x8(%rax)
movl $0x40, %edi
callq 0x3b82
testq %rax, %rax
je 0x7f79
movq %rax, %rbx
movq 0x68e2(%rip), %rdi      # 0xe7a8
movq %rax, %rsi
movl $0x40, %edx
movq %r14, %rcx
movl $0x10, %r8d
callq 0x3e7e
movl (%r15), %r9d
testl %eax, %eax
je 0x7fa6
leaq 0x1742(%rip), %rsi      # 0x9630
leaq 0x22f8(%rip), %rdx      # 0xa1ed
leaq 0x23c4(%rip), %r8       # 0xa2c0
movl $0x3, %edi
movl $0x71, %ecx
xorl %eax, %eax
callq 0x4371
movq %rbx, %rdi
callq 0x2250
movq %r14, %rdi
callq 0x2250
xorl %ebx, %ebx
jmp 0x7f6c
leaq 0x1708(%rip), %rsi      # 0x9630
leaq 0x22be(%rip), %rdx      # 0xa1ed
leaq 0x2301(%rip), %r8       # 0xa237
xorl %ebx, %ebx
movl $0x3, %edi
movl $0x5c, %ecx
jmp 0x7f65
leaq 0x16e5(%rip), %rsi      # 0x9630
leaq 0x229b(%rip), %rdx      # 0xa1ed
leaq 0x2309(%rip), %r8       # 0xa262
xorl %ebx, %ebx
movl $0x3, %edi
movl $0x62, %ecx
xorl %eax, %eax
callq 0x4371
movq %rbx, %rax
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq
movl (%r15), %r9d
leaq 0x16ad(%rip), %rsi      # 0x9630
leaq 0x2263(%rip), %rdx      # 0xa1ed
leaq 0x2301(%rip), %r8       # 0xa292
xorl %ebx, %ebx
movl $0x3, %edi
movl $0x6a, %ecx
xorl %eax, %eax
callq 0x4371
jmp 0x7fd6
movl %r9d, (%rsp)
leaq 0x1053(%rip), %rsi      # 0x9004
leaq 0x2235(%rip), %rdx      # 0xa1ed
leaq 0x2329(%rip), %r8       # 0xa2e8
xorl %edi, %edi
movl $0x76, %ecx
movq %rbx, %r9
xorl %eax, %eax
callq 0x4371
incl 0x67da(%rip)            # 0xe7b0
movq %r14, %rdi
callq 0x2250
jmp 0x7f6c