// File: /workspace/github_c_makefile_star2_O2/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 0x26ec5
xorl %r15d, %r15d
movl %esi, %eax
leaq 0x301ee(%rip), %rcx     # 0x56f38
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
pushq $0x1
jmp 0x26e2d
movq %rdi, %r14
movl (%rdi), %eax
pushq $0x8
popq %r15
cmpl $0x10, %eax
ja 0x26e2f
cmpl $0x0, 0xc(%r14)
je 0x26e2f
movq %rdx, %rbx
cmpl $0x8, %eax
jbe 0x26e41
leaq 0x20(%r14), %r15
xorl %r12d, %r12d
leaq 0x301e3(%rip), %r13     # 0x56f74
movl $0x0, -0x30(%rbp)
movl $0x0, -0x2c(%rbp)
movl 0x8(%r14), %eax
cmpq %rax, %r12
jae 0x26ead
movq (%r15), %rdx
addq %rbx, %rdx
movq -0x10(%r15), %rdi
movq -0x8(%r15), %rsi
callq 0x26d27
cmpl $0x5, %eax
ja 0x26e1f
movl %eax, %eax
movslq (%r13,%rax,4), %rax
addq %r13, %rax
jmpq *%rax
movq (%r15), %r13
addq %rbx, %r13
movq -0x10(%r15), %rdi
movq -0x8(%r15), %rsi
callq 0x25314
addq %r13, %rax
leaq 0x30187(%rip), %r13     # 0x56f74
cmpq $0x9, %rax
pushq $0x1
popq %rax
movl -0x30(%rbp), %ecx
cmovbl %eax, %ecx
movl %ecx, -0x30(%rbp)
pushq $0x2
popq %rax
movl -0x2c(%rbp), %ecx
cmovael %eax, %ecx
movl %ecx, -0x2c(%rbp)
jmp 0x26e1f
pushq $0x1
popq %rax
movl %eax, -0x30(%rbp)
pushq $0x2
popq %rax
movl %eax, -0x2c(%rbp)
jmp 0x26e1f
pushq $0x1
popq %rax
movl %eax, -0x30(%rbp)
incq %r12
addq $0x18, %r15
jmp 0x26d9f
pushq $0x7
popq %r15
movl %r15d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x20(%r14), %r12
pushq $0x7
popq %r15
xorl %r13d, %r13d
movl 0x8(%r14), %eax
cmpq %rax, %r13
jae 0x26e2f
movq (%r12), %rdx
addq %rbx, %rdx
movq -0x10(%r12), %rdi
movq -0x8(%r12), %rsi
callq 0x26d27
cmpl %r15d, %eax
jne 0x26e75
movl %r15d, %ecx
jmp 0x26ea1
movl %eax, %ecx
cmpl $0x7, %r15d
je 0x26ea1
cmpl $0x8, %r15d
sete %cl
cmpl $0x8, %eax
sete %dl
orb %cl, %dl
pushq $0x8
popq %rcx
jne 0x26ea1
testl %r15d, %r15d
setne %cl
testl %eax, %eax
setne %al
andb %cl, %al
movzbl %al, %ecx
incq %r13
addq $0x18, %r12
movl %ecx, %r15d
jmp 0x26e4c
movl -0x2c(%rbp), %eax
addl -0x30(%rbp), %eax
cltq
leaq 0x2ff64(%rip), %rcx     # 0x56e20
movl (%rcx,%rax,4), %r15d
jmp 0x26e2f
leaq 0x313de(%rip), %rdi     # 0x582aa
callq 0x177b1
nopl (%rax)