// File: /workspace/github_c_makefile_star2_O0/zuocheng-liu[P]ae-memcached/src/items.c
// Function: item_stats_sizes
char* item_stats_sizes(int *bytes) {
    int num_buckets = 32768;   /* max 1MB object, divided into 32 bytes size buckets */
    unsigned int *histogram = (unsigned int*) malloc(num_buckets * sizeof(int));
    char *buf = (char*) malloc(1024*1024*2*sizeof(char));
    int i;

    if (histogram == 0 || buf == 0) {
        if (histogram) free(histogram);
        if (buf) free(buf);
        return 0;
    }

    /* build the histogram */
    memset(histogram, 0, num_buckets * sizeof(int));
    for (i=0; i<LARGEST_ID; i++) {
        item *iter = heads[i];
        while (iter) {
            int ntotal = ITEM_ntotal(iter);
            int bucket = ntotal / 32;
            if (ntotal % 32) bucket++;
            if (bucket < num_buckets) histogram[bucket]++;
            iter = iter->next;
        }
    }

    /* write the buffer */
    *bytes = 0;
    for (i=0; i<num_buckets; i++) {
        if (histogram[i]) {
            *bytes += sprintf(&buf[*bytes], "%u %u\r\n", i*32, histogram[i]);
        }
    }
    *bytes += sprintf(&buf[*bytes], "END\r\n");
    free(histogram);
    return buf;
}

// Assembly:
subq $0x48, %rsp
movq %rdi, 0x38(%rsp)
movl $0x8000, 0x34(%rsp)     # imm = 0x8000
movslq 0x34(%rsp), %rdi
shlq $0x2, %rdi
callq 0x22e0
movq %rax, 0x28(%rsp)
movl $0x200000, %edi         # imm = 0x200000
callq 0x22e0
movq %rax, 0x20(%rsp)
cmpq $0x0, 0x28(%rsp)
je 0x6083
cmpq $0x0, 0x20(%rsp)
jne 0x60b5
cmpq $0x0, 0x28(%rsp)
je 0x6095
movq 0x28(%rsp), %rdi
callq 0x2030
cmpq $0x0, 0x20(%rsp)
je 0x60a7
movq 0x20(%rsp), %rdi
callq 0x2030
movq $0x0, 0x40(%rsp)
jmp 0x624d
movq 0x28(%rsp), %rdi
movslq 0x34(%rsp), %rdx
shlq $0x2, %rdx
xorl %esi, %esi
callq 0x21b0
movl $0x0, 0x1c(%rsp)
cmpl $0xff, 0x1c(%rsp)
jge 0x6197
movslq 0x1c(%rsp), %rcx
leaq 0xb274(%rip), %rax      # 0x11360
movq (%rax,%rcx,8), %rax
movq %rax, 0x10(%rsp)
cmpq $0x0, 0x10(%rsp)
je 0x6185
movq 0x10(%rsp), %rax
movzbl 0x29(%rax), %eax
addq $0x30, %rax
movq 0x10(%rsp), %rcx
movzbl 0x26(%rcx), %ecx
addq %rcx, %rax
movq 0x10(%rsp), %rcx
movslq 0x20(%rcx), %rcx
addq %rcx, %rax
movl %eax, 0xc(%rsp)
movl 0xc(%rsp), %eax
movl $0x20, %ecx
cltd
idivl %ecx
movl %eax, 0x8(%rsp)
movl 0xc(%rsp), %eax
movl $0x20, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
je 0x6156
movl 0x8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x8(%rsp)
movl 0x8(%rsp), %eax
cmpl 0x34(%rsp), %eax
jge 0x6173
movq 0x28(%rsp), %rax
movslq 0x8(%rsp), %rcx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
movq 0x10(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x10(%rsp)
jmp 0x60f5
jmp 0x6187
movl 0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c(%rsp)
jmp 0x60d2
movq 0x38(%rsp), %rax
movl $0x0, (%rax)
movl $0x0, 0x1c(%rsp)
movl 0x1c(%rsp), %eax
cmpl 0x34(%rsp), %eax
jge 0x6210
movq 0x28(%rsp), %rax
movslq 0x1c(%rsp), %rcx
cmpl $0x0, (%rax,%rcx,4)
je 0x6201
movq 0x20(%rsp), %rdi
movq 0x38(%rsp), %rax
movslq (%rax), %rax
addq %rax, %rdi
movl 0x1c(%rsp), %edx
shll $0x5, %edx
movq 0x28(%rsp), %rax
movslq 0x1c(%rsp), %rcx
movl (%rax,%rcx,4), %ecx
leaq 0x6041(%rip), %rsi      # 0xc230
movb $0x0, %al
callq 0x2420
movl %eax, %ecx
movq 0x38(%rsp), %rax
addl (%rax), %ecx
movl %ecx, (%rax)
jmp 0x6203
movl 0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c(%rsp)
jmp 0x61aa
movq 0x20(%rsp), %rdi
movq 0x38(%rsp), %rax
movslq (%rax), %rax
addq %rax, %rdi
leaq 0x6029(%rip), %rsi      # 0xc250
movb $0x0, %al
callq 0x2420
movl %eax, %ecx
movq 0x38(%rsp), %rax
addl (%rax), %ecx
movl %ecx, (%rax)
movq 0x28(%rsp), %rdi
callq 0x2030
movq 0x20(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x40(%rsp), %rax
addq $0x48, %rsp
retq
nopw (%rax,%rax)