// File: /workspace/github_c_makefile_star2_O1/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 $0x38, %rsp
movq %rsi, -0x38(%rbp)
movl %edi, %ebx
movq $0x0, -0x40(%rbp)
testl %edi, %edi
movl %edi, -0x30(%rbp)
jle 0x2775b
movl %ebx, %r12d
leaq 0x3c076(%rip), %r15     # 0x6376e
xorl %r13d, %r13d
movl %ebx, %r14d
movq -0x38(%rbp), %rbx
movq (%rbx,%r13,8), %rdi
movq %r15, %rsi
callq 0x193f7
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
testl %eax, %eax
jne 0x27740
movq (%rbx,%r13,8), %rdi
leaq 0x35a69(%rip), %rsi     # 0x5d18b
callq 0x193f7
xorl %ecx, %ecx
testl %eax, %eax
setne %cl
movq -0x40(%rbp), %rax
movl $0x1, %edx
cmovnel %edx, %eax
movq %rax, -0x40(%rbp)
negl %ecx
addl %ecx, %r14d
incq %r13
cmpq %r13, %r12
jne 0x27702
cmpl $0x0, -0x40(%rbp)
setne %al
movq %rax, -0x40(%rbp)
movl -0x30(%rbp), %ebx
jmp 0x2775e
movl %ebx, %r14d
movslq %ebx, %rax
leaq (%rax,%rax,2), %rax
leaq 0x10(,%rax,8), %rsi
leaq 0x5a83c(%rip), %rdi     # 0x81fb0
callq 0x144d2
movq %rax, %r10
movl $0x0, 0x8(%rax)
movabsq $0x100000000, %rax      # imm = 0x100000000
movq %rax, (%r10)
testl %ebx, %ebx
je 0x2796b
movq -0x38(%rbp), %r15
jle 0x2791b
movq %r10, %rax
addq $0x10, %rax
movq %rax, -0x58(%rbp)
movl $0x1, -0x2c(%rbp)
xorl %r13d, %r13d
movl $0x0, -0x44(%rbp)
movq %r10, -0x50(%rbp)
movslq %r13d, %rbx
movq (%r15,%rbx,8), %rdi
leaq 0x3bf9e(%rip), %rsi     # 0x6376e
callq 0x193f7
testl %eax, %eax
jne 0x277ed
movq (%r15,%rbx,8), %rdi
leaq 0x359a7(%rip), %rsi     # 0x5d18b
callq 0x193f7
testl %eax, %eax
je 0x27807
incl %r13d
movb $0x1, %r12b
movl -0x30(%rbp), %r9d
cmpl %r9d, %r13d
jne 0x2780a
xorl %eax, %eax
movq -0x50(%rbp), %r10
jmp 0x27909
xorl %r12d, %r12d
movslq -0x44(%rbp), %rax
leaq (%rax,%rax,2), %r15
movslq %r13d, %rbx
movq -0x38(%rbp), %rax
movq (%rax,%rbx,8), %rdi
callq 0x279f1
movq -0x58(%rbp), %rcx
movq %rax, (%rcx,%r15,8)
movq %rdx, 0x8(%rcx,%r15,8)
movq %rdx, %rsi
sarq $0x20, %rsi
testq %rdx, %rdx
movl $0x1, %ecx
cmovsq %rcx, %rsi
movl %edx, %ecx
cmpq $0xe, %rcx
jne 0x27852
movl (%rax), %edx
imulq %rdx, %rsi
jmp 0x27865
movq %rcx, %rdx
shlq $0x4, %rdx
leaq 0x35640(%rip), %rdi     # 0x5cea0
imulq (%rdx,%rdi), %rsi
cmpl $0xe, %ecx
jne 0x27870
movl 0x4(%rax), %r8d
jmp 0x27880
shlq $0x4, %rcx
leaq 0x35625(%rip), %rax     # 0x5cea0
movq 0x8(%rcx,%rax), %r8
testq %r8, %r8
je 0x27955
movq -0x58(%rbp), %rax
leaq (%rax,%r15,8), %rdi
orb -0x40(%rbp), %r12b
cmpb $0x1, %r12b
jne 0x278cb
movq -0x50(%rbp), %r10
movl (%r10), %ecx
movq %rcx, %rax
xorl %edx, %edx
divq %r8
testq %rdx, %rdx
movl -0x2c(%rbp), %eax
movl $0x0, %edx
cmovnel %edx, %eax
movl %eax, -0x2c(%rbp)
movq %rcx, 0x10(%rdi)
addl %ecx, %esi
movq -0x38(%rbp), %r15
movl -0x30(%rbp), %r9d
jmp 0x27901
movq -0x50(%rbp), %r10
movl 0x4(%r10), %eax
cmpq %rax, %r8
movq -0x38(%rbp), %r15
movl -0x30(%rbp), %r9d
jbe 0x278e4
movl %r8d, 0x4(%r10)
movl (%r10), %eax
leaq (%r8,%rax), %rcx
decq %rcx
movq %rcx, %rax
xorl %edx, %edx
divq %r8
subq %rdx, %rcx
movl %ecx, %eax
movq %rax, 0x10(%rdi)
addl %ecx, %esi
movl %esi, (%r10)
incl -0x44(%rbp)
movb $0x1, %al
testb %al, %al
je 0x27922
incl %r13d
cmpl %r9d, %r13d
jl 0x277c2
jmp 0x27922
movl $0x1, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, 0xc(%r10)
movl 0x4(%r10), %esi
movl (%r10), %ecx
addl %esi, %ecx
decl %ecx
movl %ecx, %eax
xorl %edx, %edx
divl %esi
subl %edx, %ecx
movl %ecx, (%r10)
movl %r14d, 0x8(%r10)
movq %r10, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq -0x38(%rbp), %rax
movq (%rax,%rbx,8), %rsi
leaq 0x35845(%rip), %rdi     # 0x5d1a9
xorl %eax, %eax
callq 0x1917b
leaq 0x35822(%rip), %rdi     # 0x5d194
callq 0x19263