// File: /workspace/github_c_makefile_star2_O0/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
subq $0x70, %rsp
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
movl -0x4(%rbp), %eax
movl %eax, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x4(%rbp), %eax
jge 0x32d1f
movq -0x10(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x5cb2c(%rip), %rsi     # 0x8f7fa
callq 0x1b010
cmpl $0x0, %eax
je 0x32ce3
movl -0x14(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x32d12
movq -0x10(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x564c5(%rip), %rsi     # 0x891bb
callq 0x1b010
cmpl $0x0, %eax
je 0x32d10
movl -0x14(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x14(%rbp)
movl $0x1, -0x18(%rbp)
jmp 0x32d12
jmp 0x32d14
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x32cb3
movslq -0x4(%rbp), %rax
imulq $0x18, %rax, %rsi
addq $0x10, %rsi
leaq 0x79a9e(%rip), %rdi     # 0xac7d0
callq 0x12de0
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movl $0x0, 0x8(%rax)
movq -0x28(%rbp), %rax
movl $0x0, (%rax)
movq -0x28(%rbp), %rax
movl $0x1, 0x4(%rax)
cmpl $0x0, -0x4(%rbp)
jne 0x32d6d
leaq 0x5645c(%rip), %rdi     # 0x891c4
callq 0x1ad60
movl $0x1, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x4(%rbp), %eax
jge 0x32f7e
movl $0x0, -0x38(%rbp)
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x5ca52(%rip), %rsi     # 0x8f7fa
callq 0x1b010
cmpl $0x0, %eax
jne 0x32dcf
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x563f6(%rip), %rsi     # 0x891bb
callq 0x1b010
cmpl $0x0, %eax
je 0x32dee
movl $0x1, -0x38(%rbp)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x4(%rbp), %eax
jne 0x32dec
jmp 0x32f7e
jmp 0x32dee
movq -0x28(%rbp), %rax
addq $0x10, %rax
movslq -0x30(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x330d0
movq %rax, %rcx
movq -0x60(%rbp), %rax
movq %rcx, -0x48(%rbp)
movq %rdx, -0x40(%rbp)
movq -0x48(%rbp), %rcx
movq %rcx, (%rax)
movq -0x40(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x28(%rbp), %rax
addq $0x10, %rax
movslq -0x30(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rdi
movq 0x8(%rax), %rsi
callq 0x33060
movq %rax, -0x50(%rbp)
movq -0x28(%rbp), %rax
addq $0x10, %rax
movslq -0x30(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rdi
movq 0x8(%rax), %rsi
callq 0x33310
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
ja 0x32e9b
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
leaq 0x56345(%rip), %rdi     # 0x891d9
movb $0x0, %al
callq 0x1ac40
cmpl $0x0, -0x18(%rbp)
jne 0x32ea7
cmpl $0x0, -0x38(%rbp)
je 0x32ef1
movq -0x28(%rbp), %rax
movl (%rax), %eax
xorl %ecx, %ecx
movl %ecx, %edx
divq -0x58(%rbp)
cmpq $0x0, %rdx
je 0x32ec2
movl $0x0, -0x2c(%rbp)
movq -0x28(%rbp), %rax
movl (%rax), %eax
movl %eax, %ecx
movq -0x28(%rbp), %rax
addq $0x10, %rax
movslq -0x30(%rbp), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x10(%rax)
movq -0x50(%rbp), %rax
movl %eax, %ecx
movq -0x28(%rbp), %rax
addl (%rax), %ecx
movl %ecx, (%rax)
jmp 0x32f67
movq -0x58(%rbp), %rax
movq -0x28(%rbp), %rcx
movl 0x4(%rcx), %ecx
cmpq %rcx, %rax
jbe 0x32f0e
movq -0x58(%rbp), %rax
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x28(%rbp), %rax
movl (%rax), %eax
addq -0x58(%rbp), %rax
subq $0x1, %rax
xorl %ecx, %ecx
movl %ecx, %edx
divq -0x58(%rbp)
imulq -0x58(%rbp), %rax
movl %eax, %eax
movl %eax, %ecx
movq -0x28(%rbp), %rax
addq $0x10, %rax
movslq -0x30(%rbp), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x10(%rax)
movq -0x50(%rbp), %rax
movq -0x28(%rbp), %rcx
addq $0x10, %rcx
movslq -0x30(%rbp), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
addq 0x10(%rcx), %rax
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x32d82
movl -0x2c(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x28(%rbp), %rax
movl 0x4(%rax), %ecx
subl $0x1, %ecx
movq -0x28(%rbp), %rax
addl (%rax), %ecx
movl %ecx, (%rax)
movq -0x28(%rbp), %rax
movl 0x4(%rax), %ecx
movq -0x28(%rbp), %rax
movq %rax, -0x68(%rbp)
movl (%rax), %eax
xorl %edx, %edx
divl %ecx
movl %eax, %ecx
movq -0x68(%rbp), %rax
movl %ecx, (%rax)
movq -0x28(%rbp), %rax
movl 0x4(%rax), %ecx
movq -0x28(%rbp), %rax
imull (%rax), %ecx
movl %ecx, (%rax)
movl -0x14(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x28(%rbp), %rax
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax,%rax)