// File: /workspace/github_c_makefile_star2_O1/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 0x2978a
movq %rdx, %rbx
xorl %eax, %eax
movl %esi, %ecx
leaq 0x32964(%rip), %rdx     # 0x5bf38
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 0x295dd
movq %rdi, %r14
movl (%rdi), %ecx
movl $0x8, %eax
cmpl $0x10, %ecx
ja 0x295dd
cmpl $0x0, 0xc(%r14)
je 0x295dd
movl 0x8(%r14), %eax
cmpl $0x8, %ecx
jbe 0x2970c
xorl %ecx, %ecx
testl %eax, %eax
je 0x296fd
movq $0x0, -0x30(%rbp)
leaq 0x20(%r14), %r12
xorl %r13d, %r13d
xorl %r15d, %r15d
movq (%r12), %rdx
addq %rbx, %rdx
movq -0x10(%r12), %rdi
movq -0x8(%r12), %rsi
callq 0x295af
cmpl $0x5, %eax
ja 0x296df
movl %eax, %eax
leaq 0x3291a(%rip), %rcx     # 0x5bf74
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x8(%r12), %rcx
movq %rcx, %rax
sarq $0x20, %rax
testq %rcx, %rcx
movl $0x1, %edx
cmovsq %rdx, %rax
movl %ecx, %ecx
cmpq $0xe, %rcx
jne 0x296a8
movq -0x10(%r12), %rcx
movl (%rcx), %ecx
imulq %rcx, %rax
jmp 0x296b8
movl $0x2, %eax
movq %rax, -0x30(%rbp)
movl $0x1, %r15d
jmp 0x296df
movl $0x2, %eax
jmp 0x296db
shlq $0x4, %rcx
leaq 0x337ed(%rip), %rdx     # 0x5cea0
imulq (%rcx,%rdx), %rax
movq (%r12), %rcx
addq %rbx, %rcx
addq %rax, %rcx
cmpq $0x9, %rcx
movl $0x1, %eax
cmovbl %eax, %r15d
movq -0x30(%rbp), %rax
movl $0x2, %ecx
cmovael %ecx, %eax
movq %rax, -0x30(%rbp)
incq %r13
movl 0x8(%r14), %eax
addq $0x18, %r12
cmpq %rax, %r13
jb 0x29632
movq -0x30(%rbp), %rcx
addl %r15d, %ecx
movslq %ecx, %rcx
leaq 0x3271c(%rip), %rax     # 0x5be20
movl (%rax,%rcx,4), %eax
jmp 0x295dd
testl %eax, %eax
je 0x29780
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 0x295af
cmpl %r13d, %eax
jne 0x2973a
movl %r13d, %eax
jmp 0x29768
movl %eax, %ecx
cmpl $0x7, %r13d
je 0x29768
cmpl $0x8, %r13d
sete %al
cmpl $0x8, %ecx
sete %dl
orb %al, %dl
movl $0x8, %eax
jne 0x29768
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 0x2971d
jmp 0x295dd
movl $0x7, %eax
jmp 0x295dd
leaq 0x33b19(%rip), %rdi     # 0x5d2aa
callq 0x19263
nop