// File: /workspace/github_c_makefile_star2_O3/janet-lang[P]janet/src/core/ffi.c
// Function: sysv64_classify_ext
static JanetFFIWordSpec sysv64_classify_ext(JanetFFIType type, size_t shift) {
    switch (type.prim) {
        case JANET_FFI_TYPE_PTR:
        case JANET_FFI_TYPE_STRING:
        case JANET_FFI_TYPE_BOOL:
        case JANET_FFI_TYPE_INT8:
        case JANET_FFI_TYPE_INT16:
        case JANET_FFI_TYPE_INT32:
        case JANET_FFI_TYPE_INT64:
        case JANET_FFI_TYPE_UINT8:
        case JANET_FFI_TYPE_UINT16:
        case JANET_FFI_TYPE_UINT32:
        case JANET_FFI_TYPE_UINT64:
            return JANET_SYSV64_INTEGER;
        case JANET_FFI_TYPE_DOUBLE:
        case JANET_FFI_TYPE_FLOAT:
            return JANET_SYSV64_SSE;
        case JANET_FFI_TYPE_STRUCT: {
            JanetFFIStruct *st = type.st;
            if (st->size > 16) return JANET_SYSV64_MEMORY;
            if (!st->is_aligned) return JANET_SYSV64_MEMORY;
            JanetFFIWordSpec clazz = JANET_SYSV64_NO_CLASS;
            if (st->size > 8 && st->size <= 16) {
                /* map to pair classification */
                int has_int_lo = 0;
                int has_int_hi = 0;
                for (uint32_t i = 0; i < st->field_count; i++) {
                    JanetFFIWordSpec next_class = sysv64_classify_ext(st->fields[i].type, shift + st->fields[i].offset);
                    switch (next_class) {
                        default:
                            break;
                        case JANET_SYSV64_INTEGER:
                            if (shift + st->fields[i].offset + type_size(st->fields[i].type) <= 8) {
                                has_int_lo = 1;
                            } else {
                                has_int_hi = 2;
                            }
                            break;
                        case JANET_SYSV64_PAIR_INTINT:
                            has_int_lo = 1;
                            has_int_hi = 2;
                            break;
                        case JANET_SYSV64_PAIR_INTSSE:
                            has_int_lo = 1;
                            break;
                        case JANET_SYSV64_PAIR_SSEINT:
                            has_int_hi = 2;
                            break;
                            break;
                    }
                }
                switch (has_int_hi + has_int_lo) {
                    case 0:
                        clazz = JANET_SYSV64_PAIR_SSESSE;
                        break;
                    case 1:
                        clazz = JANET_SYSV64_PAIR_INTSSE;
                        break;
                    case 2:
                        clazz = JANET_SYSV64_PAIR_SSEINT;
                        break;
                    case 3:
                        clazz = JANET_SYSV64_PAIR_INTINT;
                        break;
                }
            } else {
                /* Normal struct classification */
                for (uint32_t i = 0; i < st->field_count; i++) {
                    JanetFFIWordSpec next_class = sysv64_classify_ext(st->fields[i].type, shift + st->fields[i].offset);
                    if (next_class != clazz) {
                        if (clazz == JANET_SYSV64_NO_CLASS) {
                            clazz = next_class;
                        } else if (clazz == JANET_SYSV64_MEMORY || next_class == JANET_SYSV64_MEMORY) {
                            clazz = JANET_SYSV64_MEMORY;
                        } else if (clazz == JANET_SYSV64_INTEGER || next_class == JANET_SYSV64_INTEGER) {
                            clazz = JANET_SYSV64_INTEGER;
                        } else {
                            clazz = JANET_SYSV64_SSE;
                        }
                    }
                }
            }
            return clazz;
        }
        case JANET_FFI_TYPE_VOID:
            return JANET_SYSV64_NO_CLASS;
        default:
            janet_panic("nyi");
            return JANET_SYSV64_NO_CLASS;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
cmpl $0xe, %esi
ja 0x292b0
movq %rdx, %rbx
xorl %eax, %eax
movl %esi, %ecx
leaq 0x31e39(%rip), %rdx     # 0x5af38
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x1, %eax
jmp 0x29108
movq %rdi, %r14
movl (%rdi), %ecx
movl $0x8, %eax
cmpl $0x10, %ecx
ja 0x29108
cmpl $0x0, 0xc(%r14)
je 0x29108
movl 0x8(%r14), %eax
cmpl $0x8, %ecx
jbe 0x29228
testl %eax, %eax
je 0x292a6
leaq 0x20(%r14), %r15
xorl %r12d, %r12d
xorl %r13d, %r13d
movl $0x0, -0x2c(%rbp)
movq (%r15), %rdx
addq %rbx, %rdx
movq -0x10(%r15), %rdi
movq -0x8(%r15), %rsi
callq 0x290da
cmpl $0x5, %eax
ja 0x291fe
movl %eax, %eax
leaq 0x31df5(%rip), %rcx     # 0x5af74
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x8(%r15), %rcx
movq %rcx, %rax
sarq $0x20, %rax
testq %rcx, %rcx
movl $0x1, %edx
cmovsq %rdx, %rax
movl %ecx, %ecx
cmpq $0xe, %rcx
jne 0x291ca
movq -0x10(%r15), %rcx
movl (%rcx), %ecx
imulq %rcx, %rax
jmp 0x291da
movl $0x2, %r13d
movl $0x1, -0x2c(%rbp)
jmp 0x291fe
movl $0x2, %r13d
jmp 0x291fe
shlq $0x4, %rcx
leaq 0x32ccb(%rip), %rdx     # 0x5bea0
imulq (%rcx,%rdx), %rax
movq (%r15), %rcx
addq %rbx, %rcx
addq %rax, %rcx
cmpq $0x9, %rcx
movl $0x1, %eax
movl -0x2c(%rbp), %ecx
cmovbl %eax, %ecx
movl %ecx, -0x2c(%rbp)
movl $0x2, %eax
cmovael %eax, %r13d
incq %r12
movl 0x8(%r14), %eax
addq $0x18, %r15
cmpq %rax, %r12
jb 0x2915a
addl -0x2c(%rbp), %r13d
movslq %r13d, %rax
leaq 0x31c00(%rip), %rcx     # 0x5ae20
movl (%rcx,%rax,4), %eax
jmp 0x29108
testl %eax, %eax
je 0x2929c
leaq 0x20(%r14), %r15
movl $0x7, %r13d
xorl %r12d, %r12d
movq (%r15), %rdx
addq %rbx, %rdx
movq -0x10(%r15), %rdi
movq -0x8(%r15), %rsi
callq 0x290da
cmpl %r13d, %eax
jne 0x29256
movl %r13d, %eax
jmp 0x29284
movl %eax, %ecx
cmpl $0x7, %r13d
je 0x29284
cmpl $0x8, %r13d
sete %al
cmpl $0x8, %ecx
sete %dl
orb %al, %dl
movl $0x8, %eax
jne 0x29284
testl %r13d, %r13d
setne %al
testl %ecx, %ecx
setne %cl
andb %al, %cl
movzbl %cl, %eax
incq %r12
movl 0x8(%r14), %ecx
addq $0x18, %r15
movl %eax, %r13d
cmpq %rcx, %r12
jb 0x29239
jmp 0x29108
movl $0x7, %eax
jmp 0x29108
movl $0x6, %eax
jmp 0x29108
leaq 0x32ff3(%rip), %rdi     # 0x5c2aa
callq 0x191a3