// File: /workspace/github_c_makefile_star2_O3/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %r8d, 0xc(%rsp)
movq %rcx, %rbp
movq %rdx, %r14
movsd %xmm0, 0x10(%rsp)
cmpq $0x9, %rdi
setb %al
testq %rsi, %rsi
sete %cl
cmpq $0x9, %rdx
setb %dl
orb %al, %dl
orb %cl, %dl
jne 0x4caf
movq %rdi, %r12
cmpq %rdi, %r14
setb %al
cmpq $0x9, %rbp
setb %cl
orb %al, %cl
jne 0x4caf
movq %rsi, %r15
movl $0x1, %edi
movl $0x40, %esi
callq 0x2220
testq %rax, %rax
je 0x4caf
movq %rax, %rbx
movl $0x8, %esi
movq %r15, %rdi
callq 0x2220
testq %rax, %rax
je 0x4ca7
movq %rax, %r13
movq %rbp, 0x28(%rbx)
movsd 0x10(%rsp), %xmm0
movsd %xmm0, (%rbx)
movq %r14, 0x10(%rbx)
movq %r12, 0x8(%rbx)
movq $0x1, 0x18(%rbx)
movq %rax, 0x38(%rbx)
cmpq $0x2, %r15
jae 0x4cc3
xorl %ebp, %ebp
jmp 0x4d69
movq %rbx, %rdi
callq 0x2030
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x1, %ebp
movq %r12, %rdi
movq %r14, %rsi
movl 0xc(%rsp), %edx
callq 0x7a78
movq %rax, (%r13,%rbp,8)
leaq 0x85a5(%rip), %rcx      # 0xd288
cmpl $0x2, 0x18(%rcx)
jge 0x4d42
movq %r12, %xmm1
punpckldq 0x35fa(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x3602(%rip), %xmm1     # 0x8300
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x10(%rsp), %xmm0
movapd %xmm0, %xmm1
subsd 0x35f4(%rip), %xmm1     # 0x8310
incq %rbp
cmpq %r15, %rbp
jae 0x4d66
cvttsd2si %xmm0, %rax
movq %rax, %rcx
cvttsd2si %xmm1, %r12
sarq $0x3f, %rcx
andq %rcx, %r12
orq %rax, %r12
cmpq %r14, %r12
jbe 0x4cc8
jmp 0x4d66
movq 0x82af(%rip), %rcx      # 0xcff8
movq (%rcx), %rdi
movq (%rax), %rcx
movl 0x10(%rax), %r8d
leaq 0x35be(%rip), %rsi      # 0x8318
movq %rbp, %rdx
xorl %eax, %eax
callq 0x2260
jmp 0x4ce9
decq %rbp
movq %rbp, 0x20(%rbx)
movq %rbp, 0x30(%rbx)
jmp 0x4cb1