// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movq $0x0, -0x28(%rbp)
cmpl $0x20, 0x63a6(%rip)     # 0x107e0
jl 0xa46f
movl $0x3, %edi
leaq 0x1198(%rip), %rsi      # 0xb5e0
leaq 0x1d4e(%rip), %rdx      # 0xc19d
movl $0x57, %ecx
leaq 0x1d7b(%rip), %r8       # 0xc1d6
movb $0x0, %al
callq 0x4f90
movq $0x0, -0x8(%rbp)
jmp 0xa624
cmpq $0x0, 0x6361(%rip)      # 0x107d8
jne 0xa4ac
movl $0x3, %edi
leaq 0x115b(%rip), %rsi      # 0xb5e0
leaq 0x1d11(%rip), %rdx      # 0xc19d
movl $0x5c, %ecx
leaq 0x1d4f(%rip), %r8       # 0xc1e7
movb $0x0, %al
callq 0x4f90
movq $0x0, -0x8(%rbp)
jmp 0xa624
movl $0x10, %edi
callq 0x2140
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0xa4f4
movl $0x3, %edi
leaq 0x1113(%rip), %rsi      # 0xb5e0
leaq 0x1cc9(%rip), %rdx      # 0xc19d
movl $0x62, %ecx
leaq 0x1d32(%rip), %r8       # 0xc212
movb $0x0, %al
callq 0x4f90
movq $0x0, -0x8(%rbp)
jmp 0xa624
movq -0x10(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movq -0x28(%rbp), %rax
movq $0x0, 0x8(%rax)
movl $0x40, %edi
callq 0x4310
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0xa563
movq -0x10(%rbp), %rax
movl (%rax), %r9d
movl $0x3, %edi
leaq 0x10ad(%rip), %rsi      # 0xb5e0
leaq 0x1c63(%rip), %rdx      # 0xc19d
movl $0x6a, %ecx
leaq 0x1cfc(%rip), %r8       # 0xc242
movb $0x0, %al
callq 0x4f90
movq -0x28(%rbp), %rdi
callq 0x2240
movq $0x0, -0x8(%rbp)
jmp 0xa624
movq 0x626e(%rip), %rdi      # 0x107d8
movq -0x18(%rbp), %rsi
movq -0x28(%rbp), %rcx
movl $0x40, %edx
movl $0x10, %r8d
callq 0x4740
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0xa5d4
movq -0x10(%rbp), %rax
movl (%rax), %r9d
movl $0x3, %edi
leaq 0x1042(%rip), %rsi      # 0xb5e0
leaq 0x1bf8(%rip), %rdx      # 0xc19d
movl $0x71, %ecx
leaq 0x1cbf(%rip), %r8       # 0xc270
movb $0x0, %al
callq 0x4f90
movq -0x18(%rbp), %rdi
callq 0x2240
movq -0x28(%rbp), %rdi
callq 0x2240
movq $0x0, -0x8(%rbp)
jmp 0xa624
movq -0x18(%rbp), %r9
movq -0x10(%rbp), %rax
movl (%rax), %eax
xorl %edi, %edi
leaq 0xa1d(%rip), %rsi       # 0xb004
leaq 0x1baf(%rip), %rdx      # 0xc19d
movl $0x76, %ecx
leaq 0x1c9e(%rip), %r8       # 0xc298
movl %eax, (%rsp)
movb $0x0, %al
callq 0x4f90
movl 0x61d6(%rip), %eax      # 0x107e0
addl $0x1, %eax
movl %eax, 0x61cd(%rip)      # 0x107e0
movq -0x28(%rbp), %rdi
callq 0x2240
movq -0x18(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x30, %rsp
popq %rbp
retq
nop