// File: /workspace/github_c_makefile_star2_O0/afi-lambda[P]a_little_smalltalk/src/memory.c
// Function: allocObject
object allocObject(int memorySize)
{
    int i;
    register int position;
    boolean done;

    if (memorySize >= FREELISTMAX)
    {
        fprintf(stderr, "size %d\n", memorySize);
        sysError("allocation bigger than permitted", "allocObject");
    }

    /* first try the free lists, this is fastest */
    if ((position = objectFreeList[memorySize]) != 0)
    {
        objectFreeList[memorySize] = objectTable[position].STclass;
    }

    /* if not there, next try making a size zero object and
     making it bigger */
    else if ((position = objectFreeList[0]) != 0)
    {
        objectFreeList[0] = objectTable[position].STclass;
        objectTable[position].size = memorySize;
        objectTable[position].memory = mBlockAlloc(memorySize);
    }

    else   /* not found, must work a bit harder */
    {
        done = false;

        /* first try making a bigger object smaller */
        for (i = memorySize + 1; i < FREELISTMAX; i++)
            if ((position = objectFreeList[i]) != 0)
            {
                objectFreeList[i] = objectTable[position].STclass;
                /* just trim it a bit */
                objectTable[position].size = memorySize;
                done = true;
                break;
            }

        /* next try making a smaller object bigger */
        if (!done)
            for (i = 1; i < memorySize; i++)
                if ((position = objectFreeList[i]) != 0)
                {
                    objectFreeList[i] = objectTable[position].STclass;
                    objectTable[position].size = memorySize;
# ifdef mBlockAlloc
                    free(objectTable[position].memory);
# endif
                    objectTable[position].memory = mBlockAlloc(memorySize);
                    done = true;
                    break;
                }

        /* if we STILL don't have it then there is nothing */
        /* more we can do */
        if (!done)
            sysError("out of objects", "alloc");
    }

    /* set class and type */
    objectTable[position].referenceCount = 0;
    objectTable[position].STclass = nilobj;
    objectTable[position].size = memorySize;
    return (position << 1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movl %edi, -0x4(%rbp)
cmpl $0x7d0, -0x4(%rbp)      # imm = 0x7D0
jl 0x2c52
movq 0xc3cd(%rip), %rax      # 0xeff8
movq (%rax), %rdi
movl -0x4(%rbp), %edx
leaq 0x9589(%rip), %rsi      # 0xc1c1
movb $0x0, %al
callq 0x2170
leaq 0x94f1(%rip), %rdi      # 0xc137
leaq 0x950b(%rip), %rsi      # 0xc158
callq 0x63f0
movslq -0x4(%rbp), %rcx
leaq 0xc663(%rip), %rax      # 0xf2c0
movswl (%rax,%rcx,2), %eax
movl %eax, -0xc(%rbp)
cmpl $0x0, %eax
je 0x2c92
movslq -0xc(%rbp), %rcx
leaq 0xd5ec(%rip), %rax      # 0x10260
shlq $0x4, %rcx
addq %rcx, %rax
movw (%rax), %dx
movslq -0x4(%rbp), %rcx
leaq 0xc637(%rip), %rax      # 0xf2c0
movw %dx, (%rax,%rcx,2)
jmp 0x2e52
movswl 0xc627(%rip), %eax      # 0xf2c0
movl %eax, -0xc(%rbp)
cmpl $0x0, %eax
je 0x2cff
movslq -0xc(%rbp), %rcx
leaq 0xd5b4(%rip), %rax      # 0x10260
shlq $0x4, %rcx
addq %rcx, %rax
movw (%rax), %ax
movw %ax, 0xc603(%rip)       # 0xf2c0
movl -0x4(%rbp), %eax
movw %ax, %cx
movslq -0xc(%rbp), %rdx
leaq 0xd592(%rip), %rax      # 0x10260
shlq $0x4, %rdx
addq %rdx, %rax
movw %cx, 0x4(%rax)
movl -0x4(%rbp), %edi
callq 0x2b80
movq %rax, %rcx
movslq -0xc(%rbp), %rdx
leaq 0xd571(%rip), %rax      # 0x10260
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
jmp 0x2e50
movl $0x0, -0x10(%rbp)
movl -0x4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
cmpl $0x7d0, -0x8(%rbp)      # imm = 0x7D0
jge 0x2d85
movslq -0x8(%rbp), %rcx
leaq 0xc59d(%rip), %rax      # 0xf2c0
movswl (%rax,%rcx,2), %eax
movl %eax, -0xc(%rbp)
cmpl $0x0, %eax
je 0x2d78
movslq -0xc(%rbp), %rcx
leaq 0xd526(%rip), %rax      # 0x10260
shlq $0x4, %rcx
addq %rcx, %rax
movw (%rax), %dx
movslq -0x8(%rbp), %rcx
leaq 0xc571(%rip), %rax      # 0xf2c0
movw %dx, (%rax,%rcx,2)
movl -0x4(%rbp), %eax
movw %ax, %cx
movslq -0xc(%rbp), %rdx
leaq 0xd4fc(%rip), %rax      # 0x10260
shlq $0x4, %rdx
addq %rdx, %rax
movw %cx, 0x4(%rax)
movl $0x1, -0x10(%rbp)
jmp 0x2d85
jmp 0x2d7a
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0x2d0f
cmpl $0x0, -0x10(%rbp)
jne 0x2e35
movl $0x1, -0x8(%rbp)
movl -0x8(%rbp), %eax
cmpl -0x4(%rbp), %eax
jge 0x2e33
movslq -0x8(%rbp), %rcx
leaq 0xc513(%rip), %rax      # 0xf2c0
movswl (%rax,%rcx,2), %eax
movl %eax, -0xc(%rbp)
cmpl $0x0, %eax
je 0x2e23
movslq -0xc(%rbp), %rcx
leaq 0xd49c(%rip), %rax      # 0x10260
shlq $0x4, %rcx
addq %rcx, %rax
movw (%rax), %dx
movslq -0x8(%rbp), %rcx
leaq 0xc4e7(%rip), %rax      # 0xf2c0
movw %dx, (%rax,%rcx,2)
movl -0x4(%rbp), %eax
movw %ax, %cx
movslq -0xc(%rbp), %rdx
leaq 0xd472(%rip), %rax      # 0x10260
shlq $0x4, %rdx
addq %rdx, %rax
movw %cx, 0x4(%rax)
movl -0x4(%rbp), %edi
callq 0x2b80
movq %rax, %rcx
movslq -0xc(%rbp), %rdx
leaq 0xd451(%rip), %rax      # 0x10260
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movl $0x1, -0x10(%rbp)
jmp 0x2e33
jmp 0x2e25
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0x2d96
jmp 0x2e35
cmpl $0x0, -0x10(%rbp)
jne 0x2e4e
leaq 0x9322(%rip), %rdi      # 0xc164
leaq 0x932a(%rip), %rsi      # 0xc173
callq 0x63f0
jmp 0x2e50
jmp 0x2e52
movslq -0xc(%rbp), %rcx
leaq 0xd403(%rip), %rax      # 0x10260
shlq $0x4, %rcx
addq %rcx, %rax
movw $0x0, 0x2(%rax)
movslq -0xc(%rbp), %rcx
leaq 0xd3eb(%rip), %rax      # 0x10260
shlq $0x4, %rcx
addq %rcx, %rax
movw $0x0, (%rax)
movl -0x4(%rbp), %eax
movw %ax, %cx
movslq -0xc(%rbp), %rdx
leaq 0xd3ce(%rip), %rax      # 0x10260
shlq $0x4, %rdx
addq %rdx, %rax
movw %cx, 0x4(%rax)
movl -0xc(%rbp), %eax
shll %eax
addq $0x10, %rsp
popq %rbp
retq
nopl (%rax,%rax)