// File: /workspace/github_c_makefile_star2_O0/back1127[P]linkedge-thing-access-websocket_client_sdk/sdk/ali_ws/wsc_buffer_mgmt.c
// Function: client_buf_mgmt_push
int client_buf_mgmt_push(const char *buf, size_t len, int msg_type)
{
	msg_buf_item *p_new_msg = NULL;
    char         *tmp = NULL;
    int           windex = 0;

    if(!buf || !g_ws_buf)
        return LE_ERROR_INVAILD_PARAM;

	pthread_mutex_lock(&g_ws_buf_state.locker);
    
    windex = g_ws_buf_state.wr_index;
	if (windex >= g_ws_buf_state.max_buf_cnt){
		g_ws_buf_state.wr_index = 0;
        windex = 0;
    }
    ++len;
    if(len > g_ws_buf_state.single_buf_size - LWS_PRE){
        tmp = realloc(g_ws_buf[windex].buf, len + LWS_PRE);    
        if(!tmp){
            printf("failed to alloc more memory to store msg\n");
            pthread_mutex_unlock(&g_ws_buf_state.locker);
            return LE_ERROR_ALLOCATING_MEM;
        }
        memset(tmp, 0, len + LWS_PRE);
        g_ws_buf[windex].buf = tmp;
    }

	memset(g_ws_buf[windex].buf, 0, g_ws_buf[windex].buf_len);
	memcpy(g_ws_buf[windex].buf + LWS_PRE, buf, len - 1);
	g_ws_buf[windex].buf[LWS_PRE + len - 1] = '\0';
	g_ws_buf[windex].buf_len = len;
	g_ws_buf[windex].type = msg_type;

	g_ws_buf_state.wr_index++;

	pthread_mutex_unlock(&g_ws_buf_state.locker);

    notify_network();
	return LE_SUCCESS;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x79ab
cmpq $0x0, 0xacd7(%rip)      # 0x12680
jne 0x79b7
movl $0x186a1, -0x4(%rbp)    # imm = 0x186A1
jmp 0x7b64
leaq 0xac8a(%rip), %rdi      # 0x12648
callq 0x4770
movl 0xacab(%rip), %eax      # 0x12674
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl 0xaca7(%rip), %eax      # 0x1267c
jl 0x79e8
movl $0x0, 0xac93(%rip)      # 0x12674
movl $0x0, -0x34(%rbp)
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movl 0xac7a(%rip), %ecx      # 0x12678
subl $0x10, %ecx
movslq %ecx, %rcx
cmpq %rcx, %rax
jbe 0x7a88
movq 0xac70(%rip), %rax      # 0x12680
movslq -0x34(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rsi
addq $0x10, %rsi
callq 0x47a0
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x7a5c
leaq 0x6c59(%rip), %rdi      # 0xe696
movb $0x0, %al
callq 0x4290
leaq 0xabfd(%rip), %rdi      # 0x12648
callq 0x4480
movl $0x186a2, -0x4(%rbp)    # imm = 0x186A2
jmp 0x7b64
movq -0x30(%rbp), %rdi
movq -0x18(%rbp), %rdx
addq $0x10, %rdx
xorl %esi, %esi
callq 0x4300
movq -0x30(%rbp), %rcx
movq 0xac06(%rip), %rax      # 0x12680
movslq -0x34(%rbp), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movq 0xabf1(%rip), %rax      # 0x12680
movslq -0x34(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rdi
movq 0xabdc(%rip), %rax      # 0x12680
movslq -0x34(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rdx
xorl %esi, %esi
callq 0x4300
movq 0xabbf(%rip), %rax      # 0x12680
movslq -0x34(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rdi
addq $0x10, %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
subq $0x1, %rdx
callq 0x4400
movq 0xab95(%rip), %rax      # 0x12680
movslq -0x34(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq -0x18(%rbp), %rcx
addq $0x10, %rcx
subq $0x1, %rcx
movb $0x0, (%rax,%rcx)
movq -0x18(%rbp), %rcx
movq 0xab6c(%rip), %rax      # 0x12680
movslq -0x34(%rbp), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movl -0x1c(%rbp), %ecx
movq 0xab53(%rip), %rax      # 0x12680
movslq -0x34(%rbp), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x10(%rax)
movl 0xab33(%rip), %eax      # 0x12674
addl $0x1, %eax
movl %eax, 0xab2a(%rip)      # 0x12674
leaq 0xaaf7(%rip), %rdi      # 0x12648
callq 0x4480
movb $0x0, %al
callq 0x4050
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)