// File: /workspace/github_c_makefile_star2_O0/zuocheng-liu[P]ae-memcached/src/mem_cache.c
// Function: mem_cache_create
mem_cache_ptr mem_cache_create(size_t base_chunk_size, 
        double factor, 
        size_t power_largest, 
        size_t power_block, 
        size_t mem_limit, 
        int pre_alloc) {

    mem_cache_ptr mem_cache;
    slab_ptr *slabclass;
    size_t i;
    size_t chunk_size;
    if (base_chunk_size <= CHUNK_ALIGN_BYTES || 
            power_largest <= 0 || 
            power_block <= CHUNK_ALIGN_BYTES ||
            power_block < base_chunk_size ||
            mem_limit <= CHUNK_ALIGN_BYTES) {
        return NULL;
    }

    mem_cache = (mem_cache_ptr)calloc(1, sizeof(*mem_cache));
    if (NULL == mem_cache) {
        return NULL;
    }
    
    slabclass = (slab_ptr *)calloc(power_largest, sizeof(slab_ptr));
    if (NULL == slabclass) {
        free (mem_cache);
        return NULL;
    }

    mem_cache->mem_limit = mem_limit;
    mem_cache->mem_malloced = 0;
    mem_cache->factor = factor;
    mem_cache->power_block = power_block;
    mem_cache->base_chunk_size = base_chunk_size;
    mem_cache->power_smallest = 1;
    mem_cache->slabclass = slabclass;
    
    for (i = 1, chunk_size = base_chunk_size; i < power_largest; ++i) {
        if (chunk_size > power_block) {
            break;
        }
        slabclass[i] = slab_create(chunk_size, power_block, pre_alloc);
        LOG_DEBUG_F3("slab class %3lu: chunk size %6lu perslab %5u\n",
                    i, 
                    slabclass[i]->chunk_size, 
                    slabclass[i]->chunk_number_per_page);
        chunk_size *= factor;
    }
    
    mem_cache->power_largest = i - 1;
    mem_cache->mem_malloced = mem_cache->power_largest;
    
    return mem_cache;
}

// Assembly:
subq $0x58, %rsp
movq %rdi, 0x48(%rsp)
movsd %xmm0, 0x40(%rsp)
movq %rsi, 0x38(%rsp)
movq %rdx, 0x30(%rsp)
movq %rcx, 0x28(%rsp)
movl %r8d, 0x24(%rsp)
cmpq $0x8, 0x48(%rsp)
jbe 0x62af
cmpq $0x0, 0x38(%rsp)
jbe 0x62af
cmpq $0x8, 0x30(%rsp)
jbe 0x62af
movq 0x30(%rsp), %rax
cmpq 0x48(%rsp), %rax
jb 0x62af
cmpq $0x8, 0x28(%rsp)
ja 0x62bd
movq $0x0, 0x50(%rsp)
jmp 0x64be
movl $0x1, %edi
movl $0x40, %esi
callq 0x2240
movq %rax, 0x18(%rsp)
xorl %eax, %eax
cmpq 0x18(%rsp), %rax
jne 0x62e8
movq $0x0, 0x50(%rsp)
jmp 0x64be
movq 0x38(%rsp), %rdi
movl $0x8, %esi
callq 0x2240
movq %rax, 0x10(%rsp)
xorl %eax, %eax
cmpq 0x10(%rsp), %rax
jne 0x631d
movq 0x18(%rsp), %rdi
callq 0x2030
movq $0x0, 0x50(%rsp)
jmp 0x64be
movq 0x28(%rsp), %rcx
movq 0x18(%rsp), %rax
movq %rcx, 0x28(%rax)
movq 0x18(%rsp), %rax
movq $0x0, 0x30(%rax)
movsd 0x40(%rsp), %xmm0
movq 0x18(%rsp), %rax
movsd %xmm0, (%rax)
movq 0x30(%rsp), %rcx
movq 0x18(%rsp), %rax
movq %rcx, 0x10(%rax)
movq 0x48(%rsp), %rcx
movq 0x18(%rsp), %rax
movq %rcx, 0x8(%rax)
movq 0x18(%rsp), %rax
movq $0x1, 0x18(%rax)
movq 0x10(%rsp), %rcx
movq 0x18(%rsp), %rax
movq %rcx, 0x38(%rax)
movq $0x1, 0x8(%rsp)
movq 0x48(%rsp), %rax
movq %rax, (%rsp)
movq 0x8(%rsp), %rax
cmpq 0x38(%rsp), %rax
jae 0x6490
movq (%rsp), %rax
cmpq 0x30(%rsp), %rax
jbe 0x63b0
jmp 0x6490
movq (%rsp), %rdi
movq 0x30(%rsp), %rsi
movl 0x24(%rsp), %edx
callq 0xb4b0
movq %rax, %rdx
movq 0x10(%rsp), %rax
movq 0x8(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
leaq 0xaebe(%rip), %rax      # 0x11298
cmpl $0x1, 0x18(%rax)
jle 0x6420
movq 0xac11(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
movq 0x8(%rsp), %rdx
movq 0x10(%rsp), %rax
movq 0x8(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq (%rax), %rcx
movq 0x10(%rsp), %rax
movq 0x8(%rsp), %rsi
movq (%rax,%rsi,8), %rax
movl 0x10(%rax), %r8d
leaq 0x5ebf(%rip), %rsi      # 0xc2d8
movb $0x0, %al
callq 0x2280
jmp 0x6422
movsd 0x40(%rsp), %xmm1
movaps 0x5e81(%rip), %xmm2     # 0xc2b0
movq (%rsp), %xmm0
punpckldq %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
movapd 0x5e80(%rip), %xmm2     # 0xc2c0
subpd %xmm2, %xmm0
movaps %xmm0, %xmm2
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm2, %xmm0
mulsd %xmm1, %xmm0
movaps %xmm0, %xmm1
cvttsd2si %xmm1, %rax
movq %rax, %rdx
sarq $0x3f, %rdx
movsd 0x5e66(%rip), %xmm1     # 0xc2d0
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %rcx
andq %rdx, %rcx
orq %rcx, %rax
movq %rax, (%rsp)
movq 0x8(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x8(%rsp)
jmp 0x6390
movq 0x8(%rsp), %rcx
subq $0x1, %rcx
movq 0x18(%rsp), %rax
movq %rcx, 0x20(%rax)
movq 0x18(%rsp), %rax
movq 0x20(%rax), %rcx
movq 0x18(%rsp), %rax
movq %rcx, 0x30(%rax)
movq 0x18(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0x50(%rsp), %rax
addq $0x58, %rsp
retq
nopl (%rax,%rax)