// File: /workspace/github_c_makefile_star2_O3/afi-lambda[P]a_little_smalltalk/src/primitive.c
// Function: unaryPrims
static int unaryPrims(int number, object firstarg)
{
    int i, j, saveLinkPointer;
    object returnedObject, saveProcessStack;

    returnedObject = firstarg;
    switch (number)
    {
    case 1: /* class of object */
        returnedObject = getClass(firstarg);
        break;

    case 2: /* basic size of object */
        if (isInteger(firstarg))
            i = 0;
        else
        {
            i = sizeField(firstarg);
            /* byte objects have negative size */
            if (i < 0)
                i = (-i);
        }
        returnedObject = newInteger(i);
        break;

    case 3: /* hash value of object */
        if (isInteger(firstarg))
            returnedObject = firstarg;
        else
            returnedObject = newInteger(firstarg);
        break;

    case 4: /* debugging print */
        fprintf(stderr, "primitive 14 %d\n", firstarg);
        break;

    case 8: /* change return point - block return */
        /* first get previous link pointer */
        i = intValue(basicAt(processStack, linkPointer));
        /* then creating context pointer */
        j = intValue(basicAt(firstarg, 1));
        if (basicAt(processStack, j+1) != firstarg)
        {
            returnedObject = falseobj;
            break;
        }
        /* first change link pointer to that of creator */
        fieldAtPut(processStack, i,
                   basicAt(processStack, j))
        ;
        /* then change return point to that of creator */
        fieldAtPut(processStack, i+2,
                   basicAt(processStack, j+2))
        ;
        returnedObject = trueobj;
        break;

    case 9: /* process execute */
        /* first save the values we are about to clobber */
        saveProcessStack = processStack;
        saveLinkPointer = linkPointer;
        /* trap control-C */
        signal(SIGINT, brkfun);
        if (setjmp(jb))
        {
            returnedObject = falseobj;
        }
        else if (execute(firstarg, 5000))
            returnedObject = trueobj;
        else
            returnedObject = falseobj;
        /* then restore previous environment */
        processStack = saveProcessStack;
        linkPointer = saveLinkPointer;
        signal(SIGINT, brkdum);
        break;

    default: /* unknown primitive */
        sysError("unknown primitive", "unaryPrims");
        break;
    }
    return (returnedObject);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %esi, %ebp
decl %edi
cmpl $0x8, %edi
ja 0x59da
movl %edi, %eax
leaq 0x3cb0(%rip), %rcx      # 0x9674
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movswl %bp, %edi
callq 0x3569
jmp 0x5bb9
leaq 0x3af6(%rip), %rdi      # 0x94d7
leaq 0x3d15(%rip), %rsi      # 0x96fd
callq 0x4dec
jmp 0x5bc7
movswl %bp, %ebx
movl %ebx, %edi
callq 0x2ed2
testl %eax, %eax
jne 0x5bc7
movl %ebx, %edi
jmp 0x5bb4
leaq 0x225b6(%rip), %r14     # 0x27fc8
movswl (%r14), %eax
shrl %eax
movswq %ax, %rax
shlq $0x4, %rax
leaq 0x8819(%rip), %r15      # 0xe240
movq 0x8(%r15,%rax), %rax
leaq 0x22599(%rip), %rcx     # 0x27fcc
movslq (%rcx), %rcx
movswl -0x2(%rax,%rcx,2), %edi
callq 0x3125
movl %eax, %ebx
movswl %bp, %eax
shrl %eax
movswq %ax, %rax
shlq $0x4, %rax
movq 0x8(%r15,%rax), %rax
movswl (%rax), %edi
callq 0x3125
movswl (%r14), %ecx
shrl %ecx
movswq %cx, %rcx
shlq $0x4, %rcx
movq 0x8(%r15,%rcx), %rcx
movslq %eax, %r12
cmpw %bp, (%rcx,%r12,2)
jne 0x5bbd
leaq 0x21e14(%rip), %r13     # 0x27898
movl %ebx, (%r13)
movslq %ebx, %rbx
movswl -0x2(%rcx,%rbx,2), %edi
callq 0x2f00
movswl (%r14), %eax
shrl %eax
movswq %ax, %rax
shlq $0x4, %rax
movq 0x8(%r15,%rax), %rax
movswl -0x2(%rax,%r12,2), %edi
movslq (%r13), %rdx
movw %di, -0x2(%rax,%rdx,2)
callq 0x2eda
movl %ebx, %eax
addl $0x2, %eax
movl %eax, (%r13)
movswl (%r14), %eax
shrl %eax
movswq %ax, %rax
shlq $0x4, %rax
movq 0x8(%r15,%rax), %rax
movswl 0x2(%rax,%rbx,2), %edi
callq 0x2f00
movswl (%r14), %eax
shrl %eax
movswq %ax, %rax
shlq $0x4, %rax
movq 0x8(%r15,%rax), %rax
movswl 0x2(%rax,%r12,2), %edi
movslq (%r13), %rdx
movw %di, -0x2(%rax,%rdx,2)
callq 0x2eda
leaq 0x224c2(%rip), %rax     # 0x27fd2
jmp 0x5bc4
leaq 0x224ac(%rip), %rbx     # 0x27fc8
movzwl (%rbx), %r14d
leaq 0x224a5(%rip), %r15     # 0x27fcc
movl (%r15), %r12d
leaq -0xcd9(%rip), %rsi      # 0x4e58
movl $0x2, %edi
callq 0x2170
leaq 0x2249e(%rip), %rdi     # 0x27fe0
callq 0x2140
testl %eax, %eax
jne 0x5b5c
movswl %bp, %edi
movl $0x1388, %esi           # imm = 0x1388
callq 0x3be5
testl %eax, %eax
jne 0x5bd9
leaq 0x22471(%rip), %rax     # 0x27fd4
movzwl (%rax), %ebp
movw %r14w, (%rbx)
movl %r12d, (%r15)
leaq -0xd0a(%rip), %rsi      # 0x4e6a
movl $0x2, %edi
callq 0x2170
jmp 0x5bc7
movswl %bp, %ebx
movl %ebx, %edi
callq 0x2ed2
xorl %edi, %edi
testl %eax, %eax
jne 0x5bb4
shrl %ebx
movl %ebx, %eax
movswq %ax, %rax
shlq $0x4, %rax
leaq 0x869d(%rip), %rcx      # 0xe240
movzwl 0x4(%rcx,%rax), %eax
movl %eax, %ecx
negw %cx
cmovsw %ax, %cx
movzwl %cx, %edi
callq 0x3130
movl %eax, %ebp
jmp 0x5bc7
leaq 0x22410(%rip), %rax     # 0x27fd4
movzwl (%rax), %ebp
movswl %bp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x223f2(%rip), %rax     # 0x27fd2
jmp 0x5b63
movl %ebp, %edi
callq 0x2859
jmp 0x5bc7
nop