// File: /workspace/github_c_makefile_star2_O0/yancanchen[P]mc-bloom-filter/mc_bloom_filter.c
// Function: process_stat
void process_stat(conn *c, char *command) {
    time_t now = time(0);
    if (strcmp(command, "stats") == 0) {
        char temp[1024];
        pid_t pid = getpid();
        char *pos = temp;
        struct rusage usage;

        getrusage(RUSAGE_SELF, &usage);

        pos += sprintf(pos, "STAT pid %u\r\n", pid);
        pos += sprintf(pos, "STAT uptime %lu\r\n", now - stats.started);
        pos += sprintf(pos, "STAT time %ld\r\n", now);
        //bloom status
        pos += sprintf(pos, "STAT max_memory %lu\r\n", (unsigned long)blooms->max_bytes);
        pos += sprintf(pos, "STAT used_memory %ld\r\n", (unsigned long)blooms->bytes);
        pos += sprintf(pos, "STAT bloom_count %d\r\n", blooms->count);
        pos += sprintf(pos, "STAT bloom_power %d\r\n", blooms->power);

        pos += sprintf(pos, "STAT pointer_size %lu\r\n", (unsigned long)(8 * sizeof(void*)));
        pos += sprintf(pos, "STAT rusage_user %ld.%06ld\r\n", usage.ru_utime.tv_sec, usage.ru_utime.tv_usec);
        pos += sprintf(pos, "STAT rusage_system %ld.%06ld\r\n", usage.ru_stime.tv_sec, usage.ru_stime.tv_usec);
        pos += sprintf(pos, "STAT curr_connections %u\r\n", stats.curr_conns - 1); /* ignore listening conn */
        pos += sprintf(pos, "STAT total_connections %u\r\n", stats.total_conns);
        pos += sprintf(pos, "STAT connection_structures %u\r\n", stats.conn_structs);
        pos += sprintf(pos, "STAT bytes_read %llu\r\n", stats.bytes_read);
        pos += sprintf(pos, "STAT bytes_written %llu\r\n", stats.bytes_written);
        pos += sprintf(pos, "END");
        out_string(c, temp);
        return;
    }
    
    //show all the blooms info    
    if(strcmp(command,"stats blooms") == 0){

        char *p = c->wbuf;
        char *end  = c->wbuf + c->wsize - 6;
        if(!list_empty(&blooms->list)) {
            bloom_t *bl;
            list_for_each_entry(bl, &blooms->list, list) {
                //32+1+21+2
                if(end - p <= 55) {
                    char *new_wbuf = realloc(c->wbuf, c->wsize*2);    
                    if(!new_wbuf){
                        fprintf(stderr, "Couldn't realloc input buffer\n");
                        out_string(c, "SERVER_ERROR out of memory");
                        return;
                    }
                    c->wbuf = new_wbuf;
                    c->wcurr = c->wbuf;
                    c->wsize *= 2;
                    p = c->wbuf + c->wbytes;
                    end  = c->wbuf + c->wsize - 6;
                }
                p += snprintf(p,end - p, "%s %lu\r\n", bl->key,(unsigned long)bl->bytes);
                c->wbytes = p - c->wbuf;
            }
        }
        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;
    }

    //stats bloom key
    if(strncmp(command,"stats bloom ",12) == 0){
        char key[MAX_KEY_LEN];
        int res;
        res = sscanf(command + 12, " %32s\n", key);
        if (res!=1 || strlen(key)==0 ) {
            out_string(c, "CLIENT_ERROR bad command line format,'stats bloom key'");    
            return;
        }

        char buff[1024];
        char *pos1 = buff;
        bloom_t *bloom = blooms_search(key);

        if(!bloom){
            pos1 += sprintf(pos1,"key %s not exists\r\n", key);
        }else{
            pos1 += sprintf(pos1, "STAT key %s\r\n", bloom->key);
            pos1 += sprintf(pos1, "STAT elements %llu\r\n", bloom->n);
            pos1 += sprintf(pos1, "STAT table_size %llu\r\n", bloom->m);
            pos1 += sprintf(pos1, "STAT table_size_bytes %lu\r\n", (unsigned long)bloom->bytes);
            pos1 += sprintf(pos1, "STAT false_positive_rate %f\r\n", bloom->e);
            pos1 += sprintf(pos1, "STAT hash_functions_count %d\r\n", bloom->k);
            pos1 += sprintf(pos1, "STAT get_count %llu\r\n", bloom->get_count);
            pos1 += sprintf(pos1, "STAT get_miss_count %llu\r\n", bloom->get_miss_count);
            pos1 += sprintf(pos1, "STAT set_count %llu\r\n", bloom->set_count);

        }
        pos1 += sprintf(pos1, "END");
        
        out_string(c,buff);    
        return;    
    }

    if (strcmp(command, "stats reset") == 0) {
        stats_reset();
        out_string(c, "RESET");
        return;
    }

    out_string(c, "ERROR");
}

// Assembly:
subq $0x938, %rsp            # imm = 0x938
movq %rdi, 0x930(%rsp)
movq %rsi, 0x928(%rsp)
xorl %eax, %eax
movl %eax, %edi
callq 0x2290
movq %rax, 0x920(%rsp)
movq 0x928(%rsp), %rdi
leaq 0x34ea(%rip), %rsi      # 0x7491
callq 0x2220
cmpl $0x0, %eax
jne 0x4376
callq 0x20d0
movl %eax, 0x51c(%rsp)
leaq 0x520(%rsp), %rax
movq %rax, 0x510(%rsp)
xorl %edi, %edi
leaq 0x480(%rsp), %rsi
callq 0x2370
movq 0x510(%rsp), %rdi
movl 0x51c(%rsp), %edx
leaq 0x34a1(%rip), %rsi      # 0x7497
movb $0x0, %al
callq 0x23d0
movl %eax, %ecx
movq 0x510(%rsp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, 0x510(%rsp)
movq 0x510(%rsp), %rdi
movq 0x920(%rsp), %rdx
subq 0x6254(%rip), %rdx      # 0xa280
leaq 0x3472(%rip), %rsi      # 0x74a5
movb $0x0, %al
callq 0x23d0
movl %eax, %ecx
movq 0x510(%rsp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, 0x510(%rsp)
movq 0x510(%rsp), %rdi
movq 0x920(%rsp), %rdx
leaq 0x344e(%rip), %rsi      # 0x74b7
movb $0x0, %al
callq 0x23d0
movl %eax, %ecx
movq 0x510(%rsp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, 0x510(%rsp)
movq 0x510(%rsp), %rdi
leaq 0x61b1(%rip), %rax      # 0xa248
movq (%rax), %rax
movq 0x18(%rax), %rdx
leaq 0x3422(%rip), %rsi      # 0x74c7
movb $0x0, %al
callq 0x23d0
movl %eax, %ecx
movq 0x510(%rsp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, 0x510(%rsp)
movq 0x510(%rsp), %rdi
leaq 0x6175(%rip), %rax      # 0xa248
movq (%rax), %rax
movq 0x10(%rax), %rdx
leaq 0x33fc(%rip), %rsi      # 0x74dd
movb $0x0, %al
callq 0x23d0
movl %eax, %ecx
movq 0x510(%rsp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, 0x510(%rsp)
movq 0x510(%rsp), %rdi
leaq 0x6139(%rip), %rax      # 0xa248
movq (%rax), %rax
movl 0x20(%rax), %edx
leaq 0x33d8(%rip), %rsi      # 0x74f4
movb $0x0, %al
callq 0x23d0
movl %eax, %ecx
movq 0x510(%rsp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, 0x510(%rsp)
movq 0x510(%rsp), %rdi
leaq 0x60fe(%rip), %rax      # 0xa248
movq (%rax), %rax
movl 0x24(%rax), %edx
leaq 0x33b3(%rip), %rsi      # 0x750a
movb $0x0, %al
callq 0x23d0
movl %eax, %ecx
movq 0x510(%rsp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, 0x510(%rsp)
movq 0x510(%rsp), %rdi
leaq 0x339b(%rip), %rsi      # 0x7520
movl $0x40, %edx
movb $0x0, %al
callq 0x23d0
movl %eax, %ecx
movq 0x510(%rsp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, 0x510(%rsp)
movq 0x510(%rsp), %rdi
movq 0x480(%rsp), %rdx
movq 0x488(%rsp), %rcx
leaq 0x3370(%rip), %rsi      # 0x7538
movb $0x0, %al
callq 0x23d0
movl %eax, %ecx
movq 0x510(%rsp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, 0x510(%rsp)
movq 0x510(%rsp), %rdi
movq 0x490(%rsp), %rdx
movq 0x498(%rsp), %rcx
leaq 0x334f(%rip), %rsi      # 0x7555
movb $0x0, %al
callq 0x23d0
movl %eax, %ecx
movq 0x510(%rsp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, 0x510(%rsp)
movq 0x510(%rsp), %rdi
movl 0x6025(%rip), %edx      # 0xa258
subl $0x1, %edx
leaq 0x3337(%rip), %rsi      # 0x7574
movb $0x0, %al
callq 0x23d0
movl %eax, %ecx
movq 0x510(%rsp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, 0x510(%rsp)
movq 0x510(%rsp), %rdi
movl 0x5ff2(%rip), %edx      # 0xa25c
leaq 0x331e(%rip), %rsi      # 0x758f
movb $0x0, %al
callq 0x23d0
movl %eax, %ecx
movq 0x510(%rsp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, 0x510(%rsp)
movq 0x510(%rsp), %rdi
movl 0x5fc2(%rip), %edx      # 0xa260
leaq 0x3306(%rip), %rsi      # 0x75ab
movb $0x0, %al
callq 0x23d0
movl %eax, %ecx
movq 0x510(%rsp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, 0x510(%rsp)
movq 0x510(%rsp), %rdi
movq 0x5fb5(%rip), %rdx      # 0xa288
leaq 0x32f1(%rip), %rsi      # 0x75cb
movb $0x0, %al
callq 0x23d0
movl %eax, %ecx
movq 0x510(%rsp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, 0x510(%rsp)
movq 0x510(%rsp), %rdi
movq 0x5f88(%rip), %rdx      # 0xa290
leaq 0x32d3(%rip), %rsi      # 0x75e2
movb $0x0, %al
callq 0x23d0
movl %eax, %ecx
movq 0x510(%rsp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, 0x510(%rsp)
movq 0x510(%rsp), %rdi
leaq 0x3140(%rip), %rsi      # 0x747d
movb $0x0, %al
callq 0x23d0
movl %eax, %ecx
movq 0x510(%rsp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, 0x510(%rsp)
movq 0x930(%rsp), %rdi
leaq 0x520(%rsp), %rsi
callq 0x3b60
jmp 0x49ac
movq 0x928(%rsp), %rdi
leaq 0x3277(%rip), %rsi      # 0x75fc
callq 0x2220
cmpl $0x0, %eax
jne 0x46c1
movq 0x930(%rsp), %rax
movq 0xb0(%rax), %rax
movq %rax, 0x478(%rsp)
movq 0x930(%rsp), %rax
movq 0xb0(%rax), %rax
movq 0x930(%rsp), %rcx
movslq 0xc0(%rcx), %rcx
addq %rcx, %rax
addq $-0x6, %rax
movq %rax, 0x470(%rsp)
leaq 0x5e6a(%rip), %rax      # 0xa248
movq (%rax), %rdi
callq 0x49c0
cmpl $0x0, %eax
jne 0x4625
leaq 0x5e52(%rip), %rax      # 0xa248
movq (%rax), %rax
movq (%rax), %rax
movq %rax, 0x460(%rsp)
movq 0x460(%rsp), %rax
movq %rax, 0x458(%rsp)
movq 0x458(%rsp), %rax
movq %rax, 0x468(%rsp)
movq 0x468(%rsp), %rax
leaq 0x5e15(%rip), %rcx      # 0xa248
movq (%rcx), %rcx
cmpq %rcx, %rax
je 0x4623
movq 0x470(%rsp), %rax
movq 0x478(%rsp), %rcx
subq %rcx, %rax
cmpq $0x37, %rax
jg 0x4568
movq 0x930(%rsp), %rax
movq 0xb0(%rax), %rdi
movq 0x930(%rsp), %rax
movl 0xc0(%rax), %eax
shll %eax
movslq %eax, %rsi
callq 0x22e0
movq %rax, 0x450(%rsp)
cmpq $0x0, 0x450(%rsp)
jne 0x44c7
movq 0x5b5b(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x3162(%rip), %rsi      # 0x7609
movb $0x0, %al
callq 0x2250
movq 0x930(%rsp), %rdi
leaq 0x316b(%rip), %rsi      # 0x7628
callq 0x3b60
jmp 0x49ac
movq 0x450(%rsp), %rcx
movq 0x930(%rsp), %rax
movq %rcx, 0xb0(%rax)
movq 0x930(%rsp), %rax
movq 0xb0(%rax), %rcx
movq 0x930(%rsp), %rax
movq %rcx, 0xb8(%rax)
movq 0x930(%rsp), %rax
movl 0xc0(%rax), %ecx
shll %ecx
movl %ecx, 0xc0(%rax)
movq 0x930(%rsp), %rax
movq 0xb0(%rax), %rax
movq 0x930(%rsp), %rcx
movslq 0xc4(%rcx), %rcx
addq %rcx, %rax
movq %rax, 0x478(%rsp)
movq 0x930(%rsp), %rax
movq 0xb0(%rax), %rax
movq 0x930(%rsp), %rcx
movslq 0xc0(%rcx), %rcx
addq %rcx, %rax
addq $-0x6, %rax
movq %rax, 0x470(%rsp)
movq 0x478(%rsp), %rdi
movq 0x470(%rsp), %rsi
movq 0x478(%rsp), %rax
subq %rax, %rsi
movq 0x468(%rsp), %rcx
addq $0x20, %rcx
movq 0x468(%rsp), %rax
movq 0x18(%rax), %r8
leaq 0x30a1(%rip), %rdx      # 0x7643
movb $0x0, %al
callq 0x2190
movl %eax, %ecx
movq 0x478(%rsp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, 0x478(%rsp)
movq 0x478(%rsp), %rax
movq 0x930(%rsp), %rcx
movq 0xb0(%rcx), %rcx
subq %rcx, %rax
movl %eax, %ecx
movq 0x930(%rsp), %rax
movl %ecx, 0xc4(%rax)
movq 0x468(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x448(%rsp)
movq 0x448(%rsp), %rax
movq %rax, 0x440(%rsp)
movq 0x440(%rsp), %rax
movq %rax, 0x468(%rsp)
jmp 0x4424
jmp 0x4625
movq 0x478(%rsp), %rdi
leaq 0x3018(%rip), %rsi      # 0x764c
movb $0x0, %al
callq 0x23d0
movl %eax, %ecx
movq 0x478(%rsp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, 0x478(%rsp)
movq 0x478(%rsp), %rax
movq 0x930(%rsp), %rcx
movq 0xb0(%rcx), %rcx
subq %rcx, %rax
movl %eax, %ecx
movq 0x930(%rsp), %rax
movl %ecx, 0xc4(%rax)
movq 0x930(%rsp), %rax
movq 0xb0(%rax), %rcx
movq 0x930(%rsp), %rax
movq %rcx, 0xb8(%rax)
movq 0x930(%rsp), %rax
movl $0x2, 0x4(%rax)
movq 0x930(%rsp), %rax
movl $0x1, 0xc8(%rax)
jmp 0x49ac
movq 0x928(%rsp), %rdi
leaq 0x2f82(%rip), %rsi      # 0x7652
movl $0xc, %edx
callq 0x2060
cmpl $0x0, %eax
jne 0x4964
movq 0x928(%rsp), %rdi
addq $0xc, %rdi
leaq 0x420(%rsp), %rdx
leaq 0x2f61(%rip), %rsi      # 0x765f
movb $0x0, %al
callq 0x22b0
movl %eax, 0x41c(%rsp)
cmpl $0x1, 0x41c(%rsp)
jne 0x4729
leaq 0x420(%rsp), %rdi
callq 0x2100
cmpq $0x0, %rax
jne 0x4742
movq 0x930(%rsp), %rdi
leaq 0x2f2e(%rip), %rsi      # 0x7666
callq 0x3b60
jmp 0x49ac
leaq 0x10(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq 0x420(%rsp), %rdi
callq 0x2af0
movq %rax, (%rsp)
cmpq $0x0, (%rsp)
jne 0x4796
movq 0x8(%rsp), %rdi
leaq 0x420(%rsp), %rdx
leaq 0x2f25(%rip), %rsi      # 0x769d
movb $0x0, %al
callq 0x23d0
movl %eax, %ecx
movq 0x8(%rsp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, 0x8(%rsp)
jmp 0x492b
movq 0x8(%rsp), %rdi
movq (%rsp), %rdx
addq $0x20, %rdx
leaq 0x2f07(%rip), %rsi      # 0x76b1
movb $0x0, %al
callq 0x23d0
movl %eax, %ecx
movq 0x8(%rsp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rdi
movq (%rsp), %rax
movq 0x40(%rax), %rdx
leaq 0x2ee8(%rip), %rsi      # 0x76bf
movb $0x0, %al
callq 0x23d0
movl %eax, %ecx
movq 0x8(%rsp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rdi
movq (%rsp), %rax
movq 0x48(%rax), %rdx
leaq 0x2ed0(%rip), %rsi      # 0x76d4
movb $0x0, %al
callq 0x23d0
movl %eax, %ecx
movq 0x8(%rsp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rdi
movq (%rsp), %rax
movq 0x18(%rax), %rdx
leaq 0x2eba(%rip), %rsi      # 0x76eb
movb $0x0, %al
callq 0x23d0
movl %eax, %ecx
movq 0x8(%rsp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rdi
movq (%rsp), %rax
movsd 0x68(%rax), %xmm0
leaq 0x2ea8(%rip), %rsi      # 0x7707
movb $0x1, %al
callq 0x23d0
movl %eax, %ecx
movq 0x8(%rsp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rdi
movq (%rsp), %rax
movl 0x78(%rax), %edx
leaq 0x2e9a(%rip), %rsi      # 0x7725
movb $0x0, %al
callq 0x23d0
movl %eax, %ecx
movq 0x8(%rsp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rdi
movq (%rsp), %rax
movq 0x50(%rax), %rdx
leaq 0x2e8c(%rip), %rsi      # 0x7744
movb $0x0, %al
callq 0x23d0
movl %eax, %ecx
movq 0x8(%rsp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rdi
movq (%rsp), %rax
movq 0x60(%rax), %rdx
leaq 0x2e75(%rip), %rsi      # 0x775a
movb $0x0, %al
callq 0x23d0
movl %eax, %ecx
movq 0x8(%rsp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rdi
movq (%rsp), %rax
movq 0x58(%rax), %rdx
leaq 0x2e63(%rip), %rsi      # 0x7775
movb $0x0, %al
callq 0x23d0
movl %eax, %ecx
movq 0x8(%rsp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rdi
leaq 0x2b46(%rip), %rsi      # 0x747d
movb $0x0, %al
callq 0x23d0
movl %eax, %ecx
movq 0x8(%rsp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, 0x8(%rsp)
movq 0x930(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x3b60
jmp 0x49ac
movq 0x928(%rsp), %rdi
leaq 0x2e18(%rip), %rsi      # 0x778b
callq 0x2220
cmpl $0x0, %eax
jne 0x4998
callq 0x3520
movq 0x930(%rsp), %rdi
leaq 0x2e06(%rip), %rsi      # 0x7797
callq 0x3b60
jmp 0x49ac
movq 0x930(%rsp), %rdi
leaq 0x2ae4(%rip), %rsi      # 0x748b
callq 0x3b60
addq $0x938, %rsp            # imm = 0x938
retq
nopw %cs:(%rax,%rax)