// File: /workspace/github_c_makefile_star2_O1/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 0x5a29
movl %edi, %eax
leaq 0x3c49(%rip), %rcx      # 0x965c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movswl %bp, %edi
callq 0x3585
jmp 0x5c08
leaq 0x3a8f(%rip), %rdi      # 0x94bf
leaq 0x3cae(%rip), %rsi      # 0x96e5
callq 0x4dfc
jmp 0x5c16
movswl %bp, %ebx
movl %ebx, %edi
callq 0x2f18
testl %eax, %eax
jne 0x5c16
movl %ebx, %edi
jmp 0x5c03
leaq 0x22567(%rip), %r14     # 0x27fc8
movswl (%r14), %eax
shrl %eax
movswq %ax, %rax
shlq $0x4, %rax
leaq 0x87ca(%rip), %r15      # 0xe240
movq 0x8(%r15,%rax), %rax
leaq 0x2254a(%rip), %rcx     # 0x27fcc
movslq (%rcx), %rcx
movswl -0x2(%rax,%rcx,2), %edi
callq 0x3141
movl %eax, %ebx
movswl %bp, %eax
shrl %eax
movswq %ax, %rax
shlq $0x4, %rax
movq 0x8(%r15,%rax), %rax
movswl (%rax), %edi
callq 0x3141
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 0x5c0c
leaq 0x21dc5(%rip), %r13     # 0x27898
movl %ebx, (%r13)
movslq %ebx, %rbx
movswl -0x2(%rcx,%rbx,2), %edi
callq 0x2f46
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 0x2f20
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 0x2f46
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 0x2f20
leaq 0x22473(%rip), %rax     # 0x27fd2
jmp 0x5c13
leaq 0x2245d(%rip), %rbx     # 0x27fc8
movzwl (%rbx), %r14d
leaq 0x22456(%rip), %r15     # 0x27fcc
movl (%r15), %r12d
leaq -0xd18(%rip), %rsi      # 0x4e68
movl $0x2, %edi
callq 0x2170
leaq 0x2244f(%rip), %rdi     # 0x27fe0
callq 0x2140
testl %eax, %eax
jne 0x5bab
movswl %bp, %edi
movl $0x1388, %esi           # imm = 0x1388
callq 0x3c09
testl %eax, %eax
jne 0x5c28
leaq 0x22422(%rip), %rax     # 0x27fd4
movzwl (%rax), %ebp
movw %r14w, (%rbx)
movl %r12d, (%r15)
leaq -0xd49(%rip), %rsi      # 0x4e7a
movl $0x2, %edi
callq 0x2170
jmp 0x5c16
movswl %bp, %ebx
movl %ebx, %edi
callq 0x2f18
xorl %edi, %edi
testl %eax, %eax
jne 0x5c03
shrl %ebx
movl %ebx, %eax
movswq %ax, %rax
shlq $0x4, %rax
leaq 0x864e(%rip), %rcx      # 0xe240
movzwl 0x4(%rcx,%rax), %eax
movl %eax, %ecx
negw %cx
cmovsw %ax, %cx
movzwl %cx, %edi
callq 0x314c
movl %eax, %ebp
jmp 0x5c16
leaq 0x223c1(%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 0x223a3(%rip), %rax     # 0x27fd2
jmp 0x5bb2
movl %ebp, %edi
callq 0x285b
jmp 0x5c16
nop