// File: /workspace/github_c_makefile_star2_O0/yancanchen[P]mc-bloom-filter/mc_bloom_filter.c
// Function: process_command
void process_command(conn *c, char *command) {

    /* 
     * for commands set/add/replace, we build an item and read the data
     * directly into it, then continue in nread_complete().
     */ 

    if (my_srv.verbose > 1)
        fprintf(stderr, "<%d %s\n", c->sfd, command);

    /* All incoming commands will require a response, so we cork at the beginning,
       and uncork at the very end (usually by means of out_string)  */
    set_cork(c, 1);
    /* the function get bloom filter by key ,format: name_key*/
    if (strncmp(command, "get ", 4) == 0) {
        char key[256];
        char *subkey;
        char *start = command + 4;
        char *p = c->wbuf;
        char *end = c->wbuf + c->wsize - 6;
        int next;
        int res;

        while(sscanf(start, " %250s%n",key,&next) >= 1){    
            start += next;
             
            if((subkey = strchr(key, '|'))) {
                *subkey = '\0';
                subkey ++;
                res = blooms_get(key,subkey);
                if (res == 1) {
                    p += snprintf(p,end - p , "VALUE %s|%s 0 1\r\n%d\r\n", key,subkey,res); 
                }
            }
        }
        p += sprintf(p, "END\r\n");
        c->wbytes = p - c->wbuf;
        c->wcurr = c->wbuf;

        c->state = conn_write;
        c->write_and_go = conn_read;
        return;
    }

    //add create bloom filter 
    //add name 0 0 10
    //10000|0.0001 bit_chongtulv
    //set insert a new bloom_filter key
    if ((strncmp(command, "add ", 4) == 0 && (c->item_comm = NREAD_ADD)) ||
        (strncmp(command, "set ", 4) == 0 && (c->item_comm = NREAD_SET))) {
        char key[251];
        int flags;
        time_t expire;
        int len, res;

        res = sscanf(command, "%*s %250s %u %ld %d\n", key, &flags, &expire, &len);
        if (res!=4 || strlen(key)==0 || len < 0) {
            out_string(c, "CLIENT_ERROR bad command line format");
            return;
        }
        if (strlen(key) >= MAX_KEY_LEN) {
            // swallow the data line
            out_string(c, "NOT_STORED");
            c->write_and_go = conn_swallow;
            c->sbytes = len+2;
            return;
        }
        strcpy(c->key,key); 

        c->rlbytes = len+2;
        c->state = conn_nread;
        return;
    }

    //del key and free the bloom filter
    if (strncmp(command, "delete ", 7) == 0) {
        char key[MAX_KEY_LEN];
        char *start = command + 7;
        char *p = c->wbuf;
        
        if(sscanf(start, " %31s", key) >= 1) {
            if(blooms_delete(key) == 0){
                p += sprintf(p, "DELETED\r\n");
            }else{
                p += sprintf(p,"NOT_FOUND\r\n");    
            }
        }
        c->wbytes = p - c->wbuf;
        c->wcurr = c->wbuf;
        c->state = conn_write;
        c->write_and_go = conn_read;
        return;
    }

    if (strncmp(command, "stats", 5) == 0) {
        process_stat(c, command);
        return;
    }
    
    //calculate of the memory size,won't malloc memory
    if(strncmp(command, "try", 3) == 0){
        process_try(c,command);
        return;
    }

    //set the max memory limit
    //you can enlarge the max memory limit without restart service
    if(strncmp(command,"setmem",6) == 0){
        process_setmem(c,command);
        return;
    }

    if (strcmp(command, "quit") == 0) {
        c->state = conn_closing;
        return;
    }

    out_string(c, "ERROR");
    return;
}

// Assembly:
subq $0x298, %rsp            # imm = 0x298
movq %rdi, 0x290(%rsp)
movq %rsi, 0x288(%rsp)
cmpl $0x1, 0x56c6(%rip)      # 0xa2a4
jle 0x4c0a
movq 0x5411(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
movq 0x290(%rsp), %rax
movl (%rax), %edx
movq 0x288(%rsp), %rcx
leaq 0x2bdc(%rip), %rsi      # 0x77df
movb $0x0, %al
callq 0x2250
movq 0x290(%rsp), %rdi
movl $0x1, %esi
callq 0x35e0
movq 0x288(%rsp), %rdi
leaq 0x2bbc(%rip), %rsi      # 0x77e7
movl $0x4, %edx
callq 0x2060
cmpl $0x0, %eax
jne 0x4e47
movq 0x288(%rsp), %rax
addq $0x4, %rax
movq %rax, 0x170(%rsp)
movq 0x290(%rsp), %rax
movq 0xb0(%rax), %rax
movq %rax, 0x168(%rsp)
movq 0x290(%rsp), %rax
movq 0xb0(%rax), %rax
movq 0x290(%rsp), %rcx
movslq 0xc0(%rcx), %rcx
addq %rcx, %rax
addq $-0x6, %rax
movq %rax, 0x160(%rsp)
movq 0x170(%rsp), %rdi
leaq 0x180(%rsp), %rdx
leaq 0x2b3f(%rip), %rsi      # 0x77ec
leaq 0x15c(%rsp), %rcx
movb $0x0, %al
callq 0x22b0
cmpl $0x1, %eax
jl 0x4dab
movl 0x15c(%rsp), %ecx
movq 0x170(%rsp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, 0x170(%rsp)
leaq 0x180(%rsp), %rdi
movl $0x7c, %esi
callq 0x2160
movq %rax, 0x178(%rsp)
cmpq $0x0, %rax
je 0x4da6
movq 0x178(%rsp), %rax
movb $0x0, (%rax)
movq 0x178(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x178(%rsp)
leaq 0x180(%rsp), %rdi
movq 0x178(%rsp), %rsi
callq 0x2d90
movl %eax, 0x158(%rsp)
cmpl $0x1, 0x158(%rsp)
jne 0x4da4
movq 0x168(%rsp), %rdi
movq 0x160(%rsp), %rsi
movq 0x168(%rsp), %rax
subq %rax, %rsi
leaq 0x180(%rsp), %rcx
movq 0x178(%rsp), %r8
movl 0x158(%rsp), %r9d
leaq 0x2a70(%rip), %rdx      # 0x77f5
movb $0x0, %al
callq 0x2190
movl %eax, %ecx
movq 0x168(%rsp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, 0x168(%rsp)
jmp 0x4da6
jmp 0x4c96
movq 0x168(%rsp), %rdi
leaq 0x2892(%rip), %rsi      # 0x764c
movb $0x0, %al
callq 0x23d0
movl %eax, %ecx
movq 0x168(%rsp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, 0x168(%rsp)
movq 0x168(%rsp), %rax
movq 0x290(%rsp), %rcx
movq 0xb0(%rcx), %rcx
subq %rcx, %rax
movl %eax, %ecx
movq 0x290(%rsp), %rax
movl %ecx, 0xc4(%rax)
movq 0x290(%rsp), %rax
movq 0xb0(%rax), %rcx
movq 0x290(%rsp), %rax
movq %rcx, 0xb8(%rax)
movq 0x290(%rsp), %rax
movl $0x2, 0x4(%rax)
movq 0x290(%rsp), %rax
movl $0x1, 0xc8(%rax)
jmp 0x51b1
movq 0x288(%rsp), %rdi
leaq 0x29b5(%rip), %rsi      # 0x780b
movl $0x4, %edx
callq 0x2060
cmpl $0x0, %eax
jne 0x4e7a
movq 0x290(%rsp), %rax
movb $0x1, 0xcd(%rax)
movb $0x1, %al
testb $0x1, %al
jne 0x4eb6
movq 0x288(%rsp), %rdi
leaq 0x2987(%rip), %rsi      # 0x7810
movl $0x4, %edx
callq 0x2060
cmpl $0x0, %eax
jne 0x4fad
movq 0x290(%rsp), %rax
movb $0x2, 0xcd(%rax)
movb $0x1, %al
testb $0x1, %al
jne 0x4eb6
jmp 0x4fad
movq 0x288(%rsp), %rdi
leaq 0x50(%rsp), %rdx
leaq 0x294b(%rip), %rsi      # 0x7815
leaq 0x4c(%rsp), %rcx
leaq 0x40(%rsp), %r8
leaq 0x3c(%rsp), %r9
movb $0x0, %al
callq 0x22b0
movl %eax, 0x38(%rsp)
cmpl $0x4, 0x38(%rsp)
jne 0x4f02
leaq 0x50(%rsp), %rdi
callq 0x2100
cmpq $0x0, %rax
je 0x4f02
cmpl $0x0, 0x3c(%rsp)
jge 0x4f1b
movq 0x290(%rsp), %rdi
leaq 0x2919(%rip), %rsi      # 0x782a
callq 0x3b60
jmp 0x51b1
leaq 0x50(%rsp), %rdi
callq 0x2100
cmpq $0x20, %rax
jb 0x4f6b
movq 0x290(%rsp), %rdi
leaq 0x287f(%rip), %rsi      # 0x77b9
callq 0x3b60
movq 0x290(%rsp), %rax
movl $0x4, 0xc8(%rax)
movl 0x3c(%rsp), %ecx
addl $0x2, %ecx
movq 0x290(%rsp), %rax
movl %ecx, 0xf0(%rax)
jmp 0x51b1
movq 0x290(%rsp), %rdi
addq $0xd0, %rdi
leaq 0x50(%rsp), %rsi
callq 0x2080
movl 0x3c(%rsp), %ecx
addl $0x2, %ecx
movq 0x290(%rsp), %rax
movl %ecx, 0xa8(%rax)
movq 0x290(%rsp), %rax
movl $0x3, 0x4(%rax)
jmp 0x51b1
movq 0x288(%rsp), %rdi
leaq 0x2893(%rip), %rsi      # 0x784f
movl $0x7, %edx
callq 0x2060
cmpl $0x0, %eax
jne 0x50d1
movq 0x288(%rsp), %rax
addq $0x7, %rax
movq %rax, 0x8(%rsp)
movq 0x290(%rsp), %rax
movq 0xb0(%rax), %rax
movq %rax, (%rsp)
movq 0x8(%rsp), %rdi
leaq 0x10(%rsp), %rdx
leaq 0x2853(%rip), %rsi      # 0x7857
movb $0x0, %al
callq 0x22b0
cmpl $0x1, %eax
jl 0x5067
leaq 0x10(%rsp), %rdi
callq 0x3080
cmpl $0x0, %eax
jne 0x5043
movq (%rsp), %rdi
leaq 0x2833(%rip), %rsi      # 0x785d
movb $0x0, %al
callq 0x23d0
movl %eax, %ecx
movq (%rsp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, (%rsp)
jmp 0x5065
movq (%rsp), %rdi
leaq 0x2819(%rip), %rsi      # 0x7867
movb $0x0, %al
callq 0x23d0
movl %eax, %ecx
movq (%rsp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, (%rsp)
jmp 0x5067
movq (%rsp), %rax
movq 0x290(%rsp), %rcx
movq 0xb0(%rcx), %rcx
subq %rcx, %rax
movl %eax, %ecx
movq 0x290(%rsp), %rax
movl %ecx, 0xc4(%rax)
movq 0x290(%rsp), %rax
movq 0xb0(%rax), %rcx
movq 0x290(%rsp), %rax
movq %rcx, 0xb8(%rax)
movq 0x290(%rsp), %rax
movl $0x2, 0x4(%rax)
movq 0x290(%rsp), %rax
movl $0x1, 0xc8(%rax)
jmp 0x51b1
movq 0x288(%rsp), %rdi
leaq 0x23b1(%rip), %rsi      # 0x7491
movl $0x5, %edx
callq 0x2060
cmpl $0x0, %eax
jne 0x5109
movq 0x290(%rsp), %rdi
movq 0x288(%rsp), %rsi
callq 0x3f70
jmp 0x51b1
movq 0x288(%rsp), %rdi
leaq 0x275b(%rip), %rsi      # 0x7873
movl $0x3, %edx
callq 0x2060
cmpl $0x0, %eax
jne 0x513e
movq 0x290(%rsp), %rdi
movq 0x288(%rsp), %rsi
callq 0x3cf0
jmp 0x51b1
movq 0x288(%rsp), %rdi
leaq 0x272a(%rip), %rsi      # 0x7877
movl $0x6, %edx
callq 0x2060
cmpl $0x0, %eax
jne 0x5173
movq 0x290(%rsp), %rdi
movq 0x288(%rsp), %rsi
callq 0x3c50
jmp 0x51b1
movq 0x288(%rsp), %rdi
leaq 0x26fc(%rip), %rsi      # 0x787e
callq 0x2220
cmpl $0x0, %eax
jne 0x519d
movq 0x290(%rsp), %rax
movl $0x5, 0x4(%rax)
jmp 0x51b1
movq 0x290(%rsp), %rdi
leaq 0x22df(%rip), %rsi      # 0x748b
callq 0x3b60
addq $0x298, %rsp            # imm = 0x298
retq
nopl (%rax)