// File: /workspace/github_c_makefile_star2_O1/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 0x21f2(%rip), %rdi      # 0xb285
xorl %eax, %eax
callq 0x6daa
movq (%r14), %rbx
testb $0x4, 0x9(%r14)
jne 0x90ee
testb $0x20, 0x98(%rbx)
jne 0x90fc
movq (%rbx), %r14
testq %r14, %r14
je 0x910c
movq 0x8(%r14), %rsi
movq 0x10(%r14), %rdx
movq %rbx, %rdi
callq *0x28(%rbx)
testq %rax, %rax
je 0x90fc
cmpq $-0x1, %rax
je 0x90fc
cmpq $-0x2, %rax
jne 0x9159
leaq 0x21d4(%rip), %rdi      # 0xb2b3
xorl %eax, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x6daa
leaq 0x13d1(%rip), %rdi      # 0xa4c6
xorl %eax, %eax
callq 0x6daa
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 0x7e46
testq %rax, %rax
je 0x90fc
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 0x7e27
movq %rax, 0x8(%r14)
testq %rax, %rax
je 0x90fc
movq %r15, 0x10(%r14)
jmp 0x90b5
movq %rax, 0x18(%r14)
movq 0x8(%r14), %rdi
callq 0x42fa
testq %rax, %rax
je 0x91c9
movq %rax, %r15
leaq 0x219b(%rip), %rsi      # 0xb310
movq %rax, %rdi
callq 0x44ae
testq %rax, %rax
je 0x91f4
cmpl $0x4, 0x18(%rax)
jne 0x91f4
movq 0x20(%rax), %r12
leaq 0x16a3(%rip), %rsi      # 0xa836
movq %r12, %rdi
callq 0x2280
testl %eax, %eax
je 0x91e9
testb $0x1, 0x118(%r14)
je 0x91f4
leaq 0x2164(%rip), %rsi      # 0xb314
movq %r12, %rdi
callq 0x2280
testl %eax, %eax
jne 0x91f4
movq %rbx, %rdi
movq %r15, %rsi
callq 0x946e
jmp 0x91f4
callq 0x3efd
leaq 0x20ed(%rip), %rsi      # 0xb2c2
xorl %edi, %edi
movq %rax, %rdx
xorl %eax, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x6c5d
movq %rbx, %rdi
movq %r15, %rsi
callq 0x9272
movq %r15, %rdi
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x3f52