// File: /workspace/github_c_makefile_star2_O3/qq-smart[P]qq_sh_server/app/qq_wifi_device.c
// Function: qq_wifi_device_pretreatment_process_handler
static void
qq_wifi_device_pretreatment_process_handler(qq_event_t *rev)
{
    qq_connection_t        *c;
    ssize_t                 n;
    size_t                  size;
    qq_wifi_device_t       *wd;
    qq_listening_t         *ls;
    cJSON                  *root, *cmd;

    qq_log_debug("qq_wifi_device_pretreatment_process_handler()");

    c = rev->data;
    ls = c->listening;

    if (rev->timedout) {
        qq_log_debug("timeout");
        qq_app_close_connection(c);
        return;
    }

    if (c->close) {
        qq_app_close_connection(c);
        return;
    }

    wd = c->data;
    if (wd == NULL) {
        wd = qq_pcalloc(c->pool, sizeof(qq_wifi_device_t));
        if (wd == NULL) {
            qq_app_close_connection(c);
            return;
        }
        c->data = (void *) wd;

        size = ls->pool_size -
            ((size_t)((uintptr_t)c->data - (uintptr_t)c->pool) + sizeof(qq_wifi_device_t));
        wd->buf = qq_pnalloc(c->pool, size);
        if (wd->buf == NULL) {
            qq_app_close_connection(c);
            return;
        }
        wd->buf_size = size;
    }

    n = c->recv(c, wd->buf, wd->buf_size);
    if (n == QQ_AGAIN) {
        qq_log_debug("recv not reday");
        return;
    }

    if (n == QQ_ERROR) {
        qq_app_close_connection(c);
        return;
    }

    if (n == 0) {
        qq_app_close_connection(c);
        return;
    }

    wd->buf_ndata = n;

    root = cJSON_Parse(wd->buf);
    if(root == NULL) {
        qq_log_error(0, "qq_wifi_device_process_connection_package()->cJSON_Parse() failed, before: %s",
            cJSON_GetErrorPtr());
    }
    else {
        cmd = cJSON_GetObjectItem(root, QQ_PKG_KEY_CMD);
        if (cmd != NULL && cmd->type == cJSON_String) {
            if (strcmp(cmd->valuestring, QQ_PKG_VALUE_CMD_CONN) == 0) {
                qq_wifi_device_connection_package_process(c, root);
            }
            else {
                if (wd->connection && strcmp(cmd->valuestring, QQ_PKG_VALUE_CMD_DEV_REPORT_STA) == 0) {
                    qq_wifi_device_status_package_process(c, root);
                }
            }
        }
        cJSON_Delete(root);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rdi, %r14
leaq 0x2376(%rip), %rdi      # 0xb275
xorl %eax, %eax
callq 0x6c74
movq (%r14), %rbx
testb $0x4, 0x9(%r14)
jne 0x8f5d
testb $0x20, 0x98(%rbx)
jne 0x8f6b
movq (%rbx), %r14
testq %r14, %r14
je 0x8f7b
movq 0x8(%r14), %rsi
movq 0x10(%r14), %r15
movq %rbx, %rdi
movq %r15, %rdx
callq *0x28(%rbx)
testq %rax, %rax
je 0x8f6b
cmpq $-0x1, %rax
je 0x8f6b
cmpq $-0x2, %rax
jne 0x8fcb
leaq 0x2355(%rip), %rdi      # 0xb2a3
xorl %eax, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x6c74
leaq 0x1562(%rip), %rdi      # 0xa4c6
xorl %eax, %eax
callq 0x6c74
movq %rbx, %rdi
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x26a2
movq 0x38(%rbx), %r15
movq 0x40(%rbx), %rdi
movl $0x120, %esi            # imm = 0x120
callq 0x7d16
testq %rax, %rax
je 0x8f6b
movq %rax, %r14
movq %rax, (%rbx)
movq 0x50(%r15), %rax
movq 0x40(%rbx), %rdi
subq %r14, %rax
leaq (%rax,%rdi), %r15
addq $-0x120, %r15           # imm = 0xFEE0
movq %r15, %rsi
callq 0x7cf7
movq %rax, 0x8(%r14)
testq %rax, %rax
je 0x8f6b
movq %rax, %rsi
movq %r15, 0x10(%r14)
jmp 0x8f29
movq %rax, 0x18(%r14)
movq 0x8(%r14), %rdi
callq 0x431c
testq %rax, %rax
je 0x903b
movq %rax, %r15
leaq 0x2319(%rip), %rsi      # 0xb300
movq %rax, %rdi
callq 0x44d0
testq %rax, %rax
je 0x9066
cmpl $0x4, 0x18(%rax)
jne 0x9066
movq 0x20(%rax), %r12
leaq 0x1831(%rip), %rsi      # 0xa836
movq %r12, %rdi
callq 0x2280
testl %eax, %eax
je 0x905b
testb $0x1, 0x118(%r14)
je 0x9066
leaq 0x22e2(%rip), %rsi      # 0xb304
movq %r12, %rdi
callq 0x2280
testl %eax, %eax
jne 0x9066
movq %rbx, %rdi
movq %r15, %rsi
callq 0x92e0
jmp 0x9066
callq 0x3f15
leaq 0x226b(%rip), %rsi      # 0xb2b2
xorl %edi, %edi
movq %rax, %rdx
xorl %eax, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x6b27
movq %rbx, %rdi
movq %r15, %rsi
callq 0x90e4
movq %r15, %rdi
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x3f6a