// File: /workspace/github_c_makefile_star2_O2/janet-lang[P]janet/src/core/ffi.c
// Function: build_struct_type
static JanetFFIStruct *build_struct_type(int32_t argc, const Janet *argv) {
    /* Use :pack to indicate a single packed struct member and :pack-all
     * to pack the remaining members */
    int32_t member_count = argc;
    int all_packed = 0;
    for (int32_t i = 0; i < argc; i++) {
        if (janet_keyeq(argv[i], "pack")) {
            member_count--;
        } else if (janet_keyeq(argv[i], "pack-all")) {
            member_count--;
            all_packed = 1;
        }
    }

    JanetFFIStruct *st = janet_abstract(&janet_struct_type,
                                        sizeof(JanetFFIStruct) + argc * sizeof(JanetFFIStructMember));
    st->field_count = 0;
    st->size = 0;
    st->align = 1;
    if (argc == 0) {
        janet_panic("invalid empty struct");
    }
    uint32_t is_aligned = 1;
    int32_t i = 0;
    for (int32_t j = 0; j < argc; j++) {
        int pack_one = 0;
        if (janet_keyeq(argv[j], "pack") || janet_keyeq(argv[j], "pack-all")) {
            pack_one = 1;
            j++;
            if (j == argc) break;
        }
        st->fields[i].type = decode_ffi_type(argv[j]);
        size_t el_size = type_size(st->fields[i].type);
        size_t el_align = type_align(st->fields[i].type);
        if (el_align <= 0) janet_panicf("bad field type %V", argv[j]);
        if (all_packed || pack_one) {
            if (st->size % el_align != 0) is_aligned = 0;
            st->fields[i].offset = st->size;
            st->size += (uint32_t) el_size;
        } else {
            if (el_align > st->align) st->align = (uint32_t) el_align;
            st->fields[i].offset = (uint32_t)(((st->size + el_align - 1) / el_align) * el_align);
            st->size = (uint32_t)(el_size + st->fields[i].offset);
        }
        i++;
    }
    st->is_aligned = is_aligned;
    st->size += (st->align - 1);
    st->size /= st->align;
    st->size *= st->align;
    st->field_count = member_count;
    return st;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, -0x40(%rbp)
xorl %ebx, %ebx
testl %edi, %edi
movl $0x0, %r14d
cmovgl %edi, %r14d
leaq 0x396ce(%rip), %r15     # 0x5e76e
pushq $-0x1
popq %r13
pushq $0x1
popq %rax
movl %eax, -0x2c(%rbp)
movl $0x0, -0x34(%rbp)
movl %edi, -0x30(%rbp)
movl %edi, -0x38(%rbp)
movq -0x40(%rbp), %r12
cmpq %rbx, %r14
je 0x25102
movq (%r12,%rbx,8), %rdi
movq %r15, %rsi
callq 0x17922
testl %eax, %eax
je 0x250d5
movl %r13d, %ecx
jmp 0x250fa
movq (%r12,%rbx,8), %rdi
leaq 0x330ab(%rip), %rsi     # 0x5818b
callq 0x17922
xorl %ecx, %ecx
testl %eax, %eax
setne %cl
pushq $0x1
popq %rax
movl -0x34(%rbp), %edx
cmovnel %eax, %edx
movl %edx, -0x34(%rbp)
negl %ecx
addl %ecx, -0x38(%rbp)
incq %rbx
jmp 0x250bb
movl -0x30(%rbp), %ebx
movslq %ebx, %rax
imulq $0x18, %rax, %rsi
addq $0x10, %rsi
leaq 0x56e99(%rip), %rdi     # 0x7bfb0
callq 0x12d92
movq %rax, %r15
andl $0x0, 0x8(%rax)
movabsq $0x100000000, %rax      # imm = 0x100000000
movq %rax, (%r15)
testl %ebx, %ebx
je 0x252b8
movq %r15, %r13
addq $0x20, %r13
xorl %ecx, %ecx
xorl %r14d, %r14d
movq -0x40(%rbp), %r12
movq %r15, -0x48(%rbp)
cmpl -0x30(%rbp), %r14d
jge 0x25273
movslq %r14d, %rbx
movq (%r12,%rbx,8), %rdi
leaq 0x3960a(%rip), %rsi     # 0x5e76e
callq 0x17922
testl %eax, %eax
movq %r13, -0x50(%rbp)
jne 0x25189
movq (%r12,%rbx,8), %rdi
leaq 0x3300f(%rip), %rsi     # 0x5818b
callq 0x17922
testl %eax, %eax
je 0x25268
incl %r14d
cmpl -0x30(%rbp), %r14d
je 0x25270
movslq %r14d, %rbx
movb $0x1, %r15b
movq (%r12,%rbx,8), %rdi
callq 0x25352
movq %rax, %r13
movq %rdx, %r12
movq -0x50(%rbp), %rax
movq %r13, -0x10(%rax)
movq %rdx, -0x8(%rax)
movq %r13, %rdi
movq %rdx, %rsi
callq 0x25314
movq %rax, %rcx
movl %r12d, %eax
cmpq $0xe, %rax
jne 0x251d4
movl 0x4(%r13), %edi
jmp 0x251e4
shlq $0x4, %rax
leaq 0x32cc1(%rip), %rdx     # 0x57ea0
movq 0x8(%rax,%rdx), %rdi
testq %rdi, %rdi
movq -0x40(%rbp), %r12
movq -0x50(%rbp), %r13
je 0x252a6
cmpl $0x0, -0x34(%rbp)
sete %al
xorb $0x1, %r15b
testb %r15b, %al
jne 0x2522b
movq -0x48(%rbp), %r15
movl (%r15), %esi
movq %rsi, %rax
xorl %edx, %edx
divq %rdi
testq %rdx, %rdx
movl -0x2c(%rbp), %eax
movl $0x0, %edx
cmovnel %edx, %eax
movl %eax, -0x2c(%rbp)
movq %rsi, (%r13)
jmp 0x25257
movq -0x48(%rbp), %r15
movl 0x4(%r15), %eax
cmpq %rax, %rdi
jbe 0x2523c
movl %edi, 0x4(%r15)
movl (%r15), %eax
leaq (%rdi,%rax), %rsi
decq %rsi
movq %rsi, %rax
xorl %edx, %edx
divq %rdi
subq %rdx, %rsi
movl %esi, %eax
movq %rax, (%r13)
addl %esi, %ecx
movl %ecx, (%r15)
incl %r14d
addq $0x18, %r13
jmp 0x2514c
xorl %r15d, %r15d
jmp 0x2519c
movl (%r15), %ecx
movl -0x2c(%rbp), %eax
movl %eax, 0xc(%r15)
movl 0x4(%r15), %esi
addl %esi, %ecx
decl %ecx
movl %ecx, %eax
xorl %edx, %edx
divl %esi
subl %edx, %ecx
movl %ecx, (%r15)
movl -0x38(%rbp), %eax
movl %eax, 0x8(%r15)
movq %r15, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%r12,%rbx,8), %rsi
leaq 0x32ef8(%rip), %rdi     # 0x581a9
xorl %eax, %eax
callq 0x176c9
leaq 0x32ed5(%rip), %rdi     # 0x58194
callq 0x177b1