// File: /workspace/github_c_makefile_star2_O0/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
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
leaq 0x279e(%rip), %rdi      # 0x10251
movb $0x0, %al
callq 0x9e70
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movl 0x8(%rax), %eax
shrl $0xa, %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0xdaff
leaq 0x19dc(%rip), %rdi      # 0xf4c6
movb $0x0, %al
callq 0x9e70
movq -0x10(%rbp), %rdi
callq 0x2800
jmp 0xdd14
movq -0x10(%rbp), %rax
movb 0x98(%rax), %al
shrb $0x5, %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
je 0xdb24
movq -0x10(%rbp), %rdi
callq 0x2800
jmp 0xdd14
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0xdbd9
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rdi
movl $0x120, %esi            # imm = 0x120
callq 0xbb60
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0xdb65
movq -0x10(%rbp), %rdi
callq 0x2800
jmp 0xdd14
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
movq -0x30(%rbp), %rax
movq 0x50(%rax), %rax
movq -0x10(%rbp), %rcx
movq (%rcx), %rcx
movq -0x10(%rbp), %rdx
movq 0x40(%rdx), %rdx
subq %rdx, %rcx
addq $0x120, %rcx            # imm = 0x120
subq %rcx, %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rdi
movq -0x20(%rbp), %rsi
callq 0xbb00
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x28(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0xdbcd
movq -0x10(%rbp), %rdi
callq 0x2800
jmp 0xdd14
movq -0x20(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rcx
movq 0x8(%rcx), %rsi
movq -0x28(%rbp), %rcx
movq 0x10(%rcx), %rdx
callq *%rax
movq %rax, -0x18(%rbp)
cmpq $-0x2, -0x18(%rbp)
jne 0xdc15
leaq 0x2676(%rip), %rdi      # 0x1027f
movb $0x0, %al
callq 0x9e70
jmp 0xdd14
cmpq $-0x1, -0x18(%rbp)
jne 0xdc2a
movq -0x10(%rbp), %rdi
callq 0x2800
jmp 0xdd14
cmpq $0x0, -0x18(%rbp)
jne 0xdc3f
movq -0x10(%rbp), %rdi
callq 0x2800
jmp 0xdd14
movq -0x18(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x5650
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0xdc80
callq 0x51d0
movq %rax, %rdx
xorl %edi, %edi
leaq 0x261a(%rip), %rsi      # 0x1028e
movb $0x0, %al
callq 0x9cc0
jmp 0xdd14
movq -0x38(%rbp), %rdi
leaq 0x2651(%rip), %rsi      # 0x102dc
callq 0x59f0
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
je 0xdd0b
movq -0x40(%rbp), %rax
cmpl $0x4, 0x18(%rax)
jne 0xdd0b
movq -0x40(%rbp), %rax
movq 0x20(%rax), %rdi
leaq 0x1b68(%rip), %rsi      # 0xf81c
callq 0x2290
cmpl $0x0, %eax
jne 0xdccd
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0xddf0
jmp 0xdd09
movq -0x28(%rbp), %rax
movb 0x118(%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
je 0xdd07
movq -0x40(%rbp), %rax
movq 0x20(%rax), %rdi
leaq 0x25f0(%rip), %rsi      # 0x102e0
callq 0x2290
cmpl $0x0, %eax
jne 0xdd07
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0xe030
jmp 0xdd09
jmp 0xdd0b
movq -0x38(%rbp), %rdi
callq 0x5270
addq $0x40, %rsp
popq %rbp
retq
nopw (%rax,%rax)