// File: /workspace/github_c_makefile_star2_O3/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, -0x38(%rbp)
movl %edi, %r12d
movq $0x0, -0x40(%rbp)
testl %edi, %edi
movl %edi, -0x30(%rbp)
jle 0x272d3
movl %r12d, %ebx
leaq 0x3b4ef(%rip), %r15     # 0x6275e
xorl %r13d, %r13d
movl %r12d, %r14d
movq -0x38(%rbp), %r12
movq (%r12,%r13,8), %rdi
movq %r15, %rsi
callq 0x19331
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
testl %eax, %eax
jne 0x272b7
movq (%r12,%r13,8), %rdi
leaq 0x34ef2(%rip), %rsi     # 0x5c18b
callq 0x19331
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, %rbx
jne 0x27279
cmpl $0x0, -0x40(%rbp)
setne %al
movq %rax, -0x40(%rbp)
movl -0x30(%rbp), %r12d
jmp 0x272d6
movl %r12d, %r14d
movslq %r12d, %rax
leaq (%rax,%rax,2), %rax
leaq 0x10(,%rax,8), %rsi
leaq 0x59cc4(%rip), %rdi     # 0x80fb0
callq 0x144c2
movq %rax, %r8
movl $0x0, 0x8(%rax)
movabsq $0x100000000, %rax      # imm = 0x100000000
movq %rax, (%r8)
testl %r12d, %r12d
je 0x274a7
movq -0x38(%rbp), %rbx
jle 0x2744b
movq %r8, %r15
addq $0x20, %r15
movl $0x1, -0x2c(%rbp)
xorl %r12d, %r12d
movq %r8, -0x48(%rbp)
movslq %r12d, %r13
movq (%rbx,%r13,8), %rdi
leaq 0x3b420(%rip), %rsi     # 0x6275e
callq 0x19331
testl %eax, %eax
jne 0x2735f
movq (%rbx,%r13,8), %rdi
leaq 0x34e39(%rip), %rsi     # 0x5c18b
callq 0x19331
testl %eax, %eax
je 0x27444
incl %r12d
cmpl -0x30(%rbp), %r12d
je 0x27459
movslq %r12d, %r13
movb $0x1, %bl
movq -0x38(%rbp), %rax
movq (%rax,%r13,8), %rdi
callq 0x2752d
movq %rax, -0x10(%r15)
movq %rdx, -0x8(%r15)
movq %rdx, %rsi
sarq $0x20, %rsi
testq %rdx, %rdx
movl $0x1, %ecx
cmovsq %rcx, %rsi
movl %edx, %ecx
cmpq $0xe, %rcx
jne 0x273ac
movl (%rax), %ecx
movl 0x4(%rax), %edi
imulq %rcx, %rsi
jmp 0x273c1
shlq $0x4, %rcx
leaq 0x34ae9(%rip), %rax     # 0x5bea0
imulq (%rcx,%rax), %rsi
movq 0x8(%rcx,%rax), %rdi
testq %rdi, %rdi
je 0x27491
orb -0x40(%rbp), %bl
cmpb $0x1, %bl
jne 0x273fd
movq -0x48(%rbp), %r8
movl (%r8), %ecx
movq %rcx, %rax
xorl %edx, %edx
divq %rdi
testq %rdx, %rdx
movl -0x2c(%rbp), %eax
movl $0x0, %edx
cmovnel %edx, %eax
movl %eax, -0x2c(%rbp)
movq %rcx, (%r15)
addl %ecx, %esi
movq -0x38(%rbp), %rbx
jmp 0x2742e
movq -0x48(%rbp), %r8
movl 0x4(%r8), %eax
cmpq %rax, %rdi
movq -0x38(%rbp), %rbx
jbe 0x27412
movl %edi, 0x4(%r8)
movl (%r8), %eax
leaq (%rdi,%rax), %rcx
decq %rcx
movq %rcx, %rax
xorl %edx, %edx
divq %rdi
subq %rdx, %rcx
movl %ecx, %eax
movq %rax, (%r15)
addl %ecx, %esi
movl %esi, (%r8)
incl %r12d
addq $0x18, %r15
cmpl -0x30(%rbp), %r12d
jl 0x27330
jmp 0x27460
xorl %ebx, %ebx
jmp 0x27371
movl $0x1, %edi
xorl %esi, %esi
movl $0x1, %eax
jmp 0x27467
movq -0x48(%rbp), %r8
movl (%r8), %esi
movl 0x4(%r8), %edi
movl -0x2c(%rbp), %eax
movl %eax, 0xc(%r8)
leal (%rdi,%rsi), %ecx
decl %ecx
movl %ecx, %eax
xorl %edx, %edx
divl %edi
subl %edx, %ecx
movl %ecx, (%r8)
movl %r14d, 0x8(%r8)
movq %r8, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq -0x38(%rbp), %rax
movq (%rax,%r13,8), %rsi
leaq 0x34d09(%rip), %rdi     # 0x5c1a9
xorl %eax, %eax
callq 0x190bb
leaq 0x34ce6(%rip), %rdi     # 0x5c194
callq 0x191a3