// File: /workspace/github_c_makefile_star2_O2/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, 0x5f1c(%rip)     # 0xd7c0
jl 0x78c7
leaq 0xd53(%rip), %rsi       # 0x8600
leaq 0x1909(%rip), %rdx      # 0x91bd
leaq 0x193b(%rip), %r8       # 0x91f6
xorl %ebx, %ebx
pushq $0x3
popq %rdi
pushq $0x57
jmp 0x799c
cmpq $0x0, 0x5ee9(%rip)      # 0xd7b8
je 0x7962
movq %rdi, %r15
pushq $0x10
popq %rdi
callq 0x2150
testq %rax, %rax
je 0x7980
movq %rax, %r14
movq %r15, (%rax)
andq $0x0, 0x8(%rax)
pushq $0x40
popq %rdi
callq 0x3981
testq %rax, %rax
je 0x79b1
movq %rax, %rbx
movq 0x5ea9(%rip), %rdi      # 0xd7b8
pushq $0x40
popq %rdx
pushq $0x10
popq %r8
movq %rax, %rsi
movq %r14, %rcx
callq 0x3bc3
movl (%r15), %r9d
testl %eax, %eax
je 0x79da
leaq 0xccd(%rip), %rsi       # 0x8600
leaq 0x1883(%rip), %rdx      # 0x91bd
leaq 0x194f(%rip), %r8       # 0x9290
pushq $0x3
popq %rdi
pushq $0x71
popq %rcx
xorl %eax, %eax
callq 0x403f
movq %rbx, %rdi
callq 0x2250
movq %r14, %rdi
callq 0x2250
xorl %ebx, %ebx
jmp 0x79a4
leaq 0xc97(%rip), %rsi       # 0x8600
leaq 0x184d(%rip), %rdx      # 0x91bd
leaq 0x1890(%rip), %r8       # 0x9207
xorl %ebx, %ebx
pushq $0x3
popq %rdi
pushq $0x5c
jmp 0x799c
leaq 0xc79(%rip), %rsi       # 0x8600
leaq 0x182f(%rip), %rdx      # 0x91bd
leaq 0x189d(%rip), %r8       # 0x9232
xorl %ebx, %ebx
pushq $0x3
popq %rdi
pushq $0x62
popq %rcx
xorl %eax, %eax
callq 0x403f
movq %rbx, %rax
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq
movl (%r15), %r9d
leaq 0xc45(%rip), %rsi       # 0x8600
leaq 0x17fb(%rip), %rdx      # 0x91bd
leaq 0x1899(%rip), %r8       # 0x9262
xorl %ebx, %ebx
pushq $0x3
popq %rdi
pushq $0x6a
popq %rcx
xorl %eax, %eax
callq 0x403f
jmp 0x7a08
movl %r9d, (%rsp)
leaq 0x61f(%rip), %rsi       # 0x8004
leaq 0x17d1(%rip), %rdx      # 0x91bd
leaq 0x18c5(%rip), %r8       # 0x92b8
pushq $0x76
popq %rcx
xorl %edi, %edi
movq %rbx, %r9
xorl %eax, %eax
callq 0x403f
incl 0x5db8(%rip)            # 0xd7c0
movq %r14, %rdi
callq 0x2250
jmp 0x79a4