// File: /workspace/github_c_makefile_star2_O0/zuocheng-liu[P]ae-memcached/src/items.c
// Function: item_alloc
item *item_alloc(char *key, int flags, rel_time_t exptime, int nbytes) {
    int nsuffix, ntotal, len;
    item *it;
    unsigned int id;
    char suffix[40];

    ntotal = item_make_header(key, flags, nbytes, suffix, &nsuffix, &len);

    id = mem_cache_clsid(mem_cache, ntotal);
    if (id == 0)
        return 0;

    it = mem_cache_alloc(mem_cache, ntotal);
    if (it == 0) {
        int tries = 50;
        item *search;

        /* If requested to not push old items out of cache when memory runs out,
         * we're out of luck at this point...
         */

        if (!settings.evict_to_free) return 0;

        /*
         * try to get one off the right LRU
         * don't necessariuly unlink the tail because it may be locked: refcount>0
         * search up from tail an item with refcount==0 and unlink it; give up after 50
         * tries
         */

        if (id > LARGEST_ID) return 0;
        if (tails[id]==0) return 0;

        for (search = tails[id]; tries>0 && search; tries--, search=search->prev) {
            if (search->refcount==0) {
                item_unlink(search);
                break;
            }
        }
        it = mem_cache_alloc(mem_cache, ntotal);
        if (it==0) return 0;
    }

    assert(it->slabs_clsid == 0);

    it->slabs_clsid = id;

    assert(it != heads[it->slabs_clsid]);

    it->next = 0;
    it->prev = 0;
    it->h_next = 0;
    it->refcount = 0;
    it->it_flags = 0;
    it->nkey = len;
    it->nbytes = nbytes;
    strcpy(ITEM_key(it), key);
    it->exptime = exptime;
    memcpy(ITEM_suffix(it), suffix, nsuffix);
    it->nsuffix = nsuffix;
    return it;
}

// Assembly:
subq $0x88, %rsp
movq %rdi, 0x78(%rsp)
movl %esi, 0x74(%rsp)
movl %edx, 0x70(%rsp)
movl %ecx, 0x6c(%rsp)
movq 0x78(%rsp), %rdi
movl 0x74(%rsp), %esi
movl 0x6c(%rsp), %edx
leaq 0x20(%rsp), %rcx
leaq 0x68(%rsp), %r8
leaq 0x60(%rsp), %r9
callq 0x5580
movl %eax, 0x64(%rsp)
leaq 0xbcd4(%rip), %rax      # 0x11348
movq (%rax), %rdi
movslq 0x64(%rsp), %rsi
callq 0x65d0
movl %eax, 0x54(%rsp)
cmpl $0x0, 0x54(%rsp)
jne 0x569d
movq $0x0, 0x80(%rsp)
jmp 0x588f
leaq 0xbca4(%rip), %rax      # 0x11348
movq (%rax), %rdi
movslq 0x64(%rsp), %rsi
callq 0x64d0
movq %rax, 0x58(%rsp)
cmpq $0x0, 0x58(%rsp)
jne 0x57cd
movl $0x32, 0x1c(%rsp)
leaq 0xbbc7(%rip), %rax      # 0x11298
cmpl $0x0, 0x24(%rax)
jne 0x56e8
movq $0x0, 0x80(%rsp)
jmp 0x588f
cmpl $0xff, 0x54(%rsp)
jbe 0x5703
movq $0x0, 0x80(%rsp)
jmp 0x588f
movl 0x54(%rsp), %eax
movl %eax, %ecx
leaq 0xc450(%rip), %rax      # 0x11b60
cmpq $0x0, (%rax,%rcx,8)
jne 0x5728
movq $0x0, 0x80(%rsp)
jmp 0x588f
movl 0x54(%rsp), %eax
movl %eax, %ecx
leaq 0xc42b(%rip), %rax      # 0x11b60
movq (%rax,%rcx,8), %rax
movq %rax, 0x10(%rsp)
xorl %eax, %eax
cmpl $0x0, 0x1c(%rsp)
movb %al, 0xf(%rsp)
jle 0x5758
cmpq $0x0, 0x10(%rsp)
setne %al
movb %al, 0xf(%rsp)
movb 0xf(%rsp), %al
testb $0x1, %al
jne 0x5762
jmp 0x5799
movq 0x10(%rsp), %rax
movzwl 0x24(%rax), %eax
cmpl $0x0, %eax
jne 0x577c
movq 0x10(%rsp), %rdi
callq 0x58a0
jmp 0x5799
jmp 0x577e
movl 0x1c(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x1c(%rsp)
movq 0x10(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x10(%rsp)
jmp 0x573e
leaq 0xbba8(%rip), %rax      # 0x11348
movq (%rax), %rdi
movslq 0x64(%rsp), %rsi
callq 0x64d0
movq %rax, 0x58(%rsp)
cmpq $0x0, 0x58(%rsp)
jne 0x57cb
movq $0x0, 0x80(%rsp)
jmp 0x588f
jmp 0x57cd
movl 0x54(%rsp), %eax
movb %al, %cl
movq 0x58(%rsp), %rax
movb %cl, 0x28(%rax)
movq 0x58(%rsp), %rax
movq $0x0, (%rax)
movq 0x58(%rsp), %rax
movq $0x0, 0x8(%rax)
movq 0x58(%rsp), %rax
movq $0x0, 0x10(%rax)
movq 0x58(%rsp), %rax
movw $0x0, 0x24(%rax)
movq 0x58(%rsp), %rax
movb $0x0, 0x27(%rax)
movl 0x60(%rsp), %eax
movb %al, %cl
movq 0x58(%rsp), %rax
movb %cl, 0x29(%rax)
movl 0x6c(%rsp), %ecx
movq 0x58(%rsp), %rax
movl %ecx, 0x20(%rax)
movq 0x58(%rsp), %rdi
addq $0x30, %rdi
movq 0x78(%rsp), %rsi
callq 0x2090
movl 0x70(%rsp), %ecx
movq 0x58(%rsp), %rax
movl %ecx, 0x1c(%rax)
movq 0x58(%rsp), %rdi
addq $0x30, %rdi
movq 0x58(%rsp), %rax
movzbl 0x29(%rax), %eax
cltq
addq %rax, %rdi
leaq 0x20(%rsp), %rsi
movslq 0x68(%rsp), %rdx
callq 0x22a0
movl 0x68(%rsp), %eax
movb %al, %cl
movq 0x58(%rsp), %rax
movb %cl, 0x26(%rax)
movq 0x58(%rsp), %rax
movq %rax, 0x80(%rsp)
movq 0x80(%rsp), %rax
addq $0x88, %rsp
retq
nop