// File: /workspace/github_c_makefile_star2_O3/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, 0x690b(%rip)     # 0xe7c0
jl 0x7edd
leaq 0x1762(%rip), %rsi      # 0x9620
leaq 0x2318(%rip), %rdx      # 0xa1dd
leaq 0x234a(%rip), %r8       # 0xa216
xorl %ebx, %ebx
movl $0x3, %edi
movl $0x57, %ecx
jmp 0x7fcb
cmpq $0x0, 0x68d3(%rip)      # 0xe7b8
je 0x7f87
movq %rdi, %r15
movl $0x10, %edi
callq 0x2150
testq %rax, %rax
je 0x7faa
movq %rax, %r14
movq %r15, (%rax)
movq $0x0, 0x8(%rax)
movl $0x40, %edi
callq 0x3a96
testq %rax, %rax
je 0x7fdf
movq %rax, %rbx
movq 0x688c(%rip), %rdi      # 0xe7b8
movq %rax, %rsi
movl $0x40, %edx
movq %r14, %rcx
movl $0x10, %r8d
callq 0x3d9f
movl (%r15), %r9d
testl %eax, %eax
je 0x800c
leaq 0x16cc(%rip), %rsi      # 0x9620
leaq 0x2282(%rip), %rdx      # 0xa1dd
leaq 0x234e(%rip), %r8       # 0xa2b0
movl $0x3, %edi
movl $0x71, %ecx
xorl %eax, %eax
callq 0x42c5
movq %rbx, %rdi
callq 0x2250
movq %r14, %rdi
callq 0x2250
xorl %ebx, %ebx
jmp 0x7fd2
leaq 0x1692(%rip), %rsi      # 0x9620
leaq 0x2248(%rip), %rdx      # 0xa1dd
leaq 0x228b(%rip), %r8       # 0xa227
xorl %ebx, %ebx
movl $0x3, %edi
movl $0x5c, %ecx
jmp 0x7fcb
leaq 0x166f(%rip), %rsi      # 0x9620
leaq 0x2225(%rip), %rdx      # 0xa1dd
leaq 0x2293(%rip), %r8       # 0xa252
xorl %ebx, %ebx
movl $0x3, %edi
movl $0x62, %ecx
xorl %eax, %eax
callq 0x42c5
movq %rbx, %rax
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq
movl (%r15), %r9d
leaq 0x1637(%rip), %rsi      # 0x9620
leaq 0x21ed(%rip), %rdx      # 0xa1dd
leaq 0x228b(%rip), %r8       # 0xa282
xorl %ebx, %ebx
movl $0x3, %edi
movl $0x6a, %ecx
xorl %eax, %eax
callq 0x42c5
jmp 0x803c
movl %r9d, (%rsp)
leaq 0xfed(%rip), %rsi       # 0x9004
leaq 0x21bf(%rip), %rdx      # 0xa1dd
leaq 0x22b3(%rip), %r8       # 0xa2d8
xorl %edi, %edi
movl $0x76, %ecx
movq %rbx, %r9
xorl %eax, %eax
callq 0x42c5
incl 0x6784(%rip)            # 0xe7c0
movq %r14, %rdi
callq 0x2250
jmp 0x7fd2